/* ═══════════════════════════════════════════════════════════
   Serpentiles — hex path puzzle (Tetravex-inspired chrome)
   ═══════════════════════════════════════════════════════════ */

:root,
[data-theme="light"] {
  --bg: #d8dde6;
  --bg-deep: #c5ccd8;
  --bg-glow: #e8f0fa;
  --bg-elevated: #f4f6fa;
  --bg-panel: #eef1f6;
  --bg-panel-top: #f8f9fc;
  --border: #b8c0ce;
  --border-strong: #8e99ab;
  --text: #1c2430;
  --text-muted: #5c6a7e;
  --heading: #152033;
  --accent: #1e88e5;
  --accent-strong: #1565c0;
  --success: #1f9d63;
  --warning: #c48a0a;
  --danger: #d64545;

  --header-bg-top: #ffffff;
  --header-bg-bot: #f4f6fa;
  --header-border: rgba(255, 255, 255, 0.7);
  --header-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 8px 24px rgba(28, 36, 48, 0.08);

  --control-track: #e4e8f0;
  --btn-ghost-top: #fff;
  --btn-ghost-bot: #eef1f6;
  --btn-ghost-hover: #fff;

  --stage-top: #c8ced9;
  --stage-bot: #aeb6c4;
  --empty-hex: #d0d6e0;
  --tile-select: #1565c0;

  --radius: 14px;
  --font: "Outfit", system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #0f1419;
  --bg-deep: #0a0e13;
  --bg-glow: rgba(30, 136, 229, 0.12);
  --bg-elevated: #1a222d;
  --bg-panel: #151c25;
  --bg-panel-top: #1a222d;
  --border: #2a3544;
  --border-strong: #3d4f66;
  --text: #e8eef6;
  --text-muted: #8b9bb0;
  --heading: #f0f4fa;
  --accent: #42a5f5;
  --accent-strong: #1e88e5;
  --success: #3ecf8e;
  --warning: #f0b429;
  --danger: #ef6b6b;

  --header-bg-top: #1e2836;
  --header-bg-bot: #151c25;
  --header-border: #2a3544;
  --header-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 8px 24px rgba(0, 0, 0, 0.35);

  --control-track: #0c1016;
  --btn-ghost-top: #1e2836;
  --btn-ghost-bot: #151c25;
  --btn-ghost-hover: #243041;

  --stage-top: #121820;
  --stage-bot: #0c1016;
  --empty-hex: #1a222d;
  --tile-select: #7ec0f0;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, var(--bg-glow) 0%, transparent 55%),
    linear-gradient(165deg, var(--bg) 0%, var(--bg-deep) 100%);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

kbd {
  display: inline-block;
  padding: 0.1em 0.4em;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 0.85em;
  font-family: inherit;
  font-weight: 600;
}

.app {
  max-width: 1480px;
  margin: 0 auto;
  padding: 1.1rem 1.5rem 1.75rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

/* ── Header ─────────────────────────────────────────────── */
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.15rem;
  background: linear-gradient(180deg, var(--header-bg-top) 0%, var(--header-bg-bot) 100%);
  border: 1px solid var(--header-border);
  border-radius: var(--radius);
  box-shadow: var(--header-shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  background: #1a1a1a;
  display: grid;
  place-items: center;
}

.logo svg {
  display: block;
  width: 44px;
  height: 44px;
}

.brand h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--heading);
}

.tagline {
  margin: 0.12rem 0 0;
  font-size: 0.84rem;
  color: var(--text-muted);
  font-weight: 500;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.size-group {
  display: inline-flex;
  padding: 3px;
  background: var(--control-track);
  border: 1px solid var(--border);
  border-radius: 11px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06) inset;
}

.size-btn {
  padding: 0.48rem 0.9rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.size-btn:hover {
  color: var(--text);
}

.size-btn.active {
  background: linear-gradient(180deg, #42a5f5, var(--accent-strong));
  color: #fff;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 2px 8px rgba(21, 101, 192, 0.35);
}

.timer {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 4.6rem;
  padding: 0.25rem 0.85rem;
  background: linear-gradient(180deg, var(--btn-ghost-top), var(--btn-ghost-bot));
  border: 1px solid var(--border);
  border-radius: 11px;
}

.timer-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 600;
}

.timer-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
}

.btn {
  padding: 0.55rem 1.15rem;
  border-radius: 11px;
  font-size: 0.9rem;
  font-weight: 600;
  transition: filter 0.15s, transform 0.1s, border-color 0.15s, background 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(180deg, #42a5f5, var(--accent-strong));
  color: #fff;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.28) inset,
    0 3px 10px rgba(21, 101, 192, 0.3);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-ghost {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--btn-ghost-top), var(--btn-ghost-bot));
  color: var(--text);
}

.btn-ghost:hover {
  border-color: var(--border-strong);
  background: var(--btn-ghost-hover);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 5.5rem;
  justify-content: center;
}

.theme-icon {
  font-size: 0.95rem;
  line-height: 1;
}

[data-theme="light"] .theme-icon-sun,
[data-theme="dark"] .theme-icon-moon {
  display: none;
}

[data-theme="light"] .theme-icon-moon,
[data-theme="dark"] .theme-icon-sun {
  display: inline;
}

/* ── Boards ─────────────────────────────────────────────── */
.main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.35rem;
  flex: 1;
  align-items: start;
}

@media (max-width: 960px) {
  .main {
    grid-template-columns: 1fr;
  }
}

.board-panel {
  background: linear-gradient(180deg, var(--bg-panel-top) 0%, var(--bg-panel) 100%);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  padding: 1.05rem 1.1rem 1.2rem;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.1);
  min-width: 0;
}

.panel-label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
  padding: 0 0.2rem;
}

.panel-label > span:first-child {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  color: var(--heading);
}

.panel-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.hex-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.75rem;
  background: linear-gradient(145deg, var(--stage-top) 0%, var(--stage-bot) 100%);
  border-radius: 12px;
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.12) inset,
    0 6px 18px rgba(0, 0, 0, 0.08);
  overflow: auto;
  min-height: 220px;
}

.hex-board {
  position: relative;
  flex-shrink: 0;
  user-select: none;
  touch-action: manipulation;
}

/* Hex slots */
.hex-slot {
  position: absolute;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.22));
}

.hex-slot.has-tile:hover {
  transform: scale(1.05);
  z-index: 3;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.3));
}

.hex-slot.selected {
  z-index: 6;
  transform: scale(1.08);
  filter: drop-shadow(0 0 0 3px var(--tile-select)) drop-shadow(0 8px 16px rgba(21, 101, 192, 0.35));
}

.hex-slot.dragging {
  opacity: 0.55;
}

.hex-slot.empty {
  cursor: default;
  filter: none;
  color: var(--empty-hex);
  opacity: 0.85;
}

.hex-slot.empty:hover {
  opacity: 1;
  filter: brightness(1.05);
}

.tile-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  pointer-events: none;
}

.hex-slot.has-tile {
  cursor: grab;
}

.hex-slot.has-tile:active {
  cursor: grabbing;
}

/* ── Footer ─────────────────────────────────────────────── */
.footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
  font-weight: 500;
}

.footer p {
  margin: 0.25rem 0;
}

.status {
  min-height: 1.4em;
  font-weight: 600;
  color: var(--accent-strong);
}

.status.success {
  color: var(--success);
}

.status.warn {
  color: var(--warning);
}

/* ── Modal ──────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20, 28, 40, 0.45);
  backdrop-filter: blur(8px);
  z-index: 2000;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-card {
  background: linear-gradient(180deg, var(--header-bg-top) 0%, var(--header-bg-bot) 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2rem 2.25rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
  animation: pop-in 0.28s ease;
  color: var(--text);
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.55rem;
  color: var(--success);
  letter-spacing: -0.02em;
}

.modal-card p {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-weight: 500;
}

.modal-actions {
  display: flex;
  gap: 0.65rem;
  justify-content: center;
}
