:root {
  --bg: #0b1020;
  --panel: #131a2e;
  --panel-2: #1a2340;
  --line: #27304f;
  --text: #e6e9f5;
  --muted: #9aa3c0;
  --fly: #ffb547;
  --human: #4cc9f0;
  --good: #3ddc84;
  --bad: #ff5c7a;
  --draw: #a78bfa;
  --accent: #7c8cff;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #1b2450 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; margin-bottom: .75rem; }
h3 { font-size: .95rem; margin: 1rem 0 .25rem; }
button, select, input { font: inherit; color: inherit; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 16px 24px; max-width: 1500px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.lang { display: flex; gap: 4px; }
.lang button { padding: 4px 10px; }
.lang button.on { background: var(--accent); border-color: var(--accent); color: #0b1020; }

.layout {
  display: grid; gap: 16px; padding: 0 24px 24px; max-width: 1500px; margin: 0 auto;
  grid-template-columns: 330px minmax(0, 1fr) 360px;
  grid-template-areas:
    "play brain memory"
    "train train about";
}
.play { grid-area: play; }
.brain { grid-area: brain; }
.memory { grid-area: memory; }
.train { grid-area: train; }
.about { grid-area: about; }

@media (max-width: 1250px) {
  .layout {
    grid-template-columns: 330px minmax(0, 1fr);
    grid-template-areas: "play brain" "memory brain" "train train" "about about";
  }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "play" "brain" "memory" "train" "about"; padding: 0 16px 16px; }
  .top { padding: 12px 16px; }
}

.panel {
  background: linear-gradient(180deg, var(--panel) 0%, #10162a 100%);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  min-width: 0;
}
.hint { color: var(--muted); font-size: .85rem; margin: .25rem 0 .75rem; }

button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; transition: background .15s, border-color .15s;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: #25306a; border-color: #3a4aa0; }
button.danger { border-color: #6b2b3b; }
button.danger:hover:not(:disabled) { border-color: var(--bad); }
select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; margin-left: 6px; }

.row { display: flex; gap: 8px; margin-top: 12px; }
.row.wrap { flex-wrap: wrap; align-items: center; }
.symbols { margin: 0 0 10px; color: var(--muted); }
button.auto {
  display: block; width: 100%; margin-top: 12px; padding: 10px 14px; font-weight: 600;
  background: linear-gradient(90deg, #3a2a10, #25306a); border-color: var(--fly);
}
button.auto.running { background: var(--panel-2); border-color: var(--bad); }
.auto-hint { margin: .4rem 0 0; text-align: center; }
.symbols b.fly { color: var(--fly); }
.symbols b.human { color: var(--human); }

/* board */
.board {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  grid-template-rows: repeat(3, 1fr);
  width: 100%; max-width: 300px; aspect-ratio: 1; margin: 0 auto;
}
.cell {
  position: relative; border-radius: 12px; border: 1px solid var(--line);
  background: #0f1528; font-size: 2.6rem; font-weight: 700; display: grid; place-items: center;
  padding: 0; min-width: 0; min-height: 0; transition: background .25s, box-shadow .25s;
}
.cell.fly { color: var(--fly); }
.cell.human { color: var(--human); }
.cell.ghost { color: rgba(255, 181, 71, .45); }
.cell.win { box-shadow: 0 0 0 3px var(--fly) inset; }
.cell.win.human-win { box-shadow: 0 0 0 3px var(--human) inset; }
.cell.focus { outline: 2px solid #fff; outline-offset: 2px; }
.cell .val {
  position: absolute; bottom: 4px; right: 6px; font-size: .72rem; font-weight: 600;
  color: var(--text); opacity: .9;
}
.status { min-height: 1.6em; text-align: center; margin-top: 10px; color: var(--muted); }
.status b { color: var(--text); }

.stepper {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px;
  padding-top: 12px; border-top: 1px solid var(--line);
}
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.speed { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .85rem; }
.speed input { width: 90px; }
.next.pulse { border-color: var(--fly); box-shadow: 0 0 0 3px rgba(255, 181, 71, .25); }

/* brain */
.phase { display: flex; align-items: center; gap: 10px; min-height: 30px; margin-bottom: 8px; }
.phase h2 { margin: 0; }
.tag {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; padding: 2px 8px;
  border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap;
}
.tag:empty { display: none; }
.badge {
  margin-left: auto; font-size: .72rem; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--line); color: var(--muted);
}
.badge.real { border-color: #2f6b4c; color: var(--good); }
.badge:empty { display: none; }
@media (max-width: 820px) { .phase { flex-wrap: wrap; } .badge { margin-left: 0; } }
.canvas-wrap { width: 100%; }
#brain { width: 100%; aspect-ratio: 1000 / 550; display: block; border-radius: 10px; background: #080c18; }
.narration {
  margin-top: 12px; min-height: 5.5em; padding: 12px 14px; border-radius: 10px;
  background: #0d1326; border: 1px solid var(--line);
}
.narration p { margin: 0 0 .4em; }
.narration p:last-child { margin-bottom: 0; }
.narration .num { font-variant-numeric: tabular-nums; font-weight: 600; }
.narration .good { color: var(--good); }
.narration .bad { color: var(--bad); }
.mini {
  display: inline-grid; grid-template-columns: repeat(3, 18px); gap: 2px; vertical-align: middle;
  margin-right: 10px; float: left;
}
.mini span {
  width: 18px; height: 18px; background: #1a2340; border-radius: 3px; font-size: 12px; line-height: 18px;
  text-align: center; font-weight: 700;
}
.mini span.f { color: var(--fly); }
.mini span.h { color: var(--human); }
.mini span.hl { outline: 1px solid var(--fly); }
.deltabar { display: inline-block; width: 120px; height: 8px; background: #1a2340; border-radius: 4px; position: relative; vertical-align: middle; margin: 0 6px; }
.deltabar i { position: absolute; top: 0; bottom: 0; border-radius: 4px; }

.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 0; margin: 10px 0 0; color: var(--muted); font-size: .82rem; }
.legend li { display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.active { background: #fff6d6; box-shadow: 0 0 6px #ffe08a; }
.dot.good { background: var(--good); }
.dot.bad { background: var(--bad); }
.dot.neutral { background: #3a4466; }
.line { width: 18px; height: 3px; border-radius: 2px; display: inline-block; }
.line.win { background: var(--good); }
.line.draw { background: var(--draw); }
.line.loss { background: var(--bad); }

/* memory */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: #0d1326; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.stat .k { color: var(--muted); font-size: .75rem; }
.stat .v { font-size: 1.15rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .v.good { color: var(--good); }
.stat .v.bad { color: var(--bad); }
.stat.wide { grid-column: span 2; }
.journal { max-height: 420px; overflow: auto; }
.jgame { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; background: #0d1326; }
.jgame header { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 4px; }
.jgame table { width: 100%; border-collapse: collapse; font-size: .8rem; font-variant-numeric: tabular-nums; }
.jgame th, .jgame td { text-align: right; padding: 2px 4px; }
.jgame th:first-child, .jgame td:first-child { text-align: left; }
.jgame th { color: var(--muted); font-weight: 500; }
.res-win { color: var(--good); }
.res-loss { color: var(--bad); }
.res-draw { color: var(--draw); }
.empty { color: var(--muted); font-size: .85rem; }

/* training */
.progress { height: 6px; background: #0d1326; border-radius: 3px; margin: 12px 0; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--good)); transition: width .2s; }
#curve { width: 100%; height: 220px; display: block; background: #0d1326; border-radius: 10px; border: 1px solid var(--line); }
.legend.small { margin-top: 6px; }
.exams { margin-top: 10px; font-size: .85rem; }
.exams table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.exams th, .exams td { padding: 3px 6px; text-align: right; border-bottom: 1px solid var(--line); }
.exams th:first-child, .exams td:first-child { text-align: left; }
.exams th { color: var(--muted); font-weight: 500; }

.about p { margin: 0 0 .7em; color: #c9cee3; font-size: .9rem; }
.about dl { margin: 0; font-size: .88rem; }
.about dt { font-weight: 650; margin-top: .5em; }
.about dd { margin: 0 0 0 .8em; color: #c9cee3; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 16px 24px; }
