:root {
  --blue: #149bd7;
  --ink: #102131;
  --muted: #5c6b78;
  --paper: #eef4f8;
  --panel: #ffffff;
  --line: #d8e2ea;
  --shadow: 0 12px 32px rgba(15, 33, 49, 0.12);
  --radius: 8px;
  --touch: 48px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
  touch-action: manipulation;
}

body {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  min-height: var(--touch);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbfd;
  color: var(--ink);
}

button {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

.app {
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100vh;
  height: 100dvh;
  min-width: 320px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  background: #071018;
  color: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand img {
  width: 142px;
  height: auto;
  display: block;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand-logo {
  display: inline-flex;
  border-radius: 6px;
}

.title-block {
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 2.05rem);
  line-height: 1.05;
  font-weight: 800;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: end;
  flex-wrap: wrap;
}

.icon-button {
  width: var(--touch);
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: #122436;
  color: #ffffff;
  border-color: #263d51;
}

.icon-button:hover,
.icon-button[aria-pressed="true"] {
  background: var(--blue);
  border-color: #8fd8f3;
  color: #06111a;
}

.icon {
  width: 24px;
  height: 24px;
  display: block;
  pointer-events: none;
}

.home-button {
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 2px solid #263d51;
  border-radius: var(--radius);
  background: #122436;
  color: #ffffff;
  text-decoration: none;
  font-weight: 800;
  white-space: nowrap;
}

.home-button:hover,
.home-button:focus-visible {
  background: var(--blue);
  border-color: #8fd8f3;
  color: #06111a;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 10px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 6px 14px rgba(15, 33, 49, 0.06);
  z-index: 3;
}

.toolbar-left,
.toolbar-right,
.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-right {
  margin-left: auto;
  justify-content: end;
}

.wide-button,
.palette-button,
.counter-button,
.small-button {
  min-height: var(--touch);
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-color: var(--line);
  background: #f8fbfd;
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
}

.wide-button:hover,
.palette-button:hover,
.small-button:hover {
  border-color: var(--blue);
  background: #e5f6fc;
}

.wide-button[aria-pressed="true"],
.small-button[aria-pressed="true"],
.primary {
  background: var(--blue);
  border-color: #0f80b3;
  color: #06111a;
}

.tool-menu {
  position: relative;
}

.tool-menu summary {
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbfd;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  list-style: none;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tool-menu summary::-webkit-details-marker {
  display: none;
}

.menu-panel {
  width: max-content;
  max-width: min(500px, calc(100vw - 36px));
  padding: 10px;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.show-panel,
.columns-panel,
.questions-panel {
  display: grid;
  gap: 8px;
  align-items: stretch;
}

.columns-panel {
  grid-template-columns: repeat(4, minmax(78px, 1fr));
}

.show-panel {
  grid-template-columns: repeat(2, minmax(128px, 1fr));
}

.questions-panel {
  width: min(460px, calc(100vw - 36px));
  grid-template-columns: 1fr auto;
}

.questions-panel select,
.questions-panel .question-output {
  grid-column: 1 / -1;
}

.check-pill {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  font-weight: 800;
  white-space: nowrap;
}

.check-pill input {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}

.workspace {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 14px;
  background:
    linear-gradient(#dce8f0 1px, transparent 1px),
    linear-gradient(90deg, #dce8f0 1px, transparent 1px);
  background-size: 34px 34px;
}

.pvc-stage {
  width: min(1500px, calc(100vw - 28px));
  min-width: calc(1040px * var(--view-zoom, 1));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(150px, 170px) minmax(0, 1fr) minmax(260px, 330px);
  gap: 12px;
  align-items: stretch;
}

.workspace.is-fit .pvc-stage {
  width: 100%;
  min-width: 0;
}

.palette,
.chart-card,
.side-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-heading {
  min-height: 48px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
  font-weight: 900;
}

.palette-list {
  padding: 8px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-content: start;
}

.palette-button {
  min-height: 58px;
  justify-content: flex-start;
}

.palette-counter-visual {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  display: block;
}

.palette-counter-visual .place-value-counter-model {
  width: 48px;
  height: 48px;
  margin: 0;
}

.palette-counter-visual .place-value-counter-model figcaption {
  display: none;
}

.palette-counter-visual .place-value-counter-visual {
  width: 48px;
  height: 48px;
  max-width: none;
  display: block;
}

.counter {
  --counter-colour: #f8d36b;
  width: 48px;
  height: 48px;
  display: inline-grid;
  place-items: center;
  border: 3px solid rgba(16, 33, 49, 0.18);
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.72), transparent 35%),
    var(--counter-colour);
  color: #06111a;
  font-size: 0.85rem;
  font-weight: 900;
  line-height: 1;
  box-shadow: inset 0 -8px 12px rgba(0, 0, 0, 0.13), 0 5px 10px rgba(15, 33, 49, 0.14);
}

.counter {
  width: 42px;
  height: 42px;
  font-size: 0.78rem;
}

.counter-button {
  min-height: 42px;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.counter-button:focus-visible {
  outline: 4px solid rgba(20, 155, 215, 0.45);
  outline-offset: 2px;
}

.counter-button:hover .counter {
  box-shadow: inset 0 -8px 12px rgba(0, 0, 0, 0.13), 0 0 0 4px rgba(20, 155, 215, 0.3);
}

.counter.c0 { --counter-colour: #bfc1c3; }
.counter.c1 { --counter-colour: #df9b7f; }
.counter.c2 { --counter-colour: #c17bab; }
.counter.c3 { --counter-colour: #1689b1; }
.counter.c4 { --counter-colour: #4daa3d; }
.counter.c5 { --counter-colour: #ffbd24; }
.counter.c6 { --counter-colour: #ef674d; }
.counter.c7 { --counter-colour: #ffbd24; }
.counter.c8 { --counter-colour: #4daa3d; }
.counter.c9 { --counter-colour: #1689b1; }

.chart-card {
  display: grid;
  grid-template-rows: auto 1fr;
}

.display-strip {
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: #f8fbfd;
}

.display-strip.single-row {
  grid-template-columns: 1fr;
}

.row-display,
.total-display {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.row-display.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(20, 155, 215, 0.16);
}

.row-display button {
  width: 100%;
  min-height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  justify-content: flex-start;
  color: var(--ink);
  font-weight: 900;
  text-align: left;
}

.display-value {
  min-height: 26px;
  margin-top: 5px;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.25;
  word-break: break-word;
}

.summary-strip {
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.total-display strong {
  display: block;
  margin-bottom: 4px;
}

.chart-scroll {
  min-height: 0;
  overflow: auto;
}

.place-chart {
  min-width: 760px;
  height: 100%;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(92px, 1fr);
}

.place-chart.shared-place-value-chart {
  display: block;
  min-width: 760px;
  padding: 12px;
  background: #ffffff;
}

.place-chart.shared-place-value-chart .place-value-model {
  width: 100%;
  height: auto;
  min-height: 0;
  margin: 0;
}

.place-chart.shared-place-value-chart .diagram-visual {
  width: 100%;
  height: auto;
  max-width: none;
}

.pvc-column {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-right: 1px solid var(--line);
  background: #ffffff;
}

.pvc-column:last-child {
  border-right: 0;
}

.col-head {
  min-height: 74px;
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
  text-align: center;
}

.col-head strong {
  font-size: 1.05rem;
}

.col-head span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.col-body {
  min-height: 430px;
  padding: 8px;
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  background:
    linear-gradient(180deg, rgba(20, 155, 215, 0.06), transparent 42%),
    #ffffff;
}

.row-zone {
  min-height: 178px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  gap: 5px;
  padding: 7px;
  border: 2px dashed transparent;
  border-radius: var(--radius);
}

.row-zone[data-active="true"] {
  border-color: rgba(20, 155, 215, 0.42);
  background: rgba(229, 246, 252, 0.72);
}

.row-zone[hidden] {
  display: none;
}

.row-zone.drag-over {
  border-color: var(--blue);
  background: #e5f6fc;
}

.row-label {
  width: 100%;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
  text-align: left;
}

.col-add {
  min-height: 48px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: #f8fbfd;
  font-weight: 900;
}

.side-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.question-card {
  min-height: 0;
  padding: 12px;
  overflow: auto;
}

.question-kicker {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 900;
}

.question-text {
  margin: 0;
  font-size: clamp(1rem, 1.6vw, 1.26rem);
  line-height: 1.24;
  font-weight: 900;
}

.feedback {
  min-height: 54px;
  margin-top: 10px;
  padding: 9px 10px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
  line-height: 1.25;
}

.feedback.good {
  border-color: #76b947;
  background: #eef9e8;
  color: #22510f;
}

.feedback.try {
  border-color: #f2b84b;
  background: #fff8e6;
  color: #6a4300;
}

.investigation-list {
  padding: 10px 12px 12px;
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  background: #fbfdff;
}

.investigation-list strong {
  font-size: 0.95rem;
}

.investigation-list ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.35;
  font-weight: 700;
}

.question-output {
  min-height: 70px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: #ffffff;
  font-weight: 800;
  line-height: 1.35;
}

.instructions-dialog {
  width: min(860px, calc(100vw - 32px));
  max-height: min(780px, calc(100vh - 32px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  color: var(--ink);
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(6, 17, 26, 0.32);
}

.instructions-dialog::backdrop {
  background: rgba(6, 17, 26, 0.5);
}

.instructions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #071018;
  color: #ffffff;
}

.instructions-header h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.15;
}

.instructions-body {
  max-height: calc(min(780px, 100vh - 32px) - 76px);
  overflow: auto;
  padding: 16px 18px 20px;
  line-height: 1.45;
}

.instructions-body h3 {
  margin: 16px 0 8px;
  font-size: 1.05rem;
}

.instructions-body h3:first-child {
  margin-top: 0;
}

.instructions-body p,
.instructions-body ul,
.instructions-body ol {
  margin: 0 0 10px;
}

.instructions-body li {
  margin-bottom: 6px;
}

.print-copyright {
  display: none;
}

.place-value-worksheet {
  display: none;
}

.instructions-dialog.worksheet-print-dialog {
  width: min(640px, calc(100vw - 24px));
}

.worksheet-print-form,
.worksheet-print-options {
  display: grid;
  min-width: 0;
}

.worksheet-print-options {
  gap: 14px;
}

.worksheet-print-options > p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.worksheet-option-group {
  min-width: 0;
  margin: 0;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
}

.worksheet-option-group legend {
  padding: 0 6px;
  font-weight: 900;
}

.worksheet-option {
  min-height: 72px;
  padding: 10px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  cursor: pointer;
}

.worksheet-option:has(input:checked) {
  border-color: var(--blue);
  background: #e5f6fc;
}

.worksheet-option input {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--blue);
}

.worksheet-option input:focus-visible {
  outline: 4px solid rgba(20, 155, 215, 0.35);
  outline-offset: 3px;
}

.worksheet-option span,
.worksheet-option small {
  display: block;
}

.worksheet-option small {
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.25;
}

.worksheet-print-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.worksheet-print-actions .wide-button {
  width: 100%;
}

.worksheet-print-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

@media (max-width: 1040px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: start;
  }

  .pvc-stage {
    width: 100%;
    min-width: 0;
    grid-template-columns: 1fr;
  }

  .palette-list {
    grid-template-columns: repeat(4, minmax(116px, 1fr));
  }

  .col-body {
    min-height: 360px;
  }
}

@media (max-width: 680px) {
  .toolbar {
    padding: 10px;
  }

  .palette-list,
  .display-strip,
  .summary-strip {
    grid-template-columns: 1fr;
  }

  .columns-panel,
  .show-panel,
  .questions-panel {
    grid-template-columns: 1fr;
  }

  .worksheet-option-group,
  .worksheet-print-actions {
    grid-template-columns: 1fr;
  }

  .place-chart {
    min-width: 720px;
  }
}

@media print {
  @page {
    size: landscape;
    margin: 10mm;
  }

  @page place-value-worksheet {
    size: A4 portrait;
    margin: 8mm;
  }

  html,
  body {
    height: auto;
    overflow: visible;
    background: #ffffff;
  }

  .app {
    display: block;
    height: auto;
  }

  .topbar,
  .toolbar,
  .palette,
  .side-card,
  .instructions-dialog {
    display: none;
  }

  .workspace {
    overflow: visible;
    padding: 0;
    background: #ffffff;
  }

  .pvc-stage {
    width: 100%;
    min-width: 0;
    display: block;
  }

  .chart-card {
    box-shadow: none;
    border-color: #7f8d98;
  }

  .col-body {
    min-height: 250px;
  }

  .print-copyright {
    display: block;
    margin-top: 10px;
    text-align: right;
    font-size: 11pt;
    font-weight: 700;
  }

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

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

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

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

  .place-value-worksheet-heading {
    min-height: 0;
    display: flex;
    align-items: center;
    gap: 5mm;
  }

  .place-value-worksheet-heading img {
    display: block;
    width: 31mm;
    height: auto;
    margin: 0;
  }

  .place-value-worksheet-heading h2,
  .place-value-worksheet-heading p {
    margin: 0;
  }

  .place-value-worksheet-heading h2 {
    font-size: 15pt;
    line-height: 1.05;
  }

  .place-value-worksheet-heading p {
    margin-top: 1mm;
    font-size: 9pt;
    font-weight: 700;
  }

  .place-value-worksheet-grids {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: repeat(4, minmax(0, 1fr));
    gap: 1.8mm;
    overflow: hidden;
  }

  .place-value-worksheet-copy,
  .place-value-worksheet-copy .place-value-model {
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
  }

  .place-value-worksheet-copy {
    display: grid;
    place-items: center;
  }

  .place-value-worksheet-copy .place-value-model {
    display: grid;
    place-items: center;
  }

  .place-value-worksheet-copy .place-value-model > figcaption {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .place-value-worksheet-copy .diagram-visual {
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
  }

  .place-value-worksheet-copyright {
    color: #000000;
    font-size: 8pt;
    font-weight: 700;
    text-align: right;
  }

  .place-value-worksheet[data-print-style="outline"] .place-value-chart-header-cell,
  .place-value-worksheet[data-print-style="outline"] .place-value-header,
  .place-value-worksheet[data-print-style="outline"] .place-value-cell,
  .place-value-worksheet[data-print-style="outline"] .place-value-counter-disc {
    fill: #ffffff !important;
    stroke: #000000 !important;
    filter: none !important;
  }

  .place-value-worksheet[data-print-style="outline"] svg text {
    fill: #000000 !important;
  }
}
