:root {
  --nrg-blue: #149bd7;
  --nrg-navy: #071018;
  --nrg-ink: #102131;
  --nrg-muted: #5b6b78;
  --nrg-line: #cbd9e4;
  --nrg-surface: #f2f7fa;
  --nrg-touch: 48px;
  font-family: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 0;
  color: var(--nrg-ink);
  background: var(--nrg-surface);
  font-family: Arial, Helvetica, sans-serif;
}

.app {
  width: 100%;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

button, input, summary { font: inherit; }
button, summary { cursor: pointer; }

.topbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  color: #fff;
  background: var(--nrg-navy);
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-logo 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-height: var(--nrg-touch);
  border: 2px solid #263d51;
  border-radius: 8px;
  color: #fff;
  background: #122436;
  font-weight: 800;
}
.icon-button { width: var(--nrg-touch); padding: 0; display: inline-grid; place-items: center; }
.icon-button .icon { width: 24px; height: 24px; }
.home-button { display: inline-flex; align-items: center; padding: 0 14px; text-decoration: none; }
.icon-button:hover, .home-button:hover { color: #06111a; background: var(--nrg-blue); border-color: #8fd8f3; }

#numberRepresentationGridModel { display: contents; }

.nrg-toolbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 72px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--nrg-line);
  background: #fff;
  box-shadow: 0 4px 14px rgba(16, 33, 49, 0.08);
  flex-wrap: wrap;
}

.nrg-toolbar-group { display: flex; align-items: center; gap: 8px; }
.nrg-number-entry label { font-weight: 900; }
.nrg-number-entry input {
  width: 178px;
  min-height: var(--nrg-touch);
  border: 2px solid #91a8b9;
  border-radius: 8px;
  padding: 0 10px;
  font-size: 1.2rem;
  font-weight: 900;
}
.nrg-history-controls { margin-left: auto; }

.nrg-button, .nrg-menu > summary, .nrg-menu-button {
  min-height: var(--nrg-touch);
  border: 2px solid #a9bdcc;
  border-radius: 8px;
  padding: 0 14px;
  color: var(--nrg-ink);
  background: #fff;
  font-weight: 850;
}
.nrg-primary, .nrg-menu-button.is-selected { color: #062239; background: #bdeafb; border-color: var(--nrg-blue); }
.nrg-button:hover:not(:disabled), .nrg-menu > summary:hover, .nrg-menu-button:hover { border-color: var(--nrg-blue); background: #e8f7fd; }
.nrg-button:disabled { cursor: not-allowed; opacity: 0.45; }

.nrg-menu { position: relative; }
.nrg-menu > summary { display: flex; align-items: center; list-style: none; }
.nrg-menu > summary::-webkit-details-marker { display: none; }
.nrg-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  display: grid;
  gap: 8px;
  min-width: 220px;
  padding: 12px;
  border: 1px solid var(--nrg-line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 14px 32px rgba(16, 33, 49, 0.18);
}
.nrg-show-panel label, .nrg-columns-panel label { display: flex; align-items: center; gap: 9px; min-height: 42px; font-weight: 800; }
.nrg-show-panel input, .nrg-columns-panel input { width: 22px; height: 22px; accent-color: var(--nrg-blue); }
.nrg-show-panel label:has(input:disabled) { color: #7b8994; }
.nrg-show-panel input:disabled { cursor: not-allowed; }
.nrg-columns-panel { min-width: 250px; max-height: min(68vh, 520px); overflow-y: auto; }
.nrg-menu-panel small { color: var(--nrg-muted); line-height: 1.35; }
.nrg-worksheet-button { white-space: nowrap; }

.nrg-workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 16px 18px 20px;
  overflow: hidden;
}

.nrg-partition-controls {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  max-width: 1400px;
  margin: 0 auto 14px;
}
.nrg-boundary-card {
  display: grid;
  grid-template-columns: minmax(76px, auto) minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--nrg-line);
  border-radius: 10px;
  background: #fff;
  text-align: center;
}
.nrg-boundary-card > strong { font-size: 0.94rem; line-height: 1.15; }
.nrg-boundary-card > div { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.nrg-boundary-card .nrg-button { min-height: var(--nrg-touch); padding: 0 6px; font-size: 0.9rem; }

.nrg-model-scroll {
  width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  place-items: stretch;
  overflow: hidden;
  border: 1px solid var(--nrg-line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(16, 33, 49, 0.09);
}
.nrg-model-host {
  width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  padding: 10px 14px 8px;
}
.nrg-model-host .question-visual {
  width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  place-items: stretch;
  margin: 0;
  overflow: hidden;
}
.nrg-model-host figcaption { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.nrg-model-host svg {
  display: block;
  width: 100%;
  min-width: 0;
  height: 100%;
  min-height: 0;
  max-height: 100%;
}

.nrg-words-line {
  width: 100%;
  min-width: 0;
  max-width: 1400px;
  margin: 13px auto 0;
  padding: 0 12px;
  color: #17394b;
  font-size: clamp(1.15rem, 2.2vw, 1.65rem);
  font-weight: 900;
  line-height: 1.35;
  text-align: center;
}
.nrg-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.nrg-print-logo, .nrg-print-copyright { display: none; }

.nrg-instructions { width: min(760px, calc(100vw - 32px)); max-height: min(82vh, 760px); padding: 0; border: 0; border-radius: 12px; box-shadow: 0 24px 64px rgba(0,0,0,.32); }
.nrg-instructions::backdrop { background: rgba(5, 16, 25, .62); }
.nrg-dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 20px; color: #fff; background: var(--nrg-navy); }
.nrg-dialog-header h2 { margin: 0; font-size: 1.35rem; }
.nrg-close { min-height: 44px; border: 1px solid #60758a; border-radius: 8px; padding: 0 14px; color: #fff; background: #122436; font-weight: 800; }
.nrg-dialog-body { padding: 20px 24px 26px; overflow-y: auto; line-height: 1.55; }
.nrg-dialog-body h3 { margin: 18px 0 6px; }
.nrg-dialog-body h3:first-child { margin-top: 0; }
.nrg-dialog-body p, .nrg-dialog-body li { color: #314958; }

.nrg-worksheet[hidden] { display: none; }
.nrg-worksheet-dialog { overflow: hidden; }
.nrg-worksheet-form {
  max-height: inherit;
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}
.nrg-worksheet-options { min-height: 0; display: grid; gap: 14px; overflow-y: auto; }
.nrg-worksheet-options > p { margin: 0; }
.nrg-worksheet-fieldset {
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--nrg-line);
  border-radius: 10px;
}
.nrg-worksheet-fieldset legend { padding: 0 6px; font-weight: 900; }
.nrg-worksheet-range { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.nrg-worksheet-range label { display: grid; gap: 6px; font-weight: 800; }
.nrg-worksheet-range select {
  width: 100%;
  min-height: var(--nrg-touch);
  padding: 0 10px;
  border: 2px solid #91a8b9;
  border-radius: 8px;
  color: var(--nrg-ink);
  background: #fff;
  font: inherit;
}
.nrg-worksheet-row-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; }
.nrg-worksheet-row-options label,
.nrg-worksheet-style-options label {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  font-weight: 800;
}
.nrg-worksheet-row-options input,
.nrg-worksheet-style-options input { width: 22px; height: 22px; flex: 0 0 auto; accent-color: var(--nrg-blue); }
.nrg-worksheet-row-options label:has(input:disabled) { color: #7b8994; }
.nrg-worksheet-fieldset > small { display: block; margin-top: 8px; color: var(--nrg-muted); }
.nrg-worksheet-style-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.nrg-worksheet-style-options label {
  align-items: flex-start;
  padding: 10px;
  border: 2px solid var(--nrg-line);
  border-radius: 8px;
}
.nrg-worksheet-style-options label:has(input:checked) { border-color: var(--nrg-blue); background: #e8f7fd; }
.nrg-worksheet-style-options span,
.nrg-worksheet-style-options small { display: block; }
.nrg-worksheet-style-options small { margin-top: 3px; color: var(--nrg-muted); font-weight: 600; line-height: 1.3; }
.nrg-worksheet-message { min-height: 1.4em; color: #9a3412 !important; font-weight: 800; }
.nrg-worksheet-actions { display: flex; justify-content: flex-end; gap: 10px; }
.nrg-worksheet-actions .nrg-button { min-width: 150px; }

button:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 4px solid rgba(20, 155, 215, 0.35);
  outline-offset: 2px;
}

@media (max-width: 820px) {
  .topbar { grid-template-columns: 1fr; }
  .top-actions { justify-content: flex-start; }
  .nrg-history-controls { margin-left: 0; }
  .nrg-workspace { padding: 12px 8px; }
  .nrg-model-host { min-width: 0; }
  .nrg-worksheet-range,
  .nrg-worksheet-style-options { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4 landscape; margin: 9mm 9mm 14mm; }
  @page number-representation-worksheet { size: A4 landscape; margin: 8mm; }
  html, body, .app { width: 100%; height: auto; min-height: 0; overflow: visible; }
  .app { display: block; }
  body { background: #fff; }
  .topbar, .nrg-toolbar, .nrg-partition-controls, .nrg-feedback, .classroom-tools-launcher, .annotation-overlay { display: none !important; }
  .nrg-workspace { display: block; padding: 0 0 8mm; overflow: visible; }
  .nrg-model-scroll { overflow: visible; border: 0; box-shadow: none; }
  .nrg-model-host { min-width: 0; padding: 0; }
  .nrg-model-host svg { width: 100% !important; max-width: 100% !important; height: auto !important; max-height: 137mm !important; }
  .nrg-words-line { margin: 2.5mm 0 0; padding: 0; font-size: 13pt; }
  .nrg-print-logo { display: block !important; width: 38mm; margin: 0 0 3mm; }
  .nrg-print-copyright {
    display: block !important;
    position: fixed;
    right: 0;
    bottom: 0;
    z-index: 20;
    color: #102131 !important;
    font-size: 9pt;
    font-weight: 700;
  }

  html[data-spire-print-page="number-representation-worksheet"],
  html[data-spire-print-page="number-representation-worksheet"] body {
    page: number-representation-worksheet;
    width: 281mm !important;
    height: 194mm !important;
    min-height: 0 !important;
    max-height: 194mm !important;
    margin: 0 !important;
    overflow: hidden !important;
  }

  body[data-number-representation-print-mode="worksheet"] .topbar,
  body[data-number-representation-print-mode="worksheet"] #numberRepresentationGridModel > :not(.nrg-worksheet),
  body[data-number-representation-print-mode="worksheet"] .spire-shared-print-logo,
  body[data-number-representation-print-mode="worksheet"] .spire-shared-print-copyright {
    display: none !important;
  }

  body[data-number-representation-print-mode="worksheet"] .app,
  body[data-number-representation-print-mode="worksheet"] #numberRepresentationGridModel {
    display: block !important;
    width: 100% !important;
    height: 194mm !important;
    min-height: 0 !important;
    max-height: 194mm !important;
    overflow: hidden !important;
  }

  body[data-number-representation-print-mode="worksheet"] .nrg-worksheet {
    width: 100%;
    height: 194mm;
    min-width: 0;
    min-height: 0;
    display: grid !important;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 2mm;
    overflow: hidden;
    color: #102131;
    background: #fff;
    break-inside: avoid-page;
    page-break-inside: avoid;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .nrg-worksheet-heading {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 4mm;
  }

  .nrg-worksheet-heading img { display: block; width: 31mm; height: auto; margin: 0; }
  .nrg-worksheet-title h2,
  .nrg-worksheet-title p,
  .nrg-worksheet-details { margin: 0; }
  .nrg-worksheet-title h2 { font-size: 15pt; line-height: 1.05; }
  .nrg-worksheet-title p { margin-top: 1mm; font-size: 8.5pt; font-weight: 700; }
  .nrg-worksheet-details { display: grid; gap: 2mm; font-size: 8.5pt; font-weight: 700; white-space: nowrap; }

  .nrg-worksheet-grids {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 3mm;
    overflow: hidden;
  }

  .nrg-worksheet-copy {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: hidden;
    break-inside: avoid;
  }

  .nrg-worksheet-model,
  .nrg-worksheet-model .number-representation-grid-model,
  .nrg-worksheet-model .question-visual {
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
  }

  .nrg-worksheet-model { display: grid; place-items: stretch; }
  .nrg-worksheet-model .number-representation-grid-model,
  .nrg-worksheet-model .question-visual { display: grid; place-items: stretch; }
  .nrg-worksheet-model figcaption { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .nrg-worksheet-model svg {
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
  }

  .nrg-worksheet-words {
    min-width: 0;
    min-height: 8mm;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: end;
    gap: 2mm;
    margin: 1mm 0 0;
    font-size: 8.5pt;
  }
  .nrg-worksheet-words span { min-width: 0; height: 6mm; border-bottom: 1.2pt solid #102131; }

  .nrg-worksheet-copyright { color: #000; font-size: 8pt; font-weight: 700; text-align: right; }

  .nrg-worksheet[data-print-style="outline"] :is(.number-representation-header, .number-representation-cell) {
    fill: #fff !important;
    stroke: #000 !important;
  }
  .nrg-worksheet[data-print-style="outline"] :is(.number-representation-header-rule, .number-representation-decimal-point) {
    fill: #000 !important;
    stroke: #000 !important;
  }
  .nrg-worksheet[data-print-style="outline"] svg text { fill: #000 !important; }
}
