/* ============================================================
   Notecard Catalog — stylesheet
   Design: a library card-catalog. Sets are drawers, cards are
   literal ruled index cards with a punch hole, and the study
   view flips them like the real thing.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Special+Elite&family=IBM+Plex+Mono:wght@400;500;600&family=Lora:ital,wght@0,400;0,500;0,600;1,400&display=swap');

:root {
  --ink-navy: #1d2b3a;
  --pine: #26392f;
  --pine-dark: #182620;
  --paper: #f1e8d0;
  --paper-light: #f8f2e2;
  --paper-shadow: #d8cba7;
  --rule-red: #b1463f;
  --gold: #d3a94e;
  --gold-dark: #a9822f;
  --ink-text: #2a2620;
  --ink-faint: #6b6455;
  --danger: #a3402f;
  --success: #3c6e4f;

  --font-display: 'Special Elite', 'Courier New', monospace;
  --font-body: 'Lora', Georgia, serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;

  --radius-card: 6px;
  --shadow-card: 0 3px 0 var(--paper-shadow), 0 10px 20px -8px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--ink-navy);
  background-image:
    radial-gradient(circle at 15% 10%, rgba(211,169,78,0.06), transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(177,70,63,0.07), transparent 45%);
  color: var(--paper);
  font-family: var(--font-body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

a { color: inherit; }

button {
  font-family: var(--font-mono);
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

input, textarea {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink-text);
  background: var(--paper-light);
  border: 1px solid var(--paper-shadow);
  border-radius: 3px;
  padding: 0.65em 0.8em;
}

::placeholder { color: var(--ink-faint); opacity: 0.8; }

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.75rem;
  border-bottom: 1px solid rgba(241,232,208,0.12);
  flex-wrap: wrap;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-family: var(--font-display);
}

.brand .brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1.5px solid var(--gold);
  border-radius: 50%;
  color: var(--gold);
  font-size: 1rem;
}

.brand h1 {
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  margin: 0;
  font-weight: 400;
}

.brand .tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--paper);
}

.topbar-right .user-email {
  color: var(--gold);
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-link {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  color: var(--paper);
  opacity: 0.85;
}
.btn-link:hover { opacity: 1; color: var(--gold); }

main {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.hidden { display: none !important; }

/* ---------- Buttons ---------- */

.btn {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  padding: 0.65em 1.2em;
  border-radius: 3px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--gold);
  color: var(--pine-dark);
  font-weight: 600;
  box-shadow: 0 2px 0 var(--gold-dark);
}
.btn-primary:hover { background: #ddb663; }
.btn-primary:active { box-shadow: 0 1px 0 var(--gold-dark); }

.btn-outline {
  border: 1px solid rgba(241,232,208,0.4);
  color: var(--paper);
}
.btn-outline:hover { border-color: var(--gold); color: var(--gold); }

.btn-danger { color: #e8a79c; }
.btn-danger:hover { color: #ff8a76; }

.btn-ghost {
  color: var(--ink-faint);
  font-size: 0.78rem;
}
.btn-ghost:hover { color: var(--paper); }

/* ---------- Auth screen ---------- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  color: var(--ink-text);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 2.4rem 2rem 2rem;
  position: relative;
}

.auth-card::before {
  content: '';
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink-navy);
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.5);
}

.auth-header {
  text-align: center;
  margin-bottom: 1.6rem;
}

.auth-header .brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  border: 1.5px solid var(--rule-red);
  border-radius: 50%;
  color: var(--rule-red);
  font-family: var(--font-display);
  margin-bottom: 0.6rem;
}

.auth-header h1 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 400;
  margin: 0 0 0.25rem;
  letter-spacing: 0.02em;
}

.auth-header p {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0;
}

.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin-bottom: 0.35rem;
}
.field input { width: 100%; }

.auth-submit { width: 100%; margin-top: 0.5rem; }

.auth-switch {
  text-align: center;
  margin-top: 1.3rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-faint);
}
.auth-switch button {
  color: var(--rule-red);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 600;
}

.auth-message {
  margin-top: 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  padding: 0.6em 0.8em;
  border-radius: 3px;
  display: none;
}
.auth-message.show { display: block; }
.auth-message.error { background: rgba(163,64,47,0.12); color: var(--danger); }
.auth-message.info { background: rgba(60,110,79,0.12); color: var(--success); }

/* ---------- Section headers ---------- */

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.6rem;
  flex-wrap: wrap;
}

.section-head .eyebrow {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--gold);
  margin: 0 0 0.3rem;
}

.section-head h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.6rem;
  margin: 0;
  letter-spacing: 0.01em;
}

.section-head p.sub {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-faint);
  margin: 0.35rem 0 0;
}

/* ---------- Study set grid (the "drawer") ---------- */

.set-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.1rem;
}

.set-tab {
  background: var(--paper);
  color: var(--ink-text);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 1.2rem 1.1rem 1rem;
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 148px;
  transition: transform 0.15s ease;
  text-align: left;
  width: 100%;
}
.set-tab:hover { transform: translateY(-3px); }

.set-tab .index-label {
  position: absolute;
  top: -0.55rem;
  left: 1.1rem;
  background: var(--rule-red);
  color: var(--paper-light);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  padding: 0.2em 0.55em;
  border-radius: 2px;
  text-transform: uppercase;
}

.set-tab h3 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.05rem;
  margin: 0.6rem 0 0.4rem;
  line-height: 1.3;
}

.set-tab p.desc {
  font-size: 0.86rem;
  color: var(--ink-faint);
  margin: 0;
  flex: 1;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.set-tab .meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.8rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--paper-shadow);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-faint);
}

.set-tab .meta-row .score-badge {
  color: var(--success);
  font-weight: 600;
}

.new-set-tab {
  border: 1.5px dashed rgba(241,232,208,0.35);
  border-radius: var(--radius-card);
  min-height: 148px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.4rem;
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: transparent;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.new-set-tab:hover { border-color: var(--gold); color: var(--gold); }
.new-set-tab .plus { font-size: 1.8rem; font-family: var(--font-body); line-height: 1; }

.empty-state {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-faint);
  border: 1px dashed rgba(241,232,208,0.25);
  border-radius: var(--radius-card);
  padding: 2rem;
  text-align: center;
}

/* ---------- Set detail (card list) ---------- */

.set-detail-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  margin-bottom: 1.8rem;
}

.card-list { display: flex; flex-direction: column; gap: 0.7rem; }

.card-row {
  background: var(--paper);
  color: var(--ink-text);
  border-radius: var(--radius-card);
  box-shadow: 0 2px 0 var(--paper-shadow);
  padding: 0.9rem 1.1rem;
  display: grid;
  grid-template-columns: 1.6rem 1fr 1fr auto;
  align-items: center;
  gap: 1rem;
}

.card-row .num {
  font-family: var(--font-mono);
  color: var(--ink-faint);
  font-size: 0.78rem;
}

.card-row .q, .card-row .a {
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-row .a { color: var(--ink-faint); font-style: italic; }

.card-row .row-actions {
  display: flex;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

@media (max-width: 640px) {
  .card-row { grid-template-columns: 1fr; gap: 0.3rem; }
  .card-row .num { display: none; }
}

/* ---------- Modal / form panel ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,15,20,0.68);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 50;
}

.modal-panel {
  background: var(--paper);
  color: var(--ink-text);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  width: 100%;
  max-width: 460px;
  padding: 1.8rem;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-panel h3 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.2rem;
  margin: 0 0 1.1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  margin-top: 1.3rem;
}

/* ---------- Study mode (the signature flip card) ---------- */

.study-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.6rem;
}

.study-progress {
  width: 100%;
  max-width: 480px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-faint);
  display: flex;
  justify-content: space-between;
}

.study-progress-bar {
  width: 100%;
  max-width: 480px;
  height: 4px;
  background: rgba(241,232,208,0.15);
  border-radius: 2px;
  overflow: hidden;
}
.study-progress-bar > div {
  height: 100%;
  background: var(--gold);
  transition: width 0.25s ease;
}

.flip-scene {
  width: 100%;
  max-width: 480px;
  height: min(300px, 62vw);
  min-height: 220px;
  perspective: 1400px;
}

.flip-card {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(.2,.8,.2,1);
  cursor: pointer;
}
.flip-card.flipped { transform: rotateY(180deg); }

.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--paper);
  color: var(--ink-text);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 2.2rem 1.8rem;
  display: flex;
  flex-direction: column;
}

.flip-face::before {
  /* punch hole */
  content: '';
  position: absolute;
  top: 0.85rem;
  left: 50%;
  transform: translateX(-50%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink-navy);
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.5);
}

.flip-face::after {
  /* ruled line under the label */
  content: '';
  position: absolute;
  top: 3.3rem;
  left: 1.6rem;
  right: 1.6rem;
  height: 1px;
  background: var(--rule-red);
  opacity: 0.55;
}

.flip-face .face-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--gold-dark);
  margin-top: 0.4rem;
}

.flip-face .face-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 1.25rem;
  line-height: 1.5;
  padding: 1rem 0;
}

.flip-face .face-hint {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.flip-back { transform: rotateY(180deg); }

.study-nav {
  display: flex;
  align-items: center;
  gap: 1.4rem;
}

.study-nav .nav-count {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--paper);
  min-width: 4rem;
  text-align: center;
}

.icon-btn {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  border: 1px solid rgba(241,232,208,0.35);
  color: var(--paper);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { border-color: var(--gold); color: var(--gold); }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ---------- Quiz mode ---------- */

.quiz-question-card {
  width: 100%;
  max-width: 560px;
  background: var(--paper);
  color: var(--ink-text);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 2rem 1.8rem;
  position: relative;
}
.quiz-question-card::before {
  content: '';
  position: absolute;
  top: 0.85rem;
  left: 50%;
  transform: translateX(-50%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink-navy);
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.5);
}

.quiz-label {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--gold-dark);
  margin: 0.6rem 0 1rem;
}

.quiz-question-text {
  text-align: center;
  font-size: 1.25rem;
  line-height: 1.5;
  margin-bottom: 1.6rem;
  padding-bottom: 1.4rem;
  border-bottom: 1px dashed var(--paper-shadow);
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.quiz-option {
  text-align: left;
  border: 1.5px solid var(--paper-shadow);
  background: var(--paper-light);
  color: var(--ink-text);
  border-radius: 4px;
  padding: 0.8em 1em;
  font-family: var(--font-body);
  font-size: 0.98rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.quiz-option .opt-letter {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-faint);
  border: 1px solid var(--paper-shadow);
  border-radius: 3px;
  width: 1.6rem;
  height: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.quiz-option:hover:not(:disabled) { border-color: var(--gold-dark); }

.quiz-option.correct {
  border-color: var(--success);
  background: rgba(60,110,79,0.14);
}
.quiz-option.correct .opt-letter { background: var(--success); color: var(--paper-light); border-color: var(--success); }

.quiz-option.incorrect {
  border-color: var(--danger);
  background: rgba(163,64,47,0.12);
}
.quiz-option.incorrect .opt-letter { background: var(--danger); color: var(--paper-light); border-color: var(--danger); }

.quiz-option:disabled { cursor: default; }

.quiz-feedback {
  margin-top: 1rem;
  min-height: 1.4rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-align: center;
}
.quiz-feedback.correct-text { color: var(--success); }
.quiz-feedback.incorrect-text { color: var(--danger); }

/* ---------- Quiz results ---------- */

.results-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1.2rem;
  padding: 2rem 0;
}

.results-score {
  font-family: var(--font-display);
  font-size: 4rem;
  color: var(--gold);
  line-height: 1;
}

.results-score .pct-sign { font-size: 2rem; }

.results-caption {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-faint);
}

.results-detail {
  width: 100%;
  max-width: 480px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.results-row {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  background: var(--paper);
  color: var(--ink-text);
  border-radius: 4px;
  padding: 0.7em 0.9em;
  font-size: 0.85rem;
}
.results-row .mark { font-family: var(--font-mono); font-weight: 700; }
.results-row.right .mark { color: var(--success); }
.results-row.wrong .mark { color: var(--danger); }
.results-row .rr-text { flex: 1; }
.results-row .rr-your { color: var(--danger); font-style: italic; }

.results-actions { display: flex; gap: 0.8rem; margin-top: 0.5rem; flex-wrap: wrap; justify-content: center; }

/* ---------- Loading / toast ---------- */

.loading-line {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink-faint);
  text-align: center;
  padding: 2rem 0;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--paper);
  color: var(--ink-text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.7em 1.2em;
  border-radius: 4px;
  box-shadow: var(--shadow-card);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-8px); }
.toast.err { color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  .flip-card, .set-tab, .btn, .toast { transition: none !important; }
}

/* ============================================================
   Mobile
   ============================================================ */

@media (max-width: 640px) {
  .topbar {
    padding: 0.9rem 1.1rem;
  }
  .brand h1 { font-size: 1rem; }
  .brand .tag { font-size: 0.6rem; }
  .brand .brand-mark { width: 1.7rem; height: 1.7rem; font-size: 0.85rem; }

  main {
    padding: 1.3rem 1rem 3rem;
  }

  .section-head h2 { font-size: 1.3rem; }

  .set-grid {
    grid-template-columns: 1fr;
  }

  .set-detail-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .set-detail-actions .btn {
    width: 100%;
    text-align: center;
  }

  .modal-panel {
    padding: 1.4rem 1.1rem;
    max-height: 85vh;
  }
  .modal-overlay {
    padding: 0.9rem;
    align-items: flex-end;
  }
  .modal-panel {
    max-width: 100%;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
  }
  .modal-actions {
    flex-direction: column-reverse;
    gap: 0.6rem;
  }
  .modal-actions .btn { width: 100%; }

  .flip-face {
    padding: 1.6rem 1.2rem;
  }
  .flip-face .face-body {
    font-size: 1.05rem;
  }

  .study-nav {
    gap: 1rem;
  }
  .icon-btn {
    width: 2.9rem;
    height: 2.9rem;
  }

  .quiz-question-card {
    padding: 1.5rem 1.2rem;
  }
  .quiz-question-text {
    font-size: 1.1rem;
  }
  .quiz-option {
    padding: 0.9em 1em;
  }

  .results-score { font-size: 3rem; }
  .results-score .pct-sign { font-size: 1.6rem; }
  .results-actions { flex-direction: column-reverse; width: 100%; max-width: 320px; }
  .results-actions .btn { width: 100%; }

  .card-row {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }
  .card-row .num { display: none; }
  .card-row .a { white-space: normal; }
  .card-row .q { white-space: normal; }
}

@media (max-width: 400px) {
  .auth-card {
    padding: 2.1rem 1.3rem 1.6rem;
  }
  .results-score { font-size: 2.5rem; }
}

/* Ensure inputs never trigger iOS zoom-on-focus */
@media (max-width: 640px) {
  input, textarea, select { font-size: 16px; }
}
