:root {
  --bg: #14201e;
  --panel: #1c2b28;
  --panel-2: #23342f;
  --line: #33474180;
  --ink: #e9e3d3;
  --ink-dim: #9aa89f;
  --accent: #d8a24a;
  --danger: #c0562e;
  --good: #4a9d7f;
  --radius: 12px;
  --font: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: radial-gradient(1200px 800px at 50% -10%, #1b2d29, var(--bg));
  color: var(--ink); font-family: var(--font); min-height: 100vh;
}
h1, h2, h3 { font-weight: 600; margin: 0; }
button {
  font-family: var(--font); cursor: pointer; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--ink); padding: 8px 12px;
  border-radius: 9px; font-size: 13px; transition: .12s;
}
button:hover:not(:disabled) { border-color: var(--accent); background: #2b3d38; }
button:disabled { opacity: .35; cursor: not-allowed; }
button.primary { background: var(--accent); color: #201a0c; border-color: var(--accent); font-weight: 600; }
button.danger { border-color: var(--danger); color: #f0b8a2; }
button.danger:hover:not(:disabled) { background: #3a221a; }

header {
  display: flex; align-items: center; gap: 20px; padding: 14px 22px;
  border-bottom: 1px solid var(--line); background: #12201d;
}
header .title { font-size: 18px; letter-spacing: .5px; }
header .title small { color: var(--ink-dim); font-weight: 400; font-size: 12px; display: block; }
header .round { margin-left: auto; font-size: 13px; color: var(--ink-dim); }
header .round b { color: var(--ink); font-size: 15px; }

/* Context track */
.ctx { display: flex; align-items: center; gap: 10px; }
.ctx .bar { width: 260px; height: 14px; border-radius: 8px; overflow: hidden;
  background: linear-gradient(90deg, #7a2a1e 0%, #b07a2a 45%, #2f7d5e 100%); position: relative; border: 1px solid var(--line); }
.ctx .bar .marker { position: absolute; top: -4px; width: 3px; height: 22px; background: #fff; box-shadow: 0 0 6px #000; }
.ctx .val { font-size: 13px; min-width: 92px; }
.ctx .val b { font-size: 16px; }

main { display: grid; grid-template-columns: minmax(520px, 1fr) 380px; gap: 18px; padding: 18px 22px; align-items: start; }

/* Board */
.board { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  gap: 10px; aspect-ratio: 1 / 1; }
.cell { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; display: flex; flex-direction: column; gap: 6px; position: relative; min-height: 92px; overflow: hidden; }
.cell-icon { position: absolute; inset: 0; display: grid; place-items: center; z-index: 0;
  color: var(--rc, #cfe0d8); opacity: .12; pointer-events: none; }
.cell-icon .rsvg { width: 54%; height: 54%; max-width: 96px; max-height: 96px; }
.cell.here .cell-icon { opacity: .2; }
.cell .rn { font-size: 13px; font-weight: 600; position: relative; z-index: 1; }
.cell .rz { font-size: 11px; color: var(--ink-dim); position: relative; z-index: 1; }
.cell.here { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.cell .pawns { display: flex; gap: 4px; flex-wrap: wrap; margin-top: auto; position: relative; z-index: 1; }
.pawn { width: 20px; height: 20px; border-radius: 50%; font-size: 10px; display: grid; place-items: center;
  color: #12100a; font-weight: 700; border: 2px solid #0004; }
.pawn.active { outline: 2px solid var(--ink); outline-offset: 1px; }

/* Center creature */
.creature { background: radial-gradient(circle at 50% 40%, #2a3d37, #16221f);
  border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; padding: 8px; }
.creature .body { font-size: 30px; filter: grayscale(.2); }
.creature .lbl { font-size: 10px; color: var(--ink-dim); letter-spacing: 1px; }
.organs { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; width: 100%; }
.organ { font-size: 10px; padding: 3px 6px 4px; border-radius: 7px; border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 1px; width: 46px; }
.organ .osvg { width: 22px; height: 22px; color: var(--oc); }
.organ.st-body { background: #24352f; }
.organ.st-extracted { background: #3a2a1a; border-style: dashed; }
.organ.st-extracted .osvg { opacity: .55; }
.organ.st-preserved { background: #24242c; }
.organ.st-preserved .osvg { color: #7a8a82 !important; opacity: .4; }
.organ.st-preserved span { text-decoration: line-through; color: #8a978f; }

.proj-head { display: flex; align-items: center; gap: 16px; margin-bottom: 6px; }
.proj-art { width: 72px; height: 72px; flex: 0 0 auto; animation: grow .8s ease; }
.proj-art .osvg { width: 100%; height: 100%; }
@keyframes grow { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* header controls */
#btn-settings, .pnp-link { font-size: 16px; padding: 6px 10px; text-decoration: none; line-height: 1;
  border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); color: var(--ink); }
#btn-settings:hover, .pnp-link:hover { border-color: var(--accent); }

/* settings knobs */
.knobs { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.knob { display: grid; grid-template-columns: 1fr 180px 40px; align-items: center; gap: 12px; }
.knob .kl { font-size: 13px; } .knob .kl small { display: block; color: var(--ink-dim); font-size: 11px; }
.knob input[type=range] { width: 100%; accent-color: var(--accent); }
.knob output { font-weight: 700; font-size: 15px; text-align: right; }
.preset-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 14px 0 4px;
  padding-bottom: 14px; border-bottom: 1px solid var(--line); font-size: 13px; }
.preset-bar select { font-family: var(--font); background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; }
.preset-bar button { padding: 6px 10px; font-size: 12px; }
.preset-bar #settings-msg { color: var(--good); flex-basis: 100%; }

/* Right column */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--ink-dim); margin-bottom: 12px; }

.turn .who { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.turn .who .dot { width: 26px; height: 26px; border-radius: 50%; }
.turn .who .name b { font-size: 15px; }
.turn .who .name small { display: block; color: var(--ink-dim); font-size: 11px; }
.turn .meta { display: flex; gap: 16px; font-size: 12px; color: var(--ink-dim); margin-bottom: 12px; }
.turn .meta b { color: var(--ink); }
.ap-dots { display: inline-flex; gap: 4px; }
.ap-dots i { width: 12px; height: 12px; border-radius: 50%; background: #3a4a44; display: inline-block; }
.ap-dots i.on { background: var(--accent); }
.actions { display: flex; flex-direction: column; gap: 8px; }
.hint { font-size: 11px; color: var(--ink-dim); margin-top: 8px; line-height: 1.5; }

/* Scoreboard */
.score-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.score-row:first-of-type { border-top: none; }
.score-row .dot { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto; }
.score-row .k { margin-left: auto; color: var(--ink-dim); font-size: 11px; }
.score-row .sc { font-weight: 700; font-size: 15px; min-width: 26px; text-align: right; }

/* Log */
.log { max-height: 210px; overflow-y: auto; font-size: 12px; line-height: 1.7; }
.log .l { color: var(--ink-dim); }
.log .l.extract, .log .l.preserve { color: #e7a173; }
.log .l.event { color: var(--accent); }
.log .l.round { color: var(--ink); font-weight: 600; }
.log .l.research, .log .l.move { color: #a8c3b6; }

.card-pop { margin-top: 10px; padding: 10px; border: 1px dashed var(--line); border-radius: 8px; font-size: 12px; }
.card-pop b { color: var(--accent); }

/* Overlays */
.overlay { position: fixed; inset: 0; background: #0a1210e0; display: grid; place-items: center; z-index: 50; padding: 24px; }
.overlay .box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; max-width: 640px; width: 100%; }
.proj-stages { display: flex; flex-direction: column; gap: 10px; margin: 18px 0; }
.proj-stage { opacity: 0; transform: translateY(8px) scale(.96); transition: .5s;
  padding: 10px 16px; border-left: 3px solid var(--accent); background: var(--panel-2); border-radius: 8px;
  display: flex; align-items: center; gap: 14px; }
.proj-stage.show { opacity: 1; transform: none; }
.pstage-art { width: 46px; height: 46px; flex: 0 0 auto; }
.pstage-art .osvg { width: 100%; height: 100%; }
.pstage-tx { min-width: 0; }
.proj-stage .st { font-size: 11px; color: var(--ink-dim); letter-spacing: 1px; }
.proj-stage .tx { font-size: 15px; }
.proj-stage:nth-child(1) .tx { font-size: 14px; }
.proj-stage:nth-child(4) .tx { font-size: 18px; color: var(--good); }

.ending .badge { display: inline-block; padding: 6px 14px; border-radius: 20px; font-weight: 600; margin-bottom: 10px; }
.ending.living .badge { background: #22503f; color: #bff0d8; }
.ending.specimen .badge { background: #5a4320; color: #f0d4a0; }
.ending.hollow .badge { background: #4a241a; color: #f0b09a; }
.ending .desc { color: var(--ink-dim); line-height: 1.7; font-size: 14px; margin: 10px 0 18px; }
.final-scores .score-row { border-color: var(--line); }
.lead-tag { font-size: 10px; background: var(--accent); color: #201a0c; padding: 2px 6px; border-radius: 5px; font-weight: 700; }

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