* {
  box-sizing: border-box;
}

:root {
  --ink: #111111;
  --paper: #fffef6;
  --sky: #ffe15a;
  --panel: #fff7cf;
  --blue-pop: #1e6bff;
  --red-pop: #ff3b30;
  --mint-pop: #22c55e;
}

body {
  margin: 0;
  font-family: "Arial Black", "Trebuchet MS", Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.4) 0 2px, transparent 2px 14px),
    radial-gradient(circle at 72% 68%, rgba(0, 0, 0, 0.05) 0 1.5px, transparent 1.5px 13px),
    linear-gradient(160deg, #ffd94d 0%, #ffbf46 50%, #ffb327 100%);
  background-size: 18px 18px, 20px 20px, 100% 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}

.card {
  width: min(92vw, 520px);
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 0;
  padding: 1rem;
  box-shadow: 10px 10px 0 var(--ink);
  text-align: center;
  position: relative;
  margin-top:2em;
  margin-bottom:2em;

}

#quiz-screen {
  position: relative;
  padding-top: 10px;
}

.screen-hidden {
  display: none;
}

.start-screen {
  display: none;
  text-align: center;
}

.start-screen.show {
  display: block;
}

.start-title {
  font-size: clamp(1.8rem, 6vw, 2.4rem);
  margin: 8px 0 10px;
  line-height: 1.2;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #fff, 4px 4px 0 var(--ink);
}

.start-logo {
  display: block;
  width: 122%;
  max-width: none;
  height: auto;
  margin: -4em -11% 0
}

.start-text {
  font-size: 1.08rem;
  margin: 0 0 10px;
}

.start-high-score {
  font-size: 1rem;
  font-weight: 700;
  color: var(--red-pop);
  margin: 0 0 18px;
  text-transform: uppercase;
}

.start-buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.primary-btn,
.secondary-btn {
  min-height: 52px;
  font-size: 1.2rem;
  font-weight: 700;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: auto;
  padding: 16px 18px;
  text-align: center;
}

.mode-btn__title {
  font-family: "Luckiest Guy", "Comic Sans MS", cursive;
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.2;
}

.mode-btn__desc {
  display: block;
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.35;
  max-width: 34em;
}

.primary-btn.mode-btn .mode-btn__desc {
  color: rgba(255, 255, 255, 0.92);
}

.secondary-btn.mode-btn .mode-btn__desc {
  color: #4a5d75;
}

.primary-btn {
  background: var(--blue-pop);
  color: #fff;
}

.secondary-btn {
  background: #fff;
  color: var(--ink);
}

.choose-screen {
  margin-top: 14px;
  padding-top: 8px;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transform: translateY(10px);
  transition: opacity 0.25s ease, transform 0.25s ease, max-height 0.25s ease;
}

.choose-screen.show {
  opacity: 1;
  max-height: 920px;
  transform: translateY(0);
}

.choose-fieldset {
  border: none;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.choose-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 10px;
  padding: 0;
}

.table-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.table-option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 72px;
  padding: 10px 12px 12px;
  border: 3px solid var(--ink);
  border-radius: 0;
  font-size: 1rem;
  font-weight: 700;
  user-select: none;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.08s ease;
  box-shadow: 4px 4px 0 var(--ink);
  background: #fff;
}

.table-option:hover {
  background: #fff4b3;
  transform: translate(-1px, -1px);
}

.table-option:has(input:checked) {
  border-color: var(--ink);
  background: #ffd6d3;
}

.table-option:focus-within {
  outline: 2px solid rgba(47, 128, 237, 0.45);
  outline-offset: 2px;
}

.table-option__row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.table-option input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.table-stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  line-height: 1;
}

.star {
  display: inline-block;
  font-size: 1rem;
  line-height: 1;
  color: #9aa7b8;
}

.star::before {
  content: "\2605";
  display: block;
  text-shadow: 1.5px 1.5px 0 var(--ink);
}

.star--picker:not(.star--lit)::before {
  color: transparent;
  -webkit-text-stroke: 1.7px var(--ink);
}

.star--picker.star--lit::before {
  color: #d4a012;
  -webkit-text-stroke: 1px var(--ink);
}

.star--session {
  font-size: 1.15rem;
}

.star--session:not(.star--lit)::before {
  color: transparent;
  -webkit-text-stroke: 1.7px var(--ink);
}

.star--session.star--lit::before {
  color: #d4a012;
  -webkit-text-stroke: 1px var(--ink);
}

#practice-session-stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.pill-hidden {
  display: none !important;
}

.quiz-header {
  position: absolute;
  left: 0;
  right: 0;
  top: -52px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 0;
  padding: 0 2px 6px;
  border-bottom: 0;
}

.quiz-header__row--top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}

.return-start-btn {
  justify-self: start;
  width: auto;
  min-height: 24px;
  padding: .25em 0;
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  color: var(--ink);
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s ease, opacity 0.15s ease;
}

button.return-start-btn {
  border: none;
  box-shadow: none;
}

.return-start-btn:hover {
  color: var(--ink);
  opacity: 0.8;
}

.return-start-btn:focus-visible {
  outline: 3px solid rgba(79, 140, 255, 0.45);
  outline-offset: 2px;
}

.quiz-header__center {
  justify-self: center;
  text-align: center;
  min-width: 0;
}

.quiz-header__mode-label {
  font-size: 0.92rem;
  font-weight: 700;
  color: #1f2d3d;
  letter-spacing: 0.02em;
}

#progress {
  justify-self: end;
  border: 0;
  box-shadow: none;
  background: transparent;
  padding: 0;
  border-radius: 0;
  text-transform: none;
  font-size: 0.95rem;
}

.quiz-stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.quiz-stats-row--hidden {
  display: none !important;
}

.pill {
  background: #fff;
  border-radius: 999px;
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
}

#score {
  font-family: "Luckiest Guy", "Comic Sans MS", cursive;
  position: relative;
  border-radius: 0;
  clip-path: polygon(
    50% 0%,
    62% 16%,
    79% 8%,
    75% 27%,
    94% 30%,
    82% 46%,
    100% 55%,
    81% 63%,
    90% 82%,
    71% 78%,
    68% 100%,
    50% 86%,
    32% 100%,
    29% 78%,
    10% 82%,
    19% 63%,
    0% 55%,
    18% 46%,
    6% 30%,
    25% 27%,
    21% 8%,
    38% 16%
  );
  min-width: 120px;
  min-height: 84px;
  padding: 16px 16px 14px;
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  line-height: 1.1;
  background: #fff26a;
  border: 0;
  box-shadow: 6px 6px 0 var(--ink);
  transform: rotate(-9deg);
  margin-left: -35px;
  margin-top: -12px;
}

#score .score-label {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  line-height: 1;
}

#score .score-value {
  font-size: 1.65rem;
  font-weight: 900;
  line-height: 1;
}

.sum {
  font-family: "Luckiest Guy", "Comic Sans MS", cursive;
  font-size: clamp(3rem, 8vw, 4.8rem);
  font-weight: 700;
  margin: 8px 0 24px;
  letter-spacing: 1px;
}

.challenge-hud {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-bottom: 0;
  flex: 0 0 auto;
  min-width: 0;
}

.challenge-hud--hidden {
  display: none !important;
}

.challenge-countdown {
  font-family: "Luckiest Guy", "Comic Sans MS", cursive;
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  margin-bottom: 0;
  color: var(--mint-pop);
  transform-origin: center;
}

.challenge-countdown.challenge-countdown--warning {
  color: var(--red-pop);
}

.challenge-countdown.challenge-countdown--minute-flash {
  animation: minuteFlash 520ms ease-out;
}

@keyframes minuteFlash {
  0% {
    transform: scale(1);
  }
  24% {
    transform: scale(1.28);
  }
  42% {
    transform: scale(1);
  }
  66% {
    transform: scale(1.18);
  }
  84% {
    transform: scale(1);
  }
  100% {
    transform: scale(1);
  }
}

.challenge-gauge-row {
  display: flex;
  justify-content: center;
  margin: -8px 0 20px;
}

.challenge-gauge {
  height: 14px;
  width: min(100%, 420px);
  border-radius: 999px;
  background: #fff;
  border: 3px solid var(--ink);
  overflow: hidden;
  max-width: 100%;
}

.challenge-gauge__fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  transform-origin: left center;
  background: linear-gradient(90deg, #d4a012, #e8c547);
  transition: width 0.05s linear, background 0.2s ease;
}

.challenge-gauge__fill.challenge-gauge__fill--fast {
  background: linear-gradient(90deg, #1e9d5c, #31c96b);
}

.done-new-record {
  font-size: 1.35rem;
  font-weight: 800;
  color: #d4a012;
  margin: 0 0 8px;
}

.done-detail {
  font-size: 1.05rem;
  font-weight: 600;
  color: #4a5d75;
  margin: -8px 0 18px;
  min-height: 0;
}

.answer {
  width: 100%;
  min-height: 2.25em;
  font-size: 2.2rem;
  padding: .5em;
  border: 4px solid var(--ink);
  border-radius: 0;
  text-align: center;
  outline: none;
  transition: border-color 0.2s ease, transform 0.2s ease, background-color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  cursor: default;
  user-select: none;
  box-shadow: 6px 6px 0 var(--ink);
}

.answer:focus {
  border-color: #4f8cff;
}

.answer:focus-visible {
  outline: 3px solid rgba(79, 140, 255, 0.45);
  outline-offset: 2px;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
  max-width: 100%;
}

.numpad-key {
  min-height: 48px;
  padding: 14px 12px;
  font-size: 1.5rem;
  font-weight: 700;
  background: #fff;
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, opacity 0.2s ease, background-color 0.15s ease;
  box-shadow: 5px 5px 0 var(--ink);
}

.numpad-key:hover {
  background: #d5e4ff;
}

.numpad-key:active {
  transform: scale(0.98);
}

.numpad-back {
  font-size: 1.35rem;
}

.numpad-spacer {
  min-height: 48px;
  pointer-events: none;
  visibility: hidden;
}

.answer.wrong {
  border-color: #e53935;
  background: #fff2f2;
  animation: shake 0.25s linear 1;
}

.buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 16px;
}

button {
  border: none;
  border-radius: 0;
  font-size: 1.4rem;
  font-weight: 700;
  padding: 16px;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.2s ease;
  border: 3px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.01em;
}

button:active {
  transform: scale(0.98);
}

.submit-btn {
  font-family: "Luckiest Guy", "Comic Sans MS", cursive;
  background: #22c55e;
  color: white;
}

.submit-btn:hover {
  opacity: 0.95;
}

.message {
  min-height: 32px;
  margin-top: 14px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--red-pop);
  text-transform: uppercase;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #2ecc71;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-out;
  overflow: hidden;
}

.overlay.show {
  opacity: 1;
  cursor: pointer;
  pointer-events: auto;
}

.overlay.show.overlay--with-actions {
  cursor: default;
}

.overlay--success {
  background: var(--mint-pop);
}

.overlay--warning {
  background: #ff8a00;
}

.overlay--reveal {
  background: #b45309;
}

.overlay--intro {
  background: var(--blue-pop);
}

.overlay--reveal .overlay-text {
  font-size: clamp(1.75rem, 6vw, 3.2rem);
}

.overlay-text {
  font-family: "Luckiest Guy", "Comic Sans MS", cursive;
  padding: 0 20px;
  text-align: center;
  white-space: pre-line;
  font-size: clamp(2.2rem, 7vw, 4rem);
  font-weight: 800;
  line-height: 1.15;
}

.overlay-actions {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  width: min(88vw, 360px);
}

.overlay-actions[hidden] {
  display: none;
}

.overlay-action-btn {
  font-family: "Luckiest Guy", "Comic Sans MS", cursive;
  font-size: 1.15rem;
}

.overlay-action-btn--primary {
  background: var(--mint-pop);
  color: white;
}

.overlay-action-btn--secondary {
  background: #fff;
  color: var(--ink);
}

.done-screen {
  display: none;
  font-family: "Luckiest Guy", "Comic Sans MS", cursive;
}

.done-screen.show {
  display: block;
}

.done-title {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 10px;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #fff, 4px 4px 0 var(--ink);
}

.done-text {
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.done-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 4px;
}

.play-again-btn {
  background: var(--mint-pop);
  color: white;
}

.done-to-start-btn {
  width: 100%;
  min-height: 48px;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 12px 16px;
  background: #fff;
  color: var(--ink);
  border: 3px solid var(--ink);
}

@media (min-width: 560px) {
  .table-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
  100% { transform: translateX(0); }
}

.overlay-text {
  position: relative;
  z-index: 2;
}

.confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 14px;
  opacity: 0.95;
  transform: translate(-50%, -50%);
  animation: explode 1.2s ease-out forwards;
}

.confetti-piece.circle {
  border-radius: 50%;
}

@keyframes explode {
  0% {
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
    opacity: 1;
  }

  60% {
    opacity: 1;
  }

  100% {
    transform:
      translate(calc(-50% + var(--x)), calc(-50% + var(--y)))
      rotate(720deg);
    opacity: 0;
  }
}
