﻿/* ==========================================================================
   Hive — theme tokens
   ========================================================================== */
/* Default: "Ebony" (dark). Alternate: "Linen" (light). */
:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Cormorant Garamond", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --bg: #141311;
  --bg-2: #0c0b0a;
  --grid: rgba(236, 226, 205, 0.035);
  --vignette-0: rgba(0, 0, 0, 0);
  --vignette-1: rgba(0, 0, 0, 0.55);
  --panel: rgba(28, 26, 23, 0.88);
  --panel-solid: #1c1a17;
  --panel-2: rgba(236, 226, 205, 0.045);
  --border: rgba(236, 226, 205, 0.08);
  --border-strong: rgba(236, 226, 205, 0.16);
  --text: #ece5d8;
  --muted: #8e8678;
  --accent: #c2a46a;
  --accent-2: #d8bf8a;
  --accent-ink: #17140e;
  --accent-soft: rgba(194, 164, 106, 0.13);
  --danger: #c8645a;
  --danger-soft: rgba(200, 100, 90, 0.14);
  --ok: #7fa27a;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35), 0 1px 0 rgba(255, 255, 255, 0.03) inset;
  --shadow-lg: 0 30px 80px rgba(0, 0, 0, 0.6);
  --tile-side-w: #a39880;
  --tile-side-b: #050504;
  --tile-inner-w: rgba(255, 255, 255, 0.55);
  --tile-inner-b: rgba(255, 255, 255, 0.06);
  --marker: #c2a46a;
  --marker-ring: rgba(194, 164, 106, 0.9);
  --radius: 14px;
  --topbar-h: 60px;
  --card-w: 272px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #e9e5dd;
  --bg-2: #d9d3c7;
  --grid: rgba(40, 32, 20, 0.05);
  --vignette-1: rgba(60, 45, 20, 0.16);
  --panel: rgba(248, 246, 241, 0.9);
  --panel-solid: #f8f6f1;
  --panel-2: rgba(40, 32, 20, 0.04);
  --border: rgba(40, 32, 20, 0.1);
  --border-strong: rgba(40, 32, 20, 0.2);
  --text: #1d1b18;
  --muted: #7a7266;
  --accent: #9a7a3e;
  --accent-2: #b39256;
  --accent-ink: #fbf8f1;
  --accent-soft: rgba(154, 122, 62, 0.12);
  --danger: #b0473d;
  --danger-soft: rgba(176, 71, 61, 0.12);
  --ok: #4d7a4a;
  --shadow: 0 14px 34px rgba(50, 38, 15, 0.12), 0 1px 3px rgba(50, 38, 15, 0.06);
  --shadow-lg: 0 30px 80px rgba(40, 28, 8, 0.25);
  --tile-side-w: #b3a88f;
  --marker: #9a7a3e;
  --marker-ring: rgba(154, 122, 62, 0.9);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.svg-defs {
  position: absolute;
  pointer-events: none;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

kbd {
  font-family: inherit;
  font-size: 0.78em;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  background: var(--panel-solid);
}

/* ==========================================================================
   Board
   ========================================================================== */
.app {
  position: fixed;
  inset: 0;
}

.board {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 45%, transparent 45%, var(--vignette-1) 100%),
    radial-gradient(ellipse at 50% 30%, var(--bg) 0%, var(--bg-2) 100%);
  touch-action: none;
}

.board-svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.board-svg.panning {
  cursor: grabbing;
}

.grid-line {
  fill: none;
  stroke: var(--grid);
  stroke-width: 1;
}

.tile-side-w {
  fill: var(--tile-side-w);
}
.tile-side-b {
  fill: var(--tile-side-b);
}
.tile-top-w {
  fill: url(#g-w);
  stroke: rgba(120, 96, 50, 0.35);
  stroke-width: 1;
}
.tile-top-b {
  fill: url(#g-b);
  stroke: rgba(0, 0, 0, 0.6);
  stroke-width: 1;
}
.tile-inner-w {
  fill: none;
  stroke: var(--tile-inner-w);
  stroke-width: 2;
}
.tile-inner-b {
  fill: none;
  stroke: var(--tile-inner-b);
  stroke-width: 2;
}

.piece {
  cursor: pointer;
}
.piece-shadow {
  fill: rgba(40, 24, 0, 0.22);
}
:root:not([data-theme="light"]) .piece-shadow {
  fill: rgba(0, 0, 0, 0.55);
}
.piece-ring {
  fill: none;
  stroke: transparent;
  stroke-width: 4;
}
.piece-body {
  transition: transform 160ms ease;
}
.piece.covered .tile-bug {
  opacity: 0.55;
}
.piece.selected .piece-body {
  transform: translateY(-5px);
}
.piece.selected .piece-ring {
  stroke: var(--accent);
  stroke-width: 3.5;
}
.piece.last-moved .piece-ring {
  stroke: var(--accent);
  stroke-opacity: 0.6;
  stroke-width: 2;
}
.piece.hinted .piece-ring {
  stroke: var(--text);
  stroke-width: 3;
  animation: ring-pulse 2.4s ease-in-out infinite;
}
.piece.losing-queen .piece-ring {
  stroke: var(--danger);
  stroke-width: 4;
}
.piece.dragging {
  opacity: 0.35;
}
.piece.moving {
  pointer-events: none;
}
.piece.moving .piece-body {
  transition: none;
}
.piece.moving .piece-shadow {
  transform: translate(8px, 18px);
  fill-opacity: 0.6;
}

.stack-badge circle {
  fill: var(--panel-solid);
  stroke: var(--accent);
  stroke-width: 1.5;
}
.stack-badge text {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  fill: var(--text);
}
.lift-badge {
  display: none;
}
.piece.lift-target .lift-badge {
  display: block;
}
.lift-badge circle {
  fill: var(--panel-solid);
  stroke: var(--accent);
  stroke-width: 2;
}
.lift-arrow {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.piece.lift-target .piece-ring {
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-dasharray: 6 5;
}

.shake {
  animation: shake 0.42s ease;
}

.cell-from {
  fill: var(--accent-soft);
  stroke: var(--accent);
  stroke-opacity: 0.35;
  stroke-width: 1.5;
  stroke-dasharray: 4 6;
}
.cell-danger {
  fill: var(--danger-soft);
}

.marker {
  pointer-events: none;
}
.marker-dot {
  fill: var(--marker);
  stroke: none;
}
.marker-halo {
  fill: var(--accent-soft);
  stroke: var(--marker-ring);
  stroke-width: 1.2;
  stroke-opacity: 0.5;
}
.marker-ring {
  fill: rgba(194, 164, 106, 0.22);
  stroke: var(--marker-ring);
  stroke-width: 2.5;
}
.marker-liftdest .marker-dot {
  fill: none;
  stroke: var(--marker);
  stroke-width: 3;
}
.marker-hint .marker-dot {
  fill: var(--text);
}
.marker-hint .marker-halo {
  fill: none;
  stroke: var(--text);
  stroke-opacity: 0.8;
  stroke-width: 1.5;
}
.marker-hint .marker-ring {
  stroke: var(--text);
  fill: rgba(255, 255, 255, 0.06);
}

.ghost {
  opacity: 0.55;
  pointer-events: none;
}
.drag-tile {
  pointer-events: none;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.25));
}

.ripple path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  transform-origin: 0 0;
  animation: ripple 0.65s ease-out forwards;
}
.ripple-land path {
  stroke-width: 3;
}
.ripple-win path {
  stroke: var(--danger);
  stroke-width: 5;
}

@keyframes ripple {
  from {
    transform: scale(0.9);
    opacity: 0.9;
  }
  to {
    transform: scale(1.5);
    opacity: 0;
  }
}
@keyframes halo {
  0%,
  100% {
    transform: scale(0.85);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.15);
    opacity: 1;
  }
}
@keyframes dash {
  to {
    stroke-dashoffset: -36;
  }
}
@keyframes ring-pulse {
  0%,
  100% {
    stroke-opacity: 1;
  }
  50% {
    stroke-opacity: 0.35;
  }
}
@keyframes bob {
  0%,
  100% {
    transform: translate(-28px, -28px);
  }
  50% {
    transform: translate(-28px, -33px);
  }
}
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-7px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(3px);
  }
}

/* ==========================================================================
   Chrome: shared controls
   ========================================================================== */
.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  transition: background 120ms ease, transform 120ms ease, opacity 120ms ease;
}
.icon-btn:hover:not(:disabled) {
  background: var(--panel-2);
  border-color: var(--border);
}
.icon-btn:active:not(:disabled) {
  transform: scale(0.94);
}
.icon-btn:disabled {
  opacity: 0.32;
  cursor: default;
}
.icon-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.pill-btn,
.ghost-btn,
.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 10px;
  font-weight: 500;
  white-space: nowrap;
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}
.pill-btn {
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  background: var(--panel-solid);
  font-size: 0.9rem;
}
.pill-btn:hover {
  border-color: var(--accent);
}
.ghost-btn {
  padding: 11px 18px;
  border: 1px solid var(--border-strong);
  background: transparent;
}
.ghost-btn:hover {
  background: var(--panel-2);
}
.primary-btn {
  padding: 12px 26px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  letter-spacing: 0.04em;
}
.primary-btn:hover {
  background: var(--accent-2);
}
.primary-btn:active {
  transform: translateY(1px);
}
.primary-btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}
[data-icon] > .ui-icon,
.pill-btn .ui-icon,
.ghost-btn .ui-icon {
  display: block;
}
span[data-icon] {
  display: inline-grid;
}

/* ==========================================================================
   Top bar
   ========================================================================== */
.topbar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 0 10px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  border: 0;
  background: none;
  padding: 6px 8px;
  border-radius: 12px;
}
.brand:hover {
  background: var(--panel-2);
}
.brand-mark {
  width: 22px;
  height: 25px;
  background: var(--accent);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 2px;
  background: var(--panel-solid);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  opacity: 0.85;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.32em;
  font-size: 1.25rem;
}

.turn-pill {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.turn-swatch {
  flex: none;
  width: 18px;
  height: 20px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: #f6efdf;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.2);
}
.turn-swatch.b {
  background: #2a2723;
}
.turn-swatch.thinking {
  animation: thinking 2.4s ease-in-out infinite;
}
.turn-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@keyframes thinking {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}
.top-sep {
  width: 1px;
  height: 26px;
  background: var(--border-strong);
  margin: 0 6px;
}
.pass-btn {
  margin-left: 4px;
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
@keyframes pulse-soft {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(194, 164, 106, 0.45);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(194, 164, 106, 0);
  }
}

/* ==========================================================================
   Player cards & trays
   ========================================================================== */
.player-card {
  position: absolute;
  left: 12px;
  width: var(--card-w);
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  padding: 12px;
  z-index: 10;
  transition: box-shadow 200ms ease, border-color 200ms ease, transform 200ms ease;
}
.player-card[data-slot="top"] {
  top: calc(var(--topbar-h) + 24px);
}
.player-card[data-slot="bottom"] {
  bottom: 12px;
}
.player-card.to-move {
  border-color: rgba(194, 164, 106, 0.55);
  box-shadow: var(--shadow), inset 0 2px 0 var(--accent);
}

.pc-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.pc-avatar {
  width: 30px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: #eee7d8;
  color: #2a251f;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.pc-avatar.b {
  background: #262320;
  color: #e2d8c4;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.pc-name {
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.01em;
}
.pc-sub {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pc-sub.thinking::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: dots 1.2s steps(4) infinite;
}
@keyframes dots {
  0% {
    content: "";
  }
  25% {
    content: ".";
  }
  50% {
    content: "..";
  }
  75% {
    content: "...";
  }
}
.pc-meta {
  flex: 1;
  min-width: 0;
}

.queen-meter {
  display: flex;
  gap: 3px;
  align-items: center;
}
.queen-meter .pip {
  width: 11px;
  height: 12px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--panel-2);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  background-color: rgba(127, 110, 80, 0.18);
}
.queen-meter .pip.on {
  background: var(--accent);
}
.queen-meter.warn .pip.on {
  background: #c98a4a;
}
.queen-meter.danger .pip.on {
  background: var(--danger);
}

.queen-meter.unplaced {
  opacity: 0.45;
}
@keyframes pulse-meter {
  50% {
    transform: scale(1.08);
  }
}
.meter-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}
.meter-label {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tray {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.tray-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 0;
  padding: 0;
  background: transparent;
  display: grid;
  place-items: center;
  border-radius: 14px;
  transition: transform 140ms ease, background 140ms ease, opacity 140ms ease;
  touch-action: none;
}
.tray-tile .tile-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}
.tray-tile .stack-under {
  position: absolute;
  inset: 0;
  transform: translate(0, -4px);
  opacity: 0.9;
}
.tray-tile.playable:hover {
  transform: translateY(-2px);
  background: var(--panel-2);
}
.tray-tile.selected {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1.5px var(--accent);
  transform: translateY(-2px);
}
.tray-tile.disabled {
  opacity: 0.38;
  cursor: default;
}
.tray-tile.empty {
  opacity: 0.12;
  cursor: default;
}
.tray-tile.must {
  box-shadow: inset 0 0 0 1.5px var(--accent);
  background: var(--accent-soft);
}
@keyframes must {
  0%,
  100% {
    box-shadow: inset 0 0 0 2px var(--accent);
  }
  50% {
    box-shadow: inset 0 0 0 2px transparent, 0 0 18px var(--accent);
  }
}
.tray-count {
  position: absolute;
  right: 1px;
  bottom: 1px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 17px;
  text-align: center;
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--border-strong);
  font-variant-numeric: tabular-nums;
}
.tray-key {
  position: absolute;
  left: 2px;
  top: 0;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--muted);
  opacity: 0;
  transition: opacity 120ms ease;
}
.app.kbd .tray:not(.inactive) .tray-key {
  opacity: 0.8;
}
.tray-empty-note {
  grid-column: 1 / -1;
  font-size: 0.82rem;
  color: var(--muted);
  padding: 4px 2px;
}

/* ==========================================================================
   Prompt, review bar, zoom
   ========================================================================== */
.prompt {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(calc(-50% + var(--card-w) / 2));
  max-width: min(560px, calc(100vw - var(--card-w) - 140px));
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 0.92rem;
  text-align: center;
  z-index: 9;
  transition: opacity 200ms ease;
}
.prompt .link-btn {
  font-size: inherit;
  color: var(--accent);
  margin-left: 4px;
}
.prompt:empty {
  opacity: 0;
  pointer-events: none;
}
.prompt strong {
  color: var(--accent);
  font-weight: 600;
}
:root:not([data-theme="light"]) .prompt strong {
  filter: none;
}

.review-bar {
  position: absolute;
  left: 50%;
  top: calc(var(--topbar-h) + 24px);
  transform: translateX(calc(-50% + var(--card-w) / 2));
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--accent);
  box-shadow: var(--shadow);
  z-index: 15;
}
.review-label {
  min-width: 120px;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
}

.zoom-controls {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 5px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 9;
}

.app.log-open .prompt,
.app.log-open .review-bar {
  transform: translateX(calc(-50% + (var(--card-w) - 324px) / 2));
}

/* ==========================================================================
   Move log drawer
   ========================================================================== */
.drawer {
  position: absolute;
  top: calc(var(--topbar-h) + 24px);
  right: 12px;
  bottom: 12px;
  width: 300px;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  z-index: 16;
  transform: translateX(calc(100% + 24px));
  transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.drawer.open {
  transform: none;
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 6px 16px;
}
.drawer-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.35rem;
}
.move-list {
  list-style: none;
  margin: 0;
  padding: 4px 8px 8px;
  overflow-y: auto;
  flex: 1;
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  align-content: start;
  gap: 2px 4px;
}
.move-list .mv-num {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 6px 0 0 6px;
}
.move-list button {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 5px 8px;
  border-radius: 8px;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.move-list button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.move-list button:hover {
  background: var(--panel-2);
}
.move-list button.current {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.move-list button.future {
  opacity: 0.45;
}
.move-list .tile-svg {
  flex: none;
}
.move-list .empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.88rem;
  padding: 8px;
}
.drawer-foot {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
}
.drawer-foot .pill-btn {
  flex: 1;
}

/* ==========================================================================
   Toasts & popover
   ========================================================================== */
.toasts {
  position: absolute;
  top: calc(var(--topbar-h) + 26px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  z-index: 40;
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--border-strong);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  max-width: min(440px, 90vw);
  animation: toast-in 220ms ease;
}
.toast.warn {
  border-color: var(--danger);
}
.toast.leaving {
  animation: toast-out 220ms ease forwards;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.97);
  }
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

.popover {
  position: absolute;
  z-index: 45;
  width: 290px;
  padding: 14px;
  border-radius: 16px;
  background: var(--panel-solid);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  animation: pop-in 160ms ease;
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
}
.pop-head {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}
.pop-head h4 {
  margin: 0;
  font-size: 1.02rem;
}
.pop-head .pc-sub {
  margin-top: 2px;
}
.popover p {
  margin: 6px 0 0;
  font-size: 0.88rem;
  line-height: 1.45;
}
.popover .why {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--accent-soft);
  font-size: 0.85rem;
}
.popover .choice-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.popover .choice-row button {
  flex: 1;
}

/* ==========================================================================
   Modals
   ========================================================================== */
.modal {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in 200ms ease;
}
:root[data-theme="light"] .modal {
  background: rgba(40, 30, 15, 0.25);
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
.modal-card {
  width: min(520px, 100%);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 22px;
  border-radius: 24px;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: card-in 260ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
  position: relative;
}
@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
}
.modal-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.6rem;
  letter-spacing: 0.01em;
}
.modal-card h3 {
  margin: 0 0 10px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
textarea {
  width: 100%;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  padding: 10px 12px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  word-break: break-all;
}
textarea:focus,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.small-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.error-text {
  color: var(--danger);
  font-size: 0.88rem;
}

/* main menu */
.menu-card {
  width: min(560px, 100%);
  padding: 0 22px 22px;
}
.menu-hero {
  margin: 0 -22px 18px;
  padding: 30px 22px 22px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.hero-tiles {
  display: flex;
  justify-content: center;
  margin-bottom: 6px;
  height: 64px;
}
.hero-tiles .tile-svg {
  margin: 0 -5px;
}
.hero-tiles .tile-svg:nth-child(2n) {
  margin-top: 20px;
}
@keyframes hero-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}
.menu-hero h1 {
  margin: 14px 0 4px;
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: 500;
  letter-spacing: 0.42em;
  padding-left: 0.42em;
  line-height: 1;
}
.tagline {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.08rem;
}
.continue-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
  border-radius: 16px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  text-align: left;
}
.continue-btn:hover {
  transform: translateY(-1px);
}
.continue-btn strong {
  display: block;
}
.continue-btn small {
  color: var(--muted);
}
.menu-section {
  margin-bottom: 18px;
}
.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.segmented button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--muted);
  transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease;
}
.segmented button.on {
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), inset 0 0 0 1px var(--accent);
}
.segmented.small button {
  padding: 7px 8px;
  font-size: 0.85rem;
}
.swatch {
  width: 12px;
  height: 13px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: #f6efdf;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25);
}
.swatch-b {
  background: #2a2723;
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.level-btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 12px;
  padding: 10px 4px 8px;
  text-align: center;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}
.level-btn:hover {
  transform: translateY(-1px);
}
.level-btn.on {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.level-btn .lv-pips {
  display: flex;
  justify-content: center;
  gap: 2px;
  margin-bottom: 6px;
}
.level-btn .lv-pips i {
  width: 7px;
  height: 8px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--border-strong);
}
.level-btn .lv-pips i.on {
  background: var(--accent);
}
.level-btn strong {
  display: block;
  font-size: 0.8rem;
}
.level-blurb {
  font-size: 0.85rem;
  color: var(--muted);
  margin: -4px 0 12px;
  min-height: 1.2em;
}
.menu-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.row-label {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}
.menu-row .segmented {
  flex: 1;
}
.exp-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.exp-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  text-align: left;
  transition: border-color 140ms ease, background 140ms ease, opacity 140ms ease;
}
.exp-btn .tile-svg {
  flex: none;
}
.exp-btn strong {
  display: block;
  font-size: 0.9rem;
}
.exp-btn small {
  color: var(--muted);
  font-size: 0.74rem;
}
.exp-btn.on {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.exp-btn:not(.on) {
  opacity: 0.6;
}
.exp-btn:not(.on) .tile-svg {
  filter: grayscale(1);
}
.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch-row strong {
  display: block;
  font-size: 0.92rem;
}
.switch-row small {
  color: var(--muted);
  font-size: 0.8rem;
}
.switch {
  flex: none;
  width: 42px;
  height: 24px;
  border-radius: 12px;
  background: var(--border-strong);
  position: relative;
  transition: background 160ms ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 160ms ease;
}
.switch-row input:checked + .switch {
  background: var(--accent);
}
.switch-row input:checked + .switch::after {
  transform: translateX(18px);
}
.switch-row input:focus-visible + .switch {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.menu-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.menu-actions .primary-btn {
  min-width: 150px;
}
.app[data-menu-mode="cpu"] .cpu-only {
  display: block;
}
.cpu-only {
  display: none;
}

/* online */
.online-card .segmented {
  margin: 14px 0;
}
.online-steps {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.step {
  display: flex;
  gap: 12px;
}
.step > div {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}
.step textarea {
  width: 100%;
}
.step-n {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
}
.code-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}
.online-status {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel-2);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}
.online-status .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}
.online-status[data-state="ready"] .dot,
.online-status[data-state="connected"] .dot {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(59, 154, 74, 0.2);
}
.online-status[data-state="waiting"] .dot,
.online-status[data-state="inviting"] .dot,
.online-status[data-state="answering"] .dot {
  background: var(--accent);
  animation: pulse-soft 1.2s infinite;
}
.online-status[data-state="lost"] .dot {
  background: var(--danger);
}

/* help */
.help-card {
  width: min(640px, 100%);
}
.rules-list {
  margin: 0 0 18px;
  padding-left: 20px;
  line-height: 1.5;
  font-size: 0.93rem;
}
.rules-list li {
  margin-bottom: 4px;
}
.bug-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.bug-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  border-radius: 14px;
  background: var(--panel-2);
}
.bug-item .tile-svg {
  flex: none;
}
.bug-item strong {
  display: block;
  font-size: 0.92rem;
}
.bug-item p {
  margin: 2px 0 0;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--muted);
}
.bug-item .bug-count {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.8rem;
}
.controls-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  font-size: 0.88rem;
  align-items: center;
}

/* end */
.end-card {
  text-align: center;
  overflow: hidden;
  width: min(440px, 100%);
}
.end-icon {
  display: inline-grid;
  place-items: center;
  width: 64px;
  height: 72px;
  margin: 8px auto 10px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--accent);
  color: var(--accent-ink);
}
.end-card.lose .end-icon {
  background: var(--muted);
  color: var(--panel-solid);
}
.end-card h2 {
  font-size: 2.2rem;
  margin-bottom: 4px;
}
.end-card .menu-actions {
  justify-content: center;
  margin-top: 18px;
}
.end-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.end-burst i {
  position: absolute;
  top: 34%;
  left: 50%;
  width: 7px;
  height: 8px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  animation: burst 1.3s cubic-bezier(0.1, 0.7, 0.3, 1) forwards;
  opacity: 0;
}
@keyframes burst {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.4);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)) scale(1);
  }
}

/* ==========================================================================
   Responsive: tablets
   ========================================================================== */
@media (max-width: 1100px) {
  :root {
    --card-w: 236px;
  }
  .drawer {
    width: 270px;
  }
}

/* ==========================================================================
   Responsive: phones — trays become strips at the top and bottom
   ========================================================================== */
@media (max-width: 760px) {
  :root {
    --topbar-h: 52px;
    --radius: 16px;
  }
  .topbar {
    top: 8px;
    left: 8px;
    right: 8px;
    gap: 4px;
    padding: 0 4px 0 4px;
  }
  .brand-name {
    display: none;
  }
  .brand {
    padding: 4px;
  }
  .turn-pill {
    justify-content: flex-start;
    font-size: 0.86rem;
    gap: 7px;
  }
  .icon-btn {
    width: 36px;
    height: 36px;
  }
  .top-sep,
  .hide-sm,
  .turn-no {
    display: none;
  }
  .pass-btn {
    padding: 6px 10px;
  }
  .player-card {
    left: 8px;
    right: 8px;
    width: auto;
    padding: 6px 6px 6px 8px;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .player-card[data-slot="top"] {
    top: calc(var(--topbar-h) + 14px);
  }
  .player-card[data-slot="bottom"] {
    bottom: 8px;
  }
  .pc-head {
    margin: 0;
    flex-direction: column;
    gap: 4px;
    width: 42px;
    flex: none;
  }
  .pc-avatar {
    display: none;
  }
  .pc-name {
    font-size: 0.78rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 42px;
  }
  .pc-sub,
  .meter-label {
    display: none;
  }
  .meter-wrap {
    align-items: center;
  }
  .queen-meter .pip {
    width: 7px;
    height: 8px;
  }
  .queen-meter {
    gap: 1px;
  }
  /* All pieces must fit on one row: tiles shrink to share the width instead of scrolling. */
  .tray {
    flex: 1;
    min-width: 0;
    display: flex;
    gap: 1px;
  }
  .tray-tile {
    flex: 1 1 0;
    min-width: 0;
    max-width: 46px;
    height: auto;
    aspect-ratio: 1 / 1;
    border-radius: 10px;
  }
  .tray-tile.empty {
    display: none;
  }
  .tray-count {
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    font-size: 0.62rem;
    padding: 0 3px;
  }
  .prompt,
  .app.log-open .prompt {
    transform: translateX(-50%);
    bottom: calc(76px);
    max-width: calc(100vw - 32px);
    font-size: 0.84rem;
    padding: 8px 14px;
  }
  .review-bar,
  .app.log-open .review-bar {
    transform: translateX(-50%);
    top: auto;
    bottom: 128px;
  }
  .zoom-controls {
    display: none;
  }
  .drawer {
    top: calc(var(--topbar-h) + 14px);
    right: 8px;
    left: 8px;
    bottom: 8px;
    width: auto;
  }
  .toasts {
    top: calc(var(--topbar-h) + 84px);
  }
  .level-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .exp-grid {
    grid-template-columns: 1fr;
  }
  .bug-list {
    grid-template-columns: 1fr;
  }
  .modal-card {
    padding: 18px;
  }
  .menu-card {
    padding: 0 16px 18px;
  }
  .menu-hero {
    margin: 0 -16px 12px;
  }
  .menu-hero h1 {
    font-size: 2rem;
  }
  .segmented button {
    font-size: 0.82rem;
    padding: 9px 4px;
    gap: 5px;
  }
  .menu-actions .primary-btn {
    flex: 1;
  }
}


/* ==========================================================================
   Online lobby
   ========================================================================== */
.online-card {
  width: min(600px, 100%);
}
.lobby-intro {
  margin: 0 0 14px;
  font-size: 0.9rem;
}
.field {
  display: block;
  margin-bottom: 14px;
}
.field input,
.lobby-pass input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.field input:focus,
.lobby-pass input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.lobby-view {
  display: none;
}
.online-card[data-view="list"] .lobby-view[data-view="list"],
.online-card[data-view="create"] .lobby-view[data-view="create"],
.online-card[data-view="wait"] .lobby-view[data-view="wait"],
.online-card[data-view="manual"] .lobby-view[data-view="manual"] {
  display: block;
}
.online-card[data-view="wait"] .field,
.online-card[data-view="manual"] .field,
.online-card[data-view="manual"] #btn-manual,
.online-card[data-view="wait"] #btn-manual {
  display: none;
}
.lobby-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.lobby-toolbar h3 {
  margin: 0;
}
.lobby-toolbar .grow {
  flex: 1;
}
.lobby-toolbar .primary-btn {
  padding: 9px 16px;
}
.lobby-toolbar .icon-btn.spinning .ui-icon {
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.room-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 46vh;
  overflow-y: auto;
}
.room {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  padding: 10px 12px;
}
.room-main {
  display: flex;
  align-items: center;
  gap: 12px;
}
.room-icon {
  flex: none;
  width: 34px;
  height: 38px;
  display: grid;
  place-items: center;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--accent-soft);
  color: var(--accent);
}
.room-icon.b {
  background: #262320;
  color: #e2d8c4;
}
.room-icon.w {
  background: #eee7d8;
  color: #2a251f;
}
.room-info {
  flex: 1;
  min-width: 0;
}
.room-name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-name .ui-icon {
  flex: none;
  color: var(--accent);
}
.room-meta {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-chip {
  flex: none;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--muted);
}
.room-chip.open {
  border-color: rgba(127, 162, 122, 0.6);
  color: var(--ok);
}
.room-chip.resume {
  border-color: var(--accent);
  color: var(--accent);
}
.room .pill-btn {
  flex: none;
}
.room.mine {
  border-color: var(--accent);
}
.lobby-pass {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.lobby-pass input {
  flex: 1;
}
.room-error {
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 0.85rem;
}
.room-empty {
  padding: 22px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
}
.room-empty strong {
  display: block;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.wait-box {
  text-align: center;
  padding: 18px 8px 6px;
}
.wait-title {
  font-family: var(--font-display);
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-size: 1.45rem !important;
  color: var(--text) !important;
  font-weight: 600;
  margin: 14px 0 4px !important;
}
.wait-hex {
  display: inline-flex;
  gap: 6px;
}
.wait-hex i {
  width: 14px;
  height: 16px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--accent);
  animation: wait 1.8s ease-in-out infinite;
}
.wait-hex i:nth-child(2) {
  animation-delay: 0.25s;
}
.wait-hex i:nth-child(3) {
  animation-delay: 0.5s;
}
@keyframes wait {
  0%,
  100% {
    opacity: 0.2;
  }
  50% {
    opacity: 1;
  }
}
.lobby-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}
.lobby-foot .online-status {
  margin: 0;
  flex: 1;
}
.link-btn {
  border: 0;
  background: none;
  padding: 4px 2px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-size: 0.85rem;
}
.link-btn:hover {
  color: var(--text);
}
.online-card .lobby-view .segmented {
  margin: 10px 0 14px;
}
@media (max-width: 760px) {
  .lobby-foot {
    flex-direction: column;
    align-items: stretch;
  }
  .room-meta {
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
