/* ============================================================
   StudySet — shared design system  ·  v3 "Exam Blue-Book"
   Warm newsprint · near-black ink · deep navy + red-pen accent.
   Editorial, flat, hairline rules. Real type. Light + dark.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700;9..144,900&family=Inter:wght@400;450;500;600;700&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  /* ---- surfaces (light / newsprint) ---- */
  --paper:      #f2ede1;
  --paper-2:    #e9e2d1;
  --card:       #fbf8f0;
  --card-2:     #f1ebdc;
  --card-3:     #e7dfcc;

  /* ---- ink ---- */
  --ink:        #1a1813;
  --ink-2:      #423d33;
  --muted:      #6e6553;
  --faint:      #9a9080;

  /* ---- hairlines ---- */
  --line:       #ded3bd;
  --line-2:     #e8e0cf;
  --line-strong:#c9bca1;

  /* ---- brand: deep navy primary + brick "red-pen" ---- */
  --accent:     #22397f;
  --accent-2:   #2c4aa0;
  --accent-deep:#182b63;
  --accent-ink: #ffffff;
  --accent-wash:#e5e8f4;
  --accent-line:#c6cfe9;

  --red:        #b13a2c;     /* red-pen: alerts, overdue, destructive */
  --red-wash:   #f3e1db;
  --gold:       #9a7418;     /* ochre highlight */
  --gold-wash:  #f0e6cf;
  --green:      #3c7850;
  --green-wash: #dfead9;
  --sky:        #2c6a8f;

  /* ---- elevation: restrained, printed ---- */
  --sh-1: 0 1px 0 var(--line-strong);
  --sh-2: 0 1px 2px rgba(40,32,14,.06), 0 2px 4px rgba(40,32,14,.05);
  --sh-3: 0 4px 10px rgba(40,32,14,.09), 0 1px 3px rgba(40,32,14,.06);
  --sh-4: 0 16px 34px rgba(40,32,14,.16), 0 4px 10px rgba(40,32,14,.08);
  --sh-glow: var(--sh-3);

  /* ---- radii: editorial, tight ---- */
  --r-xs: 5px;
  --r-sm: 7px;
  --r:    9px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-2xl:20px;

  /* ---- type ---- */
  --serif: "Fraunces", "Iowan Old Style", Palatino, Georgia, serif;
  --sans:  "Inter", ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono:  "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* ---- motion ---- */
  --sp: cubic-bezier(.3, 1.3, .5, 1);
  --out: cubic-bezier(.22, .61, .36, 1);
  --t-fast: .12s;
  --t: .18s;
  --t-slow: .3s;

  --maxw: 1140px;
  --ring: 0 0 0 2px var(--card), 0 0 0 4px var(--accent);

  /* back-compat aliases (per-app inline CSS) */
  --line-soft: var(--line-2);
  --shadow-sm: var(--sh-2);
  --shadow-md: var(--sh-3);
  --shadow-lg: var(--sh-4);
  --rose: var(--red); --rose-wash: var(--red-wash);
  --gold-2: var(--gold);
}

:root[data-theme="dark"] {
  --paper:      #16150f;
  --paper-2:    #1d1b14;
  --card:       #201d16;
  --card-2:     #26221a;
  --card-3:     #2d2820;

  --ink:        #f1ebdc;
  --ink-2:      #d6cfbe;
  --muted:      #a89e89;
  --faint:      #766d5b;

  --line:       #363126;
  --line-2:     #2c2820;
  --line-strong:#463f31;

  --accent:     #7d90d8;
  --accent-2:   #93a4e6;
  --accent-deep:#5f74c4;
  --accent-ink: #16150f;
  --accent-wash:#20233a;
  --accent-line:#374063;

  --red:        #e06450;
  --red-wash:   #2f1a15;
  --gold:       #d3a63f;
  --gold-wash:  #2c2411;
  --green:      #5aad78;
  --green-wash: #17251b;
  --sky:        #5a9ac2;

  --sh-1: 0 1px 0 rgba(0,0,0,.5);
  --sh-2: 0 1px 3px rgba(0,0,0,.45);
  --sh-3: 0 6px 16px rgba(0,0,0,.5);
  --sh-4: 0 18px 40px rgba(0,0,0,.62);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--paper);
  background-image:
    linear-gradient(180deg, color-mix(in srgb, var(--accent-wash) 35%, transparent), transparent 22%);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
/* faint newsprint grain */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .45;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.04'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}
:root[data-theme="dark"] body::before { mix-blend-mode: screen; opacity: .35; }
body > * { position: relative; z-index: 1; }

a { color: inherit; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
::selection { background: var(--accent); color: var(--accent-ink); }

* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 0; border: 4px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: content-box; }

/* ---------- layout ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }
.stack { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; }
.grow { flex: 1; }
.spacer { flex: 1; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  backdrop-filter: saturate(1.3) blur(12px);
  -webkit-backdrop-filter: saturate(1.3) blur(12px);
  background: color-mix(in srgb, var(--paper) 84%, transparent);
  border-bottom: 1.5px solid var(--ink);
}
.topbar-inner { max-width: var(--maxw); margin: 0 auto; padding: 11px 24px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: inherit; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 7px; flex: none;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  font-family: var(--serif); font-weight: 700; font-size: 18px; letter-spacing: -.5px;
  box-shadow: 2px 2px 0 var(--ink);
}
.brand b { font-family: var(--serif); font-weight: 600; letter-spacing: -.2px; font-size: 19px; }
.app-name { font-weight: 600; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px; display: inline-flex; align-items: center; gap: 7px; }
.app-name::before { content: ""; width: 16px; height: 1.5px; background: var(--line-strong); }

.icon-btn {
  width: 38px; height: 38px; border-radius: 8px; flex: none;
  border: 1.5px solid var(--line-strong); background: var(--card);
  display: grid; place-items: center; cursor: pointer; color: var(--ink-2);
  transition: transform var(--t-fast), color var(--t), border-color var(--t), background var(--t);
  font-size: 15px;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn:active { transform: scale(.94); }

/* ---------- buttons ---------- */
.btn {
  --bh: 42px;
  height: var(--bh); padding: 0 17px; border-radius: 8px;
  border: 1.5px solid var(--ink); background: var(--card);
  color: var(--ink); font-weight: 600; font-size: 14.5px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  transition: transform var(--t-fast) var(--out), box-shadow var(--t), background var(--t), color var(--t);
  white-space: nowrap; text-decoration: none; box-shadow: 2px 2px 0 var(--ink);
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); }
.btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }
.btn:focus-visible { outline: none; box-shadow: 2px 2px 0 var(--ink), var(--ring); }
.btn.primary { background: var(--accent); border-color: var(--accent-deep); color: #fff; box-shadow: 2px 2px 0 var(--accent-deep); }
.btn.primary:hover { box-shadow: 3px 3px 0 var(--accent-deep); }
.btn.primary:active { box-shadow: 1px 1px 0 var(--accent-deep); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--card-2); border-color: var(--line-strong); box-shadow: none; transform: none; }
.btn.sm { --bh: 33px; padding: 0 11px; font-size: 13px; border-radius: 7px; box-shadow: 1.5px 1.5px 0 var(--ink); }
.btn.sm:hover { box-shadow: 2.5px 2.5px 0 var(--ink); }
.btn.sm.primary { box-shadow: 1.5px 1.5px 0 var(--accent-deep); }
.btn.lg { --bh: 50px; padding: 0 24px; font-size: 16px; }
.btn.danger { color: var(--red); border-color: var(--red); box-shadow: 2px 2px 0 var(--red); }
.btn.danger:hover { background: var(--red-wash); box-shadow: 3px 3px 0 var(--red); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: 2px 2px 0 var(--line-strong); border-color: var(--line-strong); }
.btn.block { width: 100%; }

/* ---------- inputs ---------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field > label { font-size: 11.5px; font-weight: 700; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; }
.input, .textarea, select.input {
  width: 100%; padding: 11px 13px; border-radius: 8px;
  border: 1.5px solid var(--line-strong); background: var(--card);
  transition: border-color var(--t), box-shadow var(--t); outline: none; font-size: 15px;
}
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:hover, .textarea:hover, select.input:hover { border-color: var(--muted); }
.input:focus, .textarea:focus, select.input:focus { border-color: var(--accent); box-shadow: 2px 2px 0 var(--accent); }
.textarea { resize: vertical; min-height: 88px; line-height: 1.6; }
input[type="date"].input, input[type="time"].input { min-height: 45px; }
select.input { cursor: pointer; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1.5px solid var(--ink); border-radius: var(--r-lg); box-shadow: 3px 3px 0 var(--ink); }
.card.pad { padding: 22px; }
.card.lift { transition: transform var(--t) var(--out), box-shadow var(--t); }
.card.lift:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--ink); }
.panel { background: var(--card); border: 1.5px solid var(--line-strong); border-radius: var(--r); }

/* ---------- chips / badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 600;
  background: var(--card-2); border: 1.5px solid var(--line-strong); color: var(--ink-2);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.badge { font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 5px; background: var(--accent); color: #fff; letter-spacing: .3px; text-transform: uppercase; }

/* ---------- headings ---------- */
.h1 { font-family: var(--serif); font-size: clamp(28px, 4.2vw, 42px); line-height: 1.03; margin: 0; font-weight: 600; letter-spacing: -.5px; font-optical-sizing: auto; }
.h2 { font-family: var(--serif); font-size: 22px; margin: 0; font-weight: 600; letter-spacing: -.2px; }
.lead { color: var(--ink-2); font-size: 16px; line-height: 1.6; }
.eyebrow { text-transform: uppercase; letter-spacing: 2px; font-size: 11px; font-weight: 700; color: var(--accent); }
.muted { color: var(--muted); }
.hr { height: 1.5px; background: var(--line); border: 0; margin: 20px 0; }
.empty { text-align: center; padding: 50px 22px; color: var(--muted); }
.empty .big {
  font-size: 26px; margin-bottom: 14px; width: 60px; height: 60px; border-radius: 12px;
  display: grid; place-items: center; margin-inline: auto;
  background: var(--card-2); border: 1.5px solid var(--ink); color: var(--accent); box-shadow: 2px 2px 0 var(--ink);
}
.kbd { font-family: var(--mono); font-size: 11.5px; font-weight: 500; padding: 2px 7px; border-radius: 5px; border: 1.5px solid var(--line-strong); background: var(--card-2); color: var(--muted); box-shadow: 0 1.5px 0 var(--line-strong); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 24px);
  background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 8px;
  font-weight: 600; font-size: 14px; box-shadow: 4px 4px 0 var(--accent);
  opacity: 0; pointer-events: none; transition: transform var(--t-slow) var(--sp), opacity var(--t); z-index: 100; max-width: 90vw;
  display: flex; align-items: center; gap: 9px; border: 1.5px solid var(--accent);
}
#toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: color-mix(in srgb, var(--ink) 52%, transparent);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: none; place-items: center; z-index: 90; padding: 20px;
}
.modal-back.show { display: grid; animation: fade .18s var(--out); }
.modal {
  background: var(--card); border: 2px solid var(--ink); border-radius: var(--r-lg);
  box-shadow: 8px 8px 0 var(--ink); width: min(540px, 100%); max-height: 88vh; overflow: auto;
  animation: pop .26s var(--sp);
}
@keyframes pop { from { transform: translate(6px, 10px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.modal-head { display: flex; align-items: center; padding: 18px 20px 14px; border-bottom: 1.5px solid var(--line); }
.modal-head .h2 { font-size: 20px; }
.modal-body { padding: 18px 20px 6px; display: flex; flex-direction: column; gap: 15px; }
.modal-foot { padding: 16px 20px; display: flex; gap: 10px; justify-content: flex-end; border-top: 1.5px solid var(--line); }

/* subject color helper */
.sub-dot { width: 10px; height: 10px; border-radius: 2px; flex: none; display: inline-block; }

/* progress bar */
.bar { height: 8px; border-radius: 0; background: var(--card-3); overflow: hidden; border: 1.5px solid var(--ink); }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .5s var(--out); }

/* reveal / stagger */
@keyframes reveal { from { opacity: 0; transform: translateY(8px); } }
.fade { animation: reveal .34s var(--out) both; }
.reveal { animation: reveal .4s var(--out) both; }
.reveal:nth-child(1){animation-delay:.02s}.reveal:nth-child(2){animation-delay:.06s}
.reveal:nth-child(3){animation-delay:.1s}.reveal:nth-child(4){animation-delay:.14s}
.reveal:nth-child(5){animation-delay:.18s}.reveal:nth-child(6){animation-delay:.22s}

@media (max-width: 640px) {
  .app-name { display: none; }
  .wrap { padding: 0 16px; }
  .topbar-inner { padding: 10px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  html { scroll-behavior: auto; }
}
