/* Nandom Playground. Brand tokens from nandom.com: dark ink ground, paper text, gold accent. Single dark theme. */
:root {
  --ink: #0e1014; --ink2: #161922; --panel: #1b1f2a; --line: #2b3140; --paper: #ece8df; --muted: #9a9686;
  --gold: #ffb454; --slot: #0a0c10; --slot-line: #232836; --danger: #ff5a5a; --dead-word: #ff2a2a;
  --display: "Fraunces", Georgia, serif; --body: "Newsreader", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --r: 8px; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--ink); color: var(--paper); font-family: var(--body); font-size: 16px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0; line-height: 1.2; text-wrap: balance; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px; padding: 10px 20px;
  background: color-mix(in srgb, var(--ink) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--paper); }
.brand-name { font-family: var(--display); font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.brand-sub { font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); padding-top: 4px; }
.tabs { display: flex; gap: 2px; }
.tabs a { font-family: var(--mono); font-size: 13px; text-decoration: none; color: var(--muted); padding: 7px 12px; border-radius: 6px; }
.tabs a:hover { color: var(--paper); background: var(--ink2); }
.tabs a.active { color: var(--ink); background: var(--gold); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.session-pick { display: flex; align-items: center; gap: 6px; }
.lbl { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
select, input[type=number], input[type=text] { background: var(--ink2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-family: var(--mono); font-size: 13px; }
input[type=number] { width: 100%; }
select { cursor: pointer; }
.py-status { display: flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.py-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.py-status.ready i { background: #5ad19a; }
.py-status.busy i { background: var(--gold); animation: pulse 1s infinite; }
.py-status.error i { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 14px; cursor: pointer; font-family: var(--mono); font-size: 13px; }
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--gold); color: var(--ink); border-color: var(--gold); font-weight: 600; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.iconbtn { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; width: 34px; height: 32px; cursor: pointer; display: inline-grid; place-items: center; }
.iconbtn:hover { border-color: var(--muted); }
.iconbtn svg { width: 16px; height: 16px; fill: var(--paper); }

main { padding: 20px; }
.page { max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; align-items: baseline; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 28px; }
.page-head p { margin: 0; color: var(--muted); }
.empty { border: 1px dashed var(--line); border-radius: var(--r); padding: 48px 24px; text-align: center; color: var(--muted); }
.empty h2 { color: var(--paper); font-size: 22px; margin-bottom: 8px; }

/* build */
.build { display: grid; grid-template-columns: 220px minmax(0, 1fr) 280px; gap: 18px; align-items: start; }
.palette, .side { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 10px; }
.section-label { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 4px 0 2px; }
.fam { border: 1px solid var(--line); background: var(--panel); border-radius: var(--r); padding: 10px 12px; cursor: grab; display: flex; flex-direction: column; gap: 2px; }
.fam:hover { border-color: var(--gold); }
.fam:active { cursor: grabbing; }
.fam b { font-family: var(--display); font-size: 17px; font-weight: 600; }
.fam span { font-size: 13.5px; color: var(--muted); line-height: 1.35; }
.fam .add { align-self: flex-start; margin-top: 6px; }
.canvas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.block { background: var(--ink2); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; min-width: 0; }
.block.wide { grid-column: 1 / -1; }
.block-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.block-head h2 { font-size: 18px; }
.block-head .grow { flex: 1; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { display: flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.info { position: relative; display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--line); font-size: 10px; color: var(--muted); cursor: help; font-family: var(--mono); }
.info:hover::after, .info:focus::after { content: attr(data-tip); position: absolute; left: 50%; bottom: 140%; transform: translateX(-50%); width: 240px; padding: 8px 10px; background: var(--paper); color: var(--ink); font-family: var(--body); font-size: 13.5px; line-height: 1.35; border-radius: 6px; z-index: 30; white-space: normal; text-align: left; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 5px 10px; font-family: var(--mono); font-size: 12px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--gold); color: var(--ink); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-family: var(--mono); font-size: 12px; color: var(--muted); user-select: none; }
.switch input { appearance: none; width: 34px; height: 20px; border-radius: 10px; background: var(--line); position: relative; cursor: pointer; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--paper); transition: left .15s; }
.switch input:checked { background: var(--gold); }
.switch input:checked::after { left: 17px; background: var(--ink); }
.dropzone { border: 1.5px dashed var(--line); border-radius: var(--r); padding: 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; min-height: 120px; transition: border-color .15s, background .15s; }
.dropzone.over { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 6%, transparent); }
.dropzone .hint { grid-column: 1 / -1; align-self: center; text-align: center; color: var(--muted); font-size: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.card-head { display: flex; align-items: center; gap: 8px; }
.card-head b { font-family: var(--display); font-size: 17px; flex: 1; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.stepper button { border: 0; background: var(--ink2); width: 28px; height: 28px; cursor: pointer; font-family: var(--mono); }
.stepper input { width: 46px; border: 0; border-radius: 0; text-align: center; padding: 4px 0; background: var(--ink); }
.x { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 2px 4px; }
.x:hover { color: var(--danger); }
.preset { text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: var(--r); padding: 9px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.preset:hover { border-color: var(--gold); }
.preset b { font-family: var(--display); font-size: 15px; font-weight: 600; }
.preset span { font-size: 13px; color: var(--muted); }
.summary { background: var(--ink2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; font-size: 14.5px; }
.summary .row { display: flex; justify-content: space-between; gap: 8px; font-family: var(--mono); font-size: 12.5px; }
.warn { color: var(--gold); font-size: 13.5px; line-height: 1.4; }
.err { color: var(--danger); font-size: 13.5px; line-height: 1.4; }

/* watch */
.watch { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; height: calc(100vh - 100px); min-height: 520px; }
.watch-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.watch-bar .stepinfo { font-family: var(--mono); font-size: 13px; color: var(--muted); min-width: 170px; }
.watch-bar .stepinfo b { color: var(--paper); font-weight: 500; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-family: var(--mono); font-size: 11.5px; color: var(--muted); margin-left: auto; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.stage { position: relative; background: radial-gradient(ellipse at center, #141822 0%, var(--ink) 70%); border: 1px solid var(--line); border-radius: var(--r); overflow: auto; }
.stage svg { display: block; }
.slot-rect { cursor: pointer; }
.slot-rect:hover { stroke: var(--gold); }
.agent { cursor: pointer; }
.agent .ring { fill: none; stroke: var(--gold); stroke-width: 2; opacity: 0; }
.agent.revive .ring { animation: revive 900ms ease-out; }
@keyframes revive { 0% { opacity: 1; r: 10; } 100% { opacity: 0; r: 30; } }
.agent.zombie > .body { opacity: .22; }
.agent.dead > .body { opacity: .1; }
.dim .arrow:not(.hl) { opacity: .08; }
.dim .agent:not(.hl) { opacity: .35; }
.timeline { display: flex; flex-direction: column; gap: 4px; }
.tl-wrap { position: relative; height: 34px; }
.tl-wrap canvas { position: absolute; inset: 0 0 auto 0; width: 100%; height: 14px; }
.tl-wrap input[type=range] { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; margin: 0; accent-color: var(--gold); }
.speed { display: flex; align-items: center; gap: 6px; }

/* modal cards */
.modal-back { position: fixed; inset: 0; background: rgba(5, 6, 9, .6); z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--ink2); border: 1px solid var(--line); border-radius: 12px; width: min(440px, 100%); max-height: calc(100vh - 40px); overflow: auto; position: relative; }
.modal.wide { width: min(980px, 100%); }
.modal-close { position: absolute; top: 8px; right: 8px; z-index: 2; }
.modal .tcard-title { padding-right: 26px; }
.modal .faces { margin-right: 26px; }
.tcard { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.tcard-frame { border-radius: 10px; padding: 3px; background: linear-gradient(150deg, var(--c), color-mix(in srgb, var(--c) 30%, var(--ink)) 60%, var(--c)); }
.tcard-inner { background: var(--panel); border-radius: 8px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.tcard-title { display: flex; align-items: center; gap: 10px; }
.tcard-title .dot { width: 26px; height: 26px; border-radius: 50%; background: var(--c); display: grid; place-items: center; color: var(--ink); font-family: var(--mono); font-size: 12px; font-weight: 600; }
.tcard-title h3 { font-size: 20px; flex: 1; }
.badge { font-family: var(--mono); font-size: 11px; padding: 2px 8px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); }
.badge.alive { color: #5ad19a; border-color: #5ad19a55; }
.badge.zombie { color: var(--muted); }
.badge.dead { color: var(--danger); border-color: #ff5a5a55; }
.art { background: var(--slot); border: 1px solid var(--slot-line); border-radius: 6px; padding: 10px; }
.bits { display: flex; flex-wrap: wrap; gap: 3px; }
.bits i { width: 14px; height: 14px; border-radius: 3px; background: var(--line); }
.bits i.on { background: var(--c); }
.poly { font-family: var(--mono); font-size: 12px; line-height: 1.6; max-height: 230px; overflow: auto; }
.poly .o { color: var(--c); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--ink2); border-radius: 6px; padding: 6px 8px; }
.stat .k { font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.stat .v { font-family: var(--mono); font-size: 15px; }
.flavor { font-style: italic; color: var(--muted); font-size: 14px; margin: 0; }
.faces { display: flex; gap: 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { font-family: var(--mono); font-size: 12px; color: var(--muted); padding-top: 2px; }
.kv dd { margin: 0; font-family: var(--mono); font-size: 13px; }
.hp { height: 8px; border-radius: 4px; background: var(--slot); overflow: hidden; border: 1px solid var(--slot-line); }
.hp > i { display: block; height: 100%; }
.balance { display: flex; flex-direction: column; gap: 4px; }
.balance .bar { height: 10px; border-radius: 3px; }
.hist { font-family: var(--mono); font-size: 13px; display: flex; flex-direction: column; }
.hist .row { display: grid; grid-template-columns: 70px 1fr auto; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--line); align-items: center; }

/* results */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 18px; }
.tile { background: var(--ink2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.tile .k { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.tile .v { font-family: var(--display); font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); gap: 14px; }
.chart { background: var(--ink2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 12px 6px; min-width: 0; }
.chart h3 { font-size: 16px; margin-bottom: 2px; }
.chart p { margin: 0 0 6px; font-size: 13.5px; color: var(--muted); }
.u-legend { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.u-legend .u-marker { border-radius: 2px; }
table.measures { width: 100%; border-collapse: collapse; font-size: 14px; }
table.measures td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.measures td:first-child { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
table.measures td.v { font-family: var(--mono); text-align: right; white-space: nowrap; }
table.measures td.d { color: var(--muted); }
.tablebox { background: var(--ink2); border: 1px solid var(--line); border-radius: var(--r); overflow-x: auto; margin-top: 18px; }

/* code */
.code { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; height: calc(100vh - 150px); min-height: 480px; }
.sessions { display: flex; flex-direction: column; gap: 6px; overflow: auto; }
.sess { text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: var(--r); padding: 8px 10px; cursor: pointer; }
.sess.on { border-color: var(--gold); }
.sess b { display: block; font-family: var(--display); font-size: 15px; font-weight: 600; }
.sess span { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.editor-pane { display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; }
.filetabs { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.filetabs button { border: 1px solid var(--line); background: transparent; border-radius: 6px; padding: 4px 10px; font-family: var(--mono); font-size: 12.5px; cursor: pointer; color: var(--muted); }
.filetabs button.on { color: var(--ink); background: var(--paper); border-color: var(--paper); }
.filetabs button.changed::after { content: " ●"; color: var(--gold); }
.editor-box { flex: 1; min-height: 0; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.CodeMirror { height: 100%; font-family: var(--mono); font-size: 13px; background: var(--slot); color: var(--paper); }
.CodeMirror-gutters { background: var(--ink2); border-right: 1px solid var(--line); }
.CodeMirror-linenumber { color: #5b6170; }
.CodeMirror-cursor { border-left-color: var(--gold); }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: #2b3140 !important; }
.cm-s-default .cm-keyword { color: #ff7a90; } .cm-s-default .cm-def, .cm-s-default .cm-variable-2 { color: #7aa2ff; }
.cm-s-default .cm-string, .cm-s-default .cm-string-2 { color: #9ad36a; } .cm-s-default .cm-number { color: #ffd34e; }
.cm-s-default .cm-comment { color: #8a8676; font-style: italic; } .cm-s-default .cm-builtin { color: #56c6e6; }
.cm-s-default .cm-operator { color: #ffb454; } .cm-s-default .cm-property, .cm-s-default .cm-variable { color: #ece8df; }
.cm-s-default .cm-atom, .cm-s-default .cm-variable-3 { color: #ffd34e; } .cm-s-default .cm-meta { color: #56c6e6; }
.diff { font-family: var(--mono); font-size: 12.5px; line-height: 1.5; white-space: pre; overflow: auto; max-height: 70vh; background: var(--slot); border-radius: 6px; padding: 8px 0; }
.diff .add { background: #5ad19a22; color: #9ad36a; } .diff .del { background: #ff5a5a22; color: #ff9a9a; }
.diff div { padding: 0 12px; } .diff .gap { color: var(--muted); }
.readonly-note { font-size: 14px; color: var(--muted); }

/* history */
table.runs { width: 100%; border-collapse: collapse; font-size: 14px; }
table.runs th { text-align: left; font-family: var(--mono); font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.runs td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.runs td.m { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
table.runs tr.current td { background: color-mix(in srgb, var(--gold) 7%, transparent); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.name-input { width: 100%; background: transparent; border: 1px solid transparent; font-family: var(--body); font-size: 15px; padding: 3px 6px; }
.name-input:hover, .name-input:focus { border-color: var(--line); background: var(--ink); }

#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--paper); color: var(--ink); padding: 9px 16px; border-radius: 8px; font-size: 14.5px; box-shadow: 0 8px 30px rgba(0,0,0,.4); max-width: 560px; }
.toast.error { background: var(--danger); color: #fff; }
.errorbox { white-space: pre-wrap; font-family: var(--mono); font-size: 12px; background: var(--slot); border: 1px solid var(--danger); border-radius: 6px; padding: 10px; max-height: 50vh; overflow: auto; color: #ffb3b3; }

@media (max-width: 1100px) { .build { grid-template-columns: 200px minmax(0, 1fr); } .side { grid-column: 1 / -1; position: static; } }
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 10px; } .topbar-right { margin-left: 0; flex-wrap: wrap; }
  .build, .code { grid-template-columns: 1fr; } .palette { position: static; } .canvas { grid-template-columns: 1fr; }
  .charts { grid-template-columns: 1fr; } .code { height: auto; } .editor-box { height: 60vh; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
