/* FSO Flashcards — phone-first, no framework, single stylesheet */

:root {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --border: #e4e4e7;
  --text: #18181b;
  --text-muted: #71717a;
  --primary: #1e3a8a;
  --primary-soft: #eef2ff;
  --got: #10b981;
  --got-soft: #d1fae5;
  --review: #f59e0b;
  --review-soft: #fef3c7;
  --hint: #6366f1;
  --hint-soft: #e0e7ff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
  --radius: 12px;
  --tap: 48px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

/* The HTML `hidden` attribute must always win over our class-level `display: flex`
   rules — otherwise elements like `.card-face[hidden]` and `#empty-state[hidden]`
   stay visible. Specificity: [hidden] = 0,0,1,0; class selectors = 0,0,1,0. We need
   the !important to break the tie because the class selector comes later in the
   cascade. Alternative is `[hidden] { display: none; }` placed *after* all class
   rules, but !important is more robust against future stylesheet additions. */
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* topbar */
.topbar {
  background: var(--primary);
  color: #fff;
  padding: 14px 16px 12px;
  flex-shrink: 0;
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: 0.2px; }
.progress-stats {
  display: flex; align-items: center; gap: 8px; font-size: 12px;
  background: rgba(255,255,255,0.15); padding: 4px 6px 4px 10px; border-radius: 999px;
}
#stats-text { font-variant-numeric: tabular-nums; }
.ghost-btn {
  background: transparent; color: #fff; border: 1px solid rgba(255,255,255,0.4);
  padding: 3px 10px; border-radius: 999px; font-size: 11px; cursor: pointer;
  font-weight: 500;
}
.ghost-btn:hover { background: rgba(255,255,255,0.1); }
.deck-meta { font-size: 11px; opacity: 0.85; margin-top: 6px; }

/* stage */
.stage {
  flex: 1;
  display: flex; flex-direction: column;
  padding: 16px;
  max-width: 640px; width: 100%;
  margin: 0 auto;
  gap: 14px;
}

/* empty state */
.empty-state {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 20px; text-align: center;
  box-shadow: var(--shadow-sm);
}
.empty-state h2 { margin: 0 0 8px; font-size: 18px; color: var(--primary); }
.empty-state p { margin: 0 0 16px; color: var(--text-muted); font-size: 14px; }
.primary-btn {
  background: var(--primary); color: #fff; border: 0;
  padding: 10px 18px; border-radius: 8px; font-size: 14px;
  font-weight: 600; cursor: pointer;
}
.primary-btn:hover { background: #1e40af; }

/* card */
.card-wrap {
  flex: 1;
  display: flex;
  min-height: 280px;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
.card-wrap:focus-visible .card { box-shadow: 0 0 0 3px var(--primary-soft), var(--shadow-md); }
.card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 18px;
  display: flex; flex-direction: column;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.card-wrap:active .card { transform: scale(0.98); }
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}
.card-counter {
  font-size: 11px; letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--text-muted); font-weight: 600;
}
.card-status {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--bg); color: var(--text-muted); font-weight: 600;
}
.card-status.got { background: var(--got-soft); color: #065f46; }
.card-status.review { background: var(--review-soft); color: #92400e; }
.card-status.hint { background: var(--hint-soft); color: #3730a3; }
.card-face {
  flex: 1;
  display: flex; flex-direction: column;
}
.card-label {
  font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 8px; font-weight: 600;
}
.card-text {
  font-size: 19px; line-height: 1.45; color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.card-face-back .card-text { font-size: 16px; line-height: 1.5; }
/* Cite section: shown on the answer side, no collapse. The cite and mnemonic
   are part of the answer — Justin already tapped to flip, give him the full
   reference without making him tap again. */
.cite-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.cite-label {
  font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--text-muted); margin: 0 0 4px; font-weight: 600;
}
.cite-text {
  font-size: 12px; color: var(--text-muted);
  line-height: 1.5; margin: 0 0 10px;
  word-break: break-word;
}
.cite-text:last-child { margin-bottom: 0; }

/* controls */
.controls {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px;
}
.ctrl {
  border: 0;
  padding: 14px 8px;
  border-radius: 10px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  min-height: var(--tap);
  transition: transform 0.1s ease, background 0.15s ease;
}
.ctrl:active { transform: scale(0.96); }
.ctrl-got { background: var(--got); color: #fff; }
.ctrl-got:hover { background: #059669; }
.ctrl-hint { background: var(--hint); color: #fff; }
.ctrl-hint:hover { background: #4f46e5; }
.ctrl-review { background: var(--review); color: #fff; }
.ctrl-review:hover { background: #d97706; }

/* nav */
.nav {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px;
}
.nav-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  min-height: 40px;
}
.nav-btn:hover { background: var(--surface-2); }
.nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.nav-spacer { flex: 1; }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--text); color: #fff;
  padding: 10px 16px; border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  pointer-events: none;
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* footer */
.footer {
  text-align: center; padding: 10px 16px;
  font-size: 11px; color: var(--text-muted);
  background: var(--bg); border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* responsive — slightly bigger text on desktop for legibility */
@media (min-width: 640px) {
  .card-text { font-size: 21px; }
  .card-face-back .card-text { font-size: 17px; }
}

/* desktop layout — card not full height */
@media (min-width: 640px) {
  .card-wrap { min-height: 360px; }
}