/* Core layout */
:root {
  --bg: #0b1223;
  --panel: #121b2f;
  --panel-alt: #0f1729;
  --accent: #59d2ff;
  --accent-2: #9b8cff;
  --text: #f2f6ff;
  --muted: #b5c7e3;
  --success: #6df3c5;
  --danger: #ff6f78;
  --shadow: 0 15px 50px rgba(0,0,0,0.35);
  --tile-bg: #18243b;
  --tile-text: #f7fbff;
  --tile-border: rgba(255,255,255,0.25);
  --tile-human-bg: rgba(109,243,197,0.12);
  --tile-human-border: rgba(109,243,197,0.45);
  --tile-human-text: #e8fff4;
  --tile-ai-bg: rgba(255,111,120,0.12);
  --tile-ai-border: rgba(255,111,120,0.45);
  --tile-ai-text: #ffecef;
  font-family: 'Space Grotesk', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
}

.light-theme {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-alt: #eef2fb;
  --accent: #2b7cde;
  --accent-2: #7557e8;
  --text: #0f172a;
  --muted: #4b5563;
  --success: #0f9d58;
  --danger: #d93025;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  --tile-bg: #ffffff;
  --tile-text: #0f172a;
  --tile-border: rgba(15,23,42,0.15);
  --multiplier-text: #0b1b36;
  --multiplier-bg: #e3edff;
  --multiplier-border: rgba(15,23,42,0.14);
  --tile-human-bg: #eaf7ef;
  --tile-human-border: #c7e9d4;
  --tile-human-text: #0f172a;
  --tile-ai-bg: #fdecec;
  --tile-ai-border: #f6c9c9;
  --tile-ai-text: #0f172a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(120% 120% at 20% 20%, rgba(89,210,255,0.12), transparent 45%),
              radial-gradient(120% 120% at 80% 0%, rgba(155,140,255,0.12), transparent 50%),
              var(--bg);
  color: var(--text);
}

.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px 48px;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 24px;
}

.hero h1 {
  font-size: clamp(32px, 4vw, 48px);
  margin: 4px 0 12px;
  letter-spacing: -0.02em;
}

.hero h1 span {
  color: var(--accent);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 6px;
}

.lede {
  color: var(--muted);
  max-width: 640px;
  margin: 0 0 16px;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  }

.theme-toggle {
  min-width: 120px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--panel);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  box-shadow: var(--shadow);
  max-width: 720px;
  width: 100%;
  padding: 16px;
  max-height: 80vh;
  overflow: auto;
}

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

.modal-body h4 {
  margin-bottom: 6px;
}

.modal-body ul, .modal-body ol {
  color: var(--muted);
  margin-top: 4px;
  padding-left: 18px;
  line-height: 1.5;
}

.name-input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  min-width: 180px;
}

.status {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 12px;
  min-width: 320px;
}

.card {
  background: linear-gradient(160deg, rgba(89,210,255,0.18), rgba(89,210,255,0.08) 50%, rgba(155,140,255,0.2));
  border: 1px solid rgba(89,210,255,0.35);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.card .label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
}

.card .value {
  font-size: 32px;
  font-weight: 700;
}

.game {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 18px;
  align-items: start;
}

.board-section {
  background: var(--panel);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.04);
}

.board-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.board-header h2 {
  margin: 0;
}

.board-header p {
  margin: 0;
  color: var(--muted);
}

.board {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 4px;
  margin-top: 12px;
}

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  background: var(--panel-alt);
  border: 1px solid rgba(255,255,255,0.05);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--text);
  font-size: 16px;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.cell:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}

.cell .mult {
  font-size: 9px;
  text-transform: uppercase;
  color: var(--multiplier-text, var(--text));
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  letter-spacing: 0.05em;
  font-weight: 800;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--multiplier-bg, rgba(255,255,255,0.18));
  border: 1px solid var(--multiplier-border, rgba(255,255,255,0.2));
}

.cell.double-letter { background: #243859; color: #c8e4ff; }
.cell.triple-letter { background: #1f4f6f; color: #d8f2ff; }
.cell.double-word { background: #5b264f; color: #ffd6f3; }
.cell.triple-word { background: #612626; color: #ffd6d6; }

.cell.placed { border-color: var(--accent); }
.cell.existing { border-color: rgba(255,255,255,0.08); }
.cell.tile-human {
  background: var(--tile-human-bg);
  border-color: var(--tile-human-border);
  color: var(--tile-human-text);
}
.cell.tile-ai {
  background: var(--tile-ai-bg);
  border-color: var(--tile-ai-border);
  color: var(--tile-ai-text);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel {
  background: var(--panel);
  border-radius: 14px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.06);
  box-shadow: var(--shadow);
}

.panel.light {
  background: rgba(255,255,255,0.03);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.panel-header h3 {
  margin: 0;
}

.sub {
  margin: 0;
  color: var(--muted);
}

.rack {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
  margin: 14px 0;
}

.operators {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 8px;
  margin: 10px 0 6px;
}

.operator-btn {
  background: var(--tile-bg);
  border: 1px solid var(--tile-border);
  border-radius: 10px;
  padding: 10px 6px;
  color: var(--tile-text);
  font-weight: 700;
  cursor: pointer;
  position: relative;
  transition: transform 100ms ease, border-color 100ms ease, box-shadow 100ms ease;
}

.operator-btn .points {
  font-size: 12px;
  color: var(--muted);
  position: absolute;
  bottom: 6px;
  right: 8px;
}

.operator-btn.selected {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(155,140,255,0.35);
}

.tile {
  background: var(--tile-bg);
  border: 1px solid var(--tile-border);
  border-radius: 10px;
  padding: 8px;
  min-height: 64px;
  display: grid;
  place-items: center;
  color: var(--tile-text);
  font-weight: 700;
  font-size: 20px;
  cursor: pointer;
  position: relative;
  transform: translateY(0);
  transition: transform 320ms cubic-bezier(0.2, 0.75, 0.28, 1),
              border-color 180ms ease,
              box-shadow 220ms ease;
  will-change: transform;
}

.tile:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}

.tile.selected {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(155,140,255,0.35);
  transform: translateY(-8px);
  animation: rackSelectSlide 420ms cubic-bezier(0.2, 0.75, 0.28, 1);
}

.tile.human-tile {
  background: var(--tile-human-bg);
  border-color: var(--tile-human-border);
  color: var(--tile-human-text);
}

.tile.ai-tile {
  background: var(--tile-ai-bg);
  border-color: var(--tile-ai-border);
  color: var(--tile-ai-text);
}

.tile.selected:hover {
  transform: translateY(-8px);
}

.cell.incoming {
  color: transparent;
}

.cell.incoming .mult {
  opacity: 0;
}

.tile .points {
  font-size: 12px;
  color: var(--muted);
  position: absolute;
  bottom: 6px;
  right: 8px;
}

.flying-tile {
  position: fixed;
  z-index: 1100;
  pointer-events: none;
  box-shadow: 0 12px 24px rgba(0,0,0,0.3);
  transition: transform 420ms cubic-bezier(0.2, 0.75, 0.28, 1);
}

.cell.invalid-flash {
  animation: flashInvalid 500ms ease-in-out alternate infinite;
}

.center-message {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 14px 20px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 24px;
  text-align: center;
  color: #ffffff;
  letter-spacing: 0.01em;
  background: linear-gradient(135deg, rgba(217,48,37,0.9), rgba(217,48,37,0.78));
  border: 2px solid rgba(255,255,255,0.9);
  box-shadow: 0 20px 40px rgba(0,0,0,0.45), 0 0 0 8px rgba(217,48,37,0.25);
  max-width: min(90vw, 520px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;
  z-index: 1400;
}

.center-message.show {
  opacity: 1;
}

@keyframes rackSelectSlide {
  0% {
    transform: translateY(10px);
  }
  55% {
    transform: translateY(-10px);
  }
  100% {
    transform: translateY(-8px);
  }
}

@keyframes flashInvalid {
  from {
    box-shadow: 0 0 0 0 rgba(255,111,120,0.9);
    background: rgba(255,111,120,0.25);
    transform: scale(1);
  }
  to {
    box-shadow: 0 0 0 6px rgba(255,111,120,0.4);
    background: rgba(255,111,120,0.15);
    transform: scale(1.03);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile {
    transition: none;
  }
  .tile.selected {
    animation: none;
  }
  .cell.invalid-flash {
    animation: none;
  }
}

.panel-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.rules {
  margin: 8px 0 0;
  padding-left: 16px;
  color: var(--muted);
  line-height: 1.4;
}

.log {
  min-height: 120px;
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px;
}

.log-entry {
  padding: 8px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--muted);
  font-size: 14px;
}

.log-entry.success { border-color: rgba(109,243,197,0.5); color: var(--success); }
.log-entry.error { border-color: rgba(255,111,120,0.6); color: var(--danger); }

.primary, .ghost {
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--text);
  transition: transform 100ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.primary {
  background: linear-gradient(135deg, #59d2ff, #9b8cff);
  border-color: rgba(89,210,255,0.6);
  box-shadow: var(--shadow);
}

.primary:hover { transform: translateY(-1px); }

.ghost {
  background: transparent;
  border-color: rgba(255,255,255,0.12);
  color: var(--text);
}

.ghost:hover { border-color: rgba(255,255,255,0.3); }

code {
  background: rgba(255,255,255,0.06);
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--text);
}

@media (max-width: 1100px) {
  .game {
    grid-template-columns: 1fr;
  }
  .hero {
    flex-direction: column;
  }
}

@media (max-width: 720px) {
  .board {
    grid-template-columns: repeat(8, minmax(30px, 1fr));
  }
  .cell { font-size: 12px; }
  .rack { grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); }
}
