*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0e1016;
  --card: #191d28;
  --card2: #1f2433;
  --ink: #f2f4f9;
  --dim: #8b93a7;
  --line: #2b3143;
  --good: #2fbf71;
  --bad: #e05263;
  --accent: #6c8cff;
  --pad: 16px;
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.hidden { display: none !important; }

/* ---------- header ---------- */

#bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--pad) 10px;
}

#counter {
  flex: 1;
  text-align: right;
  color: var(--dim);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

#track {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: var(--line);
}

#trackFill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .3s ease;
}

.icon {
  width: 40px; height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 17px;
  cursor: pointer;
}

/* ---------- stage + card ---------- */

#stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--pad);
  min-height: 0;
}

#card {
  position: relative;
  width: 100%;
  max-width: 520px;
  height: 100%;
  max-height: 560px;
  perspective: 1400px;
  cursor: pointer;
}

#card .inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform .45s cubic-bezier(.4, .2, .2, 1);
  transform-style: preserve-3d;
}

#card.flipped .inner { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  text-align: center;
  overflow-y: auto;
}

.back {
  transform: rotateY(180deg);
  background: var(--card2);
}

.text {
  font-size: clamp(22px, 6.2vw, 34px);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -.01em;
  text-wrap: balance;
}

.back .text { font-weight: 500; }

.note {
  color: var(--dim);
  font-size: 14px;
  font-style: italic;
  max-width: 34ch;
}

.badge {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  white-space: nowrap;
}

.hint {
  position: absolute;
  bottom: 18px;
  color: var(--dim);
  font-size: 12px;
  opacity: .6;
}

/* Sits over the card rather than on a face, so one button serves both sides
   and survives the flip. */
.speak {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg);
  color: var(--dim);
  cursor: pointer;
}

.speak:active,
.speak.speaking { border-color: var(--accent); color: var(--accent); }

/* ---------- answers ---------- */

#answers {
  display: flex;
  gap: 10px;
  padding: 0 var(--pad) calc(env(safe-area-inset-bottom) + 14px);
}

.ans {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 66px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  color: var(--ink);
  font-size: 21px;
  cursor: pointer;
  transition: transform .1s ease, filter .1s ease;
}

.ans span { font-size: 12px; color: var(--dim); }
.ans:active { transform: scale(.97); filter: brightness(1.25); }
.good { border-color: color-mix(in srgb, var(--good) 45%, var(--line)); color: var(--good); }
.bad  { border-color: color-mix(in srgb, var(--bad)  45%, var(--line)); color: var(--bad); }

/* ---------- panels + sheet ---------- */

.panel {
  max-width: 420px;
  padding: 0 8px;
  text-align: center;
}

.panel h1 { font-size: 24px; margin-bottom: 10px; }
.panel p { color: var(--dim); margin-bottom: 22px; }

.wide {
  width: 100%;
  min-height: 50px;
  margin-top: 10px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  font-size: 15px;
  cursor: pointer;
}

.danger { color: var(--bad); }

#sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, .55);
}

.sheetBody {
  width: 100%;
  max-height: 86vh;
  padding: 22px var(--pad) calc(env(safe-area-inset-bottom) + 22px);
  border-radius: 22px 22px 0 0;
  background: var(--bg);
  border-top: 1px solid var(--line);
  overflow-y: auto;
}

.sheetBody h2 {
  margin: 18px 0 10px;
  color: var(--dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.sheetBody h2:first-child { margin-top: 0; }

.ep {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 50px;
  margin-bottom: 8px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--dim);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.ep[aria-pressed="true"] { color: var(--ink); border-color: var(--accent); }
.ep small { font-variant-numeric: tabular-nums; opacity: .7; }

.statRow {
  display: flex;
  justify-content: space-between;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.statRow span:first-child { color: var(--dim); }
.statRow span:last-child { font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  #card .inner, #trackFill { transition: none; }
}

/* ---------- account + sign in ---------- */

#account {
  padding: 2px 2px 4px;
  color: var(--dim);
  font-size: 13px;
  line-height: 1.4;
}

/* Sits above the sheet so an expired session can interrupt anything. */
#auth {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 24px) var(--pad)
           calc(env(safe-area-inset-bottom) + 24px);
  background: var(--bg);
}

#authForm {
  width: 100%;
  max-width: 340px;
  text-align: center;
}

#authForm h1 { font-size: 24px; margin-bottom: 10px; }

.authIntro {
  margin-bottom: 22px;
  color: var(--dim);
}

#authForm input {
  width: 100%;
  min-height: 50px;
  margin-bottom: 10px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* below 16px iOS zooms the page on focus */
  user-select: text;
}

#authForm input:focus { outline: none; border-color: var(--accent); }

#authSubmit { border-color: var(--accent); }
#authSubmit:disabled { opacity: .6; cursor: default; }

#authError:not(:empty) {
  padding: 6px 2px 2px;
  color: var(--bad);
  font-size: 13px;
  line-height: 1.4;
}

/* Labels exist for screen readers; the placeholders carry the visual design. */
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
