/* ============================================================
   台灣脆快樂指數 × 《迷航狐狸夢》 — EVENT build
   The band IS the page: one solid field of mood-colour —
   terracotta / gold / slate. The island is knocked out of it
   in cream fragments. The score is the main character: the
   brightest, most anchored element on screen; everything
   else recedes one step. Matte, no gradients.
   & Venture grounded · hooks per HOOKS.md unchanged.
   ============================================================ */

:root {
  --font-zh: "Noto Sans TC", "PingFang TC", sans-serif;
  --font-num: "Nunito Sans", sans-serif;
  --font-mono: "Fira Code", "SF Mono", monospace;

  /* mid — the terracotta event */
  --field: #B24C25;
  --field-deep: #8F3A1B;
  --star: #FFFDF8;                       /* the number — brightest thing on screen */
  --fg: rgba(253, 247, 241, 0.92);
  --fg-70: rgba(253, 247, 241, 0.68);
  --fg-45: rgba(253, 247, 241, 0.44);
  --line: rgba(253, 247, 241, 0.28);

  /* island knockout — a step dimmer than the score */
  --pos-bg: rgba(253, 247, 241, 0.82);
  --pos-ink: #8F3A1B;
  --neg-bg: rgba(30, 22, 18, 0.30);
  --neg-ink: rgba(253, 247, 241, 0.78);
  --neu-bg: rgba(253, 247, 241, 0.16);
  --neu-ink: rgba(253, 247, 241, 0.82);

  --ease: cubic-bezier(0.2, 0, 0.2, 1);
}

body[data-band="high"] {
  --field: #C08214;
  --field-deep: #97650C;
  --pos-ink: #8A5E0B;
  --neg-bg: rgba(40, 30, 10, 0.30);
}

body[data-band="low"] {
  --field: #423C60;
  --field-deep: #322D4B;
  --star: #F6F4FC;
  --fg: rgba(237, 234, 246, 0.92);
  --fg-70: rgba(237, 234, 246, 0.68);
  --fg-45: rgba(237, 234, 246, 0.44);
  --line: rgba(237, 234, 246, 0.28);
  --pos-bg: rgba(237, 234, 246, 0.80);
  --pos-ink: #423C60;
  --neg-bg: rgba(16, 14, 28, 0.42);
  --neg-ink: rgba(237, 234, 246, 0.75);
  --neu-bg: rgba(237, 234, 246, 0.13);
  --neu-ink: rgba(237, 234, 246, 0.78);
}

/* ---------- base ---------- */

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-zh);
  min-height: 100vh;
  transition: background-color 600ms var(--ease);
}

a { color: inherit; }

/* ============================================================
   PAGE 1 — the field, the island, the number
   ============================================================ */

.page-index {
  background: var(--field);
  color: var(--fg);
  overflow-x: hidden;
}

.page-index ::selection { background: var(--star); color: var(--field); }
.page-index :focus-visible { outline: 2px solid var(--star); outline-offset: 2px; }

/* --- the island: cream mosaic on the field --- */

#posts-bg {
  position: fixed; inset: 0;
  overflow: hidden; z-index: 0;
  pointer-events: none;
  transition: transform 420ms var(--ease);
}

/* mobile: shrink + lift the island so the silhouette is unmistakable —
   placement JS untouched */
@media (max-width: 859px) {
  #posts-bg { transform: translateY(-9%) scale(0.68); }
}

.post-chip {
  position: absolute;
  --shift: translate(calc(-50% + var(--px, 0px)), calc(-50% + var(--py, 0px)));
  transform: var(--shift);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.05em;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 2px;
  opacity: 0.88;
  will-change: transform, opacity;
  animation: pulse var(--dur, 8s) ease-in-out var(--delay, 0s) infinite alternate;
  transition: font-size .16s var(--ease), padding .16s var(--ease),
    background-color .25s var(--ease), color .25s var(--ease), box-shadow .25s var(--ease);
}

#comment, #trend { transition: opacity .45s var(--ease, ease); }

/* nearest chip to the pointer: enlarge into a readable card, paused, on top */
body[data-band] .post-chip.reading {
  animation: none;
  z-index: 60;
  opacity: 1 !important;
  font-size: 16px; font-weight: 600; line-height: 1.5;
  padding: 9px 13px; max-width: 240px; white-space: normal;
  background: var(--star); color: var(--field-deep);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.28);
}

/* touch: don't enlarge under the finger — just mark which chip is picked;
   the full text shows in #readout up top, away from the hand */
body[data-band] .post-chip.picked {
  animation: none;
  z-index: 60;
  opacity: 1 !important;
  background: var(--star); color: var(--field-deep);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transform: var(--shift) scale(1.22);
}

/* the readout caption — fixed near the top so a tapped post is never hidden */
#readout {
  position: fixed; left: 50%; top: 56px;
  transform: translate(-50%, -8px);
  z-index: 95; max-width: min(90vw, 460px);
  background: var(--star); color: var(--field-deep);
  font-size: 15px; line-height: 1.5; font-weight: 600;
  padding: 11px 15px; border-radius: 3px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  opacity: 0; visibility: hidden; pointer-events: none;
  text-align: center; text-wrap: pretty;
  transition: opacity .2s var(--ease), transform .2s var(--ease);
}
#readout.on { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

/* mobile full-map toggle button (hidden on desktop) */
.map-toggle {
  display: none;
  position: fixed; right: 16px; bottom: 16px; z-index: 90;
  align-items: center; gap: 7px;
  background: var(--star); color: var(--field-deep);
  border: none; border-radius: 100px;
  font-family: var(--font-zh); font-size: 12px; font-weight: 600;
  letter-spacing: 0.04em;
  padding: 9px 15px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  cursor: pointer;
}
.map-toggle .ic { font-family: var(--font-num); font-size: 14px; line-height: 1; }

.s-pos { background: var(--pos-bg); color: var(--pos-ink); }
.s-neg { background: var(--neg-bg); color: var(--neg-ink); }
.s-neu { background: var(--neu-bg); color: var(--neu-ink); }

.post-chip:nth-child(3n)   { font-size: 9px; padding: 3px 6px; opacity: 0.68; }
.post-chip:nth-child(3n+2) { font-size: 12px; padding: 5px 9px; }

/* mid (40–59): the steady, current breath */
@keyframes pulse {
  from { transform: var(--shift) scale(0.97); opacity: 0.62; }
  to   { transform: var(--shift) scale(1);    opacity: 0.95; }
}
/* low (<40): nervous, twitchy shimmer */
@keyframes jitter {
  0%   { transform: var(--shift) translate(0, 0) scale(1);            opacity: 0.70; }
  20%  { transform: var(--shift) translate(1.6px, -1.2px) scale(1.03); opacity: 0.95; }
  40%  { transform: var(--shift) translate(-1.4px, 1px) scale(0.98);   opacity: 0.74; }
  60%  { transform: var(--shift) translate(1.1px, 1.4px) scale(1.02);  opacity: 0.92; }
  80%  { transform: var(--shift) translate(-1.2px, -0.6px) scale(0.99);opacity: 0.80; }
  100% { transform: var(--shift) translate(0, 0) scale(1);            opacity: 0.70; }
}
/* high (≥60): slow, serene float */
@keyframes drift {
  from { transform: var(--shift) translateY(3px) scale(0.985);  opacity: 0.78; }
  to   { transform: var(--shift) translateY(-5px) scale(1.012); opacity: 0.96; }
}
body[data-band="low"] .post-chip {
  animation-name: jitter; animation-direction: normal; animation-timing-function: linear;
}
body[data-band="high"] .post-chip {
  animation-name: drift; animation-direction: alternate; animation-timing-function: ease-in-out;
  box-shadow: 0 0 14px 1px rgba(255, 243, 214, 0.5);   /* soft warm glow when Taiwan's happy */
}
body[data-band="high"] .hero #hero-score {
  text-shadow: 0 0 38px rgba(255, 249, 232, 0.5);       /* faint halo on the score */
}

/* --- composition --- */

.field {
  position: relative; z-index: 1;
  min-height: 100vh; min-height: 100svh;
  display: flex; flex-direction: column;
  padding: 28px 34px 26px;
}

.head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px;
}

.head .ident, .head .date {
  background: var(--field);
  box-shadow: 0 0 16px 11px var(--field);
  transition: background-color 600ms var(--ease), box-shadow 600ms var(--ease);
}

.ident { display: flex; flex-direction: column; gap: 5px; }

/* the masthead recedes — the number is the headline */
.k-zh { font-size: 13px; font-weight: 400; letter-spacing: 0.34em; color: var(--fg-70); }

.k-en {
  font-family: var(--font-mono);
  font-size: 8px; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--fg-45);
}

.date {
  font-family: var(--font-mono);
  font-size: 9.5px; letter-spacing: 0.1em;
  color: var(--fg-45);
  white-space: nowrap;
}

/* --- floor: the number left, everything else right --- */

.floor {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 40px;
}

/* THE MAIN CHARACTER — anchored by a headline rule, set in the
   only pure-bright ink on screen, on its own pool of field */
.score-side {
  background: var(--field);
  box-shadow: 0 0 30px 22px var(--field);
  transition: background-color 600ms var(--ease), box-shadow 600ms var(--ease);
}

.score-rule {
  width: 58px;
  border-top: 3px solid var(--tw-score-color, var(--star));
  margin-bottom: 18px;
}

body[data-score-rule="off"] .score-rule { display: none; }

.hero { line-height: 0.8; margin-left: -8px; color: var(--tw-score-color, var(--star)); }

.hero #hero-score {
  font-family: var(--font-num);
  font-weight: 200;
  font-size: calc(clamp(150px, 19vw, 280px) * var(--tw-score-scale, 1));
  letter-spacing: var(--tw-score-tracking, -0.05em);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* --- score style variants (Tweaks) --- */

body[data-score-style="black"] .hero #hero-score { font-weight: 900; }

body[data-score-style="outline"] .hero #hero-score {
  font-weight: 700;
  color: transparent;
  -webkit-text-stroke: clamp(2.5px, 0.3vw, 4.5px) var(--tw-score-color, var(--star));
}

body[data-score-style="mono"] .hero #hero-score {
  font-family: var(--font-mono);
  font-weight: 500;
  letter-spacing: calc(var(--tw-score-tracking, -0.05em) - 0.02em);
}

.hero #hero-unit {
  font-family: var(--font-mono);
  font-size: clamp(12px, 1.2vw, 16px);
  font-weight: 400;
  letter-spacing: 0.3em;
  color: var(--fg-45);
  margin-left: 12px;
}

.explain {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.04em;
  line-height: 1.8;
  color: var(--fg-45);
  margin-top: 14px;
  max-width: 40ch;
}

/* --- right panel: the one-liner is the co-star --- */

.panel {
  width: min(400px, 36vw);
  display: flex; flex-direction: column;
  align-items: flex-start;
  padding-bottom: 8px;
  background: var(--field);
  box-shadow: 0 0 24px 17px var(--field);
  transition: background-color 600ms var(--ease), box-shadow 600ms var(--ease);
}

/* the same headline-rule motif as the score — the two main characters rhyme */
.comment-rule {
  width: 58px;
  border-top: 3px solid var(--tw-comment-color, var(--star));
  margin-bottom: 16px;
}

body[data-comment-rule="off"] .comment-rule { display: none; }

.comment {
  font-size: calc(clamp(19px, 2vw, 25px) * var(--tw-comment-scale, 1.3));
  font-weight: var(--tw-comment-weight, 500);
  line-height: 1.8;
  color: var(--tw-comment-color, var(--star));
  text-wrap: pretty;
}

/* hand-drawn yellow marker over the trending topic — wobbly edges, slight tilt,
   two overlapping streaks for an organic highlighter feel (#marker-rough filter
   is injected by index.js; degrades to a tilted block if absent) */
mark.topic-mark {
  position: relative;
  isolation: isolate;
  color: #2A1A0E;
  background: transparent;
  font-weight: 700;
  padding: 0 .18em;
  white-space: nowrap;
}
mark.topic-mark::before,
mark.topic-mark::after {
  content: "";
  position: absolute;
  z-index: -1;
  left: -.08em; right: -.08em;
  background: #FCE34A;
  filter: url(#marker-rough);
}
mark.topic-mark::before {
  top: .02em; bottom: -.04em;
  border-radius: 47% 53% 62% 38% / 58% 44% 56% 42%;
  transform: rotate(-1.6deg);
}
mark.topic-mark::after {           /* lighter second pass, like a marker re-stroke */
  top: -.02em; bottom: .04em;
  border-radius: 55% 45% 40% 60% / 45% 58% 42% 55%;
  transform: rotate(.9deg);
  opacity: .55;
}

.meta {
  display: flex; align-items: baseline; gap: 10px;
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
  width: 100%;
}

.meta-label {
  font-family: var(--font-mono);
  font-size: 9px; letter-spacing: 0.2em;
  color: var(--fg-45);
  white-space: nowrap;
}

.meta a.trend {
  font-size: 14px; font-weight: 500;
  color: var(--fg);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
  transition: opacity 200ms var(--ease);
}

.meta a.trend:hover { opacity: 0.75; }

.countdown {
  font-family: var(--font-mono);
  font-size: 9px; letter-spacing: 0.12em;
  color: var(--fg-45);
  margin-top: 10px;
  white-space: nowrap;
}

.countdown b {
  font-weight: 500;
  color: var(--fg-70);
  font-variant-numeric: tabular-nums;
  margin-left: 4px;
}

.teaser {
  margin-top: 22px;
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line);
  color: var(--fg);
  text-decoration: none;
  font-size: 11.5px; font-weight: 400;
  letter-spacing: 0.03em;
  line-height: 1.55;
  padding: 10px 14px 10px 10px;
  width: 100%;
  transition: background-color 200ms var(--ease), color 200ms var(--ease);
}

.teaser:hover { background: var(--star); color: var(--field); }

.teaser-cover {
  width: 34px; height: 43px;
  object-fit: cover;
  border-radius: 1px;
  flex: 0 0 auto;
}

.teaser .arrow {
  margin-left: auto;
  font-family: var(--font-num);
  font-size: 16px;
  flex: 0 0 auto;
  transition: transform 200ms var(--ease);
}

.teaser:hover .arrow { transform: translateX(5px); }

/* --- mobile --- */

@media (max-width: 859px) {
  .field { padding: 22px 20px 20px; }

  .post-chip { font-size: 9.5px; }
  .post-chip:nth-child(3n)   { font-size: 8.5px; }
  .post-chip:nth-child(3n+2) { font-size: 11px; }

  .floor {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 14px;
  }

  .score-rule { margin-bottom: 12px; width: 46px; }

  .hero { margin-left: -5px; }
  .hero #hero-score { font-size: calc(clamp(120px, 32vw, 170px) * var(--tw-score-scale, 1)); }

  .panel { width: 100%; }

  .comment-rule { width: 46px; margin-bottom: 12px; }
  .comment { font-size: calc(17.5px * var(--tw-comment-scale, 1.3)); }

  .teaser { justify-content: space-between; }

  /* the expand/collapse control is mobile-only */
  .map-toggle { display: inline-flex; }

  /* --- full-map view: enlarge the island, collapse number + one-liner to a strip --- */
  body.map-focus #posts-bg { transform: translateY(0) scale(0.92); }

  body.map-focus .explain,
  body.map-focus .countdown,
  body.map-focus .teaser,
  body.map-focus .score-rule,
  body.map-focus .comment-rule { display: none; }

  body.map-focus .floor { gap: 8px; }
  body.map-focus .hero { margin-left: -3px; }
  body.map-focus .hero #hero-score { font-size: 54px; }
  body.map-focus .hero #hero-unit { font-size: 11px; }
  body.map-focus .panel { padding-bottom: 0; }
  body.map-focus .comment { font-size: 14.5px; line-height: 1.6; }
  body.map-focus .meta { margin-top: 12px; padding-top: 10px; }
}

/* ============================================================
   PAGE 2 — the book, on the event's cream
   ============================================================ */

.page-book {
  --paper: #FDF7F1;
  --ink: #1E1E1E;
  --muted: rgba(30, 30, 30, 0.62);
  --faint: rgba(30, 30, 30, 0.42);
  --hairline: rgba(30, 30, 30, 0.12);
  --rule: #CBBC9D;
  --accent: #B24C25;
  --accent-deep: #8F3A1B;

  background: var(--paper);
  color: var(--ink);
}

.page-book ::selection { background: var(--accent); color: var(--paper); }
.page-book :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.book-top {
  max-width: 1180px; margin: 0 auto;
  padding: 22px 24px 6px;
}

.book-top .back {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: 0.08em;
  color: var(--muted);
  text-decoration: none;
  transition: color 200ms var(--ease);
}

.book-top .back:hover { color: var(--accent-deep); }

.back-arrow { font-family: var(--font-num); transition: transform 200ms var(--ease); }
.book-top .back:hover .back-arrow { transform: translateX(-3px); }

.book-main {
  max-width: 560px; margin: 0 auto;
  padding: 14px 24px 96px;
}

/* --- gallery --- */

.carousel {
  position: relative;
  overflow: hidden;
  background: #F3E7D5;
  border: 1px solid var(--hairline);
  border-radius: 2px;
}

.carousel-track {
  display: flex;
  aspect-ratio: 1 / 1;
  transition: transform 420ms var(--ease);
}

.carousel-track img {
  width: 100%; height: 100%;
  flex: 0 0 100%;
  object-fit: contain;
  display: block;
}

.car-prev, .car-next {
  position: absolute; top: 50%;
  transform: translateY(-50%);
  width: 40px; height: 40px;
  border: 1px solid var(--hairline);
  border-radius: 2px;
  background: rgba(253, 247, 241, 0.94);
  color: var(--ink);
  font-family: var(--font-num);
  font-size: 22px; line-height: 1;
  cursor: pointer;
  display: grid; place-items: center;
  padding-bottom: 3px;
  transition: background-color 200ms var(--ease), color 200ms var(--ease);
}

.car-prev:hover, .car-next:hover { background: #FFFDF8; color: var(--accent-deep); }

.car-prev { left: 12px; }
.car-next { right: 12px; }

.car-dots {
  display: flex; gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

.car-dots i {
  width: 6px; height: 6px;
  border-radius: 1px;
  background: var(--rule);
  display: inline-block;
  cursor: pointer;
  transition: width 200ms var(--ease), background-color 200ms var(--ease);
}

.car-dots i.on { width: 18px; background: var(--accent); }

/* --- text body --- */

.book-head { text-align: center; margin-top: 38px; }

.book-title {
  font-size: 30px; font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.3;
}

.book-tagline {
  font-size: 14.5px; font-weight: 400;
  color: var(--muted);
  margin-top: 12px;
  line-height: 1.7;
  text-wrap: balance;
}

.book-note {
  display: inline-block;
  margin-top: 16px;
  font-family: var(--font-mono);
  font-size: 10.5px; letter-spacing: 0.08em;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: 2px;
  padding: 5px 12px;
}

.book-note:empty { display: none; }

.book-desc {
  margin-top: 40px;
  font-size: 16px; font-weight: 400;
  line-height: 2.1;
  color: var(--ink);
  text-align: justify;
}

.book-desc p { text-indent: 2em; margin: 0 0 0.5em; text-wrap: pretty; }

.book-dedication {
  margin: 36px 0;
  padding: 22px 4px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font-size: 14px; font-weight: 300;
  line-height: 2.05;
  color: var(--muted);
  text-align: left;
}

.book-dedication:empty { display: none; }

.quote {
  margin: 40px auto;
  max-width: 30ch;
  font-size: 19px; font-weight: 400;
  line-height: 1.9;
  color: var(--ink);
  text-align: center;
  text-wrap: pretty;
}

.quote span {
  display: block;
  margin-top: 14px;
  font-family: var(--font-mono);
  font-size: 12px; font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--faint);
}

.recommends {
  list-style: none;
  margin: 36px 0 0;
  padding: 0;
  display: grid;
  gap: 10px 28px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.7;
  text-align: center;
}

.recommends b {
  font-weight: 500;
  color: var(--ink);
  margin-right: 2px;
}

/* --- purchase: the page's one terracotta event --- */

.purchase {
  margin-top: 56px;
  text-align: center;
  display: flex; flex-direction: column;
  align-items: center; gap: 18px;
}

.price {
  font-size: 14px;
  color: var(--muted);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.price b {
  font-family: var(--font-num);
  font-size: 36px; font-weight: 700;
  color: var(--accent);
  vertical-align: -4px;
  margin: 0 6px;
  font-variant-numeric: tabular-nums;
}

.cta {
  display: block;
  width: min(100%, 340px);
  padding: 17px 36px;
  background: var(--accent);
  color: #FDF7F1;
  font-size: 16px; font-weight: 500;
  letter-spacing: 0.18em; text-indent: 0.18em;
  text-align: center;
  text-decoration: none;
  border-radius: 0;
  transition: background-color 200ms var(--ease);
}

.cta:hover, .cta:active { background: var(--accent-deep); }

/* --- desktop: gallery left, essay right --- */

@media (min-width: 920px) {
  .book-main {
    max-width: 1180px;
    display: grid;
    grid-template-columns: minmax(380px, 480px) minmax(420px, 560px);
    justify-content: center;
    gap: 0 88px;
    padding-top: 36px;
  }

  .book-gallery { min-height: 0; }

  .gallery-sticky {
    position: sticky;
    top: 48px;
  }

  .book-body { padding-top: 8px; }

  .book-head { text-align: left; }
  .book-title { font-size: 38px; }
  .book-tagline { font-size: 15.5px; }

  .book-desc { font-size: 16.5px; }

  .quote { text-align: left; margin-left: 0; max-width: 34ch; }

  .recommends {
    text-align: left;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .purchase { align-items: flex-start; text-align: left; }
}

/* ============================================================
   Reduced motion — calm and still
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .post-chip { animation: none !important; }
  .carousel-track { transition: none; }
  .teaser:hover .arrow, .book-top .back:hover .back-arrow { transform: none; }
}
