:root {
  --scn-ink: #102532;
  --scn-muted: #526c7a;
  --scn-line: #b8d2df;
  --scn-blue: #149bd7;
  --scn-pale: #eef8fc;
  --scn-gold: #f0b323;
  --scn-touch: 48px;
  --scn-radius: 10px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; min-width: 320px; overflow: hidden; font-family: Arial, Helvetica, sans-serif; color: var(--scn-ink); background: #edf5f8; }
button, input, select, textarea, summary { font: inherit; }
button, summary, select, input { min-height: var(--scn-touch); }
button, summary { cursor: pointer; }
button:disabled, fieldset:disabled { cursor: not-allowed; opacity: .5; }

.app { width: 100%; height: 100vh; height: 100dvh; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
.topbar { display: grid; grid-template-columns: minmax(210px, 1fr) auto; align-items: center; gap: 16px; padding: 12px 18px; color: #fff; background: #071018; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-logo { display: inline-flex; border-radius: 6px; }
.brand img { display: block; width: 142px; height: auto; }
.brand h1 { margin: 0; font-size: clamp(1.25rem, 2vw, 2rem); line-height: 1.05; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.icon-button, .home-button { min-width: var(--scn-touch); min-height: var(--scn-touch); border: 2px solid #263d51; border-radius: var(--scn-radius); color: #fff; background: #122436; }
.icon-button { display: inline-grid; place-items: center; padding: 0; }
.icon-button:hover, .icon-button:focus-visible, .home-button:hover, .home-button:focus-visible { color: #06111a; border-color: #8fd8f3; background: var(--scn-blue); }
.home-button { display: inline-flex; align-items: center; justify-content: center; padding: 0 14px; text-decoration: none; font-weight: 800; }
.icon { width: 24px; height: 24px; }
.top-view-menu { position: relative; }
.top-view-menu > summary { list-style: none; }
.top-view-menu > summary::-webkit-details-marker { display: none; }
.top-view-panel { position: absolute; z-index: 50; top: calc(100% + 8px); right: 0; display: grid; gap: 6px; width: 190px; padding: 10px; border: 1px solid #36546b; border-radius: var(--scn-radius); background: #102332; box-shadow: 0 12px 30px rgba(0,0,0,.28); }
.top-view-action { min-height: 44px; padding: 0 12px; border: 1px solid #4d687b; border-radius: 8px; color: #fff; background: #173247; text-align: left; }

#squareCubeNumbersModel { min-width: 0; min-height: 0; display: grid; overflow: hidden; }
.scn-tool { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
.scn-toolbar { position: relative; z-index: 4; display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--scn-line); background: #fff; box-shadow: 0 5px 12px rgba(15,33,49,.06); }
.scn-toolbar-main, .scn-toolbar-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.scn-toolbar-main { flex: 1 1 auto; }
.scn-toolbar-actions { flex: 0 0 auto; margin-left: auto; }
.scn-select-field, .scn-base-field { display: flex; align-items: center; gap: 7px; color: var(--scn-muted); font-weight: 800; }
.scn-base-field > span { white-space: nowrap; }
.scn-select-field select, .scn-base-field input { min-width: 0; padding: 0 34px 0 11px; border: 2px solid #9bbdcd; border-radius: var(--scn-radius); color: var(--scn-ink); background: #fff; font-weight: 800; }
.scn-select-field:first-child select { width: clamp(190px, 19vw, 286px); }
.scn-select-field:nth-child(2) select { width: clamp(160px, 15vw, 220px); }
.scn-base-field input { width: 82px; padding: 0 4px 0 10px; font-size: 1.08rem; }
.scn-base-field input[type="number"]::-webkit-inner-spin-button { width: 20px; height: 38px; margin: 0; opacity: 1; }
.scn-button { min-height: var(--scn-touch); display: inline-flex; align-items: center; justify-content: center; padding: 0 13px; border: 2px solid #9bbdcd; border-radius: var(--scn-radius); color: var(--scn-ink); background: #fff; font-weight: 800; }
.scn-button:hover, .scn-button:focus-visible { border-color: #0f80b3; background: #f3fbfe; }
.scn-button.primary { color: #06111a; border-color: #0f80b3; background: #aee7fa; }
.scn-toolbar details { position: relative; }
.scn-toolbar details > summary { list-style: none; }
.scn-toolbar details > summary::-webkit-details-marker { display: none; }
.scn-toolbar details > summary::after { content: "▾"; margin-left: 9px; font-size: .86em; }
.scn-menu-panel { position: absolute; z-index: 40; top: calc(100% + 7px); right: 0; width: 270px; padding: 10px; border: 1px solid #8fb8ca; border-radius: var(--scn-radius); background: #fff; box-shadow: 0 12px 28px rgba(15,33,49,.2); }
.scn-menu-panel fieldset { display: grid; gap: 3px; margin: 0; padding: 0; border: 0; }
.scn-menu-panel legend { margin-bottom: 6px; color: var(--scn-muted); font-weight: 900; }
.scn-menu-panel label { min-height: 42px; display: flex; align-items: center; gap: 9px; padding: 5px 7px; border-radius: 7px; font-weight: 800; cursor: pointer; }
.scn-menu-panel label:hover, .scn-menu-panel label:focus-within { background: var(--scn-pale); }
.scn-menu-panel input { width: 20px; height: 20px; min-height: 0; accent-color: #0f80b3; }
.scn-menu-panel p { margin: 8px 4px 2px; color: var(--scn-muted); font-size: .82rem; line-height: 1.3; }
.scn-workspace { min-width: 0; min-height: 0; overflow: hidden; padding: 12px; }
.scn-stage { width: min(1480px, 100%); height: 100%; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 9px; margin: 0 auto; }
.scn-question-strip { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(210px, .45fr) auto; gap: 8px 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--scn-line); border-radius: 12px; background: #fff; box-shadow: 0 5px 14px rgba(15,33,49,.06); }
.scn-question-strip h2 { min-width: 0; margin: 0; font-size: clamp(1.05rem, 1.5vw, 1.35rem); line-height: 1.18; }
.scn-answer, .scn-discussion { display: grid; gap: 4px; color: var(--scn-muted); font-weight: 800; }
.scn-answer input, .scn-discussion textarea { width: 100%; border: 2px solid #8fb8ca; border-radius: 9px; padding: 8px 10px; color: var(--scn-ink); background: #fff; font-size: 1.08rem; font-weight: 800; resize: vertical; }
.scn-choice-group { min-width: 210px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 0; padding: 0; border: 0; }
.scn-choice-group legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.scn-choice { min-height: var(--scn-touch); border: 2px solid #9bbdcd; border-radius: var(--scn-radius); color: var(--scn-ink); background: #fff; font-weight: 800; }
.scn-choice.is-selected { border-color: #0b6f7f; color: #fff; background: #0b6f7f; }
.scn-pupil-actions { align-self: end; display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.scn-feedback, .scn-hint, .scn-reveal, .scn-layer-controls { grid-column: 1 / -1; }
.scn-feedback { min-height: 42px; margin: 0; padding: 10px 12px; border-left: 5px solid var(--scn-blue); border-radius: 8px; background: #f6fafc; font-weight: 700; }
.scn-feedback:empty { min-height: 0; padding-block: 0; border-left-color: transparent; background: transparent; }
.scn-feedback.is-success { border-left-color: #1f8f55; background: #effaf4; }
.scn-feedback.is-warning { border-left-color: #c26816; background: #fff3e7; }
.scn-hint, .scn-reveal { padding: 9px 11px; border-radius: 8px; background: #fff7d8; }
.scn-reveal { background: #e8f6fb; }
.scn-layer-controls { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.scn-layer-controls > span { margin-right: auto; }
.scn-layer-controls button { min-height: 44px; padding: 0 11px; border: 2px solid #9bbdcd; border-radius: 9px; color: var(--scn-ink); background: #fff; font-weight: 800; }
.scn-layer-controls button[aria-pressed="true"] { border-color: #0f80b3; background: #dff4fc; }

.scn-model-panel { min-width: 0; min-height: 0; display: grid; align-items: stretch; overflow: hidden; padding: 10px; border: 1px solid var(--scn-line); border-radius: 12px; background: #fff; box-shadow: 0 5px 14px rgba(15,33,49,.06); }
.scn-model-layout { min-width: 0; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(560px, 590px); gap: 12px; align-items: stretch; }
.scn-model-layout.has-secondary { grid-template-columns: minmax(0, 1fr) 400px; grid-template-rows: minmax(0, 1fr); }
.scn-model-layout.no-connection { grid-template-columns: 1fr; }
.scn-model-grid { min-width: 0; min-height: 0; display: grid; grid-template-columns: minmax(350px, 1.25fr) minmax(220px, .75fr); gap: 8px; align-items: stretch; transform: scale(var(--scn-view-scale, 1)); transform-origin: center; transition: transform .18s ease; }
.scn-model-grid.is-single { grid-template-columns: minmax(0, 900px); justify-content: center; }
.scn-model-host { min-width: 0; min-height: 0; display: grid; place-items: center; overflow: hidden; border-radius: 9px; background: #f8fbfc; }
.scn-model-host[hidden] { display: none !important; }
.scn-model-host .spire-model, .scn-model-host .question-visual, .scn-model-host .diagram-frame { width: 100%; height: 100%; min-height: 0; margin: 0; }
.scn-model-host .question-visual, .scn-model-host .diagram-frame { display: grid; place-items: center; }
.scn-model-host svg { display: block; width: 100%; height: 100%; max-height: 100%; }
.scn-model-host figure > figcaption { position: absolute; left: -10000px; width: 1px; height: 1px; padding: 0; margin: 0; overflow: hidden; white-space: nowrap; border: 0; }
.scn-connection { min-height: 46px; display: flex; flex-direction: row; justify-content: center; align-items: center; flex-wrap: nowrap; gap: 11px; padding: 12px 14px; border: 0; border-radius: 0; color: #000; background: #fff; text-align: center; white-space: nowrap; font-size: clamp(1.6rem, 2.2vw, 2rem); font-weight: 900; }
.scn-model-layout.has-secondary .scn-connection { flex-direction: row; }
.scn-connection strong { color: #000; font-size: 1em; }
.scn-connection-equals { color: #000; font-size: 1em; font-weight: 900; }

.scn-dialog { width: min(760px, calc(100vw - 28px)); max-height: min(84vh, 790px); padding: 0; border: 0; border-radius: 14px; color: var(--scn-ink); box-shadow: 0 22px 70px rgba(0,0,0,.35); }
.scn-dialog::backdrop { background: rgba(5,15,23,.66); }
.scn-dialog-header { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px; color: #fff; background: #071018; }
.scn-dialog-header h2 { margin: 0; font-size: 1.3rem; }
.scn-dialog-header form { margin: 0; }
.scn-dialog-close { width: 44px; min-height: 44px; border: 1px solid #5b7385; border-radius: 8px; color: #fff; background: #173247; font-size: 1.6rem; }
.scn-dialog-body { padding: 18px 22px 24px; line-height: 1.5; }
.scn-dialog-body h3 { margin: 1.1em 0 .35em; }
.scn-dialog-body li + li { margin-top: .35em; }

@media (max-width: 1380px) {
  .scn-select-field > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
  .scn-select-field:first-child select { width: min(240px, 23vw); }
  .scn-select-field:nth-child(2) select { width: min(190px, 19vw); }
}

@media (max-width: 1180px) {
  .scn-toolbar { align-items: stretch; flex-direction: column; gap: 8px; }
  .scn-toolbar-main, .scn-toolbar-actions { width: 100%; }
  .scn-toolbar-actions { margin-left: 0; justify-content: flex-end; }
  .scn-select-field:first-child select { width: min(286px, 25vw); }
  .scn-select-field:nth-child(2) select { width: min(220px, 22vw); }
  .scn-question-strip { grid-template-columns: minmax(260px, 1fr) minmax(190px, .5fr); }
  .scn-pupil-actions { grid-column: 1 / -1; }
  .scn-model-layout, .scn-model-layout.has-secondary { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .scn-connection, .scn-model-layout.has-secondary .scn-connection { flex-direction: row; flex-wrap: wrap; white-space: normal; font-size: 1.35rem; }
}

@media (max-width: 760px) {
  html, body { height: auto; min-height: 100%; overflow: auto; }
  .app { display: block; width: 100%; height: auto; min-height: 100vh; overflow: visible; }
  .topbar { grid-template-columns: 1fr; padding: 10px 12px; }
  .top-actions { justify-content: flex-start; }
  .brand img { width: 116px; }
  #squareCubeNumbersModel, .scn-tool { display: block; overflow: visible; }
  .scn-toolbar { padding: 9px 10px; }
  .scn-toolbar-main, .scn-toolbar-actions { align-items: stretch; flex-direction: column; }
  .scn-select-field, .scn-base-field { display: grid; grid-template-columns: 84px minmax(0, 1fr); }
  .scn-select-field > span { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
  .scn-select-field select, .scn-select-field:first-child select, .scn-select-field:nth-child(2) select { width: 100%; }
  .scn-base-field { grid-template-columns: 84px minmax(0, 1fr) auto; }
  .scn-toolbar-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scn-toolbar-actions > * { min-width: 0; }
  .scn-toolbar-actions .scn-button { width: 100%; }
  .scn-menu-panel { right: auto; left: 0; width: min(300px, calc(100vw - 28px)); }
  .scn-workspace { overflow: visible; padding: 9px; }
  .scn-stage { height: auto; display: grid; grid-template-rows: auto auto; }
  .scn-question-strip { grid-template-columns: 1fr; }
  .scn-pupil-actions, .scn-feedback, .scn-hint, .scn-reveal, .scn-layer-controls { grid-column: auto; }
  .scn-pupil-actions { justify-content: flex-start; flex-wrap: wrap; }
  .scn-pupil-actions .scn-button { flex: 1 1 90px; }
  .scn-model-panel { min-height: 330px; }
  .scn-model-layout, .scn-model-layout.has-secondary { grid-template-columns: 1fr; grid-template-rows: auto auto; }
  .scn-model-grid { display: block; transform: none; }
  .scn-model-host { min-height: 300px; }
  .scn-model-host + .scn-model-host { display: none; }
  .scn-connection, .scn-model-layout.has-secondary .scn-connection { flex-direction: row; flex-wrap: wrap; white-space: normal; font-size: 1.35rem; }
  .scn-choice-group { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .scn-model-grid { transition: none; }
}

@page { size: A4 landscape; margin: 8mm; }
@media print {
  html, body { width: 100%; height: auto; min-height: 0; overflow: visible; background: #fff; }
  .topbar, .scn-toolbar, .scn-pupil-actions, .scn-answer, .scn-discussion, .scn-choice-group, .scn-dialog { display: none !important; }
  .app, #squareCubeNumbersModel, .scn-tool { display: block; width: auto; height: auto; min-height: 0; overflow: visible; }
  .scn-workspace { overflow: visible; padding: 0; }
  .scn-stage { width: 100%; height: auto; display: grid; grid-template-rows: auto auto; gap: 4mm; }
  .scn-question-strip, .scn-model-panel { box-shadow: none; break-inside: avoid; }
  .scn-question-strip { display: block; padding: 3mm 4mm; }
  .scn-question-strip h2 { font-size: 14pt; }
  .scn-feedback:empty, .scn-hint:empty { display: none; }
  .scn-model-panel { min-height: 124mm; padding: 3mm; }
  .scn-model-grid { min-height: 116mm; transform: none; }
  .scn-model-host { min-height: 108mm; }
  .scn-model-host svg { max-height: 108mm; }
  .scn-connection { min-height: 12mm; }
  .spire-shared-print-copyright { position: fixed; right: 0; bottom: 0; z-index: 2; margin: 0 !important; padding-left: 2mm; background: #fff; }
}
