/* Study Notes — clean academic website styling.
   Palette echoes the PDF stylesheet: deep blue accent, serif prose, sans UI. */

:root {
  --ink: #1a1a1a;
  --muted: #5b6572;
  --accent: #1f4e79;
  --accent-2: #2c6aa8;
  --accent-soft: #eaf1f8;
  --bg: #fbfcfd;
  --panel: #ffffff;
  --rule: #dfe4ea;
  --rule-soft: #eef1f5;
  --shadow: 0 1px 2px rgba(20, 33, 61, .04), 0 8px 24px rgba(20, 33, 61, .06);
  --radius: 12px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Helvetica Neue", Helvetica, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(251, 252, 253, .85);
  backdrop-filter: saturate(150%) blur(8px);
  border-bottom: 1px solid var(--rule);
}
.wordmark { display: flex; align-items: baseline; gap: 10px; color: var(--ink); }
.wordmark-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -.2px;
  color: var(--accent);
}
.topnav a { font-size: 14px; color: var(--muted); }
.topnav a:hover { color: var(--accent); }

/* ---- Layout shell ---- */
main {
  flex: 1;
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px 24px 32px;
}
.loading { color: var(--muted); padding: 40px 0; }

/* ---- Home ---- */
.hero { margin: 8px 0 32px; }
.hero h1 {
  font-family: var(--serif);
  font-size: clamp(28px, 4vw, 40px);
  color: var(--accent);
  margin: 0 0 8px;
  letter-spacing: -.5px;
}
.hero p { color: var(--muted); margin: 0; max-width: 60ch; font-size: 15.5px; }

.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}
.subject-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
  color: var(--ink);
}
.subject-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-2);
  box-shadow: 0 2px 4px rgba(20, 33, 61, .05), 0 14px 32px rgba(20, 33, 61, .10);
}
.subject-card .sc-accent { width: 34px; height: 4px; border-radius: 4px; background: var(--accent); }
.subject-card h2 {
  font-family: var(--serif);
  font-size: 20px;
  margin: 2px 0 0;
  color: var(--ink);
  line-height: 1.25;
}
.subject-card .sc-meta { color: var(--muted); font-size: 13.5px; margin-top: auto; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: #8a5a00;
  background: #fff4e0;
  border: 1px solid #f2dcae;
  border-radius: 999px;
  padding: 2px 9px;
}

/* ---- Back button ---- */
.backbtn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13.5px; font-weight: 600; color: var(--accent);
  background: var(--panel); border: 1px solid var(--rule); border-radius: 8px;
  padding: 6px 12px; margin-bottom: 12px; cursor: pointer;
}
.backbtn:hover { background: var(--accent-soft); border-color: var(--accent-2); color: var(--accent); }

/* ---- Subject view ---- */
.crumbs { font-size: 13.5px; color: var(--muted); margin-bottom: 14px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }
.subject-head { margin-bottom: 22px; }
.subject-head h1 {
  font-family: var(--serif);
  font-size: clamp(24px, 3.4vw, 34px);
  color: var(--accent);
  margin: 0;
}

.reader {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 20px;
  align-items: stretch;
  height: calc(100vh - 92px);   /* fill viewport below the top bar */
}
.reader-left {
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}
.reader-left .crumbs { margin-top: 2px; }
.reader-left .subject-head h1 { font-size: clamp(20px, 2.2vw, 26px); }

/* doc list */
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-group-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 6px 2px 2px;
}
.doc-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
  font: inherit;
  color: var(--ink);
}
.doc-item:hover { border-color: var(--accent-2); background: #fcfdff; }
.doc-item.active { border-color: var(--accent); background: var(--accent-soft); }
.doc-item .doc-icon {
  flex: none;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent);
}
.doc-item.full .doc-icon { background: var(--accent); color: #fff; }
.doc-item .doc-text { min-width: 0; }
.doc-item .doc-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.doc-item .doc-sub { font-size: 12px; color: var(--muted); }

/* preview pane */
.preview {
  height: 100%;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.preview-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule);
  background: #fcfdfe;
}
.preview-bar .pv-title {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); color: var(--accent); }
.preview-frame { flex: 1; border: 0; width: 100%; min-height: 0; background: #f1f3f6; }
.preview-empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 40px;
  text-align: center;
  font-size: 14.5px;
}

/* ---- Footer ---- */
.sitefoot {
  border-top: 1px solid var(--rule);
  padding: 20px 24px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.btn-ghost { background: transparent; color: var(--accent); border-color: var(--rule); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-2); }
.btn-ghost:disabled { opacity: .4; cursor: default; background: transparent; }
.btn-cards { background: #5b3fa8; border-color: #5b3fa8; }
.btn-cards:hover { background: #6d4fc0; border-color: #6d4fc0; }
.badge-cards { color: #5b3fa8; background: #efeafc; border-color: #ddd2f5; text-transform: none; letter-spacing: 0; }

/* ---- Flashcards ---- */
.flashcards { max-width: 920px; margin: 0 auto; padding: 4px 0 40px; }
.fc-head { margin-bottom: 18px; }
.fc-title { font-family: var(--serif); font-size: 26px; color: var(--accent); margin: 6px 0 4px; line-height: 1.2; }
.fc-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; }
.fc-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--rule); background: var(--panel); color: var(--muted);
  cursor: pointer;
}
.chip:hover { border-color: var(--accent-2); color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-n { font-size: 11px; opacity: .7; }
.chip.active .chip-n { opacity: .85; }

.fc-progress { height: 6px; border-radius: 999px; background: var(--rule-soft); overflow: hidden; margin: 6px 0 8px; }
.fc-progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .2s ease; }
.fc-count { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.fc-linkbtn { font: inherit; font-size: 12.5px; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.fc-linkbtn:hover { color: var(--accent-2); text-decoration: underline; }

/* the card — 3D flip */
.fc-card { perspective: 1600px; cursor: pointer; outline: none; }
.fc-card-inner {
  position: relative; width: 100%; min-height: 460px;
  transform-style: preserve-3d; transition: transform .45s cubic-bezier(.2,.7,.2,1);
}
.fc-card.flipped .fc-card-inner { transform: rotateY(180deg); }
.fc-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column;
  padding: 38px 42px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--rule);
  box-shadow: var(--shadow);
  border-top: 5px solid var(--fc-accent, var(--accent));
}
.fc-back { transform: rotateY(180deg); background: #fcfdff; }
.fc-type {
  align-self: flex-start; font-size: 12px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--fc-accent, var(--accent)); background: var(--fc-soft, var(--accent-soft));
  padding: 4px 11px; border-radius: 999px; margin-bottom: 20px;
}
.fc-text { font-size: 21px; line-height: 1.55; color: var(--ink); }
.fc-text p { margin: 0 0 14px; }
.fc-text p:last-child { margin-bottom: 0; }
.fc-text strong { color: var(--accent); }
.fc-text code { font-family: ui-monospace, Menlo, monospace; font-size: .92em; background: var(--rule-soft); padding: 1px 5px; border-radius: 4px; }
.fc-back .fc-text { font-size: 19px; }
.fc-table { border-collapse: collapse; width: 100%; margin: 6px 0 10px; font-size: 15px; }
.fc-table th, .fc-table td { border: 1px solid var(--rule); padding: 6px 10px; text-align: left; vertical-align: top; }
.fc-table th { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.fc-table td strong { color: var(--accent); }
.fc-hint { margin-top: auto; padding-top: 18px; font-size: 15px; color: var(--muted); font-style: italic; }
.fc-hint-btn {
  margin-top: auto; align-self: flex-start; font: inherit; font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  color: var(--muted); background: var(--rule-soft); border: 1px solid var(--rule);
  padding: 7px 14px; border-radius: 999px;
}
.fc-hint-btn:hover { color: var(--accent); border-color: var(--accent-2); background: var(--accent-soft); }
.fc-hint-btn .kbd { background: var(--panel); border: 1px solid var(--rule); color: var(--muted); }
.fc-tap { position: absolute; bottom: 14px; right: 20px; font-size: 12px; color: var(--muted); opacity: .6; }
.fc-source { margin-top: auto; padding-top: 18px; font-size: 13px; color: var(--muted); }

/* per-type accent colors */
.type-definition   { --fc-accent: #1f4e79; --fc-soft: #eaf1f8; }
.type-reverse      { --fc-accent: #7a3fa8; --fc-soft: #f2eafb; }
.type-mechanism    { --fc-accent: #0d7a6f; --fc-soft: #e3f5f2; }
.type-theory-match { --fc-accent: #b06a00; --fc-soft: #fdf0dc; }
.type-apply        { --fc-accent: #2f7d32; --fc-soft: #e6f4e6; }
.type-compare      { --fc-accent: #3949ab; --fc-soft: #e8eafb; }
.type-synthesis    { --fc-accent: #c2185b; --fc-soft: #fce4ec; }
.type-case         { --fc-accent: #a15c00; --fc-soft: #fbf0df; }
.type-rebuttal     { --fc-accent: #a32f2f; --fc-soft: #fbe7e7; }

.fc-controls { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.fc-controls .btn { min-width: 96px; justify-content: center; }
.btn-flip { background: var(--accent); }
.btn-good { background: #2f7d32; border-color: #2f7d32; }
.btn-good:hover { background: #37913b; border-color: #37913b; }
.btn-again { background: #c25b00; border-color: #c25b00; }
.btn-again:hover { background: #d96a09; border-color: #d96a09; }
.kbd {
  font-size: 10.5px; font-weight: 700; padding: 1px 5px; border-radius: 4px;
  background: rgba(255,255,255,.22); border: 1px solid rgba(255,255,255,.35); color: inherit;
}
.btn-ghost .kbd { background: var(--rule-soft); border-color: var(--rule); color: var(--muted); }
.fc-help { text-align: center; font-size: 12px; color: var(--muted); margin-top: 14px; }
.fc-help .kbd { background: var(--rule-soft); border: 1px solid var(--rule); color: var(--muted); }

.fc-done { text-align: center; padding: 50px 20px; }
.fc-done-mark {
  width: 62px; height: 62px; margin: 0 auto 16px; border-radius: 50%;
  display: grid; place-items: center; font-size: 30px; color: #fff; background: #2f7d32;
}
.fc-done h2 { font-family: var(--serif); color: var(--accent); margin: 0 0 8px; }
.fc-done p { color: var(--muted); margin: 0 0 22px; }
.fc-done-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.badge-map { color: #0d7a6f; background: #e3f5f2; border-color: #bfe8e1; text-transform: none; letter-spacing: 0; }
.map-item .map-icon { background: #e3f5f2; color: #0d7a6f; }
.map-item { text-decoration: none; }

/* ---- Concept map view ---- */
.mapview { display: flex; flex-direction: column; height: calc(100vh - 120px); min-height: 520px; }
.mm-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 6px 0 12px; }
.mm-title { font-family: var(--serif); font-size: 24px; color: var(--accent); margin: 0 0 3px; }
.mm-sub { color: var(--muted); font-size: 13px; }
.mm-toolbar { display: flex; gap: 6px; flex-shrink: 0; }
.mm-btn {
  font: inherit; font-size: 17px; font-weight: 700; line-height: 1;
  width: 38px; height: 38px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--rule); background: var(--panel); color: var(--accent);
}
.mm-btn-wide { width: auto; padding: 0 14px; font-size: 14px; }
.mm-btn:hover { border-color: var(--accent-2); background: var(--accent-soft); }
.mm-stage {
  flex: 1; position: relative; overflow: hidden; touch-action: none;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background:
    radial-gradient(circle, var(--rule-soft) 1px, transparent 1px) 0 0 / 22px 22px,
    var(--panel);
  cursor: grab;
}
.mm-stage.grabbing { cursor: grabbing; }
.mm-canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.mm-canvas svg { display: block; }
.mm-canvas .loading { padding: 40px; white-space: normal; }

/* ---- Responsive ---- */
@media (max-width: 860px) {
  .reader { grid-template-columns: 1fr; height: auto; }
  .reader-left { overflow: visible; }
  .preview { height: auto; }
  .preview-frame { height: 80vh; }
}
@media (max-width: 560px) {
  .fc-card-inner { min-height: 520px; }
  .fc-face { padding: 26px 22px; }
  .fc-text { font-size: 19px; }
  .fc-back .fc-text { font-size: 17px; }
  .fc-controls .btn { min-width: 0; flex: 1; }
}
