:root {
  color-scheme: light;
  --paper: #f4f1e7;
  --white: #fffcf4;
  --ink: #293e33;
  --green: #294e40;
  --muted: #7a8070;
  --line: #dcded0;
  --gold: #caa363;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button, select, input, textarea { border: 1px solid var(--line); border-radius: 9px; }
button { cursor: pointer; background: var(--white); color: var(--ink); padding: 10px 14px; font-weight: 600; transition: background .15s, transform .15s; }
button:hover:not(:disabled) { background: #e9edde; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, canvas:focus-visible { outline: 3px solid #caa363; outline-offset: 3px; }
a { color: inherit; }
button.primary { background: var(--green); border-color: var(--green); color: #fff8e7; }
button.primary:hover:not(:disabled) { background: #3c6552; }
button.quiet { border-color: transparent; background: transparent; }
button.small { padding: 7px 10px; font-size: 12px; }
button.active, button[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: #fff8e7; }
.loading { padding: 80px; text-align: center; }
.masthead { display: flex; align-items: center; justify-content: space-between; max-width: 1600px; margin: auto; min-height: 87px; padding: 16px 36px; border-bottom: 1px solid var(--line); gap: 20px; }
.brand { text-decoration: none; display: flex; align-items: center; gap: 12px; }
.brand img { width: 47px; height: 47px; }
.brand-name { font-family: Georgia, serif; font-size: 31px; letter-spacing: -1.4px; }
.brand-name span { color: #9a773d; }
.brand-note { display: block; font-size: 9px; text-transform: uppercase; letter-spacing: 2px; margin-top: 1px; color: var(--muted); }
.nav { display: flex; align-items: center; gap: 11px; font-size: 13px; }
.nav a { text-decoration: none; padding: 8px 10px; border-radius: 8px; }
.nav a:hover { background: #e7eadb; }
.nav .current { font-weight: 700; color: var(--green); }
.page { max-width: 1600px; margin: auto; padding: 24px 36px 22px; }
.level-heading { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin: 0 0 20px; }
.eyebrow { font-size: 10px; text-transform: uppercase; letter-spacing: 2px; color: #8d895f; font-weight: 700; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin: 5px 0 5px; font-family: Georgia, serif; font-size: clamp(24px, 2.5vw, 35px); font-weight: 400; letter-spacing: -.6px; }
.subtitle { font-size: 13px; color: var(--muted); margin: 0; }
.level-nav { display: flex; align-items: center; gap: 10px; }
.level-nav span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.level-nav button { padding: 8px 13px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 286px; gap: 22px; align-items: start; }
.landscape { min-width: 0; }
.board-frame { position: relative; background: #e3e5d6; border: 1px solid #c9cfba; border-radius: 18px; overflow: hidden; box-shadow: 0 9px 28px #3e533a0b; }
.board-viewport { position: relative; width: 100%; height: clamp(370px, 64vh, 760px); min-height: 300px; touch-action: none; }
canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.map-caption { position: absolute; top: 14px; left: 16px; font-size: 10px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: #637354; pointer-events: none; }
.map-buttons { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 4px; }
.map-buttons button { padding: 4px 9px; min-height: 32px; border-color: #bec6ae; background: #fffcf0e8; font-size: 15px; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 12px 0 0; }
.toolbar button { padding: 9px 12px; font-size: 12px; }
.toolbar .spacer { flex: 1; }
.toolbar .icon { min-width: 38px; font-size: 17px; padding: 5px 9px; }
.under-map { margin: 11px 0 0; color: var(--muted); font-size: 11px; display: flex; justify-content: space-between; gap: 12px; }
.sidebar { display: grid; gap: 14px; }
.panel { border: 1px solid var(--line); background: var(--white); border-radius: 14px; padding: 18px; }
.panel h2 { font-size: 14px; margin-bottom: 13px; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-bottom: 17px; border-bottom: 1px solid var(--line); }
.metric-label { display: block; color: var(--muted); font-size: 11px; }
.metric-value { display: block; font-family: Georgia, serif; font-size: 29px; line-height: 1.4; }
.metric-value small { font: 12px "Segoe UI", sans-serif; }
.metric-limit { font-size: 10px; color: var(--muted); }
.mission-title { margin: 16px 0 11px; font-size: 10px; letter-spacing: 1.7px; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.mission { font-size: 12px; display: flex; align-items: center; gap: 7px; margin: 9px 0; }
.color-chip { display: inline-grid; place-items: center; width: 23px; height: 23px; border-radius: 7px; color: #263d33; font-size: 13px; flex: 0 0 auto; }
.mission.done { color: var(--muted); }
.mission.done .color-chip { opacity: .5; }
.mission-status { margin-left: auto; color: var(--muted); font-size: 10px; }
.run-button { width: 100%; margin-top: 15px; font-size: 14px; padding: 12px; }
.playback { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 8px; }
.playback button { font-size: 11px; padding: 8px; }
.speed-row { display: flex; align-items: center; justify-content: space-between; margin-top: 11px; gap: 8px; font-size: 10px; color: var(--muted); }
.speed-row select { background: var(--white); color: var(--ink); padding: 5px; font-size: 11px; }
.status { font-size: 12px; line-height: 1.6; margin: 13px 0 0; min-height: 37px; color: #60745e; }
.status.error { color: #a84c3c; }
.hint { border-color: #e5dcc4; background: #eee9d9; }
.hint p { margin: 0; font-size: 12px; line-height: 1.75; color: #73735e; }
.hint .eyebrow { margin-bottom: 9px; display: block; }
.inspector-empty { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 0; }
.inspector-note { color: var(--muted); font-size: 10px; line-height: 1.6; margin: 10px 0 0; }
.route-row { display: grid; grid-template-columns: 63px 1fr; align-items: center; gap: 6px; margin-top: 10px; font-size: 11px; }
.route-row button { font-size: 11px; padding: 6px; text-align: left; }
.route-row .sequence { display: block; font-size: 9px; opacity: .7; margin-top: 2px; }
.toggle-junction { width: 100%; margin: 7px 0; font-size: 11px; }
.footer { max-width: 1600px; margin: 0 auto; padding: 0 36px 18px; color: #8a8d7b; font-size: 10px; letter-spacing: .4px; }
dialog { border: 1px solid var(--line); border-radius: 19px; color: var(--ink); background: var(--paper); padding: 28px; max-width: min(850px, 92vw); max-height: 88dvh; box-shadow: 0 25px 120px #172f3370; }
dialog::backdrop { background: #233c32a6; backdrop-filter: blur(5px); }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; gap: 20px; margin-bottom: 18px; }
.dialog-heading h2 { font-family: Georgia, serif; font-weight: 400; font-size: 29px; margin: 6px 0; }
.level-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.level-card { padding: 16px; text-align: left; min-height: 120px; display: flex; flex-direction: column; align-items: start; }
.level-card .number { color: #a18b5d; font-size: 11px; letter-spacing: 2px; }
.level-card strong { font-size: 13px; margin: 10px 0; }
.stars { color: #ba9858; letter-spacing: 3px; font-size: 15px; }
.level-card .stars { margin-top: auto; }
.best-result { font-size: 10px; opacity: .7; margin-top: 6px; }
.guide-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.guide-grid article { border: 1px solid var(--line); border-radius: 12px; padding: 17px; }
.guide-grid h3 { font-size: 14px; margin-bottom: 8px; }
.guide-grid p { font-size: 12px; line-height: 1.7; color: #6e7767; margin-bottom: 0; }
.guide-mark { font-size: 26px; color: #a0824e; display: block; margin-bottom: 10px; }
.result-dialog { text-align: center; width: 400px; }
.result-dialog h2 { font-family: Georgia, serif; font-size: 34px; font-weight: 400; margin: 16px 0 12px; }
.result-dialog .stars { font-size: 35px; margin: 20px 0; }
.result-dialog p { color: var(--muted); font-size: 13px; line-height: 1.7; }
.result-actions { display: grid; gap: 9px; margin-top: 20px; }
.result-detail { font-size: 12px; display: grid; gap: 7px; margin: 20px 0; text-align: left; border-top: 1px solid var(--line); padding-top: 16px; }
.field { display: grid; gap: 5px; font-size: 11px; color: #6d7867; margin: 10px 0; }
.field input, .field select, .field textarea { width: 100%; min-width: 0; background: #fffef8; color: var(--ink); padding: 7px 9px; font-size: 12px; }
.field textarea { resize: vertical; min-height: 53px; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.editor-tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.editor-tools button { padding: 7px 4px; font-size: 10px; }
.editor-tools button span { display: block; font-size: 18px; margin-bottom: 3px; }
.editor-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.editor-actions button { padding: 8px; font-size: 11px; }
.editor-feedback { font-size: 11px; line-height: 1.6; color: #697b5e; margin: 10px 0 0; }
.editor-feedback.error { color: #ac4c3c; }
.field textarea.export-json { width: min(650px, 72vw); height: 38vh; font-family: Consolas, monospace; font-size: 11px; line-height: 1.5; }
.editor-mode .board-viewport { height: clamp(420px, 73vh, 850px); }
.editor-mode .sidebar { max-height: 83vh; overflow-y: auto; padding-right: 3px; scrollbar-width: thin; }
.editor-mode .level-heading { margin-bottom: 14px; }
.hidden, [hidden] { display: none !important; }
@media (min-width: 1700px) { .page { padding-top: 32px; } }
@media (max-width: 1000px) {
  .masthead { padding: 14px 20px; }
  .page { padding: 20px; }
  .workspace { gap: 14px; grid-template-columns: minmax(0, 1fr) 255px; }
  .panel { padding: 14px; }
  .nav { gap: 2px; }
  .nav a, .nav button { padding: 8px; }
  .brand-note { letter-spacing: 1px; }
}
@media (max-width: 740px) {
  .masthead { padding: 12px 14px; min-height: 70px; gap: 8px; }
  .brand { gap: 8px; }
  .brand img { width: 37px; height: 37px; }
  .brand-name { font-size: 26px; }
  .brand-note { font-size: 7px; letter-spacing: .7px; }
  .nav { font-size: 11px; gap: 0; }
  .nav button { font-size: 11px; }
  .nav .hub-link { display: none; }
  .page { padding: 17px 12px; }
  .level-heading { gap: 10px; margin-bottom: 14px; }
  .level-nav { gap: 5px; }
  .level-nav span { font-size: 10px; }
  .level-nav button { padding: 7px 9px; }
  .subtitle { font-size: 11px; line-height: 1.5; }
  .workspace { grid-template-columns: 1fr; }
  .board-viewport, .editor-mode .board-viewport { height: 51dvh; min-height: 320px; max-height: 600px; }
  .board-frame { border-radius: 12px; }
  .map-caption { top: 9px; left: 11px; font-size: 8px; }
  .sidebar { grid-template-columns: 1fr 1fr; gap: 10px; }
  .run-panel { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; column-gap: 17px; }
  .metrics { padding-bottom: 10px; }
  .run-panel .missions { grid-column: 2; grid-row: 1 / span 3; }
  .run-panel .run-button { margin-top: 10px; }
  .run-panel .status { grid-column: 1 / -1; }
  .toolbar { gap: 5px; }
  .toolbar button { padding: 8px 10px; font-size: 11px; }
  .under-map { font-size: 10px; }
  .under-map .keyboard-note { display: none; }
  .level-grid { grid-template-columns: 1fr 1fr; }
  .level-card { min-height: 104px; padding: 12px; }
  dialog { padding: 20px; }
  .guide-grid { grid-template-columns: 1fr; }
  .editor-mode .sidebar { max-height: none; overflow: visible; }
  .editor-mode .sidebar .panel:first-child { grid-column: 1 / -1; }
  .editor-tools { grid-template-columns: repeat(4, 1fr); }
  .footer { padding: 0 14px 18px; }
}
.junction-kind { display: flex; gap: 6px; }
.junction-kind button { flex: 1; min-height: 44px; padding: 8px 5px; }
.junction-kind [aria-pressed="true"] { background: #315744; color: #fff3d0; }
.junction-kind [aria-pressed="true"]:hover:not(:disabled) { background: #315744; color: #fff3d0; }
.junction-diagram { position: relative; width: min(300px, 100%); aspect-ratio: 1; margin: 7px auto 0; border-radius: 24px; background: radial-gradient(circle, #d5dfbc, #f1ecd7 75%); }
.junction-map { width: 100%; height: 100%; overflow: visible; }
.junction-ballast { stroke: #a8a68a; stroke-width: 25; stroke-linecap: round; }
.junction-rails { stroke: #526352; stroke-width: 8; }
.junction-hub { fill: #315744; stroke: #e6cc91; stroke-width: 3; }
.junction-symbol { font: bold 22px sans-serif; fill: #fff1c6; }
.junction-route { stroke: #e6a94b; stroke-width: 9; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.junction-sign { position: absolute; transform: translate(-50%, -50%); width: 66px; min-width: 48px; height: 59px; min-height: 48px; display: grid; place-items: center; gap: 2px; padding: 5px 2px; border: 2px solid #bfad79; border-radius: 11px; background: #fff6d6; box-shadow: 0 3px 0 #8b927264; color: #345441; }
.junction-sign:disabled { opacity: 1; cursor: default; }
.junction-sign.highlighted { border-color: #a37632; background: #ffe6a9; box-shadow: 0 0 0 3px #d5ad5844; }
.junction-sign:active:not(:disabled) { transform: translate(-50%, -50%) translateY(1px); }
.sign-origin { font: 700 7px sans-serif; white-space: nowrap; letter-spacing: .25px; }
.sign-arrow { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; transition: transform 180ms ease; }
.junction-sequence { min-height: 19px; margin: 5px 0; text-align: center; font-size: 12px; color: #5d674c; }
@media (prefers-reduced-motion: reduce) { button, .sign-arrow { transition: none; } }
