:root {
  --bg: #0f1117;
  --panel: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --accent-strong: #2563eb;
  --gem-1: #ff5050;
  --gem-2: #50dc78;
  --gem-3: #508cff;
  --gem-4: #f0f0f0;
  --gem-5: #ffdc3c;
  --page-width: min(1680px, 96vw);
  --page-pad: clamp(1rem, 2.5vw, 2rem);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem var(--page-pad);
  border-bottom: 1px solid #334155;
  background: #12151c;
  width: 100%;
}

.topbar .title { font-weight: 600; flex: 1; min-width: 0; }

.topbar .back {
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

.topbar .badge {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.lang-switch {
  display: inline-flex;
  gap: 0.25rem;
  margin-left: 1rem;
  padding: 0.2rem;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
}

.lang-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.03em;
}

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

.lang-btn.active {
  background: var(--accent-strong);
  color: #fff;
}

#app {
  width: var(--page-width);
  max-width: none;
  margin: 0 auto;
  padding: 1.25rem 0 2rem;
}

.screen { display: none; width: 100%; }
.screen.active { display: block; width: 100%; }

#splash {
  padding: 1.5rem 0 2rem;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

#splash h2 {
  color: #c4b5fd;
  font-weight: 500;
  margin: 0 0 1rem;
  font-size: clamp(0.95rem, 2.5vw, 1.15rem);
  text-align: left;
}

.splash-copy .authors,
.splash-copy .source {
  text-align: left;
}

.splash-kicker {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: #a78bfa;
  margin: 0 0 0.75rem;
  text-align: left;
}

.splash-pitch {
  color: #cbd5e1;
  line-height: 1.65;
  margin: 0 0 1.5rem;
  font-size: 0.95rem;
  text-align: left;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(139, 92, 246, 0.1));
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 1rem 1.1rem;
}

.splash-pitch strong {
  color: #fde047;
}

.splash-pitch em {
  color: #86efac;
  font-style: normal;
}

.authors {
  color: var(--muted);
  line-height: 1.7;
  margin: 1rem 0;
}

.source {
  margin: 0 0 1.5rem;
}

.source a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.source a:hover {
  text-decoration: underline;
}

.site-footer {
  width: var(--page-width);
  max-width: none;
  margin: 0 auto;
  padding: 1.25rem 0 2rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
  border-top: 1px solid #334155;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.footer-authors {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
}

.btn {
  border: 1px solid #475569;
  background: #1e293b;
  color: var(--text);
  padding: 0.7rem 1.4rem;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.98rem;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
}

.btn:hover { border-color: var(--accent); }

.btn.primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}

.config-form {
  display: grid;
  gap: 1rem;
  max-width: 420px;
  margin: 0 auto;
}

.config-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.config-form input,
.config-form select {
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid #475569;
  background: #0f172a;
  color: var(--text);
  font-size: 1rem;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) auto;
  width: 100%;
  gap: clamp(1.5rem, 2.5vw, 2.75rem);
  align-items: start;
}

.panel {
  width: 100%;
  min-width: 0;
  max-width: none;
  max-height: none;
  overflow-x: hidden;
  overflow-y: visible;
  overscroll-behavior: contain;
  background: var(--panel);
  border: 1px solid #475569;
  border-radius: 14px;
  padding: 1.5rem 1.75rem;
  font-size: 1rem;
  line-height: 1.55;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.panel .stat {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  text-align: center;
}

.panel .stat.stat-wide {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}

.panel .stat-label {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.panel .stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  margin-top: 0.2rem;
}

.panel .decision {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid #334155;
  border-radius: 10px;
  font-size: 0.82rem;
}

.panel .decision > strong {
  display: block;
  color: #93c5fd;
  margin-bottom: 0.5rem;
}

.panel .decision-short {
  margin: 0.35rem 0 0.5rem;
  color: #86efac;
  font-weight: 600;
}

.panel .decision-note {
  margin: 0 0 0.5rem;
  color: #cbd5e1;
  line-height: 1.5;
  font-size: 0.78rem;
}

.ai-live {
  margin: 0.5rem 0;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #bbf7d0;
  font-size: 0.8rem;
  line-height: 1.45;
  font-weight: 600;
}

.ai-log-label {
  margin: 0.65rem 0 0.35rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
}

.ai-log {
  margin: 0;
  padding-left: 1.1rem;
  max-height: min(32rem, 42vh);
  overflow-y: auto;
  font-size: 0.88rem;
  line-height: 1.5;
  color: #94a3b8;
}

.ai-log li {
  margin-bottom: 0.35rem;
}

.ai-log-empty {
  margin: 0.35rem 0 0;
  font-size: 0.74rem;
  color: #64748b;
  font-style: italic;
}

.ml-help {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #334155;
  font-size: 0.78rem;
  color: #94a3b8;
  line-height: 1.45;
}

.ml-help summary {
  cursor: pointer;
  color: #93c5fd;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.ml-help p {
  margin: 0.35rem 0 0;
}

.board-wrap {
  justify-self: end;
  text-align: center;
  position: sticky;
  top: 4.5rem;
  background: var(--panel);
  border: 1px solid #475569;
  border-radius: 14px;
  padding: 1.5rem;
  min-width: min-content;
}

#board {
  display: block;
  width: auto;
  height: auto;
  max-width: none;
  background: #232338;
  border: 2px solid #64648a;
  border-radius: 8px;
  image-rendering: pixelated;
}

.hint {
  margin-top: 0.75rem;
  color: #fde047;
  min-height: 1.4rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-top: 1.5rem;
}

.banner {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.banner.over { color: #f87171; }
.banner.win { color: #4ade80; }

@media (min-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .panel .stat.stat-wide {
    grid-column: 1 / -1;
  }

  .ml-help {
    font-size: 0.9rem;
  }

  .panel .decision {
    font-size: 0.9rem;
  }
}

@media (max-width: 980px) {
  .game-layout {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .board-wrap {
    order: -1;
    position: static;
    top: auto;
    justify-self: center;
    width: auto;
    max-width: none;
  }

  .panel {
    width: 100%;
    max-width: 520px;
    max-height: min(48vh, 26rem);
    overflow-y: auto;
  }
}

@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
  }

  .lang-switch {
    margin-left: 0;
  }
}
