:root {
  --eb-ink: #102532;
  --eb-muted: #526c7a;
  --eb-line: #b8d2df;
  --eb-blue: #149bd7;
  --eb-blue-dark: #006b99;
  --eb-pale: #eef8fc;
  --eb-touch: 48px;
  --eb-radius: 10px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; min-width: 320px; margin: 0; overflow: hidden; color: var(--eb-ink); background: #edf5f8; font-family: Arial, Helvetica, sans-serif; }
button, input, select, summary { min-height: var(--eb-touch); font: inherit; }
button, summary { cursor: pointer; }
button: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(220px, 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(--eb-touch); min-height: var(--eb-touch); border: 2px solid #263d51; border-radius: var(--eb-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(--eb-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; }

#equationBarModel { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
.eb-toolbar { position: relative; z-index: 5; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 9px 16px; border-bottom: 1px solid var(--eb-line); background: #fff; box-shadow: 0 5px 12px rgba(15,33,49,.06); }
.eb-mode-group, .eb-toolbar-actions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.eb-toolbar-actions { margin-left: auto; }
.eb-button, .eb-menu>summary { min-height: var(--eb-touch); display: inline-flex; align-items: center; justify-content: center; padding: 0 14px; border: 2px solid #9bbdcd; border-radius: var(--eb-radius); color: var(--eb-ink); background: #fff; font-weight: 800; }
.eb-button:hover, .eb-button:focus-visible, .eb-menu>summary:hover, .eb-menu>summary:focus-visible { border-color: var(--eb-blue-dark); background: #f3fbfe; }
.eb-button.eb-primary { color: #06111a; border-color: var(--eb-blue-dark); background: #aee7fa; }
.eb-field { display: flex; align-items: center; gap: 8px; color: var(--eb-muted); font-weight: 800; }
.eb-field select { min-width: 205px; padding: 0 34px 0 11px; border: 2px solid #9bbdcd; border-radius: var(--eb-radius); color: var(--eb-ink); background: #fff; font-weight: 800; }
.eb-menu { position: relative; }
.eb-menu>summary { list-style: none; }
.eb-menu>summary::-webkit-details-marker { display: none; }
.eb-menu-panel { position: absolute; z-index: 50; top: calc(100% + 8px); right: 0; display: grid; gap: 8px; width: 205px; padding: 10px; border: 1px solid var(--eb-line); border-radius: var(--eb-radius); background: #fff; box-shadow: 0 12px 28px rgba(15,33,49,.2); }
.eb-menu-panel .eb-button[aria-pressed="true"] { border-color: var(--eb-blue-dark); background: #dff3fa; }

.eb-workspace { min-width: 0; min-height: 0; overflow: auto; padding: 14px; }
.eb-stage { width: min(1480px, 100%); min-height: 100%; margin: 0 auto; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 10px; }
.eb-question-card { padding: 12px 18px; border: 1px solid var(--eb-line); border-radius: 12px; background: #fff; text-align: center; }
.eb-question-card h2 { margin: 0; font-size: clamp(1.05rem, 1.8vw, 1.35rem); }
.eb-equation { margin: 8px 0 0; font-size: clamp(1.5rem, 3vw, 2.45rem); font-weight: 900; }
.eb-feedback { min-height: 50px; display: flex; align-items: center; padding: 11px 14px; border-left: 5px solid var(--eb-blue); border-radius: 8px; background: #fff; font-weight: 800; }
.eb-feedback[data-tone="complete"] { border-left-color: #1f8f55; background: #effaf4; }
.eb-feedback[data-tone="error"] { border-left-color: #c43f3f; background: #fff2f2; }

.eb-main-grid { min-width: 0; min-height: 0; display: grid; grid-template-columns: minmax(0, 2fr) minmax(310px, .72fr); gap: 12px; align-items: stretch; }
.eb-model-card, .eb-work-card { min-width: 0; padding: 14px; border: 1px solid var(--eb-line); border-radius: 12px; background: #fff; box-shadow: 0 5px 14px rgba(15,33,49,.06); }
.eb-model-card { min-height: 430px; display: grid; align-items: stretch; overflow: hidden; }
.eb-model-host { min-width: 0; min-height: 0; display: grid; align-items: center; }
.eb-model-host>.equation-bar-visual { min-height: 100%; }
.eb-model-host .equation-bar-equation { display: none; }
.eb-model-host .equation-bar-models>.bar-model-figure { background: #fafdff; }
.eb-work-card { display: grid; gap: 16px; align-content: start; overflow: auto; }
.eb-work-card h3 { margin: 0 0 9px; font-size: 1.08rem; }
.eb-step-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.eb-step-heading h3 { margin: 0; }
.eb-previous-button { flex: 0 0 auto; }
.eb-action-grid { display: grid; gap: 8px; }
.eb-step-button { width: 100%; justify-content: flex-start; text-align: left; }
.eb-step-button.is-complete { border-color: #238859; background: #effaf4; }
.eb-step-button.is-hint { border-color: #9b6a00; background: #fff0c9; box-shadow: 0 0 0 3px rgba(243,178,58,.22); }
.eb-answer-section, .eb-pairs-section { padding-top: 14px; border-top: 1px solid #d3e2e9; }
.eb-answer-field { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px; margin-bottom: 9px; font-size: 1.2rem; font-weight: 900; }
.eb-answer-field input { width: 100%; min-width: 0; padding: 0 12px; border: 2px solid #8fb8ca; border-radius: 9px; color: var(--eb-ink); background: #fff; font-size: 1.2rem; font-weight: 900; }
.eb-answer-field input:focus { outline: 3px solid rgba(20,155,215,.2); border-color: var(--eb-blue-dark); }
.eb-two-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.eb-pairs-section p { margin: 0 0 9px; color: var(--eb-muted); font-weight: 700; }
.eb-pairs-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.eb-pairs-list span { padding: 7px 8px; border: 1px solid #c8dce5; border-radius: 7px; background: #f4fafc; font-weight: 800; text-align: center; }

.eb-dialog { width: min(760px, calc(100vw - 28px)); max-height: min(82vh, 780px); padding: 0; border: 0; border-radius: 14px; color: var(--eb-ink); box-shadow: 0 22px 70px rgba(0,0,0,.35); }
.eb-dialog::backdrop { background: rgba(5,15,23,.66); }
.eb-dialog-header { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px; color: #fff; background: #071018; }
.eb-dialog-header h2 { margin: 0; font-size: 1.3rem; }
.eb-dialog-close { width: 44px; min-height: 44px; border: 1px solid #5b7385; border-radius: 8px; color: #fff; background: #173247; font-size: 1.6rem; }
.eb-dialog-body { padding: 18px 22px 24px; line-height: 1.5; overflow: auto; }
.eb-dialog-body h3 { margin: 1.1em 0 .35em; }
.eb-dialog-body li+li { margin-top: .35em; }
.eb-worksheet-form { display: grid; gap: 16px; padding: 20px 22px 24px; }
.eb-worksheet-form>p { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--eb-pale); font-weight: 800; }
.eb-check-option { min-height: 64px; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 2px solid #9bbdcd; border-radius: 10px; cursor: pointer; }
.eb-check-option input { width: 24px; height: 24px; flex: 0 0 auto; accent-color: var(--eb-blue-dark); }
.eb-check-option span { display: grid; gap: 3px; }
.eb-check-option small { color: var(--eb-muted); }
.eb-dialog-actions { display: flex; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }
.eb-worksheet-surface, .eb-worksheet-page { display: none; }

@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr; }
  .top-actions { justify-content: flex-start; }
  .eb-main-grid { grid-template-columns: 1fr; }
  .eb-model-card { min-height: 390px; }
  .eb-work-card { overflow: visible; }
}

@media (max-width: 680px) {
  .topbar { padding: 10px 12px; }
  .brand img { width: 116px; }
  .eb-toolbar { align-items: stretch; padding: 9px 10px; }
  .eb-mode-group, .eb-toolbar-actions { width: 100%; }
  .eb-mode-group .eb-button, .eb-toolbar-actions .eb-button { flex: 1 1 120px; }
  .eb-field { width: 100%; display: grid; grid-template-columns: auto minmax(0, 1fr); }
  .eb-field select { min-width: 0; width: 100%; }
  .eb-menu { flex: 1 1 150px; }
  .eb-menu>summary { justify-content: center; }
  .eb-menu-panel { right: auto; left: 0; width: min(240px, calc(100vw - 20px)); }
  .eb-toolbar-actions { margin-left: 0; }
  .eb-workspace { padding: 9px; }
  .eb-question-card { padding: 10px; }
  .eb-model-card, .eb-work-card { padding: 10px; }
  .eb-model-card { min-height: 340px; }
  .eb-two-inputs { grid-template-columns: 1fr; }
  .eb-step-heading { align-items: stretch; flex-direction: column; }
  .eb-previous-button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

@page { size: A4 landscape; margin: 9mm; }
@media print {
  html, body { width: 100%; height: auto; min-height: 0; overflow: visible; background: #fff; }
  .topbar, .eb-toolbar, .eb-feedback, .eb-work-card, .eb-dialog { display: none !important; }
  .app, #equationBarModel, .eb-workspace, .eb-stage { display: block; width: 100%; height: auto; min-height: 0; overflow: visible; padding: 0; }
  .eb-question-card { margin-bottom: 5mm; padding: 3mm; border: 0; }
  .eb-question-card h2 { font-size: 13pt; }
  .eb-equation { margin-top: 2mm; font-size: 24pt; }
  .eb-main-grid { display: block; }
  .eb-model-card { min-height: 0; padding: 3mm; border: 1px solid #9db9c6; box-shadow: none; break-inside: avoid; }
  .eb-model-host>.equation-bar-visual { min-height: 0; gap: 3mm; align-content: start; }
  .eb-model-host .equation-bar-models { grid-template-columns: repeat(auto-fit, minmax(min(100%, 120mm), 1fr)); gap: 5mm; }
  .eb-model-host .equation-bar-models>.bar-model-figure { padding: 3mm; box-shadow: none; }
  .eb-model-host .expanded-bar-model .bar-model-strip { min-height: 18mm; }
  .eb-model-host .expanded-bar-model .bar-model-strip span { min-width: 9mm; padding: 1mm; font-size: 15pt; }
  .equation-bar-working { padding: 2.5mm 4mm; font-size: 9pt; }
  .equation-bar-working h3 { margin-bottom: 1.5mm; }
  .equation-bar-working ol { columns: 2; column-gap: 9mm; }
  .equation-bar-working li { break-inside: avoid; }
  .equation-bar-working li+li { margin-top: 2mm; }
  .equation-bar-working-equation { margin-top: 1mm; }

  html[data-spire-print-page="a4-landscape"] body.eb-printing-worksheet { display: block !important; width: 279mm !important; height: auto !important; max-height: none !important; margin: 0 !important; overflow: visible !important; }
  html[data-spire-print-page="a4-landscape"] body.eb-printing-worksheet>.app { display: none !important; }
  html[data-spire-print-page="a4-landscape"] body.eb-printing-worksheet>.eb-worksheet-page { display: flex !important; }
  .eb-worksheet-page { box-sizing: border-box; width: 279mm; max-width: 279mm; height: 180mm; flex-direction: column; gap: 3mm; overflow: hidden; color: #102532; background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .eb-worksheet-page:not(:last-child) { break-after: page; page-break-after: always; }
  .eb-worksheet-header { min-height: 18mm; display: grid; grid-template-columns: 34mm minmax(0, 1fr) auto; align-items: center; gap: 4mm; padding-bottom: 2mm; }
  .eb-worksheet-header img { display: block; width: 32mm; height: auto; }
  .eb-worksheet-header h1 { margin: 0; font-size: 18pt; line-height: 1.05; }
  .eb-worksheet-header p { margin: 1mm 0 0; font-size: 10pt; font-weight: 800; }
  .eb-worksheet-pupil { display: grid; gap: 3mm; font-size: 10pt; font-weight: 800; white-space: nowrap; }
  .eb-worksheet-grid { min-height: 0; flex: 1; display: grid; gap: 4mm; }
  .eb-worksheet-grid[data-layout="one"] { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); }
  .eb-worksheet-grid[data-layout="linked"], .eb-worksheet-grid[data-layout="pairs"] { grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(2, minmax(0, 1fr)); }
  .eb-worksheet-question { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; padding: 2.5mm; border: .4mm solid #9bbdcd; border-radius: 2mm; break-inside: avoid; }
  .eb-worksheet-question h2 { margin: 0 0 1.5mm; font-size: 12pt; line-height: 1.1; }
  .eb-worksheet-question-body { width: 100%; max-width: 100%; min-width: 0; min-height: 0; flex: 1; display: grid; grid-template-columns: minmax(0, 58fr) minmax(0, 42fr); gap: 3mm; overflow: hidden; }
  .eb-worksheet-grid[data-layout="one"] .eb-worksheet-question-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; gap: 1.5mm; }
  .eb-worksheet-model { width: 100%; max-width: 100%; min-width: 0; min-height: 0; overflow: hidden; display: grid; align-items: center; }
  .eb-worksheet-model .question-visual { margin: 0; }
  .eb-worksheet-model figcaption { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
  .eb-worksheet-model .equation-bar-visual { width: 100%; max-width: 100%; min-width: 0; min-height: 0; gap: 1.5mm; align-content: center; }
  .eb-worksheet-model .equation-bar-equation, .eb-worksheet-model .equation-bar-working { display: none !important; }
  .eb-worksheet-model .equation-bar-models { grid-template-columns: repeat(auto-fit, minmax(min(100%, 55mm), 1fr)); gap: 2mm; }
  .eb-worksheet-model .equation-bar-models { align-items: center; }
  .eb-worksheet-model .equation-bar-models>.bar-model-figure { min-width: 0; height: auto; align-self: center; padding: 1.5mm; box-shadow: none; }
  .eb-worksheet-model .equation-bar-models .bar-model { height: auto; min-height: 0; }
  .eb-worksheet-model .expanded-bar-model { gap: 0; }
  .eb-worksheet-model .expanded-bar-model .bar-model-strip { min-height: 10mm; }
  .eb-worksheet-model .expanded-bar-model .bar-model-strip span { min-width: 5mm; padding: .5mm; font-size: 9pt; }
  .eb-worksheet-work { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 1.2mm; font-size: 8.5pt; }
  .eb-worksheet-work>p { margin: 0; font-weight: 800; }
  .eb-worksheet-drawing-space { min-height: 11mm; flex: 1; border: .35mm solid #b8d2df; border-radius: 1mm; }
  .eb-worksheet-equation-lines { display: grid; gap: 1.2mm; }
  .eb-worksheet-equation-lines span { min-height: 4mm; border-bottom: .3mm solid #839ba7; color: #526c7a; font-size: 7.5pt; }
  .eb-worksheet-answer-line { padding-top: .5mm; font-size: 9pt; }
  .eb-worksheet-complete { overflow: hidden; }
  .eb-worksheet-complete ol { min-height: 0; margin: 0; padding-left: 4.5mm; display: grid; gap: .7mm; font-size: 7.5pt; line-height: 1.1; }
  .eb-worksheet-complete li { break-inside: avoid; }
  .eb-worksheet-complete li span { display: block; margin-top: .25mm; }
  .eb-worksheet-final-answer { margin-top: auto !important; text-align: right; font-size: 10pt !important; }
  .eb-worksheet-pair-work { min-width: 0; min-height: 0; overflow: hidden; font-size: 7.5pt; }
  .eb-worksheet-pair-work p { margin: 0 0 1mm; font-weight: 800; }
  .eb-worksheet-pair-work table { width: 100%; height: calc(100% - 5mm); border-collapse: collapse; table-layout: fixed; }
  .eb-worksheet-pair-work th, .eb-worksheet-pair-work td { height: 3mm; padding: 0 .5mm; border: .25mm solid #9bbdcd; text-align: center; line-height: 1; }
  .eb-worksheet-pair-work th { background: #eef8fc; font-weight: 900; }
  .eb-worksheet-pair-work th:nth-child(3), .eb-worksheet-pair-work td:nth-child(3) { width: 48%; }
  .eb-worksheet-page footer { min-height: 5mm; display: flex; align-items: flex-end; justify-content: flex-end; font-size: 8.5pt; font-weight: 800; }
}
