:root {
  color-scheme: light;
  --navy: #100060;
  --navy-deep: #090038;
  --violet: #6546d7;
  --blue: #246bfd;
  --blue-soft: #eaf2ff;
  --ink: #17162b;
  --muted: #66667a;
  --line: #dedff0;
  --surface: #ffffff;
  --canvas: #f5f7ff;
  --success: #14734b;
  --danger: #a8324a;
  --radius-lg: 28px;
  --radius-md: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(36, 107, 253, .12), transparent 32rem),
    radial-gradient(circle at 92% 12%, rgba(101, 70, 215, .12), transparent 28rem),
    var(--canvas);
}

button, a { font: inherit; }
button { color: inherit; }
a { color: inherit; }

:focus-visible {
  outline: 3px solid #ffb400;
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  transform: translateY(-150%);
  padding: 10px 14px;
  border-radius: 10px;
  color: #fff;
  background: var(--navy);
}

.skip-link:focus { transform: translateY(0); }

.page-shell,
.practice-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.page-shell { padding: 32px 0 64px; }
.practice-shell { min-height: 100vh; }

.page-header,
.compact-header,
.test-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-header { margin-bottom: 64px; }
.compact-header { padding: 22px 0; }

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 15px;
  color: #fff;
  background: linear-gradient(145deg, var(--navy), var(--violet));
  font-weight: 850;
  letter-spacing: -.04em;
  box-shadow: 0 10px 24px rgba(16, 0, 96, .2);
}

.back-link,
.icon-link,
.icon-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--navy);
  background: rgba(255, 255, 255, .82);
  text-decoration: none;
  cursor: pointer;
}

.back-link { padding: 10px 16px; }
.back-link svg { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 2; }
.icon-link, .icon-button { width: 46px; padding: 0; }
.icon-button { appearance: none; }
.icon-link svg, .icon-button svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 2; }

.hero { max-width: 760px; margin-bottom: 36px; }
.hero h1,
.instruction-card h1,
.completion-card h1,
.ist-intro h1 {
  margin: 8px 0 16px;
  color: var(--navy-deep);
  font-size: clamp(2rem, 6vw, 4rem);
  line-height: 1.02;
  letter-spacing: -.045em;
}

.hero p:not(.eyebrow),
.instruction-card > p:not(.eyebrow),
.completion-card > p,
.ist-intro > p:not(.eyebrow) {
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.7;
}

.eyebrow {
  margin: 0;
  color: var(--blue);
  font-size: .77rem;
  font-weight: 850;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.privacy-note,
.info-strip {
  padding: 14px 16px;
  border: 1px solid #cbdcff;
  border-radius: 14px;
  color: #29406f;
  background: var(--blue-soft);
  line-height: 1.55;
}

.privacy-note { display: inline-flex; align-items: center; gap: 12px; margin-top: 8px; }
.privacy-note svg { width: 24px; height: 24px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; }

.practice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.practice-card {
  position: relative;
  display: flex;
  min-height: 300px;
  flex-direction: column;
  align-items: flex-start;
  overflow: hidden;
  padding: 30px;
  border: 1px solid rgba(101, 70, 215, .15);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 20px 60px rgba(27, 19, 77, .09);
}

.practice-card::after {
  position: absolute;
  right: -45px;
  bottom: -60px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(36, 107, 253, .12), rgba(101, 70, 215, .2));
  content: "";
}

.card-number { color: var(--violet); font-weight: 850; }
.card-kicker { margin: 26px 0 4px; color: var(--blue); font-size: .8rem; font-weight: 800; text-transform: uppercase; }
.practice-card h2 { margin: 0; color: var(--navy-deep); font-size: 2rem; }
.practice-card p:not(.card-kicker) { max-width: 38ch; color: var(--muted); line-height: 1.65; }

.primary-button,
.secondary-button {
  position: relative;
  z-index: 1;
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  margin-top: auto;
  padding: 12px 20px;
  border: 0;
  border-radius: 14px;
  font-weight: 780;
  text-decoration: none;
  cursor: pointer;
}

.primary-button { color: #fff; background: linear-gradient(135deg, var(--navy), var(--violet)); box-shadow: 0 12px 25px rgba(16, 0, 96, .22); }
.secondary-button { border: 1px solid var(--line); color: var(--navy); background: #fff; }
.full-button { width: 100%; }
.primary-button:hover { filter: brightness(1.08); }

.practice-screen { min-height: 100vh; }
.practice-screen:not(.is-active) { display: none; }
.content-stack { width: min(760px, 100%); margin: 24px auto 0; padding-bottom: 56px; }
.content-stack > * + * { margin-top: 18px; }

.instruction-card,
.completion-card,
.ist-intro,
.instruction-panel {
  padding: clamp(24px, 5vw, 46px);
  border: 1px solid rgba(101, 70, 215, .15);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 20px 60px rgba(27, 19, 77, .08);
}

.instruction-card h1,
.completion-card h1,
.ist-intro h1 { font-size: clamp(2rem, 5vw, 3.2rem); }
.rule-list { padding-left: 24px; color: var(--ink); line-height: 1.75; }
.rule-list li::marker { color: var(--blue); font-weight: 800; }

.kraepelin-example {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 28px;
  align-items: center;
  margin-top: 28px;
  padding: 22px;
  border-radius: 20px;
  background: #f7f7ff;
}

.example-column { display: grid; gap: 2px; justify-items: center; font-size: 1.8rem; font-weight: 850; }
.example-column span { width: 54px; padding: 4px; border-bottom: 2px solid #d8daf0; text-align: center; }
.example-explanation { display: grid; gap: 10px; }
.example-explanation p { display: flex; justify-content: space-between; gap: 14px; margin: 0; }
.example-explanation span { color: var(--muted); }

.test-header { padding: 20px 0 16px; }
.test-header h1 { margin: 2px 0 0; color: var(--navy-deep); font-size: 1.25rem; }
.timer { min-width: 82px; padding: 10px 12px; border-radius: 13px; color: #fff; background: var(--navy); font-variant-numeric: tabular-nums; font-weight: 850; text-align: center; }
.progress-track { height: 7px; overflow: hidden; border-radius: 99px; background: #dfe4f5; }
.progress-track span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--blue), var(--violet)); }
.stage-help { margin: 28px auto 18px; color: var(--muted); text-align: center; }

.number-stack {
  display: grid;
  width: 140px;
  gap: 4px;
  margin: 0 auto;
  padding: 18px 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 16px 40px rgba(27, 19, 77, .08);
}

.number-row { padding: 5px; border-radius: 9px; font-size: 2rem; font-weight: 850; text-align: center; }
.number-row.is-pair { color: var(--navy); background: #e9efff; }
.feedback { min-height: 28px; margin: 14px 0; font-weight: 750; text-align: center; }
.feedback.is-correct { color: var(--success); }
.feedback.is-wrong { color: var(--danger); }

.keypad {
  display: grid;
  width: min(500px, 100%);
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin: 0 auto 30px;
}

.keypad button {
  min-height: 58px;
  border: 1px solid #ccd2e6;
  border-radius: 15px;
  color: var(--navy-deep);
  background: #fff;
  font-size: 1.15rem;
  font-weight: 850;
  cursor: pointer;
}

.keypad button:hover:not(:disabled) { border-color: var(--blue); background: var(--blue-soft); }
.keypad button:disabled { opacity: .45; cursor: not-allowed; }

.completion-card { width: min(620px, 100%); margin: 8vh auto 0; text-align: center; }
.completion-mark { display: grid; width: 72px; height: 72px; margin: 0 auto 22px; place-items: center; border-radius: 50%; color: #fff; background: var(--success); }
.completion-mark svg { width: 36px; fill: none; stroke: currentColor; stroke-width: 2; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 24px 0; }
.result-grid > div { padding: 16px 10px; border-radius: 14px; background: #f2f4fd; }
.result-grid span, .result-grid strong { display: block; }
.result-grid span { color: var(--muted); font-size: .82rem; }
.result-grid strong { margin-top: 5px; color: var(--navy); font-size: 1.3rem; }
.text-link { display: inline-block; margin-top: 18px; color: var(--blue); font-weight: 700; }

.ist-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 22px; padding: 12px 0 56px; }
.ist-intro { grid-column: 1 / -1; }
.ist-intro h1 { max-width: 16ch; }
.subtest-nav { display: grid; align-content: start; gap: 8px; position: sticky; top: 18px; }
.subtest-tab {
  display: grid;
  grid-template-columns: 38px 1fr;
  min-height: 54px;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .88);
  text-align: left;
  cursor: pointer;
}
.subtest-tab strong { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 10px; color: var(--navy); background: var(--blue-soft); font-size: .78rem; }
.subtest-tab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subtest-tab[aria-current="step"] { border-color: var(--violet); color: #fff; background: var(--navy); }
.subtest-tab[aria-current="step"] strong { color: #fff; background: rgba(255, 255, 255, .18); }

.instruction-panel { min-height: 580px; }
.instruction-panel h2 { margin: 8px 0 4px; color: var(--navy-deep); font-size: clamp(1.65rem, 3vw, 2.5rem); letter-spacing: -.03em; }
.instruction-panel .subtitle { margin: 0 0 28px; color: var(--muted); }
.instruction-copy { display: grid; gap: 14px; }
.instruction-copy p { margin: 0; line-height: 1.75; white-space: pre-line; }
.instruction-visual { width: 100%; height: auto; margin-top: 24px; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.instruction-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 34px; padding-top: 20px; border-top: 1px solid var(--line); }
.instruction-actions button { min-width: 120px; }
.instruction-status { color: var(--muted); font-size: .9rem; }

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

@media (max-width: 760px) {
  .page-shell, .practice-shell { width: min(100% - 24px, 680px); }
  .page-header { margin-bottom: 42px; }
  .practice-grid { grid-template-columns: 1fr; }
  .practice-card { min-height: 255px; padding: 24px; }
  .kraepelin-example { grid-template-columns: 72px 1fr; gap: 15px; padding: 18px 14px; }
  .example-explanation p { display: block; }
  .example-explanation span { display: block; margin-top: 2px; font-size: .9rem; }
  .ist-layout { grid-template-columns: 1fr; }
  .subtest-nav { position: static; display: flex; overflow-x: auto; padding: 2px 2px 8px; scroll-snap-type: x mandatory; }
  .subtest-tab { min-width: 104px; grid-template-columns: 34px 1fr; scroll-snap-align: start; }
  .subtest-tab span { font-size: .82rem; }
  .instruction-panel { min-height: auto; }
}

@media (max-width: 420px) {
  .back-link span { display: none; }
  .hero h1 { font-size: 2.25rem; }
  .content-stack { margin-top: 12px; }
  .instruction-card, .completion-card, .ist-intro, .instruction-panel { padding: 22px 18px; border-radius: 22px; }
  .keypad { grid-template-columns: repeat(5, 1fr); gap: 7px; }
  .keypad button { min-height: 52px; }
  .result-grid { grid-template-columns: 1fr; }
  .test-header { gap: 9px; }
  .timer { min-width: 70px; padding-inline: 8px; }
  .instruction-actions { flex-direction: column-reverse; }
  .instruction-actions button { width: 100%; }
}

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