/* Towers of Hanoi — styles.
   Colours, type and buttons follow design-system/ (tokens + guides).
   White mode only, portrait-first, single column. */

:root {
  /* greyscale (color-tokens.md) */
  --grey-100: #18181c; --grey-90: #41454a; --grey-80: #6b7481; --grey-70: #808b9a;
  --grey-60: #a1aab6;  --grey-50: #bcc3cc; --grey-40: #d3dbe4; --grey-30: #ebf0f5;
  --grey-20: #f1f5f9;  --grey-10: #f8fafc; --white: #ffffff;

  /* action */
  --teal: #0e9289; --teal-dark: #01766f;
  --fuchsia: #f263a2; --fuchsia-dark: #e65796; --fuchsia-light: #ffb9d8;

  /* status families: bg · border · token · text */
  --success-bg: #ebf8f0; --success-border: #9adbb4; --success-token: #35b86a;
  --error-bg: #f7cabf;   --error-border: #f0a796;   --error-token: #e14f2e;
  --info-bg: #edf6fc;    --info-border: #a3d0ef;    --info-text: #0b66a3;
  --orange-bg: #fef3ee;  --orange-border: #fbc4aa;  --orange-text: #ac4413;

  /* purple ramp — the discs */
  --purple-70: #7139b7; --purple-60: #b67efc; --purple-50: #c498fd; --purple-40: #d3b2fd; --purple-30: #dabefd;

  --text-primary: var(--grey-100);
  --text-secondary: var(--grey-80);
  --text-tertiary: var(--grey-70);

  /* typography-tokens.css */
  --font-display: 'Lora', Georgia, serif;
  --font-heading: 'Lexend', -apple-system, 'Segoe UI', sans-serif;
  --font-body: 'Nunito', -apple-system, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;

  --text-display: clamp(1.75rem, 1rem + 2.5vw, 3.25rem);
  --text-h2: clamp(1.125rem, 0.425rem + 1.75vw, 2rem);
  --text-h3: clamp(0.9375rem, 0.4875rem + 1.125vw, 1.5rem);
  --text-body: clamp(1rem, 0.9rem + 0.25vw, 1.125rem);
  --text-label: clamp(0.8125rem, 0.7625rem + 0.125vw, 0.875rem);
  --text-number: clamp(1.875rem, 0.675rem + 3vw, 3.375rem);
  --text-stat: clamp(1.125rem, 0.625rem + 1.25vw, 1.75rem);
  --text-helper: 0.6875rem;
  --text-code: 0.8125rem;

  /* card-tokens.css */
  --card-radius: 24px; --card-radius-inner: 12px; --card-pad: 24px; --card-gap: 16px;
  --card-shadow: 0 4px 24px rgba(24, 24, 28, .04);

  --ease: cubic-bezier(.2, .9, .25, 1);
  --col: 560px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--grey-10);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
em { font-style: italic; }
sup { font-size: .7em; line-height: 0; vertical-align: .55em; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--white); padding: 8px 12px; border-radius: 8px; }
.skip:focus { left: 8px; z-index: 10; }

/* ---------- type classes (typography-tokens.css, trimmed to what is used) ---------- */
.t-display { font-family: var(--font-display); font-size: var(--text-display); font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; color: var(--text-primary); margin: 0; }
.t-h2 { font-family: var(--font-heading); font-size: var(--text-h2); font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; color: var(--text-primary); margin: 0; }
.t-h3 { font-family: var(--font-heading); font-size: var(--text-h3); font-weight: 600; line-height: 1.3; color: var(--text-primary); margin: 0; }
.t-body, .t-body-relaxed { font-family: var(--font-body); font-size: var(--text-body); font-weight: 500; color: var(--text-secondary); margin: 0; }
.t-body { line-height: 1.6; }
.t-body-relaxed { line-height: 1.8; }
.t-label { font-family: var(--font-body); font-size: var(--text-label); font-weight: 500; line-height: 1.4; color: var(--text-secondary); }
.t-number { font-family: var(--font-heading); font-size: var(--text-number); font-weight: 600; line-height: 1.05; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.t-stat { font-family: var(--font-mono); font-size: var(--text-stat); font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.t-code { font-family: var(--font-mono); font-size: var(--text-code); font-weight: 500; color: var(--text-secondary); white-space: nowrap; }
.t-helper { font-family: var(--font-body); font-size: var(--text-helper); font-weight: 400; line-height: 1.45; color: var(--text-tertiary); margin: 0; }
.screen p em, .math { color: var(--text-primary); }
.math { font-family: var(--font-mono); font-weight: 500; white-space: nowrap; }

/* ---------- shell ---------- */
.top { position: sticky; top: 0; z-index: 5; background: var(--grey-10); }
.top__inner { max-width: var(--col); margin: 0 auto; padding: 14px 16px 10px; display: flex; align-items: center; gap: 12px; }
.top__name { font-family: var(--font-heading); font-weight: 500; font-size: var(--text-label); color: var(--text-tertiary); white-space: nowrap; }
.progress { flex: 1; height: 6px; border-radius: 99px; background: var(--grey-30); overflow: hidden; }
.progress__fill { height: 100%; width: 0; background: var(--grey-40); border-radius: 99px; transition: width 320ms var(--ease); }

.app { max-width: var(--col); margin: 0 auto; padding: 8px 16px 32px; padding-bottom: calc(32px + env(safe-area-inset-bottom)); }

/* ---------- screen = one Default card ---------- */
.screen {
  background: var(--white);
  border: 1px solid var(--grey-30);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: var(--card-pad);
  display: flex; flex-direction: column; gap: var(--card-gap);
  animation: enter 220ms var(--ease) both;
}
@keyframes enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (max-width: 767px) { .screen { padding: 16px; } }

.screen--intro .t-display { margin-top: 8px; }
.screen--intro p:last-of-type { color: var(--text-primary); }

.rules { margin: 0; padding-left: 1.4em; display: grid; gap: 8px; color: var(--text-secondary); }
.rules li::marker { font-family: var(--font-mono); color: var(--text-tertiary); }
.how { padding: 12px 14px; background: var(--info-bg); border: 1px solid var(--info-border); border-radius: var(--card-radius-inner); color: var(--info-text); }

.actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 4px; flex-wrap: wrap; }
.actions--split { justify-content: space-between; }
.actions .btn--primary { order: 2; }
@media (max-width: 420px) {
  .actions:not(.actions--split) .btn--primary { flex: 1 1 100%; }
}

/* ---------- buttons (button-tokens.css) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 112px;
  font-family: var(--font-body); font-weight: 600; letter-spacing: .02em; white-space: nowrap;
  border: 1px solid transparent; cursor: pointer; outline: none;
  transform-origin: center bottom; transform: translateY(0);
  transition: transform 140ms var(--ease), box-shadow 140ms var(--ease), background 160ms, color 160ms, border-color 160ms;
  user-select: none; position: relative;
}
.btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.btn--l  { padding: 10px 16px; font-size: 14px; line-height: 20px; border-radius: 12px; }
.btn--xl { padding: 12px 16px; font-size: 16px; line-height: 20px; border-radius: 12px; }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(2px) scale(.99); }
.btn--primary.btn--affirm { background: var(--teal); border-color: var(--teal-dark); color: #fff; box-shadow: 0 2px 0 var(--teal-dark); }
.btn--primary.btn--affirm:hover { box-shadow: 0 5px 0 var(--teal-dark); }
.btn--primary.btn--affirm:active { background: var(--teal-dark); box-shadow: 0 0 0 var(--teal-dark); }
.btn--tertiary { background: #fff; border-color: var(--grey-40); color: var(--grey-100); box-shadow: 0 2px 0 var(--grey-40); }
.btn--tertiary:hover { box-shadow: 0 5px 0 var(--grey-40); }
.btn--tertiary:active { border-color: var(--grey-50); box-shadow: 0 0 0 var(--grey-50); }
.btn--alt { background: var(--fuchsia); border-color: var(--fuchsia-dark); color: #fff; box-shadow: 0 2px 0 var(--fuchsia-dark); }
.btn--alt:hover { box-shadow: 0 5px 0 var(--fuchsia-dark); }
.btn--alt:active { background: var(--fuchsia-dark); box-shadow: 0 0 0 var(--fuchsia-dark); }
.btn[disabled] { cursor: not-allowed; background: var(--grey-40) !important; border-color: var(--grey-50) !important; color: var(--grey-50) !important; box-shadow: 0 2px 0 var(--grey-50) !important; transform: none !important; }
@media (prefers-reduced-motion: reduce) { .btn { transition: background 100ms, color 100ms; transform: none !important; } }

/* ---------- landing hero: a tower that builds itself ---------- */
.hero { position: relative; height: 128px; margin: 4px auto 0; width: min(100%, 260px); display: flex; flex-direction: column-reverse; align-items: center; padding-bottom: 10px; }
.hero__peg { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); width: 10px; height: 110px; background: var(--grey-40); border-radius: 6px 6px 0 0; }
.hero__base { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; background: var(--grey-40); border-radius: 4px; }
.hero__disc { height: 20px; border-radius: 999px; position: relative; z-index: 1; box-shadow: inset 0 -2px 0 rgba(24, 24, 28, .12); animation: drop 520ms var(--ease) both; }
.hero__disc[data-size="5"] { width: 100%; background: var(--purple-70); animation-delay: 80ms; }
.hero__disc[data-size="4"] { width: 84%; background: var(--purple-60); animation-delay: 260ms; }
.hero__disc[data-size="3"] { width: 68%; background: var(--purple-50); animation-delay: 440ms; }
.hero__disc[data-size="2"] { width: 52%; background: var(--purple-40); animation-delay: 620ms; }
.hero__disc[data-size="1"] { width: 36%; background: var(--purple-30); animation-delay: 800ms; }
@keyframes drop { 0% { opacity: 0; transform: translateY(-60px); } 70% { opacity: 1; transform: translateY(3px) scale(1.04, .9); } 100% { transform: none; } }

.puzzle__level { margin: -4px 0 -8px; color: var(--text-tertiary); }

.bignum { font-family: var(--font-mono); font-weight: 700; font-size: var(--text-stat); letter-spacing: .02em; color: var(--text-primary); margin: 0; padding: 12px 14px; background: var(--grey-20); border-radius: var(--card-radius-inner); text-align: center; word-break: break-all; min-height: 2.8em; }
.bignum__cursor { display: inline-block; width: .55ch; height: 1em; vertical-align: -.1em; background: var(--grey-50); animation: blink 700ms steps(2) infinite; }
@keyframes blink { to { opacity: 0; } }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 20; }

/* ---------- stats ---------- */
.puzzle__head, .chess__stats { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat--right { text-align: right; }

/* ---------- the board ---------- */
.board {
  --peg-w: 10px;
  --disc-h: clamp(26px, 7.5vw, 36px);
  position: relative;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 0 4px 34px;
  background: var(--grey-20);
  border-radius: var(--card-radius-inner);
  touch-action: none;
  user-select: none;
  min-height: calc(var(--disc-h) * 6 + 72px);
}
.rod {
  appearance: none; background: none; border: 0; padding: 0; margin: 0;
  position: relative; display: block;
  height: calc(var(--disc-h) * 6 + 40px);
  cursor: pointer; border-radius: 12px; outline: none;
}
.rod:focus-visible { box-shadow: inset 0 0 0 2px var(--teal); }
.rod__peg {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  width: var(--peg-w); height: calc(100% - 10px);
  background: var(--grey-40); border-radius: 6px 6px 0 0;
  transition: background 160ms;
}
.rod.is-target .rod__peg { background: var(--fuchsia-light); }
.rod.is-source .rod__peg { background: var(--fuchsia); }
.rod.is-wrong .rod__peg { background: var(--error-token); }
.rod__stack { position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column-reverse; align-items: center; }
.rod__name {
  position: absolute; left: 50%; bottom: -30px; transform: translateX(-50%);
  font-family: var(--font-heading); font-weight: 500; font-size: var(--text-label); color: var(--text-tertiary);
}
.board__base { position: absolute; left: 4px; right: 4px; bottom: 26px; height: 8px; background: var(--grey-40); border-radius: 4px; pointer-events: none; }

.disc {
  height: var(--disc-h);
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-heading); font-weight: 600; font-size: var(--text-label);
  color: var(--grey-100);
  box-shadow: inset 0 -2px 0 rgba(24, 24, 28, .12);
  position: relative; z-index: 1;
  will-change: transform;
}
.disc[data-size="5"] { width: 94%; background: var(--purple-70); color: #fff; }
.disc[data-size="4"] { width: 80%; background: var(--purple-60); }
.disc[data-size="3"] { width: 66%; background: var(--purple-50); }
.disc[data-size="2"] { width: 52%; background: var(--purple-40); }
.disc[data-size="1"] { width: 38%; background: var(--purple-30); }
.disc.is-lifted { box-shadow: 0 0 0 3px var(--fuchsia), 0 10px 22px rgba(24, 24, 28, .18); z-index: 3; animation: float 1.1s ease-in-out infinite alternate; }
@keyframes float { from { transform: translateY(-6px); } to { transform: translateY(-14px); } }
.disc.is-landed { animation: land 260ms var(--ease); }
@keyframes land { 0% { transform: scale(1.06, .82); } 60% { transform: scale(.97, 1.06); } 100% { transform: none; } }
.t-number.is-tick { animation: tick 220ms var(--ease); }
@keyframes tick { 40% { transform: scale(1.18); } }
.disc.is-dragging { transition: none; z-index: 4; pointer-events: none; }
.board.is-locked .rod { cursor: default; }

/* ---------- notices (surface = bg + border + text) ---------- */
.notice { padding: 12px 14px; border-radius: var(--card-radius-inner); font-size: var(--text-body); line-height: 1.5; font-weight: 500; }
.notice[hidden] { display: none; }
.notice--info { background: var(--info-bg); border: 1px solid var(--info-border); color: var(--info-text); }
.notice--success { background: var(--success-bg); border: 1px solid var(--success-border); color: var(--grey-90); }
.notice--error { background: var(--error-bg); border: 1px solid var(--error-border); color: var(--grey-90); }
.notice--nudge { background: var(--orange-bg); border: 1px solid var(--orange-border); color: var(--orange-text); }
.notice .math { color: inherit; }
.notice__actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: separate; border-spacing: 0; border: 1px solid var(--grey-30); border-radius: var(--card-radius-inner); overflow: hidden; }
.table th, .table td { padding: 10px 8px; text-align: center; border-bottom: 1px solid var(--grey-30); }
.table thead th { background: var(--grey-20); }
.table tbody tr:last-child th, .table tbody tr:last-child td { border-bottom: 0; }
.table th:first-child, .table td:first-child { text-align: left; padding-left: 12px; }
.table--tall td:first-child { text-align: center; padding-left: 8px; }
.table--inline { font-size: var(--text-label); }
.table--wide th, .table--wide td { padding: 10px 4px; }
.table--wide th:first-child, .table--wide td:first-child { padding-left: 10px; }
.table--wide .t-stat { font-size: var(--text-body); }
.table--wide .cell-input { max-width: 54px; font-size: var(--text-body); }
.table--inline .t-stat { font-size: var(--text-body); }
.table--powers .t-code { color: var(--text-secondary); }

.cell-input, .formula__input, .power__base, .power__exp {
  font-family: var(--font-mono); font-weight: 700; font-size: var(--text-stat); color: var(--text-primary);
  text-align: center; background: var(--white);
  border: 1px solid var(--grey-40); border-radius: 8px; outline: none;
  min-height: 44px;
}
.cell-input { width: 100%; max-width: 64px; }
.cell-input:focus, .formula__input:focus, .power__base:focus, .power__exp:focus { border-color: var(--teal); box-shadow: 0 0 0 2px var(--teal); }
.cell-input.is-locked, .formula__input.is-locked, .power__base.is-locked, .power__exp.is-locked { background: var(--success-bg); border-color: var(--success-border); }

.formula { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.formula__input { flex: 1 1 12ch; min-width: 12ch; max-width: 100%; padding: 6px 10px; text-align: left; }

.power { display: flex; align-items: flex-start; justify-content: center; gap: 4px; padding: 8px 0; }
.power__base { width: 3.2ch; min-height: 56px; font-size: calc(var(--text-stat) * 1.3); margin-top: 18px; }
.power__exp { width: 6.5ch; min-height: 40px; font-size: var(--text-body); }

/* ---------- options (fuchsia = selection) ---------- */
.options { border: 0; margin: 0; padding: 0; display: grid; gap: 10px; }
.option { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--grey-30); border-radius: var(--card-radius-inner); cursor: pointer; background: var(--white); min-height: 44px; }
.option:hover { background: var(--grey-20); }
.option input { appearance: none; width: 22px; height: 22px; margin: 0; border: 2px solid var(--grey-50); border-radius: 50%; display: grid; place-items: center; flex: none; }
.option input::after { content: ''; width: 12px; height: 12px; border-radius: 50%; background: var(--fuchsia); transform: scale(0); transition: transform 120ms var(--ease); }
.option input:checked { border-color: var(--fuchsia); }
.option input:checked::after { transform: scale(1); }
.option input:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.option:has(input:checked) { border-color: var(--fuchsia); }
.option.is-right { background: var(--success-bg); border-color: var(--success-border); }
.option.is-wrong { background: var(--error-bg); border-color: var(--error-border); }
.options.is-locked .option { pointer-events: none; }

/* ---------- chessboard ---------- */
.chess {
  display: grid; grid-template-columns: repeat(8, 1fr); aspect-ratio: 1;
  border: 1px solid var(--grey-40); border-radius: var(--card-radius-inner); overflow: hidden;
  background: var(--white);
}
.sq { position: relative; display: grid; place-items: center; }
.sq.is-dark { background: var(--grey-40); }
.sq.is-lit { outline: 3px solid var(--fuchsia); outline-offset: -3px; z-index: 1; }
.sq__n { font-family: var(--font-mono); font-size: 10px; color: var(--grey-80); position: absolute; top: 3px; left: 4px; opacity: 0; transition: opacity 200ms; }
.sq.is-filled .sq__n { opacity: 1; }
.sq svg { width: 84%; height: 84%; display: block; overflow: visible; }
.grain { fill: #fff7c4; stroke: #ca8a04; stroke-width: 1.4; transform-box: fill-box; transform-origin: center; animation: pop 260ms var(--ease) both; }
@keyframes pop { from { transform: scale(.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.sq.is-many::after { content: '…'; font-family: var(--font-mono); color: var(--grey-80); font-size: var(--text-stat); }

@media (prefers-reduced-motion: reduce) {
  .screen, .grain, .hero__disc, .disc.is-lifted, .disc.is-landed, .t-number.is-tick, .bignum__cursor { animation: none; }
  .disc.is-lifted { transform: translateY(-6px); }
  .progress__fill, .rod__peg, .option input::after { transition: none; }
}
