:root {
  --navy: #0f2a4a;
  --navy-2: #15375e;
  --navy-3: #1c4471;
  --gold: #ffc400;
  --gold-dim: #caa233;
  --green: #2e7d4f;
  --red: #c0392b;
  --ink: #eaf1fb;
  --ink-dim: #a9bbd3;
  --card: #16365c;
  --border: #28507f;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--navy);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body { padding-bottom: calc(16px + var(--safe-bottom)); }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--navy-2);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; flex-direction: column; line-height: 1.15; }
.brand-title { font-weight: 800; font-size: 1.05rem; color: var(--gold); letter-spacing: 0.3px; }
.brand-sub { font-size: 0.72rem; color: var(--ink-dim); }

.icon-btn {
  background: var(--navy-3);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

main#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

h1.page-title { font-size: 1.2rem; margin: 4px 0 14px; color: var(--ink); }
h2.section-title { font-size: 0.95rem; margin: 22px 0 8px; color: var(--gold); text-transform: uppercase; letter-spacing: 0.5px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.option-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}
.option-row:last-child { border-bottom: none; }
.option-row label { flex: 1; font-size: 0.95rem; }
.option-row .count { color: var(--ink-dim); font-size: 0.8rem; }

input[type="checkbox"], input[type="radio"] {
  width: 20px; height: 20px; accent-color: var(--gold);
}

select, input[type="number"] {
  background: var(--navy-3);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  width: 100%;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.85rem; color: var(--ink-dim); margin-bottom: 6px; }

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

button {
  font-family: inherit;
  cursor: pointer;
}

.btn {
  background: var(--navy-3);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 600;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--gold); border-color: var(--gold); color: #1a1300; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; border-radius: 10px; }
.btn-danger { border-color: var(--red); color: #ffd6d0; }

.mode-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.mode-card {
  display: flex; flex-direction: column; gap: 4px;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--ink);
}
.mode-card .mode-title { font-weight: 700; font-size: 1.02rem; color: var(--gold); }
.mode-card .mode-desc { font-size: 0.85rem; color: var(--ink-dim); }
.mode-card:disabled { opacity: 0.45; }

.scope-pill {
  display: inline-block;
  background: var(--navy-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.78rem;
  color: var(--gold);
  margin-bottom: 10px;
}

.session-bar {
  position: sticky;
  top: 53px;
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--navy-2);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  font-size: 0.82rem;
  color: var(--ink-dim);
}
.session-bar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.session-bar .progress-text { font-weight: 700; color: var(--ink); white-space: nowrap; }
.session-bar .scope-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  text-align: right;
}
.session-controls { display: flex; gap: 6px; }
.session-controls .btn { flex: 1; padding: 8px 6px; font-size: 0.8rem; white-space: nowrap; }

.progress-track {
  height: 5px;
  background: var(--navy-3);
  border-radius: 4px;
  overflow: hidden;
  margin: 0 16px 10px;
}
.progress-fill { height: 100%; background: var(--gold); transition: width 0.2s ease; }

.q-section-tag { font-size: 0.78rem; color: var(--ink-dim); margin-bottom: 6px; }
.q-text { font-size: 1.08rem; font-weight: 600; line-height: 1.4; margin-bottom: 18px; }

.option-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  font-size: 0.95rem;
  color: var(--ink);
  margin-bottom: 10px;
  line-height: 1.35;
}
.option-btn:active { transform: scale(0.99); }
.option-btn.correct { background: rgba(46,125,79,0.35); border-color: var(--green); }
.option-btn.incorrect { background: rgba(192,57,43,0.35); border-color: var(--red); }
.option-btn[disabled] { opacity: 0.85; }

.feedback-box {
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--navy-3);
  border-left: 4px solid var(--gold);
  font-size: 0.88rem;
  color: var(--ink-dim);
}
.feedback-box strong { color: var(--ink); }

.flashcard {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 20px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 12px;
}
.flashcard .fc-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 1px; color: var(--gold-dim); }
.flashcard .fc-text { font-size: 1.1rem; font-weight: 600; line-height: 1.4; }
.flashcard .fc-explain { font-size: 0.85rem; color: var(--ink-dim); margin-top: 6px; }

.overlay {
  position: fixed; inset: 0;
  background: rgba(7,17,30,0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
  z-index: 50;
  padding: 20px;
  text-align: center;
}

.summary-row {
  display: flex; justify-content: space-between;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.summary-row:last-child { border-bottom: none; }

.review-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.review-item:last-child { border-bottom: none; }
.review-item .rq { font-weight: 600; margin-bottom: 4px; }
.review-item .ra-wrong { color: #ff9d92; font-size: 0.85rem; }
.review-item .ra-right { color: #8fe0ab; font-size: 0.85rem; }

.empty-state { text-align: center; padding: 40px 16px; color: var(--ink-dim); }

.toast {
  position: fixed;
  bottom: calc(16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy-3);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 60;
}

.tree-chapter { margin-bottom: 4px; }
.tree-chapter summary {
  cursor: pointer;
  padding: 10px 4px;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  color: var(--ink);
}
.tree-section-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 4px 8px 18px;
  font-size: 0.85rem;
  color: var(--ink-dim);
  border-top: 1px solid var(--border);
}

.stepper { display: flex; align-items: center; gap: 14px; }
.stepper button {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--navy-3);
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 1.2rem;
}
.stepper .val { font-size: 1.1rem; font-weight: 700; min-width: 50px; text-align: center; }
