:root {
  /* 台股慣例：紅漲綠跌 */
  --up: #f6465d;
  --down: #2ebd85;
  --flat: #9aa4b2;
  --bg: #0d1117;
  --panel: rgba(22, 27, 34, 0.92);
  --text: #e6edf3;
  --muted: #8b949e;
}

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

html, body { height: 100%; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  overflow: hidden;
}

/* ---- 大盤資訊列 ---- */

#ticker {
  padding: 14px 20px 10px;
  background: var(--panel);
  border-bottom: 1px solid #21262d;
  z-index: 10;
}

#channel-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

#channel-nav a {
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  background: #161b22;
  border: 1px solid #21262d;
}

#channel-nav a.active {
  color: var(--text);
  background: #21262d;
  border-color: #58a6ff;
}

#credit {
  margin-left: auto;
  align-self: center;
  padding: 4px 12px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  opacity: 0.75;
}
#credit:hover { color: var(--text); opacity: 1; }

@media (max-width: 600px) {
  #credit { font-size: 11px; padding: 4px 6px; }
}

.ticker-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}

.ticker-main {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin: 2px 0 4px;
}

#index-price {
  font-size: 40px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s;
}

#index-change {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

.ticker-sub {
  display: flex;
  gap: 18px;
  font-size: 13px;
  color: var(--muted);
}
.ticker-sub b { color: var(--text); font-weight: 600; }

#disclaimer {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
  opacity: 0.7;
}

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #21262d;
  color: var(--muted);
  white-space: nowrap;
}

/* ---- 彈幕飛行區 ---- */

#danmaku-stage {
  position: relative;
  flex: 1;
  overflow: hidden;
}

#chart {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.danmaku { z-index: 1; }

.danmaku {
  position: absolute;
  left: 100%;
  white-space: nowrap;
  font-size: 22px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  will-change: transform;
  animation-name: fly;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
  pointer-events: none;
}

.danmaku.mine {
  text-decoration: underline;
  text-underline-offset: 4px;
}

@keyframes fly {
  from { transform: translateX(0); }
  to { transform: translateX(var(--fly-distance)); }
}

/* ---- 輸入列 ---- */

#composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: var(--panel);
  border-top: 1px solid #21262d;
  z-index: 10;
}

#barrage-form {
  display: flex;
  flex: 1;
  gap: 10px;
}

#barrage-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #30363d;
  border-radius: 8px;
  background: #0d1117;
  color: var(--text);
  font-size: 16px;
  outline: none;
}
#barrage-input:focus { border-color: #58a6ff; }

#barrage-form button {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  background: #238636;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
#barrage-form button:hover { background: #2ea043; }
#barrage-form button:disabled { background: #30363d; cursor: not-allowed; }

/* ---- 提示訊息 ---- */

#toast {
  position: fixed;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 14px;
  z-index: 20;
}

@media (max-width: 600px) {
  #index-price { font-size: 30px; }
  .danmaku { font-size: 18px; }

  /* 手機版：房間人數往上折，輸入列獨佔一整行 */
  #composer {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 10px 12px;
  }
  #room-badge { align-self: flex-start; }
  #barrage-form { gap: 8px; }
  #barrage-input { min-width: 0; }
  #barrage-form button { padding: 10px 14px; white-space: nowrap; }
}
