:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #5f6f7f;
  --line: #c9d5df;
  --line-strong: #6c7d8c;
  --paper: #f7f4ee;
  --surface: #ffffff;
  --accent: #226d68;
  --accent-dark: #164f4c;
  --accent-soft: #d7eeea;
  --mark: #cf5d36;
  --mark-soft: #ffe2d5;
  --header: #edf3f7;
  --shadow: 0 18px 45px rgba(36, 49, 63, 0.16);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(34, 109, 104, 0.08), transparent 260px),
    var(--paper);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.workspace {
  display: grid;
  gap: 18px;
}

.intro {
  display: block;
}

.result-label {
  display: block;
  margin: 0 0 7px;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  max-width: none;
  margin: 0;
  font-size: clamp(1.85rem, 3vw, 3.15rem);
  line-height: 1;
  letter-spacing: 0;
}

.result-panel {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.result-panel strong {
  display: block;
  color: var(--mark);
  font-size: clamp(1.2rem, 2vw, 2rem);
  line-height: 1.15;
}

.question-panel strong {
  color: var(--ink);
}

.control-bar {
  display: grid;
  grid-template-columns: minmax(150px, 1.2fr) auto minmax(120px, 0.6fr) auto auto auto auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
}

.field,
.toggle,
.segmented {
  min-height: 58px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.segmented legend {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.field input,
.field select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 11px;
}

.field input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

.field input:focus,
.field select:focus {
  outline: 3px solid var(--accent-soft);
  border-color: var(--accent);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(44px, 1fr));
  gap: 3px;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented legend {
  grid-column: 1 / -1;
  margin-bottom: 6px;
}

.segmented label {
  display: grid;
}

.segmented input,
.toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 38px;
  place-items: center;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-weight: 850;
  cursor: pointer;
}

.segmented label:first-of-type span {
  border-radius: 6px 0 0 6px;
}

.segmented label:last-of-type span {
  border-radius: 0 6px 6px 0;
}

.segmented input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.segmented.wide span {
  min-width: 92px;
  padding: 0 10px;
  font-size: 0.88rem;
}

.toggle {
  display: flex;
  align-items: end;
  padding-bottom: 1px;
}

.toggle span {
  display: flex;
  align-items: center;
  min-height: 38px;
  gap: 9px;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 750;
  cursor: pointer;
}

.toggle span::before {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: #a9b7c3;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.08);
  content: "";
}

.toggle span::after {
  position: absolute;
  width: 14px;
  height: 14px;
  margin-left: 3px;
  border-radius: 50%;
  background: white;
  content: "";
  transition: transform 180ms ease;
}

.toggle input:checked + span::before {
  background: var(--accent);
}

.toggle input:checked + span::after {
  transform: translateX(14px);
}

.primary-action {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: var(--mark);
  color: white;
  padding: 0 18px;
  font-weight: 850;
  cursor: pointer;
}

.primary-action:focus-visible {
  outline: 3px solid var(--mark-soft);
}

.settings-menu {
  position: relative;
  min-height: 58px;
  align-self: end;
}

.settings-menu summary {
  display: grid;
  min-height: 38px;
  margin-top: 20px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 16px;
  font-weight: 850;
  cursor: pointer;
  list-style: none;
}

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

.settings-panel {
  position: absolute;
  right: 0;
  z-index: 20;
  display: grid;
  width: min(360px, 88vw);
  gap: 14px;
  margin-top: 8px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.speed-field {
  min-width: 240px;
}

.error {
  border: 1px solid #b93d3d;
  border-radius: 6px;
  background: #fff0f0;
  color: #8a2525;
  padding: 10px 12px;
  font-weight: 700;
}

.stage-card {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

#placeValueSvg {
  display: block;
  width: 100%;
  min-width: 940px;
  height: 790px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.column-header {
  fill: var(--header);
  stroke: var(--line-strong);
  stroke-width: 1.3;
}

.column-body {
  fill: #fffdf9;
  stroke: var(--line);
  stroke-width: 1.2;
}

.column-header.decimal-column,
.column-body.decimal-column {
  fill: #fbf6e7;
}

.hide-grid .column-header,
.hide-grid .column-body,
.hide-grid .header-text,
.hide-grid .fraction-host,
.hide-grid .row-label {
  opacity: 0;
}

.hide-grid .answer-cell {
  border-color: transparent;
  background: transparent;
}

.header-text {
  fill: var(--ink);
  font-size: 14px;
  font-weight: 850;
  text-anchor: middle;
}

.fraction-label {
  display: grid;
  height: 118px;
  place-items: center;
  color: var(--ink);
  font-size: 24px;
  font-weight: 850;
  text-align: center;
}

.fraction-label .katex {
  font-size: 1.15em;
}

.cell-digit,
.moving-digit {
  fill: var(--ink);
  font-size: 54px;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: middle;
}

.moving-digit {
  fill: var(--accent);
  filter: drop-shadow(0 8px 8px rgba(22, 79, 76, 0.18));
}

.pale-digit {
  fill: #9ca9b4;
  opacity: 0.55;
}

.answer-cell-host {
  overflow: visible;
}

.reveal-button-host {
  overflow: visible;
}

.reveal-button {
  width: 100%;
  height: 28px;
  border: 1px solid rgba(95, 111, 127, 0.34);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.reveal-button:hover,
.reveal-button:focus {
  border-color: var(--accent);
  color: var(--accent-dark);
  outline: 2px solid var(--accent-soft);
}

.reveal-button:disabled {
  cursor: default;
  opacity: 0.36;
}

.answer-cell {
  width: 100%;
  height: 100%;
  border: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 54px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
}

.answer-cell:focus {
  outline: 3px solid var(--accent-soft);
}

.answer-correct {
  color: var(--ink);
}

.answer-incorrect {
  color: #b93d3d;
}

.row-label {
  fill: var(--muted);
  font-size: 16px;
  font-weight: 850;
  text-anchor: end;
}

.hidden-row {
  opacity: 0;
}

.row-rule {
  stroke: var(--line);
  stroke-width: 1.2;
}

.arrow-path {
  fill: none;
  stroke: #6c7d8c;
  stroke-width: 2.6;
  stroke-linecap: round;
  opacity: 0.82;
}

.pale-arrow {
  opacity: 0.36;
}

.decimal-point {
  fill: var(--ink);
  font-size: 64px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: middle;
}

.answer-feedback {
  fill: var(--ink);
  font-size: 30px;
  font-weight: 850;
  text-anchor: middle;
}

.answer-feedback.correct-feedback {
  fill: #2f7a56;
}

.answer-feedback.incorrect-feedback {
  fill: #b93d3d;
}

@media (max-width: 1050px) {
  .app-shell {
    padding: 18px;
  }

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

  .intro {
    display: grid;
  }

  .control-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 12px;
  }

  .control-bar {
    grid-template-columns: 1fr;
  }

  #placeValueSvg {
    height: 760px;
    min-width: 910px;
  }
}
