:root {
  color-scheme: dark;
  --bg: #050506;
  --panel: rgba(14, 14, 15, 0.84);
  --panel-strong: rgba(22, 22, 23, 0.94);
  --line: rgba(246, 246, 241, 0.12);
  --line-strong: rgba(246, 246, 241, 0.24);
  --text: #f4f4f0;
  --muted: #a9a9a2;
  --x: #ff7900;
  --x-glow: rgba(255, 121, 0, 0.56);
  --x-glow-soft: rgba(255, 121, 0, 0.36);
  --o: #7c3aed;
  --o-glow: rgba(124, 58, 237, 0.52);
  --o-glow-soft: rgba(124, 58, 237, 0.32);
  --control-accent: #ff7900;
  --control-accent-glow: rgba(255, 121, 0, 0.48);
  --danger: #ff7900;
  --gold: #f4f4f0;
  --shadow: rgba(0, 0, 0, 0.44);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f7f2;
  --panel: rgba(255, 255, 252, 0.82);
  --panel-strong: rgba(255, 255, 252, 0.94);
  --line: rgba(5, 5, 6, 0.12);
  --line-strong: rgba(5, 5, 6, 0.24);
  --text: #050506;
  --muted: #5e5e59;
  --gold: #050506;
  --shadow: rgba(0, 0, 0, 0.16);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  background: linear-gradient(145deg, #050506 0%, #0c0c0d 58%, #151515 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

:root[data-theme="light"] body {
  background: #f7f7f2;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

.game-shell,
.stage {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

.game-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.stage {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.018) 58%, rgba(0, 0, 0, 0.58)),
    linear-gradient(115deg, rgba(255, 255, 255, 0.04), rgba(0, 0, 0, 0.08) 48%, rgba(255, 255, 255, 0.025)),
    var(--bg);
}

:root[data-theme="light"] .stage {
  background: #f7f7f2;
}

.stage::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 28%;
  pointer-events: none;
  background: linear-gradient(0deg, rgba(3, 5, 11, 0.72), transparent);
}

:root[data-theme="light"] .stage::after {
  background: linear-gradient(0deg, rgba(255, 255, 252, 0.5), transparent);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#game-canvas.is-targeting {
  cursor: pointer;
}

#game-canvas.is-waiting-turn {
  cursor: grab;
}

.modal-card {
  border: 1px solid var(--line-strong);
  background: var(--panel);
  box-shadow: 0 14px 34px var(--shadow);
  backdrop-filter: blur(16px);
}

.score-hud {
  position: absolute;
  z-index: 3;
  top: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  gap: 20px;
  max-width: min(420px, calc(50vw - 88px));
  height: 38px;
  padding: 0;
  overflow: visible;
}

.score-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: 15px 17px;
  align-content: center;
  align-items: center;
  column-gap: 7px;
  min-width: 108px;
  height: 38px;
  padding: 0;
  opacity: 0.72;
  transition: opacity 160ms ease, text-shadow 160ms ease;
}

.score-card + .score-card {
  border-left: 0;
}

.score-card[data-active="true"] {
  opacity: 1;
}

.score-card > div {
  display: contents;
}

.score-card p,
.status-strip p {
  margin: 0;
}

.score-card p {
  grid-column: 2;
  grid-row: 1;
  max-width: 92px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-card strong {
  display: block;
  grid-column: 2;
  grid-row: 2;
  margin: 0;
  font-size: 1rem;
  line-height: 1;
}

.turn-note {
  grid-column: 2;
  grid-row: 2;
  justify-self: end;
  max-width: 68px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.56rem;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.1;
  text-align: right;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.score-card[data-active="true"] .turn-note {
  color: var(--text);
}

.x-card[data-active="true"] .turn-note {
  color: var(--x);
}

.o-card[data-active="true"] .turn-note {
  color: var(--o);
}

.token-mark {
  display: block;
  grid-column: 1;
  grid-row: 1;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.x-card .token-mark {
  background: var(--x);
  box-shadow: 0 0 12px var(--x-glow);
}

.o-card .token-mark {
  background: var(--o);
  box-shadow: 0 0 12px var(--o-glow);
}

.x-card[data-active="true"] {
  text-shadow: 0 0 16px var(--x-glow-soft);
}

.o-card[data-active="true"] {
  text-shadow: 0 0 16px var(--o-glow-soft);
}

.mobile-bottom-dock {
  display: contents;
}

.top-controls {
  position: absolute;
  z-index: 4;
  top: 18px;
  left: 50%;
  display: flex;
  gap: 14px;
  height: auto;
  padding: 0;
  overflow: visible;
  border-radius: 0;
  background: transparent;
  backdrop-filter: none;
  transform: translateX(-50%);
}

.icon-toggle,
.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: rgba(246, 246, 241, 0.06);
  color: var(--muted);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.icon-toggle:hover,
.icon-button:hover {
  transform: translateY(-1px);
  color: var(--text);
}

.icon-toggle[aria-pressed="true"],
.icon-toggle[aria-pressed="mixed"] {
  border-color: var(--control-accent-glow);
  background: rgba(255, 121, 0, 0.16);
  color: var(--control-accent);
}

.top-controls > button {
  position: relative;
  border-radius: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.top-controls > button + button {
  border-left: 0;
}

.top-controls .icon-toggle:hover,
.top-controls .icon-button:hover {
  transform: none;
  background: transparent;
}

.top-controls .icon-toggle[aria-pressed="true"],
.top-controls .icon-toggle[aria-pressed="mixed"],
.top-controls .icon-button[aria-expanded="true"] {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--control-accent);
}

.top-controls .icon-toggle[aria-pressed="true"]::after,
.top-controls .icon-toggle[aria-pressed="mixed"]::after,
.top-controls .icon-button[aria-expanded="true"]::after {
  content: "";
  position: absolute;
  right: 14px;
  bottom: 4px;
  left: 14px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
}

.top-controls .icon-toggle[aria-pressed="true"] .ui-icon,
.top-controls .icon-toggle[aria-pressed="mixed"] .ui-icon,
.top-controls .icon-button[aria-expanded="true"] .ui-icon {
  filter: drop-shadow(0 0 9px var(--control-accent-glow));
}

.top-controls #combo-overlay-toggle {
  color: var(--control-accent);
}

.top-controls #combo-overlay-toggle::after {
  content: "";
  position: absolute;
  right: 14px;
  bottom: 4px;
  left: 14px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
}

.top-controls #combo-overlay-toggle .ui-icon {
  filter: drop-shadow(0 0 9px var(--control-accent-glow));
}

.ui-icon,
.ui-icon use {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ui-icon circle,
.ui-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ui-icon .icon-dot {
  fill: currentColor;
  stroke: none;
}

.timeline-nav .ui-icon {
  width: 18px;
  height: 18px;
}

.modal-close .ui-icon {
  width: 20px;
  height: 20px;
}

.turn-hud {
  position: absolute;
  z-index: 3;
  top: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  min-width: 0;
  padding: 0;
  overflow: visible;
  text-align: right;
}

.turn-readout {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  backdrop-filter: none;
}

.turn-reset-button {
  border-radius: 0;
  border: 0;
  background: transparent;
  backdrop-filter: none;
}

.turn-reset-button:hover {
  transform: none;
  background: transparent;
}

.auth-panel {
  position: static;
  display: grid;
  justify-items: stretch;
  gap: 10px;
  width: 100%;
  margin: 0 0 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1;
}

.auth-panel[hidden] {
  display: none;
}

:root[data-theme="light"] .auth-panel {
  background: rgba(5, 5, 6, 0.035);
}

.auth-form,
.auth-session {
  min-width: 0;
}

.auth-form {
  display: block;
  margin: 0;
}

.auth-session,
.auth-row {
  display: flex;
  align-items: center;
  justify-content: stretch;
  gap: 8px;
}

.auth-form[hidden],
.auth-session[hidden] {
  display: none;
}

.auth-field {
  margin: 0;
}

.auth-field input {
  width: 100%;
  min-width: 0;
  flex: 1 1 auto;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: rgba(5, 5, 6, 0.66);
  color: var(--text);
}

:root[data-theme="light"] .auth-field input {
  background: rgba(255, 255, 252, 0.86);
}

.auth-field input:focus {
  border-color: var(--control-accent);
  box-shadow: 0 0 0 3px rgba(255, 121, 0, 0.12);
}

.auth-button {
  height: 28px;
  padding: 0 9px;
  border-radius: 8px;
  background: rgba(255, 121, 0, 0.14);
  color: var(--control-accent);
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 800;
}

.auth-button:hover {
  background: rgba(255, 121, 0, 0.22);
}

.auth-button:disabled,
.auth-field input:disabled,
.bsky-game-button:disabled {
  cursor: default;
  opacity: 0.48;
}

.bsky-game-button {
  min-height: 36px;
  margin-top: 0;
}

.bsky-opponents {
  display: grid;
  gap: 8px;
}

.bsky-opponents[hidden] {
  display: none;
}

.bsky-opponents-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

#bsky-opponent-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bsky-opponent {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  padding: 0 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

:root[data-theme="light"] .bsky-opponent {
  background: rgba(5, 5, 6, 0.045);
}

.bsky-opponent-main,
.bsky-opponent-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bsky-opponent-main {
  color: var(--text);
}

.bsky-opponent-meta {
  color: var(--muted);
  font-size: 0.68rem;
}

.bsky-opponent[data-status="ready"] .bsky-opponent-meta {
  color: var(--control-accent);
}

.bsky-open-button {
  min-width: 52px;
}

.bsky-delete-button {
  min-width: 58px;
  background: rgba(5, 5, 6, 0.08);
  color: var(--muted);
}

.bsky-delete-button:hover {
  background: rgba(5, 5, 6, 0.14);
  color: var(--text);
}

#auth-identity {
  overflow: hidden;
  max-width: 100%;
  flex: 1 1 auto;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

#auth-status {
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#turn-pill {
  display: none;
  order: 2;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

#turn-count {
  order: 1;
  min-width: 0;
  font-size: 0.94rem;
  line-height: 1;
  white-space: nowrap;
}

.status-strip {
  position: absolute;
  z-index: 3;
  right: 18px;
  bottom: 18px;
  display: none;
  max-width: min(420px, calc(100vw - 36px));
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.timeline-shell {
  position: absolute;
  z-index: 4;
  right: 18px;
  bottom: 16px;
  left: 18px;
  height: 44px;
}

.move-timeline {
  position: absolute;
  inset: 0 34px;
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 0;
  padding: 0 4px;
  overflow-x: auto;
  overflow-y: hidden;
  list-style: none;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.move-timeline::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.move-timeline::before {
  content: "";
  position: absolute;
  right: 0;
  left: 0;
  top: 21px;
  height: 1px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(244, 247, 251, 0.24), transparent);
}

:root[data-theme="light"] .move-timeline::before {
  background: linear-gradient(90deg, transparent, rgba(5, 5, 6, 0.22), transparent);
}

.move-timeline:empty {
  opacity: 0;
  pointer-events: none;
}

.timeline-nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid transparent;
  border-radius: 50%;
  background: rgba(8, 8, 14, 0.76);
  color: var(--muted);
  box-shadow: none;
  cursor: pointer;
  transform: translateY(-50%);
  transition: color 160ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.timeline-nav:hover {
  background: rgba(20, 17, 27, 0.94);
  color: var(--text);
}

:root[data-theme="light"] .timeline-nav {
  border-color: rgba(5, 5, 6, 0.18);
  background: rgba(255, 255, 252, 0.9);
  color: #050506;
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.12);
}

:root[data-theme="light"] .timeline-nav:hover {
  border-color: #050506;
  background: #050506;
  color: #f7f7f2;
}

.timeline-nav[disabled] {
  cursor: default;
  opacity: 0;
  pointer-events: none;
}

.timeline-nav-left {
  left: 0;
}

.timeline-nav-right {
  right: 0;
}

.timeline-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 44px;
  min-width: max-content;
  max-width: 260px;
  padding: 0;
  flex: 0 0 auto;
}

.timeline-token {
  display: block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(8, 12, 17, 0.92);
  z-index: 1;
}

.timeline-item[data-token="x"] .timeline-token {
  background: var(--x);
  box-shadow: 0 0 0 1px var(--x-glow), 0 0 14px var(--x-glow-soft);
}

.timeline-item[data-token="o"] .timeline-token {
  background: var(--o);
  box-shadow: 0 0 0 1px var(--o-glow), 0 0 14px var(--o-glow-soft);
}

.timeline-main {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding-right: 2px;
}

.timeline-combo {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-combo {
  color: var(--muted);
  font-size: 0.68rem;
}

.timeline-combo[data-scored="true"] {
  color: var(--gold);
  text-shadow: 0 0 14px rgba(246, 246, 241, 0.24);
}

.timeline-meta {
  display: none;
}

.game-over-overlay {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  pointer-events: none;
}

.game-over-overlay[hidden] {
  display: none;
}

.game-over-panel {
  display: grid;
  justify-items: center;
  gap: 10px;
  text-align: center;
}

#game-over-title {
  max-width: min(520px, calc(100vw - 40px));
  margin: 0;
  color: var(--text);
  font-size: clamp(2.2rem, 9vw, 5.6rem);
  font-weight: 900;
  letter-spacing: 0;
  line-height: 0.92;
  text-transform: uppercase;
  text-shadow: 0 0 26px var(--shadow), 0 0 4px var(--bg);
}

#game-over-summary {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  text-transform: uppercase;
}

.replay-button {
  width: auto;
  min-width: 132px;
  margin-top: 4px;
  padding: 0 22px;
  pointer-events: auto;
}

.modal-backdrop {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(3, 7, 11, 0.58);
  backdrop-filter: blur(7px);
}

:root[data-theme="light"] .modal-backdrop {
  background: rgba(247, 247, 242, 0.72);
}

.modal-backdrop.is-open {
  display: grid;
}

.modal-card {
  width: min(360px, 100%);
  padding: 18px;
  border-radius: 8px;
  background: rgba(16, 14, 22, 0.95);
}

:root[data-theme="light"] .modal-card {
  border-color: rgba(5, 5, 6, 0.16);
  background: rgba(255, 255, 252, 0.96);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.16);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

h2 {
  margin: 0;
  color: var(--text);
  font-size: 1rem;
  text-transform: uppercase;
}

.modal-close {
  width: 32px;
  height: 32px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0d16;
}

:root[data-theme="light"] .segmented {
  background: rgba(5, 5, 6, 0.055);
}

.segment {
  min-height: 38px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.segment:hover {
  transform: translateY(-1px);
  color: var(--text);
}

.segment.active {
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

:root[data-theme="light"] .segment.active {
  background: #050506;
  color: #f7f7f2;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.86rem;
}

.field input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: #070708;
  color: var(--text);
}

:root[data-theme="light"] .field input {
  background: #ffffff;
}

.field input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(246, 246, 241, 0.12);
}

.primary-button {
  width: 100%;
  min-height: 44px;
  margin-top: 16px;
  border-radius: 8px;
  background: var(--control-accent);
  color: #f7f7f4;
  cursor: pointer;
  font-weight: 800;
}

.confirm-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 18px;
}

.secondary-button,
.danger-button {
  min-height: 40px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.secondary-button {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

:root[data-theme="light"] .secondary-button {
  border: 1px solid rgba(5, 5, 6, 0.14);
  background: rgba(5, 5, 6, 0.06);
}

.danger-button {
  background: var(--danger);
  color: #120806;
}

.guide-drawer {
  position: absolute;
  z-index: 2;
  top: 82px;
  right: 18px;
  bottom: 74px;
  width: min(142px, calc(100vw - 36px));
  opacity: 0;
  pointer-events: none;
  transform: translateX(calc(100% + 18px));
  transition: opacity 180ms ease, transform 180ms ease;
}

.guide-drawer.is-open {
  opacity: 1;
  transform: translateX(0);
}

.guide-body {
  width: 100%;
  height: 100%;
  padding-right: 0;
  overflow-y: auto;
  pointer-events: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.guide-body::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.combo-guide-row h4 {
  margin: 0;
}

.combo-guide-list {
  display: grid;
  gap: 0;
  margin-top: 0;
}

.combo-guide-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 0 13px;
}

.combo-guide-row h4 {
  color: var(--text);
  font-size: 0.78rem;
  line-height: 1.18;
  text-align: center;
  text-shadow: 0 0 14px rgba(8, 12, 17, 0.95);
}

:root[data-theme="light"] .combo-guide-row h4 {
  text-shadow: none;
}

.combo-guide-row h4 span {
  margin-left: 3px;
  color: var(--gold);
  font-size: 0.72rem;
}

.combo-guide-row > div:not(.combo-diagram) {
  order: -1;
  width: 100%;
}

.combo-diagram {
  position: relative;
  display: grid;
  place-items: center;
  width: 82px;
  min-height: 64px;
}

.diagram-plane {
  display: grid;
  grid-template-columns: repeat(3, 10px);
  grid-template-rows: repeat(3, 10px);
  gap: 4px;
  padding: 4px;
  background: rgba(244, 247, 251, 0.035);
  transform: skewX(-12deg);
}

:root[data-theme="light"] .diagram-plane {
  background: rgba(5, 5, 6, 0.035);
}

.diagram-flat .diagram-plane {
  grid-template-columns: repeat(3, 12px);
  grid-template-rows: repeat(3, 12px);
  gap: 5px;
  padding: 6px;
}

.diagram-plane span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(244, 247, 251, 0.13);
}

:root[data-theme="light"] .diagram-plane span {
  background: rgba(5, 5, 6, 0.13);
}

.diagram-flat .diagram-plane span {
  width: 12px;
  height: 12px;
}

.diagram-plane .filled {
  background: var(--gold);
  box-shadow: 0 0 16px rgba(246, 246, 241, 0.26);
}

:root[data-theme="light"] .diagram-plane .filled {
  background: #050506;
  box-shadow: 0 0 0 2px rgba(5, 5, 6, 0.18), 0 0 14px rgba(5, 5, 6, 0.24);
}

.diagram-3d {
  gap: 3px;
}

.diagram-level {
  display: flex;
  align-items: center;
  gap: 5px;
}

.diagram-level > span {
  width: 10px;
  color: rgba(244, 247, 251, 0.5);
  font-size: 0.58rem;
  font-weight: 900;
  text-align: center;
}

.mini-plane {
  opacity: 0.88;
}

.diagram-level:nth-of-type(2) {
  transform: translateX(-2px);
}

.diagram-level:nth-of-type(3) {
  transform: translateX(-4px);
}

@media (max-width: 800px) {
  .score-hud {
    max-width: calc(100vw - 172px);
  }

  .score-card {
    min-width: 86px;
  }

  .token-mark,
  .score-card strong {
    grid-row: 2;
  }

  .turn-note {
    grid-row: 2;
    max-width: 46px;
    font-size: 0.5rem;
  }
}

@media (max-width: 560px) {
  .score-hud {
    top: max(10px, env(safe-area-inset-top));
    left: 12px;
    gap: 8px;
    max-width: calc(100vw - 126px);
    height: 38px;
  }

  .score-card {
    flex: 1 1 0;
    grid-template-rows: 15px 17px;
    min-width: 0;
    height: 38px;
    padding: 0;
  }

  .score-card p {
    display: block;
    max-width: clamp(48px, 18vw, 86px);
    font-size: 0.66rem;
  }

  .token-mark {
    grid-row: 2;
    font-size: 0.78rem;
  }

  .score-card strong {
    grid-row: 2;
    font-size: 0.92rem;
  }

  .turn-note {
    display: none;
  }

  .mobile-bottom-dock {
    position: absolute;
    z-index: 6;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 12px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: center;
    justify-items: center;
    gap: 4px;
    min-height: 54px;
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--panel);
    box-shadow: 0 14px 34px var(--shadow);
    backdrop-filter: blur(16px);
  }

  .top-controls {
    display: contents;
    position: static;
    transform: none;
  }

  .mobile-bottom-dock .top-controls > button {
    display: grid;
    grid-template-rows: 24px 8px;
    place-items: center;
    align-content: center;
    row-gap: 1px;
  }

  .mobile-bottom-dock .top-controls .ui-icon {
    grid-row: 1;
  }

  .turn-hud {
    top: max(10px, env(safe-area-inset-top));
    right: 12px;
    height: 38px;
    gap: 4px;
    text-align: center;
  }

  .top-controls .icon-toggle::after,
  .top-controls .icon-button::after,
  .top-controls #combo-overlay-toggle::after {
    position: static;
    grid-row: 2;
    width: 14px;
    transform: none;
  }

  .turn-readout {
    display: flex;
    place-items: center;
    height: 38px;
    padding: 0;
  }

  #turn-pill {
    display: none;
  }

  #turn-count {
    min-width: 42px;
    font-size: 0.84rem;
  }

  .turn-reset-button {
    width: 38px;
    height: 38px;
  }

  .icon-toggle,
  .icon-button {
    width: 38px;
    height: 38px;
  }

  .top-controls > button {
    justify-self: center;
    width: 42px;
    height: 38px;
  }

  .ui-icon {
    width: 20px;
    height: 20px;
  }

  .timeline-shell {
    right: 12px;
    bottom: calc(max(12px, env(safe-area-inset-bottom)) + 66px);
    left: 12px;
    height: 44px;
  }

  .move-timeline {
    inset: 0 30px;
    gap: 8px;
    padding: 0 2px;
    touch-action: pan-x;
  }

  .timeline-item {
    height: 44px;
    max-width: 190px;
  }

  .stage::after {
    height: 36%;
  }

  .guide-drawer {
    top: calc(max(10px, env(safe-area-inset-top)) + 46px);
    bottom: calc(max(12px, env(safe-area-inset-bottom)) + 122px);
    right: 10px;
    width: min(126px, calc(100vw - 18px));
  }

  .combo-guide-row {
    gap: 5px;
    padding: 7px 0 11px;
  }

  .combo-diagram {
    width: 74px;
    min-height: 60px;
  }
}

@media (max-width: 390px) {
  .top-controls > button {
    width: 40px;
  }

  .mobile-bottom-dock {
    gap: 6px;
    padding-right: 6px;
    padding-left: 6px;
  }

  .turn-readout {
    padding: 0;
  }

  #turn-count {
    min-width: 38px;
    font-size: 0.78rem;
  }

  .turn-reset-button {
    width: 36px;
  }

  .score-card strong {
    font-size: 0.86rem;
  }

  .token-mark {
    width: 10px;
    height: 10px;
  }
}
