@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --faint: #86868b;
  --line: #d2d2d7;
  --line-soft: rgba(0, 0, 0, 0.08);
  --surface: #ffffff;
  --alt: #f5f5f7;
  --brand: #005ea2;
  --brand-dark: #004785;
  --brand-soft: rgba(0, 94, 162, 0.08);
  --gap: #c2410c;
  --gap-soft: #fff4ec;
  --gap-line: rgba(194, 65, 12, 0.3);
  --ok: #1f7a4d;
  --ok-soft: #eef7f1;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --ease: cubic-bezier(0.3, 0.7, 0.4, 1);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--alt);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p, ol, ul, dl, dd { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button { font: inherit; color: inherit; }
a { color: var(--brand); }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 50;
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 999px; text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: 10px; }

.kicker, .ro-kicker, .gap-label, .ex-kicker {
  font-size: 11px; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; color: var(--brand);
}
.kicker--tight { margin-top: 14px; margin-bottom: 6px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 18px;
  padding: 18px;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 9px 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 14px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn:active { transform: scale(0.98); }
.btn[disabled] { cursor: not-allowed; opacity: 0.45; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn--run { background: var(--ink); border-color: var(--ink); color: #fff; font-size: 16px; padding: 11px 26px; min-height: 46px; }
.btn--run svg { width: 14px; height: 14px; }
.btn--run:hover { background: #000; border-color: #000; color: #fff; }
.btn--run[disabled] { opacity: 1; background: #b8b8bd; border-color: #b8b8bd; }
.btn--quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn--sm { min-height: 32px; padding: 5px 12px; font-size: 13px; }

/* ---------- header ---------- */

.top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 36px; height: 36px; flex: none; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.brand-sub { font-size: 12px; color: var(--muted); line-height: 1.3; }

.tabs { display: flex; gap: 2px; padding: 3px; background: #ebebef; border-radius: 999px; margin: 0 auto; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; border: 0; background: transparent; cursor: pointer;
  padding: 7px 14px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.tab[aria-selected='true'] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.tab-k {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  font-size: 11px; background: var(--brand-soft); color: var(--brand);
}
.top-tools { display: flex; gap: 6px; align-items: center; }
.t-short { display: none; }
.foot { display: none; }
.b-dock { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; min-height: 34px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 600; cursor: pointer;
  text-decoration: none; color: var(--ink); white-space: nowrap;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip--link { color: var(--brand); }
#open-log span[aria-hidden] { color: var(--gap); }
#open-log.is-pulse { animation: pulse 0.9s var(--ease) 2; }
@keyframes pulse { 50% { background: var(--gap-soft); border-color: var(--gap); transform: scale(1.05); } }

/* ---------- Part A layout ---------- */

.a-grid { display: grid; gap: 16px; padding: 16px; }
.a-left, .a-right { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.a-stage { display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: 0; }
.a-stage > * { flex-shrink: 0; }

.levels ol { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.lvl {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px;
  border: 1px solid var(--line-soft); background: var(--surface); border-radius: 14px; cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.lvl:hover { border-color: var(--brand); }
.lvl-n {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--alt); font-size: 12px; font-weight: 700;
}
.lvl-t { font-size: 11px; font-weight: 600; color: var(--muted); line-height: 1.2; text-align: center; }
.lvl.is-current { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.lvl.is-current .lvl-n { background: var(--brand); color: #fff; }
.lvl.is-done .lvl-n { background: var(--ok-soft); color: var(--ok); }
.lvl.is-current.is-done .lvl-n { background: var(--ok); color: #fff; }

/* Headings take focus only so screen readers land on the news (Part B's verdict does the same). */
.brief h2:focus, .readout h3:focus { outline: none; }
.brief h2 { font-size: 23px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.15; margin: 4px 0 6px; }
.brief-story { color: var(--muted); font-size: 14px; }
.brief-dl { display: grid; gap: 8px; margin: 12px 0; padding: 12px 14px; background: var(--alt); border-radius: 14px; }
.brief-dl dt { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.brief-dl dd { font-size: 14px; font-weight: 500; }
.brief-hint { font-size: 13px; color: var(--muted); }
.brief-hint::before { content: 'Hint  '; font-weight: 700; color: var(--ink); }

.rule-head h3 { font-size: 17px; font-weight: 700; letter-spacing: -0.015em; }
.rule-head p { font-size: 13px; color: var(--muted); margin: 2px 0 10px; }
.rule-head .rule-cost {
  display: flex; flex-wrap: wrap; gap: 2px 10px; margin: -4px 0 10px; padding: 7px 10px; border-radius: 10px;
  background: var(--alt); color: #3a3a3c; font-size: 12.5px;
}
.rule-cost b { color: var(--ink); font-variant-numeric: tabular-nums; }
.rc-best { color: var(--ok); font-weight: 600; }
.chk {
  display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 999px; font-size: 10.5px; font-weight: 600;
  line-height: 1.6; white-space: nowrap; background: #ebebef; color: #3a3a3c; vertical-align: 1px;
}
.chk--camera { background: #e6f0f8; color: var(--brand-dark); }
.chk--teacher, .chk--inspector { background: #fdf0e6; color: #9a3412; }
.chk--person { background: var(--gap); color: #fff; }
.terms { display: grid; gap: 6px; }
.term {
  display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: 'sw text' 'sw weight';
  align-items: center; column-gap: 10px; row-gap: 6px;
  padding: 10px 10px 10px 10px; border-radius: 14px; border: 1px solid var(--line-soft); background: var(--surface);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.term.is-on { background: var(--brand-soft); border-color: rgba(0, 94, 162, 0.22); }
.term--watcher { border-style: dashed; border-color: var(--line); }
.switch {
  grid-area: sw; position: relative; width: 40px; height: 24px; border-radius: 999px; border: 0; cursor: pointer;
  background: #d1d1d6; transition: background 0.18s ease; align-self: start; margin-top: 2px;
}
.switch .knob {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.18s var(--ease);
}
.switch[aria-checked='true'] { background: var(--brand); }
.switch[aria-checked='true'] .knob { transform: translateX(16px); }
.switch[disabled] { cursor: not-allowed; }
.term-text { grid-area: text; display: flex; flex-direction: column; min-width: 0; }
.term-label { font-size: 14px; font-weight: 500; line-height: 1.3; }
.term-sensor { font-size: 12px; color: var(--muted); }
.term:not(.is-on) .term-label { color: #3a3a3c; }
.term-weight { grid-area: weight; display: inline-flex; align-items: center; gap: 2px; justify-self: start; }
.term-weight output { min-width: 82px; text-align: center; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.term:not(.is-on) .term-weight output { color: var(--muted); font-weight: 600; }
.step {
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-size: 16px; line-height: 1; display: grid; place-items: center;
}
.step:hover:not([disabled]) { border-color: var(--brand); color: var(--brand); }
.step[disabled] { opacity: 0.35; cursor: not-allowed; }

/* ---------- the room ---------- */

.room-wrap { position: relative; width: 100%; max-width: 640px; }
.room { position: relative; width: 100%; aspect-ratio: 1 / 1; }
.room-svg { display: block; width: 100%; height: 100%; overflow: visible; }
.room::after {
  content: ''; position: absolute; inset: 4%; border-radius: 18px; background: #fff; opacity: 0; pointer-events: none;
}
.room.is-flash::after { animation: flash 0.5s ease-out; }
@keyframes flash { 0% { opacity: 0.85; } 100% { opacity: 0; } }

.floor-fill { fill: #fbf9f5; }
.floor-grid { stroke: rgba(29, 29, 31, 0.06); stroke-width: 1.5; fill: none; }
.wall { fill: none; stroke: #e4ded3; stroke-width: 22; }
.window { fill: #d7edfb; stroke: var(--ink); stroke-width: 2.5; }
.window-bar { stroke: var(--ink); stroke-width: 2; }
.grass { fill: #e4f1dc; }
.door { fill: #d9a46c; stroke: var(--ink); stroke-width: 2.5; }
.nextdoor { fill: #efe9df; }
.wall-label { font: 600 12px var(--font); letter-spacing: 0.12em; fill: #8a8378; }
.cone rect { fill: rgba(0, 94, 162, 0.06); transition: opacity 0.3s ease; }
.cone.is-off rect { opacity: 0; }
.cone.is-blocked rect { opacity: 0.25; }
.shadow { fill: rgba(0, 0, 0, 0.1); }
.eye { fill: #7fd4ff; }
.eye-line { stroke: #7fd4ff; stroke-width: 3.4; fill: none; stroke-linecap: round; }
.eye-line.thin { stroke-width: 2.4; }
.antenna { fill: var(--brand); transition: fill 0.2s ease; }
.pip.is-sly .antenna { fill: #f06418; }
.pip.is-think .antenna { animation: blink 0.7s steps(2) infinite; }
.cam-led { fill: #e5484d; animation: blink 1.6s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.25; } }
.pip, .item, .bin, .plant, .camera { transition: transform 0.22s var(--ease), opacity 0.22s ease; }
.pip-inner { transform-origin: 50px 92px; }
.pip-inner.bounce { animation: hop 0.26s var(--ease); }
@keyframes hop { 40% { transform: translateY(-7px) scale(1.02, 0.98); } }
.pop { font: 700 30px var(--font); paint-order: stroke; stroke: #fff; stroke-width: 6px; animation: rise 1.05s var(--ease) forwards; }
.pop--plus { fill: var(--ok); }
.pop--minus { fill: var(--gap); }
@keyframes rise { 0% { opacity: 0; transform: translateY(8px); } 15% { opacity: 1; } 100% { opacity: 0; transform: translateY(-44px); } }

.bubble {
  position: absolute; z-index: 3; width: max-content; max-width: min(250px, 58vw); padding: 9px 12px; border-radius: 14px;
  background: var(--ink); color: #fff; font-size: 14px; font-weight: 500; line-height: 1.35;
  transform: translate(-50%, calc(-100% - 4px)) scale(0.92); transform-origin: 50% 100%;
  opacity: 0; pointer-events: none; transition: opacity 0.16s ease, transform 0.2s var(--ease);
}
.bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -6px; width: 12px; height: 12px; background: var(--ink);
  transform: translateX(-50%) rotate(45deg); border-radius: 2px;
}
.bubble.is-on { opacity: 1; transform: translate(-50%, calc(-100% - 4px)) scale(1); }
.bubble.is-left { transform: translate(-82%, calc(-100% - 4px)); }
.bubble.is-left::after { left: 82%; }
.bubble.is-right { transform: translate(-18%, calc(-100% - 4px)); }
.bubble.is-right::after { left: 18%; }
.bubble.is-below { transform: translate(-50%, 6px); transform-origin: 50% 0; }
.bubble.is-below::after { top: -6px; bottom: auto; }
.bubble.is-below.is-left { transform: translate(-82%, 6px); }
.bubble.is-below.is-right { transform: translate(-18%, 6px); }

.room-banner {
  position: absolute; z-index: 4; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(0.9);
  padding: 10px 18px; border-radius: 999px; background: var(--ink); color: #fff; font-weight: 700; font-size: 15px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity 0.18s ease, transform 0.22s var(--ease);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
}
.room-banner.is-on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.room-banner--gap { background: var(--gap); }
.room-banner--ok { background: var(--ok); }

.room-wrap { display: flex; flex-direction: column; gap: 6px; }
.hud {
  order: -1; display: flex; gap: 6px; flex-wrap: wrap; justify-content: center;
  font-size: 12px; color: var(--muted); pointer-events: none;
}
.hud-item {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.92); border: 1px solid var(--line-soft);
}
.hud-item b { color: var(--ink); font-variant-numeric: tabular-nums; }
.batt { width: 18px; height: 11px; }

.run-bar { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.speed { display: inline-flex; padding: 3px; border-radius: 999px; background: #ebebef; }
.speed button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  color: var(--muted); cursor: pointer;
}
.speed button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.search-stat { font-size: 13px; color: var(--muted); text-align: center; max-width: 62ch; min-height: 1.5em; }
.plan-box { font-size: 13px; color: var(--muted); max-width: 62ch; width: 100%; }
.plan-box summary { cursor: pointer; font-weight: 600; color: var(--ink); text-align: center; list-style-position: inside; }
.plan-box ol { list-style: decimal; padding-left: 1.6em; margin-top: 6px; columns: 3 9em; }
.sim-note { font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- readout ---------- */

.readout { display: flex; flex-direction: column; gap: 12px; transition: opacity 0.2s ease; }
.readout.is-stale > :not(.stale-note) { opacity: 0.5; }
.stale-note { font-size: 13px; font-weight: 600; color: var(--gap); background: var(--gap-soft); border-radius: 10px; padding: 7px 10px; }
.readout h3, .b-reveal h3 { font-size: 22px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.15; margin-top: 2px; }
.ro-intro { display: flex; flex-direction: column; gap: 10px; }
.ro-intro > p { color: var(--muted); font-size: 14px; }
.ro-running { padding: 6px 0; }
.ro-live { font-size: 14px; color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums; }
.ro-error { color: var(--gap); font-weight: 600; }
.verdict--gap .ro-kicker { color: var(--gap); }
.verdict--ok .ro-kicker { color: var(--ok); }

.gap { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.gap-col { background: var(--alt); border-radius: 14px; padding: 12px; min-width: 0; }
.gap-label { color: var(--muted); }
.gap-big { font-size: 26px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; }
.gap-big.is-no { color: var(--gap); }
.gap-big.is-ok { color: var(--ok); }
.gap-note { font-size: 12px; color: var(--muted); line-height: 1.35; }
.gap--empty .gap-big { color: var(--line); }
.gap-lines { margin-top: 8px; display: grid; gap: 4px; }
.gap-lines li { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; line-height: 1.35; }
.gap-lines li span { color: #3a3a3c; }
.gap-lines b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.gap-lines b.is-plus { color: var(--ok); }
.gap-lines b.is-minus { color: var(--gap); }
.checks { margin-top: 8px; display: grid; gap: 6px; }
.checks li { display: flex; gap: 7px; font-size: 12.5px; line-height: 1.35; }
.checks small { display: block; color: var(--muted); font-size: 11.5px; }
.mark {
  flex: none; display: grid; place-items: center; width: 17px; height: 17px; border-radius: 50%;
  font-size: 10px; font-weight: 700; margin-top: 1px;
}
.checks .is-ok .mark { background: var(--ok-soft); color: var(--ok); }
.checks .is-no .mark { background: var(--gap-soft); color: var(--gap); }
.gap-compare { font-size: 13.5px; line-height: 1.5; color: #3a3a3c; }

.ex-card { border: 1px dashed var(--gap-line); background: var(--gap-soft); border-radius: 14px; padding: 14px 15px; display: grid; gap: 6px; }
.ex-kicker { color: var(--gap); }
.ex-card h4 { font-size: 17px; font-weight: 700; letter-spacing: -0.015em; }
.ex-card p { font-size: 13.5px; line-height: 1.5; }
.ex-quip { font-weight: 600; color: var(--ink); }
.ex-wild { color: #3a3a3c; }
.ex-wild span { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.ex-wild a { font-weight: 600; white-space: nowrap; }
.ex-card--compact { padding: 11px 13px; }
.ex-card--compact h4 { font-size: 15px; }
.ok-card { border: 1px solid rgba(31, 122, 77, 0.25); background: var(--ok-soft); border-radius: 14px; padding: 14px 15px; font-size: 14px; }
.ok-sub { margin-top: 6px; font-size: 13px; color: var(--ok); font-weight: 600; }
.cost-card { border: 1px solid var(--line-soft); background: var(--alt); border-radius: 14px; padding: 14px 15px; display: grid; gap: 4px; font-size: 13.5px; line-height: 1.5; }
.cost-big { font-size: 26px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.cost-record { font-weight: 600; color: var(--ok); }
.cost-goal { color: #3a3a3c; }
.where-next { display: grid; gap: 8px; }
.where-next ul { display: grid; gap: 8px; }
.where-next a {
  display: grid; gap: 2px; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; color: var(--ink); transition: border-color 0.15s ease;
}
.where-next a:hover { border-color: var(--brand); }
.where-next a b { color: var(--brand); font-size: 15px; }
.where-next a b::after { content: ' →' / ''; }
.where-next a span { font-size: 13px; color: var(--muted); line-height: 1.45; }
.definition { font-size: 13px; color: var(--muted); line-height: 1.5; }
.definition b { color: var(--ink); }
.finale { background: var(--ink); color: #fff; border-radius: 14px; padding: 16px; }
.finale .ro-kicker { color: #9fd0ff; }
.finale p:last-child { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.4; margin-top: 4px; }
.ro-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Part B ---------- */

.b-grid { display: grid; gap: 16px; padding: 16px; }
.b-left, .b-right { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.b-brief h2 { font-size: 23px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.15; margin: 4px 0 6px; }
.b-brief p:last-child { color: var(--muted); font-size: 14px; }
.prompt { font-size: 17px; font-weight: 600; letter-spacing: -0.015em; line-height: 1.3; margin: 4px 0 14px; }
.rubric-head { display: flex; align-items: baseline; justify-content: space-between; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.rubric-head h3 { font-size: 16px; font-weight: 700; }
.b-score { font-size: 30px; font-weight: 700; color: var(--brand); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.rubric { display: grid; gap: 10px; margin-top: 8px; }
.rb-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.rb-top b { font-variant-numeric: tabular-nums; }
.rb-bar { height: 6px; border-radius: 999px; background: #e8e8ed; margin: 5px 0 3px; overflow: hidden; }
.rb-bar i { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width 0.3s var(--ease); }
.rubric .is-ok .rb-bar i { background: var(--ok); }
.rubric small { font-size: 12px; color: var(--muted); }
.wordbank { display: flex; flex-wrap: wrap; gap: 5px; }
.wordbank li { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--alt); color: #3a3a3c; }

.b-essay { display: flex; flex-direction: column; gap: 10px; background: #fffdf9; min-width: 0; }
.essay-head { display: flex; align-items: center; gap: 10px; }
.essay-head h3 { font-size: 17px; font-weight: 700; margin-right: auto; }
.wc { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.essay-empty { font-size: 14px; color: var(--muted); padding: 20px; border: 1px dashed var(--line); border-radius: 14px; text-align: center; }
.essay { display: grid; gap: 6px; }
.sent {
  display: flex; gap: 8px; align-items: flex-start; padding: 9px 10px 9px 12px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line-soft); font-size: 14px; line-height: 1.5;
}
.sent.is-new { animation: arrive 0.4s var(--ease); }
@keyframes arrive { from { background: var(--brand-soft); transform: translateY(4px); } }
.sent-text { flex: 1; min-width: 0; }
.sent-tools { display: flex; gap: 4px; flex: none; }
.mini {
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line-soft); background: var(--alt);
  cursor: pointer; font-size: 12px; display: grid; place-items: center; color: var(--muted);
}
.mini:hover:not([disabled]) { color: var(--brand); border-color: var(--brand); }
.mini[disabled] { opacity: 0.3; cursor: not-allowed; }
#b-submit { align-self: flex-start; margin-top: 4px; }

.b-bank h3 { font-size: 17px; font-weight: 700; }
.bank-note { font-size: 13px; color: var(--muted); margin: 2px 0 10px; }
.frags { display: grid; gap: 6px; }
.frag {
  width: 100%; display: flex; gap: 10px; align-items: flex-start; text-align: left; cursor: pointer;
  padding: 10px 10px 10px 12px; border-radius: 12px; border: 1px solid var(--line-soft); background: var(--surface);
  font-size: 13.5px; line-height: 1.45; transition: border-color 0.15s ease, background 0.15s ease;
}
.frag:hover { border-color: var(--brand); background: #fbfdff; }
.frag.is-added { animation: added 0.6s var(--ease); }
@keyframes added { from { background: var(--ok-soft); border-color: var(--ok); } }
.frag-text { flex: 1; }
.frag-add {
  flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand); font-weight: 700;
}

.b-reveal { display: flex; flex-direction: column; gap: 12px; }
.grade { position: relative; padding-right: 100px; min-height: 90px; }
.grade p:last-child { font-size: 14px; color: #3a3a3c; margin-top: 6px; }
.grade h3:focus { outline: none; }
.stamp {
  position: absolute; right: 0; top: 0; width: 88px; height: 88px; border-radius: 50%; display: grid; place-items: center;
  font-size: 24px; font-weight: 700; letter-spacing: -0.03em; border: 3px solid currentColor; transform: rotate(-12deg);
  color: var(--brand);
}
.grade--gap .stamp { color: var(--gap); }
.grade--gap .ro-kicker { color: var(--gap); }
.grade--ok .stamp, .grade--ok .ro-kicker { color: var(--ok); }
.tricks { background: var(--gap-soft); border: 1px dashed var(--gap-line); border-radius: 14px; padding: 12px 14px; }
.tricks .gap-label { color: var(--gap); }
.tricks ul { display: grid; gap: 4px; margin-top: 6px; }
.tricks li { font-size: 13px; padding-left: 16px; position: relative; }
.tricks li::before { content: '↯'; position: absolute; left: 0; color: var(--gap); font-weight: 700; }
.tricks-log { margin-top: 8px; font-size: 12.5px; font-weight: 600; color: var(--gap); }
.marked summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.marked ol { display: grid; gap: 6px; margin-top: 8px; }
.mk { font-size: 13.5px; line-height: 1.45; padding: 8px 10px; border-radius: 10px; background: var(--alt); }
.mk-role { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.mk--idea .mk-role { color: var(--brand); }
.mk--bait { background: var(--gap-soft); }
.mk--bait .mk-role { color: var(--gap); }
.law { background: var(--alt); border-radius: 14px; padding: 14px 15px; display: grid; gap: 5px; }
.law h4 { font-size: 16px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.3; }
.law p:last-child { font-size: 13.5px; line-height: 1.55; color: #3a3a3c; }
.law a { font-weight: 600; }

/* ---------- dialogs ---------- */

.sheet {
  width: min(640px, calc(100% - 24px)); max-height: min(86vh, 760px); border: 0; border-radius: 20px; padding: 0;
  color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.sheet::backdrop { background: rgba(29, 29, 31, 0.35); }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; background: var(--surface); border-bottom: 1px solid var(--line-soft); }
.sheet-head h2 { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
.sheet-close { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.sheet-note { padding: 14px 20px 0; font-size: 14px; color: var(--muted); }
.sheet-body { padding: 14px 20px 22px; display: grid; gap: 10px; font-size: 14px; line-height: 1.55; }
.sheet-body h3 { font-size: 15px; font-weight: 700; margin-top: 6px; }
.src-list { display: grid; gap: 10px; }
.sheet-body kbd {
  font: 600 12px var(--font); padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); background: var(--alt);
}
.kbd-row { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.kbd-row .switch { margin-top: 0; }
.src-list a { font-weight: 600; text-decoration: none; }
.src-list a:hover { text-decoration: underline; }
.src-list span { display: block; color: var(--muted); font-size: 13px; }
.log-group + .log-group { border-top: 1px solid var(--line-soft); }
.log-head { display: flex; justify-content: space-between; gap: 10px; padding: 14px 20px 0; font-size: 15px; font-weight: 700; }
.log-head span { font-size: 13px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.log { display: grid; gap: 8px; padding: 10px 20px 18px; counter-reset: lg; }
.log-item { padding: 10px 12px 10px 40px; border-radius: 12px; background: var(--gap-soft); position: relative; counter-increment: lg; }
.log-item::before { content: counter(lg); position: absolute; left: 14px; top: 10px; font-weight: 700; color: var(--gap); }
.log-item b { display: block; font-size: 14px; }
.log-item span { display: block; font-size: 13px; color: #3a3a3c; }
.log-item.is-locked { background: var(--alt); }
.log-item.is-locked::before, .log-item.is-locked b { color: var(--muted); }
.log-item.is-locked span { color: var(--muted); }

/* ---------- responsive ---------- */

@media (min-width: 1100px) {
  html, body { height: 100%; }
  body { display: flex; flex-direction: column; overflow: hidden; }
  main { flex: 1; min-height: 0; }
  .panel { height: 100%; }
  .a-grid {
    height: 100%; grid-template-columns: minmax(300px, 340px) minmax(0, 1fr) minmax(310px, 360px);
    padding: 14px 18px; gap: 18px;
  }
  .a-left, .a-right { overflow-y: auto; min-height: 0; padding-bottom: 14px; scrollbar-width: thin; }
  .a-stage { min-height: 0; overflow-y: auto; scrollbar-width: thin; }
  .room-wrap { width: min(100%, calc(100vh - 252px)); max-width: none; }
  .b-grid { height: 100%; grid-template-columns: minmax(280px, 320px) minmax(0, 1fr) minmax(320px, 400px); padding: 14px 18px; gap: 18px; }
  .b-left, .b-right, .b-essay { overflow-y: auto; min-height: 0; scrollbar-width: thin; }
  .b-essay { max-height: 100%; }
}

@media (min-width: 760px) and (max-width: 1099px) {
  .a-grid { grid-template-columns: minmax(280px, 330px) minmax(0, 1fr); align-items: start; }
  .a-stage { grid-column: 2; grid-row: 1; }
  .a-right { grid-column: 2; grid-row: 2; }
  .a-left { grid-column: 1; grid-row: 1 / span 2; }
  .b-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .b-left { grid-column: 1; }
  .b-essay { grid-column: 2; grid-row: 1 / span 2; }
  .b-right { grid-column: 1; }
}

@media (max-width: 759px) {
  body { font-size: 15px; }
  .top { padding: 10px 14px; gap: 10px; }
  .brand-sub { display: none; }
  .tabs { order: 3; width: 100%; margin: 0; }
  .tab { flex: 1; justify-content: center; padding: 8px 6px; font-size: 13px; }
  .top-tools { margin-left: auto; }
  .chip { padding: 6px 10px; font-size: 12px; min-height: 32px; }
  .chip--link { display: none; }
  .foot { display: block; padding: 4px 16px 20px; text-align: center; font-size: 14px; font-weight: 600; }
  .foot a { text-decoration: none; }
  .t-long { display: none; }
  .t-short { display: inline; }
  .brand-name { font-size: 16px; }
  #part-b { padding-bottom: 8px; }
  .b-dock {
    position: sticky; bottom: 10px; z-index: 5; margin: 0 12px; display: flex; align-items: center; gap: 12px;
    padding: 8px 8px 8px 16px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 13px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  }
  .b-dock b { font-variant-numeric: tabular-nums; }
  .b-dock #b-dock-wc { color: #c7c7cc; margin-right: auto; font-variant-numeric: tabular-nums; }
  .is-graded .b-dock { display: none; }
  .a-grid, .b-grid { padding: 12px; gap: 12px; }
  /* Levels, brief, rule, room, result: the same order on screen as in the
     markup, so Tab follows what you see and the rule is read before Run. */
  .a-left { display: contents; }
  .lvl-t { display: none; }
  .lvl { padding: 6px 2px; }
  .brief h2, .b-brief h2 { font-size: 21px; }
  .card { padding: 15px; border-radius: 16px; }
  .gap { grid-template-columns: 1fr 1fr; }
  .gap-big { font-size: 22px; }
  .bubble { font-size: 13px; max-width: 70%; }
  .room-banner { font-size: 13px; padding: 8px 14px; }
  .plan-box ol { columns: 2 8em; }
  .grade { padding-right: 80px; }
  .stamp { width: 72px; height: 72px; font-size: 19px; }
  .b-grid { display: flex; flex-direction: column; }
}

@media (max-width: 380px) {
  .gap { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .chip-word { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}
