/* Layout: a teaching tool. Slim header, then either the topic index or one simulation (stage left, controls right, stacked on phones). */
:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #18202b;
  --muted: #5d6877;
  --line: #d8dee6;
  --accent: #2f5fd0;
  --box: #f08a24;
  --weight: #3b4452;
  --balloon: #e5484d;
  --ok: #1f9d55;
  --warn: #c2410c;
  --beam: #8a96a6;
  --machine: #4d7fd6;
  --machine2: #34589e;
  --mouth: #1d2f52;
  --water: #2f9ee0;
  --road: #4a5361;
  --lane: #f3f5f8;
  --font-body: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #11151b; --panel: #1a2029; --ink: #e9eef4; --muted: #9ba7b6; --line: #2c3541; --accent: #6f9bff;
  --box: #ff9d42; --weight: #b8c2cf; --balloon: #ff6b6f; --ok: #4ccf86; --warn: #ff8a4c; --beam: #7c889a; --machine: #3c63ad; --machine2: #6f9bff; --mouth: #0b1220; --water: #48b4f0; --road: #2a313b; --lane: #c9d2dc; color-scheme: dark; } }
:root[data-theme="dark"] {
  --bg: #11151b; --panel: #1a2029; --ink: #e9eef4; --muted: #9ba7b6; --line: #2c3541; --accent: #6f9bff;
  --box: #ff9d42; --weight: #b8c2cf; --balloon: #ff6b6f; --ok: #4ccf86; --warn: #ff8a4c; --beam: #7c889a; --machine: #3c63ad; --machine2: #6f9bff; --mouth: #0b1220; --water: #48b4f0; --road: #2a313b; --lane: #c9d2dc; color-scheme: dark; }

body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.6; }
.wrap { max-width: 1100px; margin: 0 auto; padding-block: 0 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
header.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 16px; border-bottom: 1px solid var(--line); margin-bottom: 24px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 20px; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.brand b { color: var(--accent); }
.brand-en { margin-left: 6px; font: 600 12px var(--font-num); color: var(--muted); letter-spacing: 0.02em; }
.tag { font-size: 12px; color: var(--muted); }
a { color: var(--accent); }
h1 { font-size: clamp(24px, 4vw, 34px); line-height: 1.3; margin: 0 0 8px; text-wrap: balance; }
h2 { font-size: 20px; margin: 0 0 4px; }
.lede { color: var(--muted); max-width: 62ch; margin: 0; }
.chip { display: inline-block; font: 600 12px var(--font-num); padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); }

/* index */
.crumb { display: inline-flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.crumb a { color: var(--muted); text-decoration: none; font-size: 13px; }
.crumb a:hover { color: var(--accent); }
.crumb span { color: var(--muted); font-size: 13px; }
.topic { margin-top: 28px; display: grid; gap: 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: grid; gap: 6px; align-content: start; text-decoration: none; color: var(--ink); }
.card .kind { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; color: var(--muted); }
.card h3 { margin: 0; font-size: 17px; }
.card p { margin: 0; font-size: 14px; color: var(--muted); }
a.card:hover { border-color: var(--accent); }
.card .state { font-size: 12px; font-weight: 600; }
.card .live { color: var(--ok); } .card .soon { color: var(--muted); }

/* sim */
.simhead { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; margin-bottom: 14px; }
.simgrid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
@media (max-width: 820px) { .simgrid { grid-template-columns: 1fr; } }
.stage { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; min-width: 0; }
.stage svg { display: block; width: 100%; height: auto; max-width: 100%; }
.eqbar { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; min-height: 64px; }
.eq { font: 600 clamp(22px, 3.4vw, 32px) var(--font-num); letter-spacing: 0.02em; }
.eq.broken { color: var(--warn); }
.eq.solved { color: var(--ok); }
.msg { font-size: 14px; color: var(--muted); text-align: center; padding: 0 16px 12px; min-height: 1.6em; }
.msg.warn { color: var(--warn); font-weight: 600; } .msg.ok { color: var(--ok); font-weight: 600; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: grid; gap: 18px; min-width: 0; }
.group { display: grid; gap: 8px; }
.glabel { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; color: var(--muted); }
.btns { display: flex; flex-wrap: wrap; gap: 6px; }
button { font: 600 14px var(--font-body); color: var(--ink); background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 7px 11px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { border-style: dashed; color: var(--warn); }
button.big { font: 700 18px var(--font-num); min-width: 56px; padding: 8px 12px; }
.sides { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.sides .btns { align-items: center; }
.side { font-size: 13px; color: var(--muted); min-width: 3em; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
input[type=text] { font: 600 16px var(--font-num); padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); min-width: 0; flex: 1 1 140px; }
input[type=range] { width: 100%; accent-color: var(--box); }
.guessline { display: flex; justify-content: space-between; font: 600 14px var(--font-num); color: var(--muted); }
.steps { margin: 0; padding-left: 0; list-style-position: inside; font: 500 14px var(--font-num); color: var(--muted); max-height: 160px; overflow: auto; }
.steps li.cur { color: var(--ink); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: var(--c); }
.note { margin-top: 18px; font-size: 14px; color: var(--muted); max-width: 72ch; }
.note b { color: var(--ink); }
.guessnum { font: 700 22px var(--font-num); color: var(--box); min-width: 3ch; }
.lines { display: grid; grid-template-columns: max-content max-content max-content 1fr; gap: 2px 10px; padding: 0 16px 16px; font: 500 15px var(--font-num); color: var(--muted); overflow-x: auto; justify-content: center; }
.lines:empty { display: none; }
.line { display: contents; }
.line span:nth-child(1) { text-align: right; }
.line span:nth-child(4) { font-family: var(--font-body); font-size: 13px; }
.line.cur { color: var(--ink); font-weight: 600; }
.line.bad span:nth-child(-n+3) { color: var(--warn); }
.plate { transform-box: fill-box; transform-origin: center; }
.plate.flip { animation: flip 0.45s ease; }
@keyframes flip { 0% { transform: scaleY(1); } 50% { transform: scaleY(0.05); } 100% { transform: scaleY(1); } }
.keys { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.keys button { font: 700 18px var(--font-num); padding: 8px 0; }
.keys button.x { color: var(--box); border-color: var(--box); }
.keys button[data-k=clr] { font: 600 13px var(--font-body); grid-column: span 2; }
.err.info { color: var(--muted); }
/* shorts mode: a 9:16 page that plays one scene by itself for screen recording */
body.shorts .wrap { box-sizing: border-box; min-height: 100vh; display: flex; flex-direction: column; justify-content: center; gap: 6px; padding-block: 8px; }
body.shorts header.top, body.shorts footer.site, body.shorts .simhead, body.shorts .panel, body.shorts .note, body.shorts .msg, body.shorts .lines { display: none; }
body.shorts .simgrid { grid-template-columns: 1fr; }
body.shorts .stage { border: none; }
body.shorts .msg { font-size: 16px; }
.capt { font: 700 clamp(24px, 6.5vw, 40px)/1.35 var(--font-body); text-align: center; min-height: 2.8em; display: flex; align-items: center; justify-content: center; }
/* one inner block so bold words stay in the sentence (flex would split them into separate items) */
.capt > span { display: block; text-wrap: balance; }
.capt b { color: var(--box); }
.capt.end small { display: block; margin-top: 6px; font-size: 0.5em; color: var(--muted); font-weight: 600; }
.err { color: var(--warn); font-size: 13px; min-height: 1.2em; }
footer.site { margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; }
footer.site a { color: var(--muted); }
