:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --ink: #1d1b18;
  --muted: #6b665e;
  --line: #e4dfd6;
  --accent: #2f5bd3;
  --hot: 8, 72%, 50%;      /* hsl parts for the heat scale */
  --free: #1d7a46;
  --error: #b3261e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141311; --surface: #1d1c19; --ink: #efebe4; --muted: #a39d93; --line: #34312c;
    --accent: #8aa8ff; --hot: 8, 80%, 58%; --free: #5cc98a; --error: #ff8a80; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141311; --surface: #1d1c19; --ink: #efebe4; --muted: #a39d93; --line: #34312c;
  --accent: #8aa8ff; --hot: 8, 80%, 58%; --free: #5cc98a; --error: #ff8a80; color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
header, main { max-width: 960px; margin: 0 auto; padding: 0 16px; }
header { padding-top: 40px; }
h1 { font-size: clamp(2rem, 6vw, 3rem); margin: 0; letter-spacing: -0.02em; }
.tag { color: var(--muted); margin: 4px 0 24px; font-size: 1.1rem; }
h2 { margin: 40px 0 12px; font-size: 1.25rem; }
h2 small { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
label { font-weight: 600; display: block; margin-bottom: 6px; }

textarea {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: 14px/1.45 ui-monospace, Menlo, monospace; resize: vertical;
}
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
button {
  font: inherit; font-weight: 600; padding: 10px 18px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: var(--bg);
}
button.ghost { background: transparent; color: var(--accent); }
button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#status { color: var(--muted); }

.callout {
  margin-top: 32px; padding: 20px 24px; border-radius: 12px;
  background: hsla(var(--hot), 0.12); border-left: 8px solid hsl(var(--hot));
}
.callout p { margin: 0; }
.callout.calm { background: color-mix(in srgb, var(--free) 12%, transparent); border-left-color: var(--free); }
.callout.calm .kicker { color: var(--free); }
.callout .kicker { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.8rem; font-weight: 700; color: hsl(var(--hot)); }
.callout .headline { font-size: clamp(1.4rem, 3.5vw, 2rem); font-weight: 800; letter-spacing: -0.01em; line-height: 1.2; margin-top: 2px; }
.callout .what { color: var(--muted); margin-top: 2px; }
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 12px 0 0; }
.chips li { padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 0.95rem; }
.chips li b { color: var(--muted); font-weight: 600; margin-right: 2px; }
.chips li.exam, .chips li.project, .chips li.essay { border-color: hsl(var(--hot)); }
.nudge { margin-top: 12px !important; font-size: 1.1rem; font-weight: 600; }
.nudge::before { content: "→ "; color: hsl(var(--hot)); }

.heatmap { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
.cell {
  position: relative; display: flex; flex-direction: column; justify-content: space-between; min-height: 80px; padding: 8px 10px;
  border-radius: 8px; text-decoration: none; color: var(--ink); border: 1px solid var(--line);
  background: hsla(var(--hot), calc(var(--heat) * 0.85));
}
.cell .wk { font-size: 0.85rem; font-weight: 600; }
.cell .n { font-weight: 800; font-size: 1.6rem; }
.cell .tag { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); padding: 1px 7px; border-radius: 999px; background: hsl(var(--hot)); color: #fff; font-size: 0.65rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
.heatmap { padding-top: 10px; }
.cell.worst { color: #fff; outline: 3px solid hsl(var(--hot)); outline-offset: 2px; animation: glow 1.4s ease-in-out infinite alternate; }
.legend { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 0.85rem; color: var(--muted); }
.legend i { width: 120px; height: 10px; border-radius: 5px; background: linear-gradient(90deg, hsla(var(--hot), 0.05), hsla(var(--hot), 0.85)); }
@keyframes glow { from { box-shadow: 0 0 4px hsla(var(--hot), 0.4); } to { box-shadow: 0 0 28px 4px hsla(var(--hot), 0.8); } }

/* Reveal after Unpack: cells pop in left to right (~0.6 s), then the callout rises, then the worst week starts to glow. */
.reveal .cell { animation: pop 0.35s ease-out both; animation-delay: calc(var(--i) * 35ms); }
.reveal .cell.worst { animation: pop 0.35s ease-out both, glow 1.4s ease-in-out infinite alternate; animation-delay: calc(var(--i) * 35ms), 0.8s; }
.reveal .callout { animation: rise 0.5s ease-out 0.5s both; }
@keyframes pop { from { opacity: 0; transform: scale(0.85); } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@media (prefers-reduced-motion: reduce) {
  .cell.worst, .reveal .cell, .reveal .cell.worst, .reveal .callout { animation: none; }
}

.weeks { list-style: none; padding: 0; margin: 24px 0 0; }
.weeks > li { padding: 12px 0; border-top: 1px solid var(--line); scroll-margin-top: 16px; }
.weeks > li.worst h3 { color: hsl(var(--hot)); }
.weeks h3 { margin: 0 0 6px; font-size: 1rem; }
.weeks ul { list-style: none; padding: 0; margin: 0; }
.item { display: grid; grid-template-columns: 7.5em 6em 5.5em 1fr; gap: 8px; padding: 3px 0; }
.item time { color: var(--muted); }
.item .course { font-weight: 600; }
.item .type { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); align-self: center; }
.item.exam .type, .item.project .type { color: hsl(var(--hot)); font-weight: 700; }
@media (max-width: 560px) {
  .item { grid-template-columns: 6.5em 1fr; }
  .item .type { grid-column: 1; }
}

.banner { font-size: 1.3rem; font-weight: 700; color: var(--free); margin: 0 0 12px; }
.muted { color: var(--muted); }
.error { color: var(--error); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 64px; }
.book {
  display: flex; flex-direction: column; gap: 4px; padding: 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); color: var(--ink); text-decoration: none;
}
.book img { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 4px; background: var(--line); }
.book .badge { margin-top: auto; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.book.free { border-color: var(--free); }
.book.free .badge { color: var(--free); }

/* Books loading state: spinner on the status line, shimmering placeholder cards. */
.loading::before {
  content: ""; display: inline-block; width: 0.9em; height: 0.9em; margin-right: 8px; vertical-align: -0.1em;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite;
}
.book.placeholder { min-height: 260px; border-style: dashed; background: linear-gradient(100deg, var(--surface) 30%, var(--line) 50%, var(--surface) 70%) 0 0 / 300% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .loading::before, .book.placeholder { animation: none; } }

.banner small { font-size: 0.9rem; font-weight: 500; color: var(--muted); }
.book strong { overflow-wrap: anywhere; }
.book:hover { border-color: var(--accent); }
textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

/* Phone: tighter header, full-width primary actions. */
@media (max-width: 480px) {
  header { padding-top: 24px; }
  .tag { font-size: 1rem; }
  .callout { padding: 16px; }
  .input .actions button { flex: 1 1 auto; }
  #status { flex-basis: 100%; }
  .chips li { border-radius: 14px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
