/* Peak PSW Study — gamified study app UI.
   Warm-cream canvas, teal accent, Plus Jakarta Sans, mobile-first with a bottom
   tab bar; desktop moves nav into the top bar. Tokens map 1:1 to the design. */
:root {
  --bg: #fdf7ea;          /* warm cream canvas */
  --bg-edge: #f1ead9;     /* deeper cream (page edges / behind cards) */
  --card: #ffffff;
  --ink: #1b2430;         /* headings / primary text */
  --mut: #5d6b7a;         /* muted text */
  --mut-warm: #9a9485;    /* warm muted (sub-labels) */
  --line: #ece4d4;        /* warm hairline border */
  --line-soft: #f0ead d;
  --teal: #0e9384;        /* primary action / accent */
  --teal-2: #1ec3b2;      /* gradient top / hover */
  --teal-ink: #0a4f48;    /* dark teal text on soft teal */
  --teal-soft: #e3f3f0;   /* soft teal fill (New pill, correct option) */
  --good: #15803d;        /* recent-form ≥80% */
  --bad: #c0392b;         /* wrong / recent-form <60% */
  --bad-soft: #fbeae6;
  --gold: #b9842a;        /* badge / mastered accent */
  --gold-soft: #f4e8c9;
  --slate-soft: #e7edf2;  /* Ahead pill */
  --radius: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 12px 32px rgba(24, 48, 44, .06), 0 2px 6px rgba(24, 48, 44, .04);
  --shadow-btn: 0 10px 22px rgba(14, 147, 132, .28);
  --maxw: 540px;
  --font: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px; line-height: 1.55; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--mut); }
.mascot { display: block; }

/* ---------- Sign-in ---------- */
#signin { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.signin-card { width: 100%; max-width: 380px; text-align: center; }
.signin-card .mascot-lg { width: 92px; height: 92px; margin: 0 auto 18px; filter: drop-shadow(0 10px 18px rgba(14,147,132,.22)); }
.signin-card h1 { font-size: 27px; font-weight: 800; letter-spacing: -.02em; color: var(--ink); margin: 0 0 8px; }
.signin-sub { color: var(--mut); font-size: 15px; margin: 0 0 26px; }
.field-label { display: block; text-align: left; font-size: 13px; font-weight: 700; color: var(--mut); margin: 0 0 7px 2px; }
#signin input[type=email] {
  width: 100%; padding: 15px 18px; border: 1.5px solid var(--line); border-radius: 16px;
  font-size: 15px; background: var(--card); color: var(--ink); outline: none; box-shadow: var(--shadow-card);
}
#signin input[type=email]:focus { border-color: var(--teal); box-shadow: 0 0 0 4px var(--teal-soft); }
.btn-primary {
  width: 100%; margin-top: 14px; padding: 16px 20px; border: none; border-radius: 16px;
  background: var(--teal); color: #fff; font-weight: 700; font-size: 15.5px; box-shadow: var(--shadow-btn);
  transition: transform .08s ease, background .15s ease;
}
.btn-primary:hover:not(:disabled) { background: #0c8275; }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:disabled { opacity: .55; cursor: default; box-shadow: none; }
.signin-msg { margin-top: 14px; font-size: 13.5px; }
.signin-msg.err { color: var(--bad); }
.signin-msg.ok { color: var(--good); }
.demo-link, .dev-link { display: inline-block; margin-top: 18px; color: var(--teal); font-weight: 700; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.dev-link { font-size: 12px; }

/* ---------- App shell ---------- */
#app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; background: rgba(253, 247, 234, .9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 9px; flex-shrink: 0; }
.brand .mascot-sm { width: 30px; height: 30px; }
.brand-name { font-weight: 800; font-size: 16px; color: var(--ink); letter-spacing: -.01em; white-space: nowrap; }
.brand-name b { color: var(--teal); font-weight: 800; }
.topbar .spacer { flex: 1; }
.hdr-chip {
  font-size: 12.5px; font-weight: 700; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 11px; white-space: nowrap;
  flex-shrink: 0;
}
/* Tiny phones (SE/mini): drop the glance chip rather than clip it — it's one tap away on the Progress tab. */
@media (max-width: 384px) { .hdr-chip { display: none; } }
.signout { flex-shrink: 0; white-space: nowrap; border: 1px solid var(--line); background: var(--card); color: var(--mut); font-weight: 600; font-size: 13px; padding: 7px 13px; border-radius: 999px; }
.signout:hover { color: var(--ink); }
.topnav { display: none; gap: 4px; }
.topnav button { border: none; background: none; color: var(--mut); font-weight: 600; font-size: 14px; padding: 8px 14px; border-radius: 999px; }
.topnav button.active { background: var(--teal-soft); color: var(--teal-ink); }

.view { flex: 1; width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 18px 16px 104px; }

/* ---------- Bottom tab bar (mobile) ---------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
  background: rgba(253, 247, 234, .94); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding: 7px 6px calc(7px + env(safe-area-inset-bottom));
}
.bottomnav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: none; background: none; color: var(--mut); font-size: 11px; font-weight: 600; padding: 5px 0;
}
.bottomnav svg { width: 23px; height: 23px; }
.bottomnav button.active { color: var(--teal); }

/* ---------- Quiz ---------- */
.quiz-filter { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; margin: 2px 4px 12px; }
.link-btn { border: none; background: none; color: var(--teal); font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 2px; padding: 0; }
.quiz-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-card); padding: 22px; }
.qmeta { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.qmeta span:not(.pill-kind) { font-size: 13.5px; font-weight: 600; color: var(--mut); }
.pill-kind { font-size: 11.5px; font-weight: 800; letter-spacing: .02em; padding: 3px 11px; border-radius: 999px; text-transform: none; }
.pill-kind.new { background: var(--teal-soft); color: var(--teal-ink); }
.pill-kind.review { background: var(--gold-soft); color: var(--gold); }
.pill-kind.ahead { background: var(--slate-soft); color: #41566a; }
.qtext { font-size: 20px; line-height: 1.3; font-weight: 800; letter-spacing: -.01em; color: var(--ink); margin-bottom: 18px; }
.opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 13px; text-align: left; width: 100%;
  border: 1.5px solid var(--line); background: var(--card); border-radius: var(--radius-md);
  padding: 14px 15px; font-size: 15px; color: var(--ink); transition: border-color .12s, background .12s;
}
.opt:hover:not(:disabled) { border-color: var(--teal); }
.optletter {
  flex: none; width: 30px; height: 30px; border-radius: 9px; background: var(--bg-edge);
  color: var(--mut); font-weight: 800; font-size: 14px; display: grid; place-items: center;
}
.opt.correct { border-color: var(--teal); background: var(--teal-soft); }
.opt.correct .optletter { background: var(--teal); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .optletter { background: var(--bad); color: #fff; }
.opt:disabled { cursor: default; }
.explain { margin-top: 16px; padding: 15px 16px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-md); font-size: 14.5px; line-height: 1.55; color: var(--ink); }
.explain .verdict { font-weight: 800; }
.explain .verdict.right { color: var(--teal); }
.explain .verdict.wrong { color: var(--bad); }
.qfoot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.qfoot .sources { font-size: 12.5px; color: var(--mut); }
.nextBtn { border: none; background: var(--teal); color: #fff; padding: 12px 20px; border-radius: 13px; font-weight: 700; font-size: 14.5px; box-shadow: var(--shadow-btn); }
.nextBtn:active { transform: translateY(1px); }

/* ---------- Topics ---------- */
.topics-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.section-title { font-size: 19px; font-weight: 800; letter-spacing: -.01em; color: var(--ink); }
.topics-head .muted { font-size: 13.5px; max-width: 360px; margin-top: 4px; }
.last30-overall { flex: none; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 10px 16px; text-align: center; box-shadow: var(--shadow-card); }
.last30-overall span { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--mut-warm); }
.last30-overall b { font-size: 20px; color: var(--ink); }
.topics-actions { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.topics-actions .spacer { flex: 1; }
.chip-btn { border: 1px solid var(--line); background: var(--card); color: var(--mut); padding: 8px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 600; }
.chip-btn:hover { border-color: var(--teal); color: var(--teal); }
.trows { display: flex; flex-direction: column; gap: 9px; }
.trow {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 13px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-md);
  padding: 14px 16px; cursor: pointer; box-shadow: var(--shadow-card);
}
.trow:hover { border-color: var(--teal); }
.trow input { width: 22px; height: 22px; accent-color: var(--teal); cursor: pointer; flex: none; }
.trow .tname { font-size: 14.5px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trow .tlast { font-size: 13px; font-weight: 700; color: var(--mut); white-space: nowrap; }
.trow .tlast.good { color: var(--good); }
.trow .tlast.bad { color: var(--bad); }
#startSel { display: block; width: 100%; margin-top: 16px; }

/* ---------- Progress ---------- */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 22px; }
.stat-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 18px; text-align: center; box-shadow: var(--shadow-card); }
.stat-box .num { font-size: 30px; font-weight: 800; letter-spacing: -.02em; color: var(--ink); line-height: 1; }
.stat-box .lbl { font-size: 12.5px; color: var(--mut); margin-top: 6px; }
.mastery { display: flex; flex-direction: column; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 8px 16px; box-shadow: var(--shadow-card); margin-bottom: 24px; }
.mrow { display: grid; grid-template-columns: minmax(0, 1fr) 110px auto; gap: 12px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.mrow:last-child { border-bottom: none; }
.mrow .mtitle { font-size: 14px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 7px; }
.mrow .mtag { flex: none; font-size: 9.5px; font-weight: 800; letter-spacing: .04em; color: var(--gold); background: var(--gold-soft); padding: 2px 7px; border-radius: 999px; }
.bar { height: 9px; background: var(--bg-edge); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--teal), var(--gold)); transition: width .35s ease; }
.mrow.mastered .bar > i { background: linear-gradient(90deg, var(--teal-2), var(--teal)); }
.mrow .mnum { font-size: 12.5px; font-weight: 700; color: var(--mut); min-width: 40px; text-align: right; }

.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 11px; }
.badge { border: 1px solid var(--line); border-radius: var(--radius-md); padding: 15px 12px; background: var(--card); text-align: center; opacity: .6; box-shadow: var(--shadow-card); }
.badge.earned { opacity: 1; border-color: var(--gold); background: linear-gradient(180deg, #fffdf6, var(--card)); }
.badge .ico { font-size: 26px; }
.badge .bname { font-weight: 800; font-size: 13.5px; color: var(--ink); margin-top: 4px; }
.badge .bdesc { font-size: 11.5px; color: var(--mut); margin-top: 3px; line-height: 1.4; }

/* ---------- Practice exam ---------- */
.exam-intro, .exam-result { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-card); padding: 26px; text-align: center; }
.exam-intro h2, .exam-result h2 { margin: 0 0 8px; font-size: 22px; font-weight: 800; color: var(--ink); }
.exam-intro p { color: var(--mut); margin: 0 0 20px; }
.exam-lens { display: flex; gap: 10px; justify-content: center; margin-bottom: 20px; flex-wrap: wrap; }
.lens-opt { border: 1.5px solid var(--line); background: var(--card); border-radius: var(--radius-md); padding: 16px 18px; font-weight: 700; color: var(--ink); min-width: 92px; }
.lens-opt .lens-n { display: block; font-size: 24px; font-weight: 800; color: var(--teal); }
.lens-opt .lens-l { font-size: 12px; color: var(--mut); font-weight: 600; }
.lens-opt.sel { border-color: var(--teal); background: var(--teal-soft); }
.exam-progress { font-size: 13.5px; font-weight: 700; color: var(--mut); text-align: center; margin-bottom: 12px; }
.exam-progress .bar { margin-top: 8px; }
.score-big { font-size: 52px; font-weight: 800; letter-spacing: -.02em; color: var(--teal); line-height: 1; margin: 6px 0; }
.score-big.low { color: var(--bad); }
.exam-result .breakdown { text-align: left; margin-top: 18px; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(80px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 50; pointer-events: none; padding: 0 16px; }
.toast { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; box-shadow: 0 12px 30px rgba(0,0,0,.2); font-size: 13.5px; font-weight: 600; display: flex; gap: 11px; align-items: center; animation: pop .25s ease; }
.toast .ico { font-size: 22px; }
.toast .t-sub { font-size: 11.5px; opacity: .75; font-weight: 500; }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- Loading / empty ---------- */
.loading { text-align: center; color: var(--mut); padding: 48px 16px; font-size: 14.5px; }

/* ---------- Desktop ---------- */
@media (min-width: 760px) {
  .topnav { display: flex; }
  .bottomnav { display: none; }
  .view { padding-bottom: 40px; }
  #toasts { bottom: 24px; right: 24px; left: auto; align-items: flex-end; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
