:root {
  --ground: #151a24;
  --ground-raised: #1c2230;
  --paper: #e8e2cc;
  --paper-shade: #dcd4b9;
  --ink: #2a2420;
  --ink-soft: #5a5148;
  --rule: #c9bf9e;

  --bible: #7a2e2e;
  --art: #a8781f;
  --music: #1f5c54;
  --shakespeare: #5c3a54;

  --correct: #4c7a52;
  --missed: #a8462f;

  --serif: "Spectral", Georgia, "Iowan Old Style", serif;
  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ground);
}

body {
  font-family: var(--sans);
  color: var(--paper);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: var(--sans);
}

/* Same specificity as a class rule like `.card-actions-mark { display: flex }`
   loses the cascade tie to the UA default without this — hidden elements
   would stay visible. */
[hidden] {
  display: none !important;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.screen {
  width: 100%;
  max-width: 420px;
  margin: auto 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---------- shared: catalogue card ---------- */

.card {
  position: relative;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid #00000022;
  box-shadow: 0 18px 40px -20px rgba(0, 0, 0, 0.6);
  padding: 22px 22px 26px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ground);
  transform: translateX(-50%);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
}

.card-tag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
}

.card-tag .cat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.card-tag .cat::before {
  content: "";
  width: 8px;
  height: 8px;
  display: inline-block;
  background: var(--tab-color, var(--ink-soft));
}

.card-prompt {
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.45;
  font-weight: 500;
}

.card-media {
  width: 100%;
  background: var(--paper-shade);
  border: 1px solid #00000018;
  overflow: hidden;
}

.card-media img {
  display: block;
  width: 100%;
  height: auto;
}

.card-media .yt-embed {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
}

/* #yt-mount is where the YouTube JS API attaches its player iframe. It's
   always fully covered by .yt-cover — see the comment in ui.js renderMedia
   for why the video frame itself (thumbnail, cover art, pause overlay) is
   never shown, only played. */
.card-media .yt-embed #yt-mount,
.card-media .yt-embed #yt-mount iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.card-media .yt-embed .yt-cover {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--paper-shade);
  border: 0;
  font-family: var(--sans);
  color: var(--ink);
  cursor: pointer;
}

.card-media .yt-embed .yt-cover:disabled {
  cursor: default;
  opacity: 0.7;
}

.yt-cover-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.yt-cover[data-playing="true"] .yt-cover-icon {
  animation: yt-pulse 1.6s ease-in-out infinite;
}

.yt-cover-label {
  font-size: 13px;
  color: var(--ink-soft);
}

@keyframes yt-pulse {
  0%, 100% { box-shadow: 0 0 0 0 #00000022; }
  50% { box-shadow: 0 0 0 6px #00000000; }
}

.card-reveal {
  border-top: 1px solid var(--rule);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-answer {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 18px;
}

.card-fact {
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--ink-soft);
  line-height: 1.5;
}

.card-actions {
  margin-top: auto;
  display: flex;
  gap: 10px;
}

.card-actions-mark {
  display: flex;
  gap: 10px;
  flex: 1;
}

.btn {
  font-size: 15px;
  font-weight: 500;
  padding: 12px 16px;
  border: 1px solid transparent;
  cursor: pointer;
  flex: 1;
  transition: transform 80ms ease, background 120ms ease;
}

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

.btn-primary {
  background: var(--ink);
  color: var(--paper);
}

.btn-primary:hover { background: #3a3129; }

.btn-outline {
  background: transparent;
  border-color: var(--ink-soft);
  color: var(--ink);
}

.btn-outline:hover { background: #00000010; }

.btn-correct {
  background: var(--correct);
  color: #eef4ee;
}

.btn-missed {
  background: var(--missed);
  color: #f7ece7;
}

.btn-ghost {
  background: transparent;
  color: var(--paper);
  border-color: #ffffff33;
}

.btn-ghost:hover { background: #ffffff10; }

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- home screen ---------- */

.home-stack {
  position: relative;
  height: 150px;
  margin: 8px 0 4px;
}

.home-stack .stack-card {
  position: absolute;
  left: 50%;
  top: 0;
  width: 150px;
  height: 100px;
  background: var(--paper);
  border: 1px solid #00000022;
  box-shadow: 0 10px 24px -14px rgba(0,0,0,0.7);
}

.home-stack .stack-card:nth-child(1) { transform: translateX(-50%) rotate(-9deg); top: 30px; opacity: 0.55; }
.home-stack .stack-card:nth-child(2) { transform: translateX(-50%) rotate(5deg); top: 18px; opacity: 0.75; }
.home-stack .stack-card-logo {
  transform: translateX(-50%) rotate(-2deg);
  top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
}

.home-stack .stack-card-logo svg {
  width: 74%;
  height: auto;
  color: var(--ink);
}

.home-title {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  text-align: center;
  margin: 0;
}

.home-sub {
  text-align: center;
  color: #b9b3a0;
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
}

.home-sub strong { color: var(--paper); font-weight: 600; }

.home-meta {
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
  color: #8a8471;
  margin: 0;
}

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

.session-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 13px;
  color: #c9c3ae;
}

.session-progress {
  height: 3px;
  background: #ffffff1a;
  position: relative;
  overflow: hidden;
}

.session-progress > span {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--paper);
  transition: width 200ms ease;
}

/* ---------- end screen ---------- */

.end-slip {
  background: var(--paper);
  color: var(--ink);
  padding: 22px;
  border: 1px solid #00000022;
}

.end-slip h2 {
  font-family: var(--serif);
  font-size: 22px;
  margin: 0 0 4px;
}

.end-slip .end-sub {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
  margin: 0 0 16px;
}

.end-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--rule);
  font-size: 14px;
}

.end-row:first-of-type { border-top: none; }

.end-row .cat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.end-row .cat::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--tab-color, var(--ink-soft));
}

/* ---------- stats screen ---------- */

.stats-list { display: flex; flex-direction: column; gap: 14px; }

.stats-row .head {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin-bottom: 6px;
}

.stats-row .head .cat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.stats-row .head .cat::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--tab-color, var(--ink-soft));
}

.stats-bar {
  height: 6px;
  background: #ffffff1a;
  position: relative;
}

.stats-bar > span {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--tab-color, var(--paper));
}

.nav-row {
  display: flex;
  gap: 10px;
}

.hint {
  text-align: center;
  color: #8a8471;
  font-size: 13px;
}

@media (prefers-reduced-motion: reduce) {
  .btn, .session-progress > span, .stats-bar > span { transition: none; }
  .yt-cover[data-playing="true"] .yt-cover-icon { animation: none; }
}
