:root {
  color-scheme: light;
  --ink: #1c1b17;
  --muted: #6f6a5e;
  --paper: #f8f5ec;
  --panel: #fffdf7;
  --line: #d8d1c2;
  --yellow: #f4b942;
  --yellow-dark: #d99b20;
  --red: #c83c35;
  --shadow: 0 18px 55px rgba(50, 43, 24, .12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(244, 185, 66, .15), transparent 34rem),
    var(--paper);
  -webkit-tap-highlight-color: transparent;
}

button, select { font: inherit; }

button { color: inherit; }

button:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #2468c4;
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.app, .screen { width: 100%; height: 100%; height: 100dvh; }

.screen { display: none; }
.screen.is-active { display: flex; }

.home-screen {
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.home-card { width: min(100%, 460px); text-align: center; }

.hero-logo {
  width: clamp(108px, 25vw, 148px);
  height: auto;
  filter: drop-shadow(0 12px 18px rgba(89, 64, 14, .16));
}

.eyebrow {
  margin: 14px 0 5px;
  color: var(--muted);
  font-size: .71rem;
  font-weight: 800;
  letter-spacing: .15em;
}

h1 { margin: 0; font-size: clamp(2rem, 9vw, 3.6rem); line-height: .98; letter-spacing: -.045em; }
.tagline { margin: 14px 0 26px; color: var(--muted); font-size: 1.02rem; }

.loading-state { margin: 32px 0; color: var(--muted); }

.data-error {
  display: grid;
  gap: 10px;
  margin: 26px 0;
  padding: 20px;
  border: 1px solid #e4aaa5;
  border-radius: 16px;
  background: #fff3f1;
  color: #75241f;
}

.mode-menu { display: grid; gap: 10px; }

.mode-button {
  display: flex;
  align-items: center;
  gap: 15px;
  min-height: 72px;
  width: 100%;
  padding: 12px 18px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--panel);
  box-shadow: 0 5px 0 #ded7c9;
  text-align: left;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}

.mode-button:hover { border-color: var(--yellow-dark); }
.mode-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #ded7c9; }
.mode-button strong, .mode-button small { display: block; }
.mode-button strong { font-size: 1.14rem; }
.mode-button small { margin-top: 3px; color: var(--muted); font-size: .83rem; }

.mode-icon {
  display: grid;
  place-items: center;
  flex: 0 0 43px;
  height: 43px;
  border-radius: 50%;
  background: #f0eadb;
  font: 800 .72rem/1 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.performance-button .mode-icon { background: var(--yellow); }
.home-best { margin: 22px 0 0; color: var(--muted); font-size: .85rem; }
.home-best strong { color: var(--ink); }

.browser-toys-link {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  text-decoration: none;
}

.topbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 13px;
  min-height: 78px;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(248, 245, 236, .94);
  backdrop-filter: blur(12px);
  z-index: 2;
}

.topbar .eyebrow { margin: 0 0 3px; font-size: .59rem; }
.topbar h1 { font-size: 1.45rem; letter-spacing: -.025em; }

.icon-button, .text-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  font-size: 1.35rem;
}

.text-button { min-height: 44px; padding: 0 5px; color: var(--muted); font-size: .8rem; font-weight: 800; }

.group-control { display: grid; gap: 3px; color: var(--muted); font-size: .62rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.group-control select { min-width: 82px; height: 38px; padding: 0 28px 0 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--ink); font-weight: 750; }

.study-screen { flex-direction: column; }
.study-scroll { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; }
.study-digits {
  width: min(100%, 940px);
  min-height: 100%;
  margin: 0 auto;
  padding: clamp(25px, 5vw, 60px) clamp(18px, 5vw, 52px);
  font: 500 clamp(1.05rem, 2.4vw, 1.38rem)/1.82 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: .055em;
  overflow-wrap: anywhere;
  user-select: text;
}

.pi-prefix { color: var(--yellow-dark); font-weight: 900; }
.study-chunk { display: inline; }
.to-top { display: block; margin: 10px auto 36px; padding: 11px 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); cursor: pointer; }

.play-screen { flex-direction: column; }
.play-topbar { min-height: 70px; }
.play-body {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: min(100%, 700px);
  margin: 0 auto;
  padding: 14px 16px 8px;
}

.progress-row { display: flex; justify-content: space-between; padding: 0 4px 10px; color: var(--muted); font-size: .75rem; }
.progress-row strong { color: var(--ink); }

.digit-history {
  flex: 1 1 0;
  min-height: 95px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--panel);
  box-shadow: inset 0 1px 2px rgba(50, 43, 24, .04);
  font: 600 clamp(1.25rem, 5vw, 1.72rem)/1.62 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: .075em;
  overflow-wrap: anywhere;
  user-select: text;
}

.mistake { color: var(--red); font-weight: 900; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }

.correction-panel, .completion-panel {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding: 10px 12px 10px 16px;
  border: 1px solid #e1aaa5;
  border-radius: 14px;
  background: #fff3f1;
  color: #75241f;
}

.completion-panel { border-color: #d7b868; background: #fff8df; color: var(--ink); }
.correction-panel strong { font: 900 1.35rem ui-monospace, monospace; }

.run-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.run-stats > div { display: flex; align-items: baseline; justify-content: space-between; padding: 8px 11px; border-radius: 10px; background: #ede8dc; }
.run-stats span { color: var(--muted); font-size: .69rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.run-stats strong { font: 800 1rem ui-monospace, monospace; }

.keypad-wrap {
  flex: 0 0 auto;
  width: min(100%, 480px);
  margin: 0 auto;
  padding: 4px 14px max(10px, env(safe-area-inset-bottom));
}

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.digit-key {
  position: relative;
  min-height: clamp(47px, 7.7vh, 63px);
  border: 1px solid #cfc7b7;
  border-radius: 13px;
  background: var(--panel);
  box-shadow: 0 4px 0 #cec5b4;
  font: 800 clamp(1.2rem, 5vw, 1.65rem)/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .06s ease, box-shadow .06s ease, background .06s ease;
}

.digit-key.zero { grid-column: 2; }
.digit-key:is(:active, .is-pressed) { transform: translateY(3px); box-shadow: 0 1px 0 #cec5b4; background: #fff3c9; }
.keypad.is-disabled .digit-key { opacity: .45; pointer-events: none; }

.button {
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.button.primary { border-color: #bd8111; background: var(--yellow); box-shadow: 0 3px 0 #bd8111; }
.button.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #bd8111; }
.button.secondary { border-color: var(--line); background: var(--panel); }
.button.ghost { background: transparent; color: var(--muted); }
.button.compact { justify-self: center; min-height: 40px; padding: 7px 14px; }

.results-screen { align-items: center; justify-content: center; overflow-y: auto; padding: max(24px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom)); }
.results-card { width: min(100%, 440px); text-align: center; }
.results-logo { filter: drop-shadow(0 8px 12px rgba(89, 64, 14, .14)); }
.results-card h1 { margin-top: 7px; font-size: clamp(2.1rem, 10vw, 3.3rem); }
.result-score { margin: 27px 0 20px; }
.result-score strong { display: block; font: 900 clamp(4.2rem, 22vw, 7rem)/.9 ui-monospace, monospace; letter-spacing: -.09em; }
.result-score span { display: block; margin-top: 8px; color: var(--muted); font-size: .83rem; font-weight: 750; }
.result-details { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.result-details div { padding: 13px 10px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel); }
.result-details span, .result-details strong { display: block; }
.result-details span { margin-bottom: 4px; color: var(--muted); font-size: .69rem; text-transform: uppercase; font-weight: 800; }
.result-details strong { font: 800 1.05rem ui-monospace, monospace; }
.new-best { margin: 14px 0 0; color: #8a5a00; font-weight: 850; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 22px; }
.result-actions .primary, .result-actions .ghost { grid-column: 1 / -1; }
.share-status { min-height: 1.25em; margin: 12px 0 0; color: var(--muted); font-size: .78rem; }

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

@media (min-width: 760px) {
  .play-body { padding-top: 22px; }
  .keypad-wrap { padding-bottom: 20px; }
  .digit-key { min-height: 58px; }
}

@media (max-height: 610px) {
  .play-topbar { min-height: 58px; padding-top: 7px; padding-bottom: 7px; }
  .play-body { padding-top: 7px; }
  .digit-key { min-height: 42px; }
  .keypad-wrap { padding-bottom: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .001ms !important; animation-duration: .001ms !important; }
}
