* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #0f1117;
  --card: #1a1e2a;
  --card-edge: #262c3d;
  --text: #e8eaf0;
  --dim: #8a91a5;
  --orange: #ff9900;
  --green: #34d27b;
  --red: #ff5c6c;
}

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

/* ---- top bar ---- */
#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  /* safe-area insets for the iPhone notch / home indicator (Capacitor) */
  padding: calc(12px + env(safe-area-inset-top)) 14px 8px;
  gap: 10px;
}
#tabs { display: flex; gap: 6px; }
.tab {
  background: none;
  border: 1px solid var(--card-edge);
  color: var(--dim);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active { background: var(--orange); border-color: var(--orange); color: #1a1200; }
#review-badge {
  background: var(--red);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  margin-left: 2px;
}
.tab.active #review-badge { background: #1a1200; color: var(--orange); }
#cat-select {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--card-edge);
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 13px;
  max-width: 46vw;
}

/* ---- progress / stats ---- */
#progress-wrap {
  height: 4px;
  background: var(--card-edge);
  margin: 4px 14px 0;
  border-radius: 2px;
  overflow: hidden;
}
#progress-bar { height: 100%; width: 0; background: var(--orange); transition: width .3s; }
#stats-line {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 12px;
  color: var(--dim);
  padding: 6px 0 2px;
}
#stat-known b { color: var(--green); }
#stat-review b { color: var(--red); }
#stat-remaining b { color: var(--text); }

/* ---- paywall ---- */
#paywall {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 14px 0;
  padding: 10px 12px;
  background: rgba(255,153,0,.1);
  border: 1px solid rgba(255,153,0,.35);
  border-radius: 12px;
  font-size: 13px;
  color: var(--text);
}
#paywall button {
  background: var(--orange);
  border: none;
  color: #1a1200;
  font-weight: 700;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
}
#reset-row a { color: #565d72; }
#reset-row span { color: #565d72; font-size: 11px; }

/* ---- card stage ---- */
#stage-area {
  flex: 1;
  position: relative;
  margin: 8px 14px;
  min-height: 0;
}
.card {
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, var(--card) 0%, #151824 100%);
  border: 1px solid var(--card-edge);
  border-radius: 20px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
  touch-action: none;
  will-change: transform;
  overflow: hidden;
}
.card.under {
  transform: scale(.955) translateY(10px);
  opacity: .55;
  pointer-events: none;
}
.card.snap-back { transition: transform .22s ease-out; }
.card.fly { transition: transform .3s ease-in, opacity .3s ease-in; opacity: 0; }

.badge {
  align-self: flex-start;
  background: rgba(255,153,0,.14);
  color: var(--orange);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}

.card-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 8px; }
.card-scroll::-webkit-scrollbar { width: 0; }

.q { font-size: 19px; font-weight: 650; line-height: 1.45; white-space: pre-line; }

.section { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--card-edge); animation: fadeup .3s ease-out; }
.sec-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.ans .sec-label { color: var(--green); }
.deep .sec-label { color: #6fb3ff; }
.sec-body { font-size: 15px; line-height: 1.55; white-space: pre-line; color: #cdd2e0; }
.ans .sec-body { color: var(--text); font-weight: 550; }

@keyframes fadeup { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.hint {
  text-align: center;
  font-size: 12px;
  color: var(--dim);
  padding-top: 8px;
  flex-shrink: 0;
}

.stamp {
  position: absolute;
  top: 26px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 2px;
  padding: 4px 14px;
  border: 3px solid;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
}
.stamp.got { right: 20px; color: var(--green); border-color: var(--green); transform: rotate(12deg); }
.stamp.again { left: 20px; color: var(--red); border-color: var(--red); transform: rotate(-12deg); }

/* ---- empty state ---- */
#empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 24px;
}
#empty-title { font-size: 24px; font-weight: 700; }
#empty-sub { color: var(--dim); font-size: 15px; line-height: 1.5; }
#empty-actions { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; justify-content: center; }
#empty-actions button {
  background: var(--orange);
  border: none;
  color: #1a1200;
  font-weight: 700;
  font-size: 14px;
  padding: 11px 20px;
  border-radius: 999px;
  cursor: pointer;
}
#empty-actions button.ghost { background: none; border: 1px solid var(--card-edge); color: var(--text); }

/* ---- controls ---- */
#controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  padding: 10px 0 4px;
}
.ctl {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 2px solid;
  background: var(--card);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ctl:active { transform: scale(.92); }
.ctl.nope { color: var(--red); border-color: var(--red); }
.ctl.yep { color: var(--green); border-color: var(--green); }
.ctl.small { width: 46px; height: 46px; font-size: 18px; color: var(--dim); border-color: var(--card-edge); }

#reset-row { text-align: center; padding: 2px 0 calc(10px + env(safe-area-inset-bottom)); }
#btn-reset {
  background: none;
  border: none;
  color: #565d72;
  font-size: 11px;
  cursor: pointer;
  text-decoration: underline;
}

/* ---- glossary terms ---- */
.term {
  text-decoration: underline dotted var(--dim);
  text-underline-offset: 3px;
  cursor: pointer;
}

#glossary-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
#glossary-sheet {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  padding: 18px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 40px rgba(0,0,0,.5);
  animation: sheetup .18s ease-out;
}
@keyframes sheetup { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
#glossary-term {
  color: var(--orange);
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 8px;
}
#glossary-def { font-size: 15px; line-height: 1.5; color: var(--text); }

.hidden { display: none !important; }
