/* Advent of Code 2022 showcase.
   Dark terminal palette is native to the subject and keeps this app visually
   separate from the Scratch index and every other app it sits beside. */

:root {
  --bg: #0e1016;
  --surface: #161a24;
  --surface-2: #1d2230;
  --surface-3: #252b3b;
  --line: #2b3244;
  --line-soft: #222838;
  --text: #e7eaf2;
  --text-dim: #9aa3b8;
  --text-faint: #6b7488;
  --gold: #ffd75f;
  --green: #6ddc8b;
  --green-deep: #2c6b45;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
}

a { color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 28px;
  background: rgba(14, 16, 22, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; }
.brand-star { color: var(--gold); font-size: 22px; line-height: 1; }
.brand b { display: block; font-size: 15px; letter-spacing: -0.01em; }
.brand i { display: block; font-style: normal; font-size: 11.5px; color: var(--text-faint); }

.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  font: inherit;
  font-size: 13.5px;
  color: var(--text-dim);
  background: none;
  border: 0;
  padding: 7px 15px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.is-active { color: var(--bg); background: var(--green); font-weight: 600; }

.ghost-link {
  font-size: 12.5px;
  color: var(--text-dim);
  text-decoration: none;
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 7px;
  transition: border-color 0.15s, color 0.15s;
}
.ghost-link:hover { color: var(--text); border-color: var(--text-faint); }

/* ---------- view switching ---------- */
.view { display: none; max-width: 1180px; margin: 0 auto; padding: 28px; }
.view.is-active { display: block; }

h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--text-dim); margin: 0 0 14px; font-weight: 600; }
.panel-hint, .section-hint { text-transform: none; letter-spacing: 0; color: var(--text-faint); font-weight: 400; margin-left: 8px; font-size: 11px; }

/* ---------- summary: banner ---------- */
.banner {
  display: grid;
  grid-template-columns: 1.4fr repeat(6, 1fr);
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 22px;
}
.banner-stat { background: var(--surface); padding: 18px 16px; }
.banner-stat b { display: block; font-family: var(--mono); font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.banner-stat small { font-size: 15px; color: var(--text-faint); font-weight: 400; }
.banner-stat span { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; }
.banner-stat--hero { background: linear-gradient(135deg, #1f2333 0%, #181c28 100%); }
.banner-stat--hero b { color: var(--gold); font-size: 32px; }
.banner-stat .star { font-size: 20px; margin-left: 4px; }

/* ---------- summary: charts ---------- */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.panel--wide { grid-column: 1 / -1; }
.panel-note { font-size: 11.5px; color: var(--text-faint); margin: 14px 0 0; line-height: 1.5; }

.bars { display: flex; flex-direction: column; gap: 7px; }
.bar {
  display: grid;
  grid-template-columns: 74px 1fr 30px;
  align-items: center;
  gap: 10px;
  width: 100%;
  font: inherit;
  font-size: 12px;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
}
.bar:disabled { cursor: default; }
.bar-l { color: var(--text-dim); text-align: right; font-size: 11.5px; }
.bar-track { height: 16px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--green-deep), var(--green)); border-radius: 4px; transition: filter 0.15s; }
.bar-v { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
/* 25 rows of measured values need a wider label and value gutter than the
   5-bucket charts above them */
.bars--perf { gap: 4px; }
.bars--perf .bar { grid-template-columns: 46px 1fr 58px; font-size: 11.5px; }
.bars--perf .bar-track { height: 13px; }
.bars--perf .bar-v { text-align: right; }
.bar:hover:not(:disabled) .bar-fill { filter: brightness(1.25); }
.bar:hover:not(:disabled) .bar-l { color: var(--text); }

.scatter { position: relative; height: 210px; margin: 8px 0 24px 46px; border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.pt {
  position: absolute;
  width: 11px; height: 11px;
  margin: -5.5px 0 0 -5.5px;
  border-radius: 50%;
  background: var(--green);
  border: 0;
  padding: 0;
  cursor: pointer;
  opacity: 0.75;
  transition: transform 0.15s, opacity 0.15s;
}
.pt:hover, .pt:focus-visible { transform: scale(1.5); opacity: 1; outline: none; }
.pt--hard { background: var(--gold); }
.axis-x { position: absolute; right: 0; bottom: -20px; font-size: 10.5px; color: var(--text-faint); }
.axis-y { position: absolute; left: -46px; top: 0; font-size: 10.5px; color: var(--text-faint); writing-mode: vertical-rl; }

/* ---------- summary: tags ---------- */
.tagcloud { display: flex; flex-wrap: wrap; gap: 7px; }
/* Borderless on purpose: tags sit directly under the nav buttons on narrow
   screens, and a bordered pill next to a bordered button reads as a second row
   of controls. Fill-only keeps them legible as metadata. */
.tag {
  font: inherit;
  font-size: 12px;
  color: var(--text-faint);
  background: var(--surface-2);
  border: 0;
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.tag:hover { color: var(--text); background: var(--surface-3); }
.tag i { font-style: normal; color: var(--text-faint); margin-left: 6px; font-family: var(--mono); font-size: 11px; }
.tag--static { cursor: default; }
.tag--static:hover { color: var(--text-faint); background: var(--surface-2); }

/* ---------- summary: day cards (bespoke — deliberately not the Scratch card) ---------- */
.cards-section { margin-top: 26px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 12px; }
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.16s ease, border-color 0.16s, box-shadow 0.16s;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--green-deep);
  transition: background 0.16s;
}
.card:hover { transform: translateY(-3px); border-color: var(--surface-3); box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45); }
.card:hover::before { background: var(--green); }
.card--hard::before { background: var(--gold); }
.card-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card-day { font-family: var(--mono); font-size: 11px; color: var(--text-faint); letter-spacing: 0.06em; text-transform: uppercase; }
.card-diff { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.card h4 { margin: 5px 0 7px; font-size: 14.5px; font-weight: 600; letter-spacing: -0.01em; }
.card-quote { font-size: 11.5px; color: var(--text-faint); line-height: 1.45; margin: 0 0 11px; flex: 1; font-style: italic; }
.card-foot { display: flex; align-items: center; gap: 9px; font-size: 10.5px; color: var(--text-faint); font-family: var(--mono); border-top: 1px solid var(--line-soft); padding-top: 9px; }
.card-note { margin-left: auto; color: var(--gold); font-style: normal; }

/* ---------- days: split explorer ---------- */
.split { display: grid; grid-template-columns: 268px 1fr; gap: 22px; align-items: start; }
.pane-list { position: sticky; top: 74px; max-height: calc(100vh - 100px); display: flex; flex-direction: column; }

.filters { border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 10px; }
/* both are mobile affordances; the media query below reveals them */
.filter-toggle { display: none; }
.mobile-back { display: none; }
.search, .sort select {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  width: 100%;
}
.search:focus, .sort select:focus { outline: none; border-color: var(--green-deep); box-shadow: 0 0 0 3px rgba(109, 220, 139, 0.12); }
.sort { display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 8px; margin-top: 9px; }
.sort span { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; }

.fgroup { border: 0; margin: 12px 0 0; padding: 0; }
.fgroup legend { font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); padding: 0; margin-bottom: 5px; }
.fgroup label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-dim); padding: 2px 0; cursor: pointer; }
.fgroup label:hover { color: var(--text); }
.fgroup input { accent-color: var(--green); margin: 0; }
.fgroup i { font-style: normal; margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--text-faint); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 12px; }
.chip {
  font: inherit;
  font-size: 11px;
  background: var(--green-deep);
  color: #dff7e6;
  border: 0;
  border-radius: 999px;
  padding: 3px 8px 3px 10px;
  cursor: pointer;
}
.chip::after { content: " ✕"; opacity: 0.65; }
.chip:hover::after { opacity: 1; }
.chip--clear { background: none; color: var(--text-faint); text-decoration: underline; padding: 3px 4px; }
.chip--clear::after { content: ""; }

.daylist { overflow-y: auto; flex: 1; margin: 0 -6px; padding: 0 6px; }
.row {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: baseline;
  gap: 9px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--text-dim);
  background: none;
  border: 0;
  border-radius: 7px;
  padding: 7px 9px;
  cursor: pointer;
  transition: background 0.13s, color 0.13s;
}
.row:hover { background: var(--surface-2); color: var(--text); }
.row.is-active { background: var(--surface-3); color: var(--text); box-shadow: inset 2px 0 0 var(--green); }
.row-n { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }
.row.is-active .row-n { color: var(--green); }
.row-t { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-m { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }
.row-note { color: var(--gold); }
.list-empty { font-size: 12.5px; color: var(--text-faint); padding: 14px 9px; }

/* ---------- days: detail pane ---------- */
.pane-detail { min-width: 0; }
.detail-head { border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 20px; }
.eyebrow { font-family: var(--mono); font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.07em; }
.detail-head h1 { font-size: 28px; margin: 5px 0 12px; letter-spacing: -0.02em; }
.detail-nav { display: flex; gap: 8px; margin-left: auto; }
.detail-top { display: flex; align-items: flex-start; gap: 16px; }
.detail-head .tagcloud { margin-top: 16px; }
.navbtn { font: inherit; font-size: 12px; color: var(--text-dim); background: var(--surface-3); border: 1px solid var(--line); border-radius: 7px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.navbtn:hover:not(:disabled) { color: var(--text); border-color: var(--text-faint); }
.navbtn:disabled { opacity: 0.35; cursor: default; }

.detail-body { display: grid; grid-template-columns: minmax(0, 1fr) 232px; gap: 26px; align-items: start; }
.detail-body > * { min-width: 0; }
.writeup { font-size: 15.5px; line-height: 1.65; margin: 0 0 14px; }
.placeholder { color: var(--text-faint); font-style: italic; border-left: 2px solid var(--surface-3); padding-left: 12px; }

.factbox { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.factbox div { display: flex; justify-content: space-between; gap: 10px; padding: 8px 13px; border-bottom: 1px solid var(--line-soft); font-size: 12.5px; }
.factbox div:last-child { border-bottom: 0; }
.factbox dt { color: var(--text-faint); }
.factbox dd { margin: 0; font-family: var(--mono); font-size: 12px; text-align: right; }
.factbox .fact-none { color: var(--text-faint); font-style: italic; font-family: var(--sans); }

.log { margin-top: 18px; }
.log h5 { font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); margin: 0 0 8px; }
.log ol { margin: 0; padding: 0; list-style: none; }
.log li { font-size: 11.5px; color: var(--text-dim); line-height: 1.45; padding: 5px 0 5px 14px; position: relative; border-left: 1px solid var(--line); }
.log li::before { content: ""; position: absolute; left: -3px; top: 11px; width: 5px; height: 5px; border-radius: 50%; background: var(--line); }
.log li:last-child::before { background: var(--green); }
.fact-sub { display: block; font-size: 10.5px; color: var(--text-faint); }
.log-more { font-size: 11px; color: var(--text-faint); padding-left: 14px; }

.quote {
  margin: 0 0 20px;
  padding: 14px 18px;
  background: var(--surface);
  border-left: 3px solid var(--gold);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 14.5px;
  line-height: 1.55;
}
.quote cite { display: block; font-style: normal; font-size: 11px; color: var(--text-faint); margin-top: 7px; font-family: var(--mono); }

.note { margin: 0 0 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
/* contain + a dark mat: portrait scans stay whole and read as a framed
   artifact instead of a white slab. Full size is one click away. */
.note img { display: block; width: 100%; max-height: 520px; object-fit: contain; background: var(--surface-2); cursor: zoom-in; }
.note--wide img { max-height: 720px; }
.note figcaption { font-size: 12px; color: var(--text-dim); padding: 11px 15px; border-top: 1px solid var(--line); line-height: 1.5; }
.note-flag { display: inline-flex; align-items: center; gap: 6px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--gold); margin-bottom: 9px; }

.code { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-top: 20px; }
.code-bar { display: flex; justify-content: space-between; align-items: center; background: var(--surface-2); padding: 8px 14px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); }
.code-bar a { color: var(--green); text-decoration: none; }
.code-bar a:hover { text-decoration: underline; }
.code pre { margin: 0; padding: 14px; font-family: var(--mono); font-size: 12px; line-height: 1.6; color: var(--text-dim); overflow: auto; max-height: 460px; tab-size: 4; }
.code-tabs { display: flex; gap: 4px; }
.code-tab { font: inherit; font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); background: none; border: 0; border-radius: 5px; padding: 2px 8px; cursor: pointer; }
.code-tab:hover { color: var(--text-dim); background: var(--surface-3); }
.code-tab.is-active { color: var(--text); background: var(--surface-3); }

/* ---------- story ---------- */
.story { max-width: 720px; margin: 0 auto; }
.story-head { border-bottom: 1px solid var(--line); padding-bottom: 22px; margin-bottom: 8px; }
.story-head h1 { font-size: 30px; line-height: 1.25; letter-spacing: -0.02em; margin: 0 0 14px; }
.story-head p, .act p { color: var(--text-dim); line-height: 1.7; }
.act { padding-top: 30px; margin-top: 30px; border-top: 1px solid var(--line-soft); }
.act-head { margin-bottom: 16px; }
.act-n { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--green); }
.act-head h2 { font-size: 23px; margin: 5px 0 3px; letter-spacing: -0.02em; }
.act-sub { font-size: 12.5px; color: var(--text-faint); margin: 0; }
.act blockquote { margin: 20px 0; padding: 0 0 0 18px; border-left: 3px solid var(--gold); font-size: 16px; line-height: 1.5; }
.act blockquote cite { display: block; font-style: normal; font-size: 11px; color: var(--text-faint); margin-top: 8px; font-family: var(--mono); }
.note--wide { margin: 22px 0; }
.diary { list-style: none; margin: 20px 0; padding: 0; }
.diary li { font-family: var(--mono); font-size: 12.5px; color: var(--text-dim); padding: 8px 0 8px 18px; border-left: 1px solid var(--line); position: relative; }
.diary li::before { content: ""; position: absolute; left: -4px; top: 15px; width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.diary b { color: var(--text-faint); font-weight: 400; margin-right: 12px; }
.diary-win { color: var(--green); }
.diary-win::before { background: var(--green) !important; }
.act-days { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 6px; margin-top: 22px; }
.minitile {
  font: inherit;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 0;
  cursor: pointer;
  transition: color 0.14s, border-color 0.14s, background 0.14s;
}
.minitile:hover { color: var(--text); background: var(--surface-2); border-color: var(--green-deep); }

/* ---------- footer ---------- */
.foot {
  max-width: 1180px;
  margin: 40px auto 0;
  padding: 20px 28px 34px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--text-faint);
}
.foot a { color: var(--text-dim); }

/* ---------- responsive ---------- */
/* Below 980px the panes can no longer sit side by side, so everything that
   depends on "beside" changes together at this one breakpoint. Splitting them
   (stack at 980, drill-down at 700) left landscape phones ~896px wide stacked
   with the filters fully expanded and no way to reach a day. */
@media (max-width: 980px) {
  .charts { grid-template-columns: 1fr; }
  .banner { grid-template-columns: 1fr 1fr 1fr; }
  .detail-body { grid-template-columns: 1fr; }

  /* the explorer becomes two screens: the list, then the day */
  .split { display: block; }
  .pane-list { position: static; max-height: none; border-right: 0; padding-right: 0; overflow: visible; }
  .daylist { max-height: none; overflow: visible; }
  .pane-detail { display: none; }
  .split.is-detail .pane-list { display: none; }
  .split.is-detail .pane-detail { display: block; }

  .mobile-back { display: inline-flex; }
  .detail-top { flex-direction: column; align-items: stretch; gap: 12px; }
  .detail-head h1 { font-size: 24px; }

  /* "All days" is a level-up action, so it takes its own row. Prev and Next are
     siblings and mirror each other, which puts their arrows on the outer edges
     instead of floating at different offsets inside centred buttons. */
  .detail-nav { margin-left: 0; flex-wrap: wrap; }
  .mobile-back { flex: 1 0 100%; justify-content: center; }
  #prev, #next { flex: 1; }
  #prev { text-align: left; }
  #next { text-align: right; }

  /* filters collapse so the day list is the first thing on screen */
  .filter-toggle {
    display: block;
    width: 100%;
    margin-top: 9px;
    font: inherit;
    font-size: 12.5px;
    color: var(--text-dim);
    background: var(--surface-3);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 8px 11px;
    text-align: left;
    cursor: pointer;
  }
  .filter-toggle::after { content: " ▾"; float: right; color: var(--text-faint); }
  .filter-toggle[aria-expanded="true"]::after { content: " ▴"; }
  .filter-body { display: none; }
  .filter-body.is-open { display: block; }
  .row { padding: 10px 9px; }
  .row-t { font-size: 14px; }
}

@media (max-width: 620px) {
  .view, .foot { padding: 18px; }
  .topbar { flex-wrap: wrap; gap: 12px; padding: 12px 18px; }
  .tabs { margin-left: 0; width: 100%; }
  .tab { flex: 1; }
  .ghost-link { display: none; }
  .banner { grid-template-columns: 1fr 1fr; }
  .story-head h1 { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- note lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: rgba(6, 8, 12, 0.92);
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 6px; }
.lightbox-hint { position: absolute; bottom: 18px; left: 0; right: 0; text-align: center; font-size: 11.5px; color: var(--text-faint); }

/* difficulty ratings not yet written by hand are flagged rather than hidden */
.est { color: var(--gold); margin-left: 2px; cursor: help; }
.load-error { color: var(--text-dim); padding: 24px 0; }

/* Syntax colours come from the vendored Tokyo Night Dark theme. It is kept
   verbatim so upgrading is a re-download, so the two rules that reconcile it
   with this app's markup live here instead.

   The theme pads via `pre code.hljs`; this app renders a bare <pre class="hljs">,
   so that selector never matches and .code pre's own padding applies. But
   .code pre also sets a colour, and at higher specificity than the theme's
   .hljs, so restate the theme's base colour to let it win. */
.code pre.hljs { color: #9aa5ce; }
