@font-face {
  font-family: "Inter";
  src: url("fonts/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

/* The app's AppColors. */
:root {
  --bg-top: #0a0f1f;
  --bg-mid: #080a17;
  --bg-bottom: #03050d;
  --card: rgba(255, 255, 255, 0.04);
  --card-elevated: rgba(255, 255, 255, 0.06);
  --stroke: rgba(255, 255, 255, 0.08);
  --stroke-strong: rgba(255, 255, 255, 0.16);
  --text: #fff;
  --text-2: rgba(255, 255, 255, 0.65);
  --text-3: rgba(255, 255, 255, 0.5);
  --blue: #1e8bff;
  --blue-deep: #1a4dcc;
  --orange: #ff9a1f;
  --orange-deep: #d96609;
  --success: #4dd980;
  --danger: #ff5966;
  --warning: #ffc733;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* `.options` and friends set display, which would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-bottom);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: linear-gradient(180deg, var(--bg-top), var(--bg-mid) 50%, var(--bg-bottom));
  overflow: hidden;
}

#app {
  position: relative;
  max-width: 540px;
  height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.screen {
  display: none;
  height: 100%;
  flex-direction: column;
  gap: 14px;
}
.screen.active { display: flex; }

button, .primary {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}

.primary {
  display: block;
  text-align: center;
  background: linear-gradient(180deg, var(--blue), var(--blue-deep));
  border-radius: 16px;
  padding: 14px 18px;
  font-weight: 700;
  box-shadow: 0 6px 24px rgba(30, 139, 255, 0.35);
}
.primary:active { transform: scale(0.98); }
.big { font-size: 1.15rem; padding: 18px; width: 100%; }

.ghost {
  background: var(--card-elevated);
  border: 1px solid var(--stroke-strong);
  border-radius: 14px;
  padding: 12px 22px;
  font-weight: 600;
}
.ghost:active { background: rgba(255, 255, 255, 0.12); }

.card {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: 20px;
  padding: 16px;
}

.accent { color: var(--orange); }

/* Start */

#screen-start { justify-content: center; }

.hero { text-align: center; }
.app-icon {
  border-radius: 22px;
  box-shadow: 0 10px 40px rgba(30, 139, 255, 0.35);
}
h1 {
  margin: 12px 0 6px;
  font-size: clamp(2rem, 9vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.tagline { margin: 0; color: var(--text-2); line-height: 1.45; }
.tagline b { color: var(--text); }

.how { display: grid; gap: 10px; font-size: 0.95rem; color: var(--text-2); }
.how-row { display: flex; align-items: center; gap: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.blue { background: var(--blue); box-shadow: 0 0 8px var(--blue); }
.dot.orange { background: var(--orange); box-shadow: 0 0 8px var(--orange); }
.dot.dim { background: var(--text-3); }

.pack-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pack-picker button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 6px;
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-2);
}
.pack-picker button[aria-checked="true"] {
  color: var(--text);
  background: rgba(30, 139, 255, 0.14);
  border-color: var(--blue);
  box-shadow: 0 0 18px rgba(30, 139, 255, 0.3);
}
.pack-icon { font-size: 1.6rem; line-height: 1; }

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: 14px;
}
.mode-toggle button {
  background: transparent;
  border-radius: 10px;
  padding: 10px 8px;
  font-weight: 600;
  color: var(--text-2);
}
.mode-toggle button[aria-checked="true"] {
  background: var(--card-elevated);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--stroke-strong);
}
.mode-toggle button:disabled { opacity: 0.4; cursor: not-allowed; }
.mode-toggle.small button { padding: 8px 10px; font-size: 0.9rem; }

.notice {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 154, 31, 0.1);
  border: 1px solid rgba(255, 154, 31, 0.3);
  color: #ffd6a3;
  font-size: 0.85rem;
  line-height: 1.4;
}

.fine { margin: 0; font-size: 0.75rem; line-height: 1.45; color: var(--text-3); }
.fine a, .credits a { color: var(--blue); }
.center { text-align: center; }

/* Play */

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
.clock {
  font-size: 1.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.clock.low { color: var(--danger); }
.score { justify-self: end; font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.score small { font-size: 0.8rem; font-weight: 600; color: var(--text-2); margin-left: 4px; }

.streak {
  min-height: 30px;
  padding: 4px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  border: 1px solid transparent;
  transition: background 0.2s, color 0.2s;
}
.streak:empty { visibility: hidden; }
.streak[data-tier="none"] { color: var(--text-2); background: var(--card); border-color: var(--stroke); }
.streak[data-tier="warm"] { color: var(--warning); background: rgba(255, 199, 51, 0.1); border-color: rgba(255, 199, 51, 0.3); }
.streak[data-tier="hot"] { color: var(--orange); background: rgba(255, 154, 31, 0.14); border-color: rgba(255, 154, 31, 0.45); }
.streak[data-tier="blazing"] { color: #fff; background: linear-gradient(90deg, var(--orange-deep), var(--danger)); box-shadow: 0 0 18px rgba(255, 89, 102, 0.5); }

.timebar { height: 4px; border-radius: 2px; background: var(--card-elevated); overflow: hidden; }
#timebar-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--blue), var(--orange)); transform-origin: left; }

.photo-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 22px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--stroke);
  transition: box-shadow 0.2s, border-color 0.2s;
}
.photo-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-wrap[data-kind="flag"] { display: grid; place-items: center; padding: 18px; }
.photo-wrap[data-kind="flag"] img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.photo-wrap[data-kind="math"] { display: grid; place-items: center; padding: 16px; }
.math {
  display: grid;
  gap: 0.35em;
  justify-items: center;
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.math .question { color: var(--orange); }
.photo-wrap.flash-good { border-color: var(--success); box-shadow: 0 0 0 3px var(--success), 0 0 40px rgba(77, 217, 128, 0.45); }
.photo-wrap.flash-bad { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger), 0 0 40px rgba(255, 89, 102, 0.4); }

.pop {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(3, 5, 13, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
.pop.show { animation: pop 1s ease-out; }
.pop.good { color: var(--success); }
.pop.bad { color: var(--danger); }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  15%, 70% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -6px); }
}

.panel { flex: none; }

.listening {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-2);
  font-weight: 600;
}
.mic-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-3); }
.listening.live .mic-dot { background: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 89, 102, 0.6); }
  100% { box-shadow: 0 0 0 12px rgba(255, 89, 102, 0); }
}
.heard {
  margin-top: 6px;
  min-height: 1.5em;
  text-align: center;
  color: var(--text-3);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.options button {
  background: var(--card-elevated);
  border: 1px solid var(--stroke-strong);
  border-radius: 14px;
  padding: 16px 8px;
  font-weight: 700;
  font-size: 1.05rem;
  text-transform: capitalize;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.options button:active { background: rgba(30, 139, 255, 0.2); }
.options button.correct { background: rgba(77, 217, 128, 0.2); border-color: var(--success); color: var(--success); }
.options button.wrong { background: rgba(255, 89, 102, 0.2); border-color: var(--danger); color: var(--danger); }
.options button.dim { opacity: 0.35; }

.controls { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.controls .mode-toggle { flex: 1; }

/* End */

#screen-end { justify-content: center; }
.kicker { margin: 0; color: var(--orange); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.final-score { font-size: 5rem; font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.final-score small { display: block; font-size: 1rem; font-weight: 600; color: var(--text-2); letter-spacing: 0; margin-top: 6px; }
.new-best { margin: 8px 0 0; color: var(--success); font-weight: 700; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.stats b { display: block; font-size: 1.5rem; }
.stats span { font-size: 0.8rem; color: var(--text-2); }
.store { background: linear-gradient(180deg, var(--orange), var(--orange-deep)); box-shadow: 0 6px 24px rgba(255, 154, 31, 0.35); }

/* Credits page */

body.credits { overflow: auto; }
.credits main { max-width: 540px; margin: 0 auto; padding: 24px 16px; line-height: 1.6; }
.credits ul { padding-left: 18px; color: var(--text-2); }

@media (max-height: 640px) {
  .app-icon { width: 64px; height: 64px; }
  .how { display: none; }
}

/* Short frames (itch's default embed is 640×360): tighter everything, and the start and end
   screens may scroll rather than clip. */
@media (max-height: 520px) {
  #app { padding-top: 10px; padding-bottom: 10px; }
  .screen { gap: 8px; }
  #screen-start, #screen-end { justify-content: flex-start; overflow-y: auto; }
  .app-icon { width: 48px; height: 48px; border-radius: 12px; }
  h1 { margin: 4px 0 2px; font-size: 1.75rem; }
  .big { padding: 12px; font-size: 1rem; }
  .fine { font-size: 0.7rem; }
  .final-score { font-size: 3rem; }
  .final-score small { margin-top: 2px; }
  .stats { padding: 10px; }
  .stats b { font-size: 1.2rem; }
  .clock, .score { font-size: 1.3rem; }
  .options { gap: 8px; }
  .options button { padding: 10px 6px; font-size: 0.95rem; }
  .notice { padding: 6px 10px; font-size: 0.75rem; }
  .pack-picker button { flex-direction: row; justify-content: center; padding: 8px 6px; }
  .pack-icon { font-size: 1.1rem; }
  .math { font-size: 1.5rem; }
}

/* Short and wide: photo on the left, everything else on the right, so the photo keeps its
   height instead of being squeezed into a strip. */
@media (max-height: 520px) and (min-aspect-ratio: 5/4) {
  #app { max-width: 900px; }
  #screen-play.active {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    grid-template-rows: auto auto 1fr auto auto auto;
    column-gap: 14px;
    row-gap: 8px;
  }
  #screen-play > .photo-wrap { grid-column: 1; grid-row: 1 / -1; }
  #screen-play > :not(.photo-wrap) { grid-column: 2; }
  #screen-play > .hud { grid-row: 1; }
  #screen-play > .timebar { grid-row: 2; }
  #screen-play > .panel { grid-row: 4; }
  #screen-play > .notice { grid-row: 5; }
  #screen-play > .controls { grid-row: 6; }
}

/* Never let the photo collapse into a strip. */
.photo-wrap { min-height: 140px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .pop.show { opacity: 1; }
}
