/* ————————————————————————————————————————————————
   事件 × 注意力時間軸 — Spike Demo
   風格：編輯部 × 儀器面板。紙感淺底、明體標題、單一藍資料主色。
   投影優先：高對比、粗字重、不靠淡色傳達資訊。離線：僅系統字型。
———————————————————————————————————————————————— */
:root {
  color-scheme: light only; /* 投影展示固定亮色，禁止瀏覽器強制暗色反轉 */
  /* dataviz 參考色盤（light mode，validator 驗證過的槽位） */
  --paper: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);

  --series: #2a78d6;      /* 注意力曲線（7 日平均主線） */
  --series-deep: #1c5cab;
  --series-area: #cde2fb; /* 每日原始值面積 */

  --t-release: #4a3aa7;   /* 發行 */
  --t-live: #1baf7a;      /* 演出 */
  --t-media: #eda100;     /* 媒體/獎項 */
  --t-controversy: #e34948; /* 爭議 */
  --t-other: #898781;     /* 其他 */

  --serif: "Songti TC", "Noto Serif TC", "Songti SC", serif;
  --sans: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--sans);
  background:
    radial-gradient(1200px 500px at 85% -10%, #eef3f9 0%, transparent 60%),
    var(--paper);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  padding: 0 clamp(16px, 4vw, 56px) 96px;
}

/* ——— masthead ——— */
.masthead {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  flex-wrap: wrap;
  padding: clamp(20px, 4vh, 44px) 0 20px;
  border-bottom: 3px solid var(--ink);
}
.kicker {
  font-size: 12px;
  letter-spacing: 0.35em;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.title {
  font-family: var(--serif);
  font-weight: 900;
  font-size: clamp(34px, 5.2vw, 58px);
  line-height: 1.1;
  letter-spacing: 0.02em;
}
.title .times {
  color: var(--series);
  font-family: var(--sans);
  font-weight: 300;
  padding: 0 0.12em;
}
.title .subtitle {
  font-family: var(--sans);
  font-weight: 300;
  font-size: 0.52em;
  color: var(--ink-2);
  margin-left: 0.5em;
  letter-spacing: 0.14em;
}
.tagline { color: var(--ink-2); font-size: 14px; margin-top: 8px; }

.masthead-nav { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.overview-link { font-size: 12.5px; color: var(--series-deep); text-decoration: none; font-weight: 600; letter-spacing: 0.05em; }
.overview-link:hover { text-decoration: underline; }

/* 藝人切換 */
.artist-switch { display: flex; gap: 0; border: 2px solid var(--ink); background: var(--surface); }
.artist-switch button {
  appearance: none; border: 0; background: transparent;
  font-family: var(--sans); font-size: 16px; font-weight: 600;
  color: var(--ink); padding: 10px 22px; cursor: pointer;
  border-left: 2px solid var(--ink);
  transition: background 0.15s ease;
}
.artist-switch button:first-child { border-left: 0; }
.artist-switch button:hover { background: #efeeea; }
.artist-switch button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.artist-switch button .en { display: block; font-size: 10px; font-weight: 400; letter-spacing: 0.08em; opacity: 0.7; }

/* ——— 主圖卡 ——— */
.chart-card {
  margin-top: 28px;
  background: var(--surface);
  border: 1px solid var(--ring);
  box-shadow: 0 1px 0 var(--ring), 0 12px 32px rgba(11, 11, 11, 0.05);
  padding: 20px 24px 10px;
}
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.chart-head h2 { font-family: var(--serif); font-size: 26px; font-weight: 900; }
.chart-meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.legend { display: flex; gap: 18px; font-size: 12.5px; color: var(--ink-2); flex-wrap: wrap; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 18px; height: 0; border-top: 3px solid var(--series); display: inline-block; }
.legend .swatch.area { height: 10px; border: 0; background: var(--series-area); }
.legend .swatch.dot { width: 9px; height: 9px; border-radius: 50%; border: 0; }

.chart-wrap { position: relative; margin-top: 8px; }
#chart { display: block; width: 100%; height: clamp(300px, 44vh, 460px); }

.lane-caption { color: var(--muted); font-size: 11.5px; padding: 4px 2px 8px; }

/* 進場動畫：載入與切換藝人時，資料層淡入上浮、標記帶淡入 */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
#chart.anim .g-data { animation: rise 0.45s ease-out both; }
#chart.anim .g-lane { animation: fade 0.6s ease-out 0.15s both; }
.masthead .kicker { animation: fade 0.5s ease-out both; }
.masthead .title { animation: rise 0.5s ease-out 0.05s both; }
.masthead .tagline { animation: fade 0.5s ease-out 0.15s both; }
@media (prefers-reduced-motion: reduce) {
  #chart.anim .g-data, #chart.anim .g-lane,
  .masthead .kicker, .masthead .title, .masthead .tagline { animation: none; }
}

/* 鍵盤焦點可視（a11y／簡報遙控） */
button:focus-visible, a:focus-visible {
  outline: 2px solid var(--series-deep); outline-offset: 2px;
}

/* 圖上文字（SVG 內） */
#chart text { font-family: var(--sans); font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
#chart .axis-year { font-weight: 700; fill: var(--ink-2); }

/* tooltip */
.tooltip {
  position: absolute; pointer-events: none; z-index: 30;
  background: var(--ink); color: #fff;
  padding: 10px 12px; font-size: 12.5px; line-height: 1.5;
  max-width: 300px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.tooltip .tt-date { font-weight: 700; font-size: 13px; }
.tooltip .tt-views { font-variant-numeric: tabular-nums; color: #cde2fb; }
.tooltip .tt-event { margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(255, 255, 255, 0.25); display: flex; gap: 6px; align-items: baseline; }
.tooltip .tt-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; position: relative; top: 1px; }

/* ——— 事件類型彙總 ——— */
.type-summary {
  margin-top: 24px; background: var(--surface);
  border: 1px solid var(--ring); padding: 16px 20px 12px;
}
.ts-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.ts-head h3 { font-family: var(--serif); font-size: 18px; font-weight: 900; }
.ts-sub { color: var(--muted); font-size: 12px; }
.ts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 12px; }
.ts-cell { border-left: 1px solid var(--grid); padding-left: 12px; }
.ts-type { font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.ts-type .dot { width: 8px; height: 8px; border-radius: 50%; }
.ts-type .ts-n { color: var(--muted); font-size: 11px; }
.ts-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.ts-value.up { color: #006300; }
.ts-value.down { color: #8f2020; }
.ts-label { font-size: 11px; color: var(--muted); }
.ts-warn { font-size: 11px; color: #7a5200; background: #fdf2dc; display: inline-block; padding: 1px 8px; border-radius: 999px; margin-top: 5px; }
.ts-note { color: var(--muted); font-size: 11.5px; margin-top: 12px; border-top: 1px solid var(--grid); padding-top: 8px; }

/* ——— 下半部 ——— */
.lower {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: 24px;
  margin-top: 24px;
  align-items: start;
}
@media (max-width: 900px) { .lower { grid-template-columns: 1fr; } }

.events-panel { background: var(--surface); border: 1px solid var(--ring); padding: 18px 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.panel-head h3 { font-family: var(--serif); font-size: 19px; font-weight: 900; }
.panel-head .count { color: var(--muted); font-size: 13px; font-weight: 400; font-family: var(--sans); }
.conf-toggle { font-size: 12.5px; color: var(--ink-2); cursor: pointer; user-select: none; display: inline-flex; gap: 6px; align-items: center; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 14px; }
.chips button {
  appearance: none; cursor: pointer;
  border: 1.5px solid var(--baseline); background: transparent;
  font-family: var(--sans); font-size: 12.5px; color: var(--ink-2);
  padding: 4px 12px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.12s ease;
}
.chips button .dot { width: 8px; height: 8px; border-radius: 50%; }
.chips button:hover { border-color: var(--ink); color: var(--ink); }
.chips button[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: #fff; }
.chips button .n { font-variant-numeric: tabular-nums; opacity: 0.75; }

.event-list { list-style: none; max-height: 520px; overflow-y: auto; overscroll-behavior: contain; }
.event-list li {
  border-top: 1px solid var(--grid);
  padding: 10px 8px 10px 12px;
  cursor: pointer;
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 4px 12px;
  align-items: baseline;
  border-left: 3px solid transparent;
  transition: background 0.12s ease;
}
.event-list li:hover { background: #f4f3ef; }
.event-list li.selected { background: #eef3f9; border-left-color: var(--series); }
.event-list .ev-date { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.event-list .ev-title { font-size: 14px; font-weight: 600; line-height: 1.45; }
.event-list .ev-tags { grid-column: 2; display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: 10.5px; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--baseline); color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 5px;
}
.tag .dot { width: 7px; height: 7px; border-radius: 50%; }
.tag.conf-high { border-color: transparent; background: #e9f2e9; color: #006300; }
.tag.conf-medium { border-color: transparent; background: #fdf2dc; color: #7a5200; }
.tag.conf-low { border-color: transparent; background: #fbe9e9; color: #8f2020; }
.tag.corrected { border-style: dashed; color: var(--series-deep); border-color: var(--series); }

/* 詳情面板 */
.detail-panel {
  background: var(--surface); border: 1px solid var(--ring);
  padding: 20px; position: sticky; top: 16px;
  min-height: 280px;
}
.detail-empty { color: var(--muted); font-size: 13.5px; text-align: center; padding: 60px 12px; }
.detail-empty-mark { font-size: 34px; margin-bottom: 10px; color: var(--baseline); }
.detail-date { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 13px; }
.detail-title { font-family: var(--serif); font-size: 21px; font-weight: 900; line-height: 1.35; margin: 6px 0 10px; }
.detail-summary { font-size: 14px; color: var(--ink-2); }
.detail-tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.detail-sec { font-size: 11.5px; letter-spacing: 0.2em; color: var(--muted); margin: 18px 0 6px; border-top: 1px solid var(--grid); padding-top: 12px; }
.detail-links { list-style: none; }
.detail-links li { margin: 6px 0; font-size: 13px; line-height: 1.45; }
.detail-links a { color: var(--series-deep); text-decoration: none; border-bottom: 1px solid var(--series-area); }
.detail-links a:hover { border-bottom-color: var(--series-deep); }
.detail-links .src { color: var(--muted); font-size: 11.5px; margin-left: 4px; }
.correction-note {
  margin-top: 8px; padding: 10px 12px; font-size: 12.5px;
  background: #eef3f9; border-left: 3px solid var(--series);
  color: var(--ink-2);
}
.correction-note a { color: var(--series-deep); }

/* 歸因面板 */
.attr-box { margin-top: 4px; }
.attr-toggles { display: flex; gap: 6px; margin-bottom: 10px; }
.attr-toggles button {
  appearance: none; cursor: pointer;
  border: 1.5px solid var(--baseline); background: transparent;
  font-family: var(--sans); font-size: 12px; color: var(--ink-2);
  padding: 3px 12px; border-radius: 999px; transition: all 0.12s ease;
}
.attr-toggles button:hover { border-color: var(--ink); color: var(--ink); }
.attr-toggles button[aria-pressed="true"] { border-color: var(--series-deep); background: var(--series-deep); color: #fff; }
.attr-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.attr-stat .attr-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.attr-stat .attr-label { font-size: 11px; color: var(--muted); margin-top: 1px; }
.attr-stat.up .attr-value { color: #006300; }
.attr-stat.down .attr-value { color: #8f2020; }
.attr-note { margin-top: 10px; font-size: 11.5px; color: var(--ink-2); background: #f4f3ef; padding: 7px 10px; }

/* 圖上歸因視窗標籤 */
#chart text.attr-cap { fill: var(--series-deep); font-weight: 700; }
#chart text.attr-cap.base { fill: var(--ink-2); font-weight: 400; }

/* ——— 頁尾 ——— */
.sources { margin-top: 40px; border-top: 3px solid var(--ink); padding-top: 18px; }
.sources h3 { font-family: var(--serif); font-size: 17px; font-weight: 900; margin-bottom: 10px; }
.sources ul { list-style: none; }
.sources li { font-size: 12.5px; color: var(--ink-2); margin: 6px 0; padding-left: 14px; position: relative; }
.sources li::before { content: "—"; position: absolute; left: 0; color: var(--muted); }

/* ——— 總覽頁 ——— */
.nav-btn {
  display: inline-block; padding: 10px 22px;
  font-size: 15px; font-weight: 600; color: var(--ink); text-decoration: none;
}
.nav-btn:hover { background: #efeeea; }
.tier-sec { margin-top: 30px; }
.tier-title {
  font-family: var(--serif); font-size: 22px; font-weight: 900;
  border-left: 5px solid var(--series); padding-left: 12px; margin-bottom: 14px;
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  display: block; background: var(--surface); border: 1px solid var(--ring);
  padding: 14px 16px; color: inherit; text-decoration: none;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.card.linked:hover { box-shadow: 0 8px 24px rgba(11, 11, 11, 0.10); transform: translateY(-2px); }
.card-name { font-weight: 700; font-size: 15.5px; margin-bottom: 8px; }
.spark { width: 100%; height: 64px; display: block; }
.spark-peak { font-size: 9.5px; fill: var(--ink-2); font-variant-numeric: tabular-nums; }
.card-meta { display: flex; align-items: baseline; gap: 10px; margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.card-stat b { font-size: 15px; font-variant-numeric: tabular-nums; color: var(--ink); }
.card-delta { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.card-delta.up { color: #006300; }
.card-delta.down { color: #8f2020; }
.card-events { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.card-events.has-events { color: var(--series-deep); }
.card-go { font-size: 12px; color: var(--series-deep); margin-top: 8px; font-weight: 600; }
.card.no-wiki { background: repeating-linear-gradient(45deg, var(--surface), var(--surface) 10px, #f4f3ef 10px, #f4f3ef 11px); }
.card-empty { color: var(--ink-2); font-size: 13.5px; padding: 14px 0 2px; }
.card-empty-sub { color: var(--muted); font-size: 11.5px; padding-bottom: 12px; }

/* 列印鈕（列印時自身隱藏） */
.print-btn {
  appearance: none; cursor: pointer;
  border: 1.5px solid var(--baseline); background: transparent;
  font-family: var(--sans); font-size: 12.5px; color: var(--ink-2);
  padding: 4px 14px; border-radius: 999px;
}
.print-btn:hover { border-color: var(--ink); color: var(--ink); }

/* ——— 列印 / PDF ——— */
@media print {
  @page { margin: 14mm 12mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { padding: 0; background: #fff; font-size: 11px; }
  .artist-switch, .overview-link, .conf-toggle, .chips, .print-btn,
  .lane-caption, .tooltip { display: none !important; }
  .masthead { padding-top: 0; border-bottom-width: 2px; }
  .title { font-size: 30px; }
  .stamp {
    /* !important：蓋過後方基準規則的 position:fixed，避免每頁重複疊印 */
    position: static !important; display: inline-block; margin-top: 8px;
    border: 1px solid var(--baseline); background: none;
  }
  .detail-panel:has(.detail-empty) { display: none; }
  .chart-card, .type-summary { break-inside: avoid; box-shadow: none; }
  #chart { height: 300px; }
  .lower { display: flex; flex-direction: column; gap: 14px; }
  .detail-panel { order: -1; position: static; min-height: 0; break-inside: avoid; }
  .detail-empty { display: none; }
  .event-list { max-height: none; overflow: visible; }
  .event-list li { break-inside: avoid; padding: 5px 4px; cursor: default; }
  .sources { break-before: auto; }
  .cards { grid-template-columns: 1fr 1fr; }
  .card { break-inside: avoid; }
  a { color: inherit; }
}

/* ——— Live 查詢（實驗頁） ——— */
.live-bar { margin-top: 26px; }
#live-form { display: flex; gap: 10px; max-width: 640px; }
#live-input {
  flex: 1; font-family: var(--sans); font-size: 16px;
  padding: 10px 14px; border: 2px solid var(--ink); background: var(--surface);
  color: var(--ink); outline: none;
}
#live-input:focus { box-shadow: 0 0 0 3px var(--series-area); }
.live-go {
  appearance: none; cursor: pointer; border: 2px solid var(--ink);
  background: var(--ink); color: #fff; font-family: var(--sans);
  font-size: 15px; font-weight: 600; padding: 10px 24px;
}
.live-go:hover { background: var(--series-deep); border-color: var(--series-deep); }
.live-status { margin-top: 10px; font-size: 13px; color: var(--ink-2); }
.live-status.error { color: #8f2020; }
.live-candidates { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.live-candidates .cand-label { font-size: 12px; color: var(--muted); }
.live-candidates .cand {
  appearance: none; cursor: pointer;
  border: 1.5px solid var(--series-deep); background: transparent;
  color: var(--series-deep); font-family: var(--sans); font-size: 13px;
  padding: 5px 14px; border-radius: 999px;
}
.live-candidates .cand:hover { background: var(--series-deep); color: #fff; }
#live-chart { display: block; width: 100%; height: clamp(280px, 40vh, 420px); }
#live-chart text { font-family: var(--sans); font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
#live-chart .axis-year { font-weight: 700; fill: var(--ink-2); }
#live-chart text.attr-cap { fill: var(--series-deep); font-weight: 700; }
.live-stats { display: flex; gap: 28px; padding: 12px 2px 8px; }
.live-stats .attr-stat.up .attr-value { color: #006300; }
.live-stats .attr-stat.down .attr-value { color: #8f2020; }

/* 主頁往 live 的低調入口 */
.live-link { font-size: 11.5px; color: var(--muted); text-decoration: none; letter-spacing: 0.05em; }
.live-link:hover { color: var(--series-deep); text-decoration: underline; }
@media print { .live-link, .live-bar { display: none !important; } }

/* 角落戳記 */
.stamp {
  position: fixed; right: 14px; bottom: 12px; z-index: 50;
  font-size: 11px; letter-spacing: 0.08em;
  color: var(--ink-2); background: rgba(252, 252, 251, 0.92);
  border: 1px solid var(--baseline); padding: 4px 10px;
  font-variant-numeric: tabular-nums;
}
