/*
 * 夜間交易台風格。刻意只做深色一種，不跟隨系統淺色主題——
 * 這是對「金融交易風格」的設計取捨，文字對比度全部拉到 AA 以上。
 * 台股慣例：紅漲綠跌，所以紅色是強調色而非警示色。
 */
:root {
  --ui-size: 16.5px; /* 由字級按鈕改寫 */

  --bg: #0a0e15;
  --bg-grid: #121826;
  --surface: #131a26;
  --surface-2: #1a2332;
  --surface-3: #212c3e;
  --line: #2a374d;
  --line-soft: #202b3d;

  --text: #eef3fa; /* 對 --bg 約 16:1 */
  --text-dim: #b9c7dc; /* 約 10:1，仍清楚可讀 */
  --muted: #8fa2bd; /* 約 7:1，只用於次要說明 */

  --up: #ff4d4d; /* 紅＝漲 */
  --up-soft: #3a1620;
  --down: #22c55e; /* 綠＝跌 */
  --accent: #ffb020;
  --accent-soft: #33240a;

  --radius: 10px;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, "Roboto Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

/* An author-set `display` beats the UA stylesheet's [hidden] rule, so .board
   and .timeline would stay visible when toggled off without this. */
[hidden] {
  display: none !important;
}

html {
  font-size: var(--ui-size);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------- 背景 K 線動畫 */
#candles {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

body > *:not(#candles) {
  position: relative;
  z-index: 1;
}

/* ---------------------------------------------------------------- 頂部說明 */
.notice {
  margin: 0;
  padding: 0.5rem clamp(0.75rem, 3vw, 1.75rem);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-dim);
  background: linear-gradient(90deg, var(--accent-soft), transparent 60%);
  border-bottom: 1px solid var(--line);
}

.notice:empty {
  display: none;
}

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 0.7rem clamp(0.75rem, 3vw, 1.75rem) 0.6rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 2px solid var(--line);
}

.topbar__row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.topbar h1::before {
  content: "▮";
  margin-right: 0.4rem;
  color: var(--up);
}

.scope {
  margin: 0;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.controls {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}

.search {
  position: relative;
  flex: 1 1 20rem;
  display: flex;
  gap: 0.4rem;
}

.search input {
  flex: 1;
  padding: 0.55rem 0.75rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}

.search input::placeholder {
  color: var(--muted);
}

.search input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  overflow: hidden;
}

.toggle button {
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-weight: 700;
  color: var(--text-dim);
  background: none;
  border: 0;
  cursor: pointer;
}

.toggle button.is-on {
  color: #0a0e15;
  background: var(--accent);
}

.ghost {
  padding: 0.45rem 0.7rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  cursor: pointer;
}

.ghost:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* 字級調整 */
.fontsize {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.4rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}

.fontsize button {
  width: 1.9rem;
  height: 1.7rem;
  font: inherit;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  cursor: pointer;
  line-height: 1;
}

.fontsize button:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
}

.fontsize button:disabled {
  opacity: 0.35;
  cursor: default;
}

.fontsize span {
  min-width: 3.2rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}

.filters {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}

.chips {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.chip {
  padding: 0.22rem 0.7rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.chip:hover {
  color: var(--text);
  border-color: var(--accent);
}

.chip.is-on {
  color: #0a0e15;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

.filters__right {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  flex-wrap: wrap;
}

.switch {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
}

.switch input {
  accent-color: var(--accent);
  width: 0.95rem;
  height: 0.95rem;
}

/* ------------------------------------------------------------------ board */
main {
  padding: 0.9rem clamp(0.75rem, 3vw, 1.75rem) 2.5rem;
}

.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr));
  gap: 0.85rem;
  align-items: start;
}

/* 每家一個色相，由 app.js 指定 --hue */
.card {
  --hue: 210;
  background: linear-gradient(
    180deg,
    hsl(var(--hue) 34% 14%) 0%,
    var(--surface) 5.5rem
  );
  border: 1px solid hsl(var(--hue) 30% 30%);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 35%);
}

.card__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  background: hsl(var(--hue) 42% 22%);
  border-bottom: 2px solid hsl(var(--hue) 55% 45%);
}

.card__head h2 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.02em;
}

.card__head a {
  color: hsl(var(--hue) 70% 82%);
  font-size: 0.74rem;
  text-decoration: none;
  white-space: nowrap;
}

.card__head a:hover {
  color: #fff;
  text-decoration: underline;
}

.count {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: hsl(var(--hue) 60% 85%);
}

.badge-new {
  min-width: 1.15rem;
  padding: 0.05rem 0.4rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  text-align: center;
  color: #fff;
  background: var(--up);
  border-radius: 999px;
}

.warn {
  font-size: 0.85rem;
  color: var(--accent);
}

.items {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 26rem;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.items li {
  border-bottom: 1px solid var(--line-soft);
}

.items li:last-child {
  border-bottom: 0;
}

.item {
  display: grid;
  gap: 0.15rem;
  padding: 0.5rem 0.8rem;
  color: inherit;
  text-decoration: none;
  border-left: 3px solid transparent;
}

.item:hover {
  background: var(--surface-2);
  border-left-color: var(--accent);
}

.item.is-new {
  border-left-color: var(--up);
}

/* 時間軸上以來源期貨商的色相標示左緣 */
.item--sourced {
  border-left-color: hsl(var(--hue, 210) 60% 45%);
}

.item--sourced:hover {
  border-left-color: hsl(var(--hue, 210) 80% 62%);
}

.item__meta {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--text-dim);
}

.item__title {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text);
  cursor: zoom-in;
}

.item.is-new .item__title {
  font-weight: 700;
}

.dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--up);
  box-shadow: 0 0 0.4rem var(--up);
  flex: none;
}

.dot.is-hidden {
  visibility: hidden;
}

.tag {
  padding: 0 0.45rem;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 0.25rem;
  background: var(--surface-3);
  color: var(--text-dim);
  white-space: nowrap;
}

.tag[data-tag="保證金"] {
  background: var(--up-soft);
  color: #ff8f8f;
}

.tag[data-tag="假期"] {
  background: #10301f;
  color: #6ee7a0;
}

.tag[data-tag="系統"] {
  background: #2b2340;
  color: #c4b0ff;
}

.tag[data-tag="防詐"] {
  background: var(--accent-soft);
  color: #ffce70;
}

.tag[data-tag="商品"] {
  background: #0e2c3a;
  color: #7fd8f5;
}

.broker-name {
  font-family: inherit;
  font-weight: 700;
  color: var(--text);
}

mark {
  padding: 0 0.12rem;
  background: var(--accent);
  color: #0a0e15;
  border-radius: 0.15rem;
  font-weight: 700;
}

.card__more {
  display: block;
  width: 100%;
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

.card__more:hover {
  color: var(--accent);
  background: var(--surface-3);
}

/* --------------------------------------------------------------- timeline */
.timeline {
  max-width: 60rem;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 35%);
}

.timeline .day {
  position: sticky;
  top: 0;
  padding: 0.4rem 1rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--surface-3);
  border-bottom: 1px solid var(--line);
}

.timeline ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline li {
  border-bottom: 1px solid var(--line-soft);
}

.empty {
  padding: 2.5rem 0;
  text-align: center;
  color: var(--text-dim);
}

/* ------------------------------------------------------------------- 放大鏡 */
.lens {
  position: fixed;
  z-index: 60;
  max-width: min(38rem, 80vw);
  padding: 0.6rem 0.9rem;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.45;
  color: var(--text);
  background: var(--surface-3);
  border: 2px solid var(--accent);
  border-radius: 0.6rem;
  box-shadow: 0 0.75rem 2rem rgb(0 0 0 / 60%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.lens.is-on {
  opacity: 1;
}

.lens::before {
  content: "🔍";
  margin-right: 0.4rem;
  font-size: 0.9em;
}

.lens .lens__meta {
  display: block;
  margin-top: 0.25rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
}

/* ------------------------------------------------------------------ 頁尾 */
.foot {
  padding: 0.75rem clamp(0.75rem, 3vw, 1.75rem) 2rem;
  color: var(--text-dim);
  font-size: 0.78rem;
  border-top: 2px solid var(--line);
  background: var(--surface);
}

.foot p {
  margin: 0.25rem 0;
}

.foot a {
  color: var(--accent);
}

#update-info {
  font-family: var(--mono);
  font-weight: 700;
  color: var(--text);
}

#schedule-info {
  font-family: var(--mono);
}

.errors {
  color: var(--up);
  font-weight: 700;
}

@media (max-width: 35rem) {
  .items {
    max-height: none;
  }

  .board {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  #candles {
    display: none;
  }

  .lens {
    transition: none;
  }
}
