/* ==========================================================================
   QuizMaster styles
   Uses the design tokens in tokens.css. Mobile first.
   Contents: 1 Base · 2 Layout · 3 Components · 4 Screens · 5 Motion · 6 Misc
   ========================================================================== */

/* ---------- 1. Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + var(--space-4));
  scroll-padding-bottom: calc(var(--nav-height) + var(--space-8));
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  color: var(--color-text);
  background-color: var(--color-bg);
  background-image: var(--gradient-glow);
  background-repeat: no-repeat;
  background-size: 100% 520px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--font-display);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}

p {
  margin: 0;
  text-wrap: pretty;
}

ul,
ol {
  margin: 0;
  padding: 0;
}

img,
svg {
  display: block;
  max-width: 100%;
}

a {
  color: var(--color-primary);
  text-underline-offset: 3px;
}

a:hover {
  color: var(--color-primary-hover);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

::selection {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* Headings and the main area receive focus from code when a screen changes.
   They are not controls, so they do not need a ring. */
[tabindex="-1"]:focus,
[tabindex="-1"]:focus-visible {
  outline: none;
}

/* Styled scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-strong) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border-strong);
  border-radius: var(--radius-pill);
  border: 2px solid var(--color-bg);
}

/* ---------- 2. Layout ---------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

main {
  flex: 1;
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding: var(--space-6) var(--space-5) var(--space-12);
  outline: none;
}

body.has-nav main {
  padding-bottom: calc(var(--nav-height) + var(--space-8) + env(safe-area-inset-bottom));
}

.screen {
  animation: screen-in var(--duration-slow) var(--ease-out) both;
}

.screen--narrow {
  max-width: var(--container-narrow);
  margin-inline: auto;
}

.screen__head {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
}

.screen__title {
  font-size: var(--text-2xl);
}

.screen__title:focus {
  outline: none;
}

.screen__lead {
  color: var(--color-text-muted);
}

/* Skip link */
.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -100px;
  z-index: calc(var(--z-modal) + 10);
  padding: var(--space-3) var(--space-4);
  background: var(--color-primary);
  color: var(--color-on-primary);
  border-radius: var(--radius-md);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: var(--space-4);
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  border-bottom: var(--border-width) solid transparent;
  padding-top: env(safe-area-inset-top);
  transition: border-color var(--duration-base) var(--ease-out),
    box-shadow var(--duration-base) var(--ease-out);
}

/* The frosted background lives on a pseudo-element. A blur filter on the header
   itself would make the phone navigation bar (position: fixed) stick to the header. */
.site-header::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--color-bg);
}

@supports (backdrop-filter: blur(1px)) {
  .site-header::before {
    background: color-mix(in srgb, var(--color-bg) 78%, transparent);
    backdrop-filter: blur(16px) saturate(160%);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
  }
}

.site-header.is-scrolled {
  border-bottom-color: var(--color-border);
  box-shadow: var(--shadow-sm);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  max-width: var(--container);
  margin-inline: auto;
  height: var(--header-height);
  padding-inline: var(--space-5);
  transition: height var(--duration-base) var(--ease-out);
}

.site-header.is-scrolled .site-header__inner {
  height: 56px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text);
  text-decoration: none;
  border-radius: var(--radius-md);
}

.brand:hover {
  color: var(--color-text);
}

.brand__mark {
  width: 34px;
  height: 34px;
  flex: none;
}

.brand__name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: var(--tracking-snug);
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Primary navigation: bottom bar on phones, inline on larger screens */
.primary-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-nav);
  display: flex;
  justify-content: space-around;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3) calc(var(--space-2) + env(safe-area-inset-bottom));
  background: var(--color-surface);
  border-top: var(--border-width) solid var(--color-border);
  box-shadow: 0 -8px 24px -12px rgba(19, 19, 42, 0.18);
}

.nav-link {
  flex: 1;
  display: grid;
  justify-items: center;
  gap: 2px;
  min-height: 48px;
  padding: var(--space-2);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  transition: color var(--duration-fast), background var(--duration-fast);
}

.nav-link .icon {
  width: 22px;
  height: 22px;
}

.nav-link:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
}

.nav-link[aria-current="page"] {
  color: var(--color-primary);
  background: var(--color-primary-soft);
}

@media (min-width: 900px) {
  .primary-nav {
    position: static;
    margin-left: var(--space-6);
    padding: 0;
    gap: var(--space-1);
    background: transparent;
    border: 0;
    box-shadow: none;
    justify-content: flex-start;
  }

  .nav-link {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 40px;
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
  }

  .nav-link .icon {
    width: 18px;
    height: 18px;
  }

  body.has-nav main {
    padding-bottom: var(--space-12);
  }
}

/* Hide navigation while a quiz is being played, so nothing gets tapped by accident */
body[data-screen="quiz-screen"] .primary-nav,
body:not(.has-nav) .primary-nav {
  display: none;
}

body[data-screen="quiz-screen"].has-nav main {
  padding-bottom: var(--space-12);
}

/* Footer */
.site-footer {
  border-top: var(--border-width) solid var(--color-border);
  padding: var(--space-6) 0 calc(var(--space-6) + env(safe-area-inset-bottom));
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.site-footer__inner {
  padding-inline: var(--space-5);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-3) var(--space-6);
  max-width: var(--container);
  margin-inline: auto;
}

.site-footer a {
  color: inherit;
}

body.has-nav .site-footer {
  padding-bottom: calc(var(--nav-height) + var(--space-6) + env(safe-area-inset-bottom));
}

@media (min-width: 900px) {
  body.has-nav .site-footer {
    padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
  }
}

body[data-screen="quiz-screen"] .site-footer {
  display: none;
}

/* ---------- 3. Components ---------- */

/* Icons */
.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: var(--space-3) var(--space-6);
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-md);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  transition: transform var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-base) var(--ease-out),
    background var(--duration-base), border-color var(--duration-base),
    color var(--duration-base);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.btn--primary {
  background: var(--gradient-brand);
  color: var(--color-on-primary);
  box-shadow: var(--shadow-glow);
}

.btn--primary:hover:not(:disabled) {
  color: var(--color-on-primary);
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.btn--secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-sm);
}

.btn--secondary:hover:not(:disabled) {
  color: var(--color-text);
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}

.btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
}

.btn--ghost:hover:not(:disabled) {
  color: var(--color-text);
  background: var(--color-surface-2);
}

.btn--danger {
  background: var(--color-error);
  color: #ffffff;
}

[data-theme="dark"] .btn--danger {
  color: #1a0509;
}

.btn--danger:hover:not(:disabled) {
  color: inherit;
  filter: brightness(1.08);
}

.btn--lg {
  min-height: 56px;
  padding: var(--space-4) var(--space-8);
  font-size: var(--text-lg);
  border-radius: var(--radius-lg);
}

.btn--sm {
  min-height: 40px;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
}

.btn--block {
  width: 100%;
}

.btn.is-loading {
  pointer-events: none;
}

.btn.is-loading::after {
  content: "";
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  transition: background var(--duration-fast), border-color var(--duration-fast),
    transform var(--duration-fast) var(--ease-out);
}

.icon-btn:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}

.icon-btn:active {
  transform: scale(0.95);
}

/* Theme toggle icons swap with the theme */
.theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

/* Account menu */
.account {
  position: relative;
}

.account__btn {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--color-on-primary);
  background: var(--gradient-brand);
  border: 0;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
}

.account__btn:hover {
  background: var(--gradient-brand);
  filter: brightness(1.08);
}

.account__menu {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-2));
  z-index: var(--z-menu);
  min-width: 15rem;
  padding: var(--space-2);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: pop-in var(--duration-base) var(--ease-out) both;
}

.account__who {
  padding: var(--space-3) var(--space-3) var(--space-3);
  border-bottom: var(--border-width) solid var(--color-border);
  margin-bottom: var(--space-2);
}

.account__name {
  font-weight: 700;
}

.account__type {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text);
  text-align: left;
  font-weight: 500;
}

.menu-item:hover {
  background: var(--color-surface-2);
}

/* Cards */
.card {
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
}

.card--interactive {
  display: block;
  width: 100%;
  text-align: left;
  color: inherit;
  text-decoration: none;
  transition: transform var(--duration-base) var(--ease-out),
    box-shadow var(--duration-base) var(--ease-out),
    border-color var(--duration-base);
}

.card--interactive:hover {
  color: inherit;
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}

.card--interactive:active {
  transform: translateY(-1px);
}

/* Chips and badges */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

.chip--primary {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #ffffff;
  background: var(--color-text-muted);
}

[data-theme="dark"] .badge {
  color: #0b0a20;
}

.badge--easy {
  background: var(--color-level-easy);
}

.badge--medium {
  background: var(--color-level-medium);
}

.badge--hard {
  background: var(--color-level-hard);
}

.badge--mixed {
  background: var(--color-level-mixed);
}

.badge--category,
[data-theme="dark"] .badge--category {
  background: var(--color-surface-2);
  color: var(--color-text-muted);
}

/* Segmented control (toggle buttons) */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--color-surface-2);
  border-radius: var(--radius-lg);
}

.segmented__btn {
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
  font-weight: 600;
  transition: background var(--duration-fast), color var(--duration-fast),
    box-shadow var(--duration-fast);
}

.segmented__btn:hover {
  color: var(--color-text);
}

.segmented__btn[aria-pressed="true"] {
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

/* Forms */
.form {
  display: grid;
  gap: var(--space-5);
}

.field {
  display: grid;
  gap: var(--space-2);
}

.field__label {
  font-weight: 600;
  font-size: var(--text-sm);
}

.field__hint {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.field__error {
  color: var(--color-error);
  font-size: var(--text-sm);
  font-weight: 500;
}

.input {
  width: 100%;
  min-height: 48px;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-md);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.input::placeholder {
  color: var(--color-text-muted);
  opacity: 0.8;
}

.input:hover {
  border-color: var(--color-primary);
}

.input:focus-visible {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--ring);
}

.input[aria-invalid="true"] {
  border-color: var(--color-error);
}

select.input {
  appearance: none;
  padding-right: var(--space-10);
  background-image: linear-gradient(45deg, transparent 50%, var(--color-text-muted) 50%),
    linear-gradient(135deg, var(--color-text-muted) 50%, transparent 50%);
  background-position: calc(100% - 22px) 55%, calc(100% - 16px) 55%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.status {
  min-height: 1.5em;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.status--ok {
  color: var(--color-success);
  font-weight: 600;
}

.status--error {
  color: var(--color-error);
  font-weight: 600;
}

/* Skeleton loaders */
.skeleton {
  border-radius: var(--radius-md);
  background: linear-gradient(
    90deg,
    var(--color-surface-2) 25%,
    var(--color-border) 50%,
    var(--color-surface-2) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

.skeleton-row {
  height: 64px;
}

/* Toasts */
.toast-region {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  z-index: var(--z-toast);
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding-inline: var(--space-4);
  pointer-events: none;
}

body.has-nav .toast-region {
  bottom: calc(var(--nav-height) + var(--space-4) + env(safe-area-inset-bottom));
}

@media (min-width: 900px) {
  body.has-nav .toast-region {
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  }
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 28rem;
  padding: var(--space-3) var(--space-5);
  background: var(--color-text);
  color: var(--color-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-weight: 500;
  pointer-events: auto;
  animation: toast-in var(--duration-base) var(--ease-out) both;
}

.toast.is-leaving {
  animation: toast-out var(--duration-base) var(--ease-in-out) both;
}

.toast--success .icon {
  color: #3ddc97;
}

.toast--error .icon {
  color: #ff8a99;
}

[data-theme="dark"] .toast--success .icon {
  color: #0f7b53;
}

[data-theme="dark"] .toast--error .icon {
  color: #c9283b;
}

/* Modal dialog */
.modal {
  width: min(28rem, calc(100vw - 2rem));
  padding: var(--space-6);
  background: var(--color-surface);
  color: var(--color-text);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}

.modal::backdrop {
  background: rgba(10, 10, 30, 0.55);
  backdrop-filter: blur(4px);
}

.modal[open] {
  animation: pop-in var(--duration-base) var(--ease-out) both;
}

.modal__title {
  font-size: var(--text-xl);
  margin-bottom: var(--space-3);
}

.modal__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

/* ---------- 4. Screens ---------- */

/* Loading */
.loading {
  display: grid;
  place-items: center;
  gap: var(--space-4);
  min-height: 50vh;
  color: var(--color-text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

/* Hero (signed-out landing) */
.hero {
  position: relative;
  display: grid;
  gap: var(--space-6);
  padding: var(--space-8) 0 var(--space-4);
  text-align: center;
  justify-items: center;
  isolation: isolate;
}

.hero__orb {
  position: absolute;
  z-index: -1;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.45;
  pointer-events: none;
}

.hero__orb--one {
  width: 280px;
  height: 280px;
  left: -60px;
  top: -40px;
  background: #5b4bff;
  animation: float 9s ease-in-out infinite;
}

.hero__orb--two {
  width: 240px;
  height: 240px;
  right: -40px;
  top: 80px;
  background: #ff7ab8;
  animation: float 11s ease-in-out infinite reverse;
}

[data-theme="dark"] .hero__orb {
  opacity: 0.28;
}

.hero__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-4);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.hero__title {
  max-width: 14ch;
  font-size: var(--text-3xl);
  line-height: 1.02;
  letter-spacing: -0.04em;
}

.text-gradient {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero__lead {
  max-width: 34rem;
  font-size: var(--text-lg);
  color: var(--color-text-muted);
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
}

.hero__note {
  max-width: 30rem;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.facts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
  list-style: none;
}

.steps {
  display: grid;
  gap: var(--space-4);
  margin-top: var(--space-10);
  list-style: none;
  counter-reset: step;
}

@media (min-width: 760px) {
  .steps {
    grid-template-columns: repeat(3, 1fr);
  }
}

.step {
  counter-increment: step;
  display: grid;
  gap: var(--space-2);
  padding: var(--space-6);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.step::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-family: var(--font-display);
  font-weight: 700;
}

.step__title {
  font-size: var(--text-lg);
}

.step__text {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.hero-error {
  max-width: 34rem;
  padding: var(--space-4) var(--space-5);
  background: var(--color-warning-soft);
  border: var(--border-width) solid var(--color-warning);
  border-radius: var(--radius-md);
  text-align: left;
}

/* Reveal on scroll */
.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity var(--duration-slow) var(--ease-out),
    transform var(--duration-slow) var(--ease-out);
}

.reveal.is-visible {
  opacity: 1;
  transform: none;
}

.reveal[data-delay="1"] {
  transition-delay: 80ms;
}

.reveal[data-delay="2"] {
  transition-delay: 160ms;
}

.reveal[data-delay="3"] {
  transition-delay: 240ms;
}

html:not(.js) .reveal {
  opacity: 1;
  transform: none;
}

/* Home (dashboard) */
.bento {
  display: grid;
  gap: var(--space-4);
}

@media (min-width: 760px) {
  .bento {
    grid-template-columns: repeat(6, 1fr);
  }

  .bento__start {
    grid-column: span 4;
    grid-row: span 2;
  }

  .bento__stat {
    grid-column: span 2;
  }

  .bento__half {
    grid-column: span 3;
  }
}

.bento__start {
  position: relative;
  display: grid;
  gap: var(--space-4);
  align-content: space-between;
  padding: var(--space-8);
  background: var(--gradient-brand);
  color: var(--color-on-primary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.bento__start::after {
  content: "";
  position: absolute;
  right: -60px;
  bottom: -80px;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  pointer-events: none;
}

.bento__start .btn {
  position: relative;
  z-index: 1;
  justify-self: start;
}

.btn--on-gradient {
  background: #ffffff;
  color: #3a2bd0;
  box-shadow: var(--shadow-md);
}

.btn--on-gradient:hover:not(:disabled) {
  color: #3a2bd0;
  transform: translateY(-1px);
}

[data-theme="dark"] .btn--on-gradient {
  background: #0b0a20;
  color: #d9d4ff;
}

[data-theme="dark"] .btn--on-gradient:hover:not(:disabled) {
  color: #ffffff;
}

.bento__start-title {
  font-size: var(--text-2xl);
}

.bento__start-text {
  opacity: 0.92;
  max-width: 28rem;
}

.stat {
  display: grid;
  gap: var(--space-1);
  align-content: center;
}

.stat__label {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

.stat__value {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
}

.action-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-4);
  align-items: center;
}

.action-card__icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.action-card__title {
  font-family: var(--font-display);
  font-weight: 700;
}

.action-card__text {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* Setup (choose a quiz) */
.setup-section {
  display: grid;
  gap: var(--space-3);
  margin-bottom: var(--space-8);
}

.setup-section__title {
  font-size: var(--text-lg);
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: var(--space-3);
  list-style: none;
}

.tile {
  display: grid;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-4);
  text-align: left;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  transition: border-color var(--duration-fast), transform var(--duration-base) var(--ease-out),
    box-shadow var(--duration-base);
}

.tile:hover {
  transform: translateY(-2px);
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-md);
}

.tile[aria-pressed="true"] {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
  box-shadow: var(--ring);
}

.tile__mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--tile-color, #5b4bff);
  color: #ffffff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-sm);
}

.tile__name {
  font-weight: 700;
}

.tile__count {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.setup-footer {
  position: sticky;
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-4);
  padding: var(--space-4);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

/* On phones the navigation bar sits at the bottom, so the bar rests just above it */
body.has-nav .setup-footer {
  bottom: calc(var(--nav-height) + var(--space-3) + env(safe-area-inset-bottom));
}

@media (min-width: 900px) {
  body.has-nav .setup-footer {
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  }
}

/* Quiz */
.quiz {
  display: grid;
  gap: var(--space-5);
  max-width: var(--container-narrow);
  margin-inline: auto;
}

.quiz__top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.quiz__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.quiz__count {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-lg);
}

.quiz__status {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.progress {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-2);
  overflow: hidden;
}

.progress__bar {
  width: calc(var(--progress, 0) * 1%);
  height: 100%;
  border-radius: inherit;
  background: var(--gradient-brand);
  transition: width var(--duration-slow) var(--ease-out);
}

.timer {
  position: relative;
  width: 56px;
  height: 56px;
  flex: none;
}

.timer__ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer__track,
.timer__value {
  fill: none;
  stroke-width: 5;
}

.timer__track {
  stroke: var(--color-surface-2);
}

.timer__value {
  stroke: var(--color-primary);
  stroke-linecap: round;
  stroke-dasharray: 113.1;
  stroke-dashoffset: var(--timer-offset, 0);
  transition: stroke-dashoffset 1s linear, stroke var(--duration-base);
}

.timer__text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
}

.timer.is-urgent .timer__value {
  stroke: var(--color-error);
}

.timer.is-urgent .timer__text {
  color: var(--color-error);
  animation: pulse 1s ease-in-out infinite;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--color-accent-soft);
  color: var(--color-text);
  font-weight: 700;
}

.question {
  padding: var(--space-8) var(--space-6);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}

.question__text {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-snug);
}

.options {
  display: grid;
  gap: var(--space-3);
  list-style: none;
}

.option {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  min-height: 60px;
  padding: var(--space-3) var(--space-4);
  text-align: left;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-weight: 500;
  transition: border-color var(--duration-fast), background var(--duration-fast),
    transform var(--duration-fast) var(--ease-out), box-shadow var(--duration-base);
}

.option:hover:not(:disabled) {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
  transform: translateX(3px);
}

.option:active:not(:disabled) {
  transform: scale(0.99);
}

.option__key {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-sm);
}

.option__state .icon {
  width: 24px;
  height: 24px;
}

.option:disabled {
  cursor: default;
  color: inherit;
}

.option.is-dim {
  opacity: 0.55;
}

.option.is-correct {
  border-color: var(--color-success);
  background: var(--color-success-soft);
  color: var(--color-text);
}

.option.is-correct .option__key,
.option.is-correct .option__state {
  background: var(--color-success);
  color: #ffffff;
}

.option.is-correct .option__state {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

[data-theme="dark"] .option.is-correct .option__key,
[data-theme="dark"] .option.is-correct .option__state {
  color: #05241a;
}

.option.is-wrong {
  border-color: var(--color-error);
  background: var(--color-error-soft);
  color: var(--color-text);
  animation: shake 360ms var(--ease-in-out);
}

.option.is-wrong .option__key,
.option.is-wrong .option__state {
  background: var(--color-error);
  color: #ffffff;
}

.option.is-wrong .option__state {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

[data-theme="dark"] .option.is-wrong .option__key,
[data-theme="dark"] .option.is-wrong .option__state {
  color: #2a0710;
}

.quiz__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 56px;
}

.quiz__hint {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

@media (max-width: 759px) {
  .quiz__hint {
    display: none;
  }
}

/* Result */
.result {
  display: grid;
  justify-items: center;
  gap: var(--space-5);
  max-width: var(--container-narrow);
  margin-inline: auto;
  padding: var(--space-8) var(--space-6);
  text-align: center;
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}

.result__ring {
  position: relative;
  width: 168px;
  height: 168px;
}

.result__ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.result__track,
.result__value {
  fill: none;
  stroke-width: 10;
}

.result__track {
  stroke: var(--color-surface-2);
}

.result__value {
  stroke: url(#result-gradient);
  stroke-linecap: round;
  stroke-dasharray: 301.6;
  stroke-dashoffset: var(--result-offset, 301.6);
  transition: stroke-dashoffset 1.2s var(--ease-out);
}

.result__percent {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 1.3rem + 1.2vw, 2rem);
  font-weight: 800;
  letter-spacing: var(--tracking-tight);
}

.result__title {
  font-size: var(--text-2xl);
}

.result__score {
  color: var(--color-text-muted);
  font-size: var(--text-lg);
}

.result__score strong {
  color: var(--color-text);
  font-family: var(--font-display);
}

.new-best {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--color-accent-soft);
  color: var(--color-text);
  font-weight: 700;
  animation: pop-in var(--duration-slow) var(--ease-out) both;
}

.result__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
}

.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-confetti);
  pointer-events: none;
}

/* Leaderboard */
.lb-filters {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.lb-note {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.lb-list {
  display: grid;
  gap: var(--space-3);
  list-style: none;
}

.lb-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  animation: row-in var(--duration-slow) var(--ease-out) both;
}

.lb-row.is-me {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}

.lb-rank {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  font-family: var(--font-display);
  font-weight: 700;
}

.lb-row--1 .lb-rank {
  background: linear-gradient(135deg, #ffd45a, #ffa927);
  color: #3b2600;
}

.lb-row--2 .lb-rank {
  background: linear-gradient(135deg, #e6e9f2, #aeb6c8);
  color: #1f2433;
}

.lb-row--3 .lb-rank {
  background: linear-gradient(135deg, #f2b98c, #c9814c);
  color: #3a1d08;
}

.lb-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.lb-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: 2px;
}

.lb-you {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-primary);
}

.lb-points {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--text-lg);
  text-align: right;
}

.lb-points small {
  display: block;
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--text-xs);
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-5);
  text-align: center;
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius-xl);
  color: var(--color-text-muted);
}

.empty-state__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--color-text);
}

/* Editor */
.option-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: var(--space-3);
}

.radio-pick {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: 0 var(--space-3);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

.radio-pick input {
  width: 20px;
  height: 20px;
  accent-color: var(--color-primary);
}

.radio-pick:has(input:checked) {
  border-color: var(--color-success);
  background: var(--color-success-soft);
}

.radio-pick:has(input:focus-visible) {
  box-shadow: var(--ring);
}

.form-row {
  display: grid;
  gap: var(--space-5);
}

@media (min-width: 560px) {
  .form-row {
    grid-template-columns: 1fr 1fr;
  }
}

.fieldset-plain {
  display: grid;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.fieldset-plain legend {
  padding: 0;
  margin-bottom: var(--space-2);
  font-weight: 700;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.form-actions--flush {
  margin-top: 0;
}

.form-actions--spaced {
  margin-top: var(--space-5);
}

.cloud-status {
  margin-top: var(--space-4);
}

#editor-offline {
  margin-bottom: var(--space-5);
}

.question-list {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
  list-style: none;
}

.q-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
}

.q-item__text {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.q-item__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.section-title {
  margin-top: var(--space-10);
  font-size: var(--text-xl);
}

/* Name screen / simple centred forms */
.panel {
  padding: var(--space-8) var(--space-6);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}

/* Privacy and 404 pages */
.prose {
  max-width: 44rem;
  margin-inline: auto;
}

.prose h1 {
  font-size: var(--text-2xl);
  margin-bottom: var(--space-4);
}

.prose h2 {
  font-size: var(--text-xl);
  margin: var(--space-8) 0 var(--space-3);
}

.prose p,
.prose li {
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
}

.prose ul {
  padding-left: var(--space-6);
}

.not-found {
  display: grid;
  justify-items: center;
  gap: var(--space-4);
  padding: var(--space-16) 0;
  text-align: center;
}

.not-found__code {
  font-family: var(--font-display);
  font-size: clamp(5rem, 20vw, 10rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.06em;
}

/* No-JavaScript message */
.noscript-banner {
  margin: var(--space-6) auto;
  max-width: 34rem;
  padding: var(--space-5);
  background: var(--color-warning-soft);
  border: var(--border-width) solid var(--color-warning);
  border-radius: var(--radius-md);
  text-align: center;
}

html:not(.js) #loading-screen {
  display: none;
}

/* ---------- 5. Motion ---------- */
@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

@keyframes pulse {
  50% {
    transform: scale(1.12);
  }
}

@keyframes float {
  50% {
    transform: translate(18px, 22px);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }

  .reveal {
    opacity: 1;
    transform: none;
  }
}

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

.stack {
  display: grid;
  gap: var(--space-4);
}

@media print {
  .site-header,
  .primary-nav,
  .site-footer,
  .toast-region,
  .confetti-canvas {
    display: none !important;
  }

  body {
    background: #ffffff;
    color: #000000;
  }
}

/* ----- Install and update bar (js/pwa.js) ----- */
.pwa-bar {
  position: fixed;
  left: var(--space-4);
  right: var(--space-4);
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  z-index: var(--z-toast);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  max-width: 34rem;
  margin-inline: auto;
  padding: var(--space-4);
  background: var(--color-surface);
  color: var(--color-text);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: pwa-bar-in var(--duration-slow) var(--ease-out) both;
}

body.has-nav .pwa-bar {
  bottom: calc(var(--nav-height) + var(--space-4) + env(safe-area-inset-bottom));
}

@media (min-width: 900px) {
  body.has-nav .pwa-bar {
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  }
}

.pwa-bar__text {
  flex: 1 1 14rem;
  margin: 0;
  font-size: var(--text-sm);
}

.pwa-bar__actions {
  display: flex;
  gap: var(--space-2);
}

@keyframes pwa-bar-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .pwa-bar { animation: none; }
}
