/* HUD V3 is the single gameplay HUD. Board geometry remains owned by the shared gameplay layer. */
.game-shell.tbt-game-v3 {
  --tbt-hud-v3-height: 58px;
  box-sizing: border-box;
  width: 100vw;
  height: 100dvh;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-rows: var(--tbt-hud-v3-height) minmax(0, 1fr);
  gap: 0;
  overflow: hidden;
}

.tbt-game-hud-v3,
.tbt-game-hud-v3 * {
  box-sizing: border-box;
}

.tbt-game-hud-v3 {
  position: relative;
  z-index: 80;
  width: 100%;
  height: var(--tbt-hud-v3-height);
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: clamp(8px, 1vw, 16px);
  padding: 4px clamp(10px, 1.35vw, 22px);
  border-bottom: 1px solid color-mix(in srgb, var(--ui-border-accent) 46%, var(--ui-border-default));
  background:
    radial-gradient(circle at 50% 0%, rgba(219, 135, 57, .09), transparent 34%),
    linear-gradient(90deg, rgba(4, 11, 17, .99), rgba(11, 22, 30, .97) 50%, rgba(4, 11, 17, .99));
  box-shadow: var(--ui-shadow-floating), inset 0 1px 0 rgba(255, 228, 190, .045);
  color: var(--ui-text-primary);
  overflow: visible;
}

.tbt-hud-v3-players {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(118px, 11vw, 154px) minmax(0, 1fr);
  align-items: stretch;
  gap: clamp(6px, 1vw, 18px);
}

.tbt-hud-v3-player {
  min-width: 0;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 2px 7px;
  border: 1px solid var(--ui-border-subtle);
  border-radius: var(--ui-radius-control);
  background: linear-gradient(135deg, rgba(16, 31, 42, .78), rgba(5, 13, 20, .74));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .025);
  overflow: hidden;
}

.tbt-hud-v3-player[data-tbt-hud-player="black"] {
  grid-template-columns: minmax(0, 1fr) 42px;
  text-align: right;
}

.tbt-hud-v3-player[data-tbt-hud-player="black"] .tbt-hud-v3-avatar { grid-column: 2; }
.tbt-hud-v3-player[data-tbt-hud-player="black"] .tbt-hud-v3-player-copy { grid-column: 1; grid-row: 1; }

.tbt-hud-v3-player.is-active {
  border-color: color-mix(in srgb, var(--ui-success) 44%, var(--ui-border-default));
  background: linear-gradient(90deg, color-mix(in srgb, var(--ui-success) 11%, rgba(7, 21, 28, .92)), rgba(7, 16, 23, .86));
  box-shadow: inset 3px 0 0 color-mix(in srgb, var(--ui-success) 62%, transparent), inset 0 1px 0 rgba(255, 255, 255, .035);
}

.tbt-hud-v3-player[data-tbt-hud-player="black"].is-active {
  background: linear-gradient(270deg, color-mix(in srgb, var(--ui-success) 11%, rgba(7, 21, 28, .92)), rgba(7, 16, 23, .86));
  box-shadow: inset -3px 0 0 color-mix(in srgb, var(--ui-success) 62%, transparent), inset 0 1px 0 rgba(255, 255, 255, .035);
}

.tbt-hud-v3-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
}

.tbt-hud-v3-avatar .preset-avatar {
  width: 36px;
  height: 36px;
  flex-basis: 36px;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .42));
}

.tbt-hud-v3-turn {
  position: absolute;
  right: -1px;
  bottom: 1px;
  width: 8px;
  height: 8px;
  border: 1px solid rgba(5, 11, 17, .9);
  border-radius: 50%;
  background: var(--ui-text-muted);
}

.tbt-hud-v3-player.is-active .tbt-hud-v3-turn {
  background: var(--ui-success);
  box-shadow: 0 0 9px color-mix(in srgb, var(--ui-success) 65%, transparent);
}

.tbt-hud-v3-player-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.tbt-hud-v3-player-copy > strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ui-text-primary);
  font-size: clamp(.76rem, .94vw, .9rem);
  font-weight: var(--ui-weight-title);
  letter-spacing: -.01em;
  line-height: 1.06;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tbt-hud-v3-player-copy > small {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  overflow: hidden;
  color: var(--ui-text-muted);
  font-size: clamp(.55rem, .68vw, .65rem);
  line-height: 1.06;
  white-space: nowrap;
}

.tbt-hud-v3-player[data-tbt-hud-player="black"] .tbt-hud-v3-player-copy > small { justify-content: flex-end; }
.tbt-hud-v3-player-copy b { color: color-mix(in srgb, var(--ui-success) 72%, var(--ui-accent-warm)); font-weight: 800; font-variant-numeric: tabular-nums; }

.tbt-hud-v3-score {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  place-items: center;
  align-content: center;
  padding: 2px 8px;
  border: 1px solid color-mix(in srgb, var(--ui-border-accent) 40%, var(--ui-border-default));
  border-radius: var(--ui-radius-control);
  background:
    radial-gradient(circle at 50% -30%, rgba(224, 139, 60, .12), transparent 58%),
    rgba(3, 9, 14, .78);
  box-shadow: inset 0 1px 0 rgba(255, 226, 184, .04), 0 4px 12px rgba(0, 0, 0, .18);
  overflow: hidden;
}

.tbt-hud-v3-score > strong {
  color: var(--ui-text-primary);
  font-size: clamp(1.04rem, 1.4vw, 1.36rem);
  font-weight: var(--ui-weight-title);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 1px 8px rgba(231, 151, 77, .18);
  white-space: nowrap;
}

.tbt-hud-v3-meta {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--ui-text-muted);
  font-size: .57rem;
  white-space: nowrap;
}

.tbt-hud-v3-score .turn-clock { gap: 2px; color: var(--ui-text-secondary); }
.tbt-hud-v3-score .turn-clock small { font-size: .52rem; }
.tbt-hud-v3-score .turn-clock b,
.tbt-hud-v3-score .turn-clock i { font-size: .56rem; }

.tbt-hud-v3-turn-actions {
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.tbt-hud-v3-turn-actions:empty { display: none; }
.tbt-hud-v3-turn-actions .btn {
  min-width: 0;
  min-height: 20px;
  max-width: 100%;
  padding: 2px 8px;
  border-radius: 6px;
  overflow: hidden;
  font-size: .55rem;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tbt-hud-v3-turn-actions > .muted { font-size: .52rem; white-space: nowrap; }

.tbt-hud-v3-actions {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(74px, 82px) repeat(2, minmax(50px, 56px));
  align-items: stretch;
  gap: 6px;
}

.tbt-hud-v3-auto-roll,
.tbt-game-hud-v3 .match-menu > summary,
.tbt-game-hud-v3 .match-comms > summary {
  min-width: 0;
  min-height: var(--ui-control-h-lg);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  margin: 0;
  padding: 3px 7px;
  position: relative;
  border: 1px solid var(--ui-border-default);
  border-radius: var(--ui-radius-control);
  background: linear-gradient(180deg, rgba(16, 29, 39, .9), rgba(6, 14, 21, .9));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .035), 0 3px 8px rgba(0, 0, 0, .18);
  color: var(--ui-text-secondary);
  font-size: .56rem;
  font-weight: var(--ui-weight-label);
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease, box-shadow 120ms ease, color 120ms ease, transform 120ms ease;
}

.tbt-hud-v3-auto-roll { overflow: hidden; }
.tbt-hud-v3-auto-roll > span { min-width: 0; max-width: 100%; white-space: nowrap; }
.tbt-hud-v3-auto-roll input { width: 16px; height: 16px; flex: none; margin: 0; accent-color: var(--ui-accent-warm); }
.tbt-hud-v3-auto-roll:has(input:checked) {
  border-color: var(--ui-border-accent);
  background: linear-gradient(180deg, color-mix(in srgb, var(--ui-accent-warm) 13%, rgba(16, 29, 39, .94)), rgba(8, 15, 21, .94));
  box-shadow: inset 0 1px 0 rgba(255, 230, 190, .06), var(--ui-glow-warm);
  color: var(--ui-text-primary);
}
.tbt-hud-v3-auto-roll:has(input:checked) input { filter: drop-shadow(0 0 4px color-mix(in srgb, var(--ui-accent-warm) 66%, transparent)); }
.tbt-hud-v3-auto-roll:hover:not(:has(input:disabled)),
.tbt-game-hud-v3 .match-menu > summary:hover:not([aria-disabled="true"]),
.tbt-game-hud-v3 .match-comms > summary:hover:not([aria-disabled="true"]) {
  border-color: var(--ui-border-strong);
  background: var(--ui-surface-interactive);
  color: var(--ui-text-primary);
  transform: translateY(-1px);
}
.tbt-hud-v3-auto-roll:active,
.tbt-game-hud-v3 .match-menu > summary:active,
.tbt-game-hud-v3 .match-comms > summary:active { transform: translateY(0); }
.tbt-hud-v3-auto-roll:has(input:disabled),
.tbt-game-hud-v3 .match-menu > summary[aria-disabled="true"],
.tbt-game-hud-v3 .match-comms > summary[aria-disabled="true"] { opacity: .48; cursor: not-allowed; filter: saturate(.6); }
.tbt-game-hud-v3 .match-menu,
.tbt-game-hud-v3 .match-comms { position: relative; inset: auto; z-index: 90; min-width: 0; }
.tbt-game-hud-v3 .match-menu > summary { list-style: none; }
.tbt-game-hud-v3 .match-menu > summary::-webkit-details-marker,
.tbt-game-hud-v3 .match-comms > summary::-webkit-details-marker { display: none; }
.tbt-game-hud-v3 .match-menu .menu-glyph,
.tbt-game-hud-v3 .match-comms > summary .ui-icon { width: var(--ui-icon-md); height: var(--ui-icon-md); font-size: 1.05rem; transform: none; }
.tbt-game-hud-v3 .match-comms > summary > b { position: absolute; top: -3px; right: -3px; }

.tbt-game-hud-v3 .match-menu-popover,
.tbt-game-hud-v3 .match-comms-menu {
  position: absolute;
  z-index: 110;
  top: calc(100% + 5px);
  right: 0;
  bottom: auto;
  left: auto;
  width: min(250px, calc(100vw - 16px));
  max-height: calc(100dvh - var(--tbt-hud-v3-height) - 14px);
  display: grid;
  gap: 5px;
  padding: 7px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 11px;
  background: var(--ui-surface-overlay);
  box-shadow: var(--ui-shadow-overlay);
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: none;
}

.tbt-game-hud-v3 .match-menu-popover {
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0;
  border-color: color-mix(in srgb, var(--ui-border-accent) 52%, var(--ui-border-strong));
  background:
    radial-gradient(circle at 100% 0%, rgba(222, 136, 58, .1), transparent 42%),
    var(--ui-surface-overlay);
  box-shadow: var(--ui-shadow-overlay), inset 0 0 0 1px rgba(255, 231, 194, .025);
  overflow: hidden;
}

.tbt-game-hud-v3 .match-menu-heading,
.tbt-game-hud-v3 .match-comms-heading {
  border-color: var(--ui-border-default);
  color: var(--ui-text-primary);
}

.tbt-game-hud-v3 .match-menu-heading {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ui-space-3);
  padding: 2px 2px var(--ui-space-3);
  border-bottom: 1px solid var(--ui-border-default);
}

.tbt-game-hud-v3 .match-menu-heading > strong {
  font-size: .82rem;
  font-weight: var(--ui-weight-title);
  letter-spacing: .01em;
}

.tbt-game-hud-v3 .match-menu-heading .match-menu-close {
  width: var(--ui-control-h-xs);
  min-width: var(--ui-control-h-xs);
  height: var(--ui-control-h-xs);
  min-height: var(--ui-control-h-xs);
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--ui-border-default);
  border-radius: var(--ui-radius-control);
  background: var(--ui-surface-interactive);
  color: var(--ui-text-secondary);
  font-size: 1rem;
  line-height: 1;
}

.tbt-game-hud-v3 .match-menu-body {
  min-width: 0;
  min-height: 0;
  display: grid;
  align-content: start;
  gap: var(--ui-space-3);
  padding: var(--ui-space-3) 2px 2px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--ui-border-strong) transparent;
  touch-action: pan-y;
}

.tbt-game-hud-v3 .match-menu-section,
.tbt-game-hud-v3 .match-menu-section-controls {
  min-width: 0;
  display: grid;
  gap: var(--ui-space-2);
}

.tbt-game-hud-v3 .match-menu-section + .match-menu-section {
  padding-top: var(--ui-space-3);
  border-top: 1px solid var(--ui-border-subtle);
}

.tbt-game-hud-v3 .match-menu-section-label {
  color: var(--ui-accent-warm);
  font-size: .52rem;
  font-weight: var(--ui-weight-title);
  letter-spacing: var(--ui-tracking-eyebrow);
  line-height: 1;
  text-transform: uppercase;
}

.tbt-game-hud-v3 .match-menu-popover label {
  color: var(--ui-text-secondary);
}

.tbt-game-hud-v3 .match-comms-heading small {
  color: var(--ui-text-muted);
}

.tbt-game-hud-v3 .match-menu-popover button,
.tbt-game-hud-v3 .match-message-list button,
.tbt-game-hud-v3 .match-reaction-list button {
  border-color: var(--ui-border-default);
  background: var(--ui-surface-interactive);
  color: var(--ui-text-secondary);
}

.tbt-game-hud-v3 .match-menu-section-controls > button,
.tbt-game-hud-v3 .match-menu-toggle {
  width: 100%;
  min-height: var(--ui-control-h-sm);
  margin: 0;
  padding: 6px 9px;
  border: 1px solid var(--ui-border-default);
  border-radius: var(--ui-radius-control);
  background: var(--ui-surface-interactive);
  color: var(--ui-text-secondary);
  font-size: .67rem;
  font-weight: var(--ui-weight-label);
  line-height: 1.15;
}

.tbt-game-hud-v3 .match-menu-section-controls > button {
  text-align: left;
  transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.tbt-game-hud-v3 .match-menu-section-controls > button:hover:not(:disabled),
.tbt-game-hud-v3 .match-menu-heading .match-menu-close:hover {
  border-color: var(--ui-border-strong);
  background: color-mix(in srgb, var(--ui-accent-warm) 8%, var(--ui-surface-interactive));
  color: var(--ui-text-primary);
}

.tbt-game-hud-v3 .match-menu-section-controls > button:active:not(:disabled) { transform: translateY(1px); }
.tbt-game-hud-v3 .match-menu-section-controls > button:disabled { opacity: .46; cursor: not-allowed; }

.tbt-game-hud-v3 .match-menu-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ui-space-3);
  cursor: pointer;
  white-space: normal;
}

.tbt-game-hud-v3 .match-menu-toggle > span { min-width: 0; }
.tbt-game-hud-v3 .match-menu-toggle b { color: var(--ui-text-primary); font-weight: var(--ui-weight-title); }
.tbt-game-hud-v3 .match-menu-toggle input {
  width: 16px;
  height: 16px;
  flex: none;
  margin: 0;
  accent-color: var(--ui-accent-warm);
}

.tbt-game-hud-v3 .match-menu-popover .match-menu-danger {
  margin: 0;
  border-color: color-mix(in srgb, var(--ui-danger) 44%, transparent);
  background: color-mix(in srgb, var(--ui-danger) 9%, var(--ui-surface-interactive));
  color: var(--ui-danger);
}

.tbt-hud-v3-auto-roll:focus-within,
.tbt-game-hud-v3 .match-menu > summary:focus-visible,
.tbt-game-hud-v3 .match-comms > summary:focus-visible,
.tbt-game-hud-v3 .match-menu-popover button:focus-visible,
.tbt-game-hud-v3 .match-comms-menu button:focus-visible {
  outline: 2px solid var(--ui-accent-cool);
  outline-offset: 2px;
}

.tbt-game-hud-v3 .match-menu-backdrop {
  position: fixed;
  z-index: 100;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  display: none;
  background: rgba(2, 6, 10, .56);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.tbt-game-v3-notices {
  position: fixed;
  z-index: 75;
  top: calc(var(--tbt-hud-v3-height) + 6px);
  left: 50%;
  width: min(440px, calc(100vw - 24px));
  display: grid;
  place-items: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.tbt-game-v3-notices .game-notice-slot,
.tbt-game-v3-notices .match-signal,
.tbt-game-v3-notices .profile-notice,
.tbt-game-v3-notices .connection-state {
  position: static;
  inset: auto;
  max-width: 100%;
  margin: 0;
  transform: none;
}

.tbt-opening-modal {
  position: fixed;
  z-index: 140;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(2, 6, 10, .68);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.tbt-opening-modal-panel {
  box-sizing: border-box;
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  display: grid;
  gap: 16px;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid var(--ui-border-accent);
  border-radius: var(--ui-radius-panel);
  background:
    radial-gradient(circle at 50% 0%, rgba(244, 92, 45, .13), transparent 42%),
    linear-gradient(160deg, rgba(16, 27, 37, .99), rgba(5, 10, 16, .995));
  box-shadow: var(--ui-shadow-overlay);
  overflow: auto;
  color: var(--ui-text-primary);
}

.tbt-opening-modal-panel > header { display: grid; place-items: center; gap: 3px; text-align: center; }
.tbt-opening-modal-panel > header > span { color: var(--accent-soft); font-size: .64rem; font-weight: var(--ui-weight-title); letter-spacing: .14em; text-transform: uppercase; }
.tbt-opening-modal-panel h2 { margin: 0; font-family: inherit; font-size: clamp(1.35rem, 3vw, 1.9rem); }
.tbt-opening-modal-players { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 12px; }
.tbt-opening-modal-player { min-width: 0; display: grid; place-items: center; gap: 7px; text-align: center; }
.tbt-opening-modal-player > strong { max-width: 100%; overflow: hidden; font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.tbt-opening-modal-avatar .preset-avatar { width: 46px; height: 46px; flex-basis: 46px; }
.tbt-opening-modal-die { width: 48px; height: 48px; display: grid; place-items: center; }
.tbt-opening-modal-die .die { width: 42px; height: 42px; }
.tbt-opening-modal-wait { width: 42px; height: 42px; display: grid; place-items: center; border: 1px dashed var(--ui-border-default); border-radius: var(--ui-radius-control); color: var(--ui-text-muted); }
.tbt-opening-modal-vs { color: var(--ui-text-muted); font-size: .64rem; font-weight: var(--ui-weight-title); }
.tbt-opening-modal-status { min-width: 0; display: grid; place-items: center; gap: 3px; text-align: center; }
.tbt-opening-modal-status strong { color: var(--ui-text-primary); font-size: .92rem; }
.tbt-opening-modal-status span { color: var(--ui-text-muted); font-size: .7rem; }
.tbt-opening-modal-panel.is-resolved .tbt-opening-modal-status strong { color: var(--ui-success); font-size: 1.05rem; }
.tbt-opening-modal-action { display: grid; place-items: center; }
.tbt-opening-modal-action[hidden] { display: none; }
.tbt-opening-modal-action .btn { min-width: 150px; min-height: 42px; }

.game-shell.tbt-game-v3-opening { display: block; }
.game-shell.tbt-game-v3-opening .tbt-game-hud-v3 { display: none; }
.game-shell.tbt-game-v3-opening .board-shell { pointer-events: none; filter: brightness(.52) saturate(.72); }

/* Mobile landscape: one real bottom HUD, no secondary rail or hidden reservation. */
.game-shell.tbt-game-v3:has(.game-stage[data-game-layout="compact-unrotated"]) { display: block; }
.game-stage[data-game-layout="compact-unrotated"] .tbt-game-hud-v3 {
  position: fixed;
  top: auto;
  right: max(3px, env(safe-area-inset-right));
  bottom: max(2px, env(safe-area-inset-bottom));
  left: max(3px, env(safe-area-inset-left));
  width: auto;
  height: var(--tbt-hud-v3-height);
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px;
  padding: 4px 5px;
  border: 1px solid var(--ui-border-default);
  border-radius: 12px 12px 0 0;
}

.game-stage[data-game-layout="compact-unrotated"] .tbt-hud-v3-players,
.game-stage[data-game-layout="narrow-rotated"] .tbt-hud-v3-players {
  grid-template-columns: minmax(0, 1fr) clamp(92px, 14vw, 112px) minmax(0, 1fr);
  gap: 4px;
}

.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-hud-v3-player {
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 5px;
  padding: 2px 4px;
}
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-hud-v3-player[data-tbt-hud-player="black"] { grid-template-columns: minmax(0, 1fr) 30px; }
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-hud-v3-avatar { width: 28px; height: 28px; }
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-hud-v3-avatar .preset-avatar { width: 27px; height: 27px; flex-basis: 27px; }
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-hud-v3-player-copy > strong { font-size: clamp(.58rem, 1.75dvh, .7rem); }
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-hud-v3-player-copy > small { gap: 4px; font-size: clamp(.44rem, 1.3dvh, .53rem); }
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-hud-v3-score { padding-inline: 3px; }
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-hud-v3-score > strong { font-size: clamp(.84rem, 2.55dvh, 1.02rem); }
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-hud-v3-meta { font-size: clamp(.4rem, 1.15dvh, .48rem); }
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-hud-v3-score .turn-clock small { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-hud-v3-actions { grid-template-columns: 58px repeat(2, 42px); gap: 3px; }
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-hud-v3-auto-roll,
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-game-hud-v3 .match-menu > summary,
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-game-hud-v3 .match-comms > summary { min-height: 46px; padding: 3px; font-size: .46rem; }
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-hud-v3-auto-roll input { width: 15px; height: 15px; }
.game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-game-hud-v3 .match-comms-menu { top: auto; right: 0; bottom: calc(100% + 5px); width: min(250px, calc(100vw - 12px)); max-height: calc(100dvh - var(--tbt-hud-v3-height) - 10px); }
.game-stage[data-game-layout="compact-unrotated"] .tbt-game-hud-v3 .match-menu-popover { top: auto; bottom: calc(100% + 5px); }
.game-stage[data-game-layout="compact-unrotated"] > .tbt-game-v3-notices { top: auto; bottom: calc(var(--tbt-hud-v3-height) + 7px); }

/* Portrait device, landscape-logical game: HUD and board share the same clockwise logical axis. */
.game-shell.tbt-game-v3:has(.game-stage[data-game-layout="narrow-rotated"]) { display: block; }
.game-stage[data-game-layout="narrow-rotated"] .tbt-game-hud-v3 {
  position: fixed;
  top: max(2px, env(safe-area-inset-top));
  right: auto;
  bottom: auto;
  left: calc(100vw - max(3px, env(safe-area-inset-right)));
  width: calc(100dvh - max(2px, env(safe-area-inset-top)) - max(2px, env(safe-area-inset-bottom)));
  height: var(--tbt-hud-v3-height);
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px;
  padding: 4px 5px;
  border: 1px solid var(--ui-border-default);
  border-radius: 12px 12px 0 0;
  transform: rotate(90deg);
  transform-origin: top left;
}

.game-stage[data-game-layout="narrow-rotated"] .tbt-game-hud-v3 .match-comms-menu {
  top: calc(100% + 5px);
  bottom: auto;
  width: min(250px, calc(100dvh - 12px));
  max-height: calc(100vw - var(--tbt-hud-v3-height) - 10px);
}

.game-stage[data-game-layout="narrow-rotated"] > .tbt-game-v3-notices {
  top: 50%;
  right: calc(var(--tbt-hud-v3-height) + 8px);
  bottom: auto;
  left: auto;
  width: min(360px, calc(100dvh - 24px));
  transform: translateY(-50%) rotate(90deg);
}

@media (max-width: 600px) and (orientation: portrait),
       (pointer: coarse) and (orientation: portrait),
       (max-width: 1000px) and (orientation: landscape) and (max-height: 500px),
       (pointer: coarse) and (max-width: 1200px) and (max-height: 600px) and (min-aspect-ratio: 4 / 3) {
  .game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .tbt-game-hud-v3 .match-menu-popover {
    position: fixed;
    z-index: 110;
    top: calc(50% - 29px);
    right: auto;
    bottom: auto;
    left: 50%;
    width: min(250px, calc(100vw - max(12px, env(safe-area-inset-left)) - max(12px, env(safe-area-inset-right))));
    max-height: calc(100dvh - var(--tbt-hud-v3-height) - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
    transform: translate(-50%, -50%);
  }

  .game-stage:is([data-game-layout="compact-unrotated"], [data-game-layout="narrow-rotated"]) .match-menu[open] > .match-menu-backdrop { display: block; }

  .game-stage[data-game-layout="narrow-rotated"] .tbt-game-hud-v3 .match-menu-popover {
    top: calc(50vw + 29px);
    left: 50%;
    width: min(250px, calc(100dvh - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom))));
    max-height: calc(100vw - var(--tbt-hud-v3-height) - max(12px, env(safe-area-inset-left)) - max(12px, env(safe-area-inset-right)));
    transform: translate(-50%, -50%);
  }

  .game-stage[data-game-layout="narrow-rotated"] .tbt-game-hud-v3 .match-menu-backdrop {
    top: calc(0px - env(safe-area-inset-right));
    right: auto;
    bottom: auto;
    left: calc(0px - env(safe-area-inset-top));
    width: 100dvh;
    height: 100vw;
  }
}

.game-stage[data-game-layout="narrow-rotated"] > .tbt-opening-modal .tbt-opening-modal-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(520px, calc(100dvh - 24px));
  max-height: calc(100vw - 24px);
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center;
}

@media (max-height: 430px) {
  .tbt-opening-modal-panel { gap: 9px; padding: 12px 16px; }
  .tbt-opening-modal-avatar .preset-avatar { width: 38px; height: 38px; flex-basis: 38px; }
  .tbt-opening-modal-die { width: 42px; height: 42px; }
  .tbt-opening-modal-die .die,
  .tbt-opening-modal-wait { width: 36px; height: 36px; }
  .tbt-opening-modal-action .btn { min-height: 36px; }
}
