:root {
  color-scheme: light;
  --ink: #1f2937;
  --ink-soft: #6b7280;
  --wash: #f3f4f6;
  --wash-deep: #e5e7eb;
  --accent: #047857;
  --accent-dark: #065f46;
  --whole: #ecfdf5;
  --decimal: #fff7ed;
  --decimal-edge: #c2410c;
  --surface: #ffffff;
  --line: rgba(31, 41, 55, 0.16);
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Nunito", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse 60% 45% at 85% 0%, rgba(4, 120, 87, 0.12), transparent 55%),
    radial-gradient(ellipse 50% 40% at 10% 90%, rgba(194, 65, 12, 0.08), transparent 50%),
    linear-gradient(180deg, var(--wash) 0%, var(--wash-deep) 100%);
}

.shell {
  max-width: 52rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3.5rem;
}

.back {
  margin: 0 0 1.25rem;
}

.back a {
  color: var(--accent-dark);
  font-weight: 700;
  text-decoration: none;
}

.back a:hover,
.back a:focus-visible {
  text-decoration: underline;
  outline: none;
}

.intro {
  margin-bottom: 1.5rem;
  animation: rise-in 0.7s ease-out both;
}

.eyebrow {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 5.5vw, 2.9rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.lede {
  margin: 0.75rem 0 0;
  color: var(--ink-soft);
  line-height: 1.5;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.controls {
  margin-bottom: 1.35rem;
  animation: rise-in 0.75s ease-out 0.06s both;
}

.number-label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.number-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

#number-input {
  flex: 1 1 12rem;
  min-width: 0;
  padding: 0.8rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: 0.75rem;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

#number-input:focus-visible {
  outline: 3px solid rgba(4, 120, 87, 0.35);
  outline-offset: 2px;
  border-color: var(--accent);
}

.hint {
  margin: 0.55rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 0.8rem 1.25rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: transform 160ms ease, background 160ms ease;
}

button.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button:hover,
button:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

button.secondary:hover,
button.secondary:focus-visible {
  background: rgba(31, 41, 55, 0.05);
}

button:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.chart-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1.35rem;
  animation: rise-in 0.75s ease-out 0.1s both;
}

.chart {
  display: grid;
  grid-template-columns: repeat(3, minmax(5.5rem, 1fr)) auto repeat(3, minmax(5.5rem, 1fr));
  gap: 0;
  min-width: 36rem;
  border: 2px solid var(--ink);
  border-radius: 1rem;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 16px 40px rgba(31, 41, 55, 0.08);
}

.place-col {
  display: grid;
  grid-template-rows: auto auto 1fr;
  border-right: 1px solid var(--line);
  min-height: 12rem;
}

.place-col:last-child {
  border-right: 0;
}

.place-col.whole {
  background: var(--whole);
}

.place-col.decimal {
  background: var(--decimal);
}

.place-header {
  padding: 0.7rem 0.45rem 0.35rem;
  text-align: center;
  border-bottom: 1px solid var(--line);
}

.place-name {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(0.85rem, 2vw, 1rem);
  font-weight: 600;
  line-height: 1.2;
}

.place-value {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.place-digit {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 0.4rem;
}

.place-digit input {
  width: 2.6rem;
  height: 2.6rem;
  border: 2px solid rgba(31, 41, 55, 0.2);
  border-radius: 0.55rem;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
}

.place-digit input:focus-visible {
  outline: 3px solid rgba(4, 120, 87, 0.35);
  outline-offset: 2px;
  border-color: var(--accent);
}

.place-digit input.answer-flash {
  animation: digit-pop 0.7s ease-out;
}

.decimal-point-col {
  display: grid;
  grid-template-rows: auto auto 1fr;
  align-items: stretch;
  min-width: 2.4rem;
  background: var(--ink);
  color: #fff;
  border-right: 1px solid rgba(255, 255, 255, 0.15);
}

.decimal-point-col .place-header {
  border-bottom-color: rgba(255, 255, 255, 0.2);
}

.decimal-point-col .place-name {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.decimal-point-col .place-value {
  color: rgba(255, 255, 255, 0.7);
}

.decimal-dot {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1;
}

.readout {
  display: grid;
  gap: 1.15rem;
  padding: 1.25rem 1.35rem;
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  background: var(--surface);
  box-shadow: 0 14px 36px rgba(31, 41, 55, 0.07);
  animation: rise-in 0.75s ease-out 0.14s both;
}

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

.readout-label {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.expanded-form,
.spoken-form {
  margin: 0.55rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 3vw, 1.45rem);
  font-weight: 600;
  line-height: 1.45;
  color: var(--accent-dark);
}

.spoken-form {
  color: var(--ink);
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(0.85rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes digit-pop {
  0% {
    opacity: 0.35;
    transform: scale(0.9);
    background-color: rgba(4, 120, 87, 0.28);
  }
  45% {
    opacity: 1;
    transform: scale(1.08);
    background-color: rgba(4, 120, 87, 0.18);
  }
  100% {
    opacity: 1;
    transform: scale(1);
    background-color: var(--surface);
  }
}

@media (max-width: 520px) {
  .shell {
    padding: 1.15rem 0.9rem 2.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .intro,
  .controls,
  .chart-wrap,
  .readout,
  .place-digit input.answer-flash,
  button {
    animation: none !important;
    transition: none !important;
  }
}
