:root {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #2d333b;
  --text: #e6edf3;
  --muted: #8b949e;
  --extreme-fear: #00a854;
  --fear: #6fca8f;
  --neutral: #9aa0a6;
  --greed: #f08a8a;
  --extreme-greed: #e5484d;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
  gap: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; font-weight: 600; }
.motto { color: var(--muted); font-size: 12px; border-left: 1px solid var(--border); padding-left: 10px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--extreme-fear); }
.dot.warn { background: #d29922; }
.dot.err { background: var(--extreme-greed); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.updated { color: var(--muted); font-size: 12px; }
.auto-refresh { color: var(--muted); font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.auto-refresh::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #30363d; }
.auto-refresh.live { color: #3fb950; }
.auto-refresh.live::before { background: #3fb950; box-shadow: 0 0 6px #3fb95088; }
#refresh-btn {
  background: #21262d; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 14px; cursor: pointer; font-size: 13px;
}
#refresh-btn:hover { border-color: var(--muted); }
#refresh-btn:disabled { opacity: .5; cursor: wait; }

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  /* 一屏装下：情绪条 + 两行图表；装不下时只滚主区域 */
  grid-template-rows: auto minmax(300px, 1.08fr) minmax(260px, 1fr);
  gap: 10px;
  padding: 10px 14px;
  align-items: stretch;
  overflow-y: auto;
}
#panel-verdict { grid-column: 1 / -1; }
#panel-fg { grid-column: span 4; }
#panel-indicators { grid-column: span 4; }
#panel-aaii { grid-column: span 4; }
#panel-fg-history { grid-column: span 8; }
#panel-vix { grid-column: span 4; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; margin-bottom: 6px; flex-wrap: wrap;
}
.panel-head h2 { font-size: 14px; font-weight: 600; }
.src { color: var(--muted); font-size: 12px; }
.panel-foot { color: var(--muted); font-size: 11px; margin-top: 2px; }

.gauge-wrap { display: flex; flex-direction: column; align-items: stretch; gap: 6px; flex: 1; min-height: 0; }
#gauge-chart { flex: 1; height: auto; min-height: 150px; min-width: 0; }
.gauge-side {
  flex: none; display: grid; grid-template-columns: 108px minmax(0, 1fr);
  grid-template-rows: auto auto; gap: 5px 10px; align-items: stretch; min-width: 0;
}
.rating-tag {
  grid-row: 1; display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; text-align: center;
  padding: 5px 8px; border-radius: 8px; background: #21262d;
}
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.compare-item {
  background: #21262d; border-radius: 6px; padding: 5px 8px;
  display: flex; flex-direction: column; gap: 1px;
}
.compare-item .label { color: var(--muted); font-size: 10px; }
.compare-item .value { font-size: 14px; font-weight: 600; }
.compare-item .delta { font-size: 10px; }
.delta.down { color: var(--extreme-fear); }
.delta.up { color: var(--extreme-greed); }
.percentile-note { grid-column: 2; color: var(--muted); font-size: 11px; line-height: 1.4; }

.indicator-grid {
  display: flex; flex-direction: column;
  gap: 5px; flex: 1; min-height: 0; overflow-y: auto;
}
.ind-card {
  background: #21262d; border-radius: 8px; padding: 6px 10px;
  border-left: 3px solid var(--neutral); cursor: default;
  transition: background .12s;
  flex: 1; min-height: 30px;
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto; align-content: center;
  column-gap: 10px; row-gap: 4px;
}
.ind-card:hover { background: #262d35; }
.ind-card .ind-name {
  grid-area: 1 / 1; font-size: 12px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ind-card .ind-score-row {
  grid-area: 1 / 2 / span 2 / 3; display: flex; flex-direction: column;
  align-items: flex-end; gap: 1px;
}
.ind-card .ind-score { font-size: 16px; font-weight: 700; line-height: 1.1; }
.ind-card .ind-rating { font-size: 10px; color: var(--muted); }
.ind-bar { grid-area: 2 / 1; height: 4px; border-radius: 3px; background: #30363d; overflow: hidden; align-self: center; }
.ind-bar-fill { height: 100%; border-radius: 3px; }

.chart-box { flex: 1; min-height: 0; }
.stat-chip {
  font-size: 15px; font-weight: 700; padding: 2px 10px;
  border-radius: 12px; background: #21262d;
}

.verdict-grid { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.action-scale { position: relative; flex: 1.1; min-width: 300px; display: flex; padding-top: 24px; }
.action-scale .seg { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: help; }
.action-scale .seg::before { content: ""; width: 100%; height: 12px; background: var(--c); opacity: .85; }
.action-scale .seg:first-of-type::before { border-radius: 6px 0 0 6px; }
.action-scale .seg:last-of-type::before { border-radius: 0 6px 6px 0; }
.action-scale .seg b { font-size: 11px; font-weight: 500; color: var(--muted); }
.action-scale .seg span { font-size: 12px; color: var(--text); white-space: nowrap; }
.action-scale .marker { position: absolute; top: 0; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; transition: left .6s ease; pointer-events: none; }
.action-scale .marker b { font-size: 13px; font-weight: 700; color: var(--text); line-height: 1.35; }
.action-scale .marker i { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid var(--text); }
.action-scale .marker.warn b { color: var(--greed); }
.action-scale .marker.warn i { border-top-color: var(--greed); }

.signal-row { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 300px; }
.signal { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; background: #161b22; flex: 1; min-width: 148px; }
.signal .lamp { width: 8px; height: 8px; border-radius: 50%; background: #30363d; flex: none; }
.signal.fear { border-color: #00a85466; }
.signal.fear .lamp { background: var(--extreme-fear); box-shadow: 0 0 8px #00a85488; }
.signal.greed { border-color: #e5484d66; }
.signal.greed .lamp { background: var(--extreme-greed); box-shadow: 0 0 8px #e5484d88; }
.signal.near { border-color: #d2992266; }
.signal.near .lamp { background: #d29922; box-shadow: 0 0 6px #d2992255; }
.sig-body { display: flex; flex-direction: column; gap: 1px; }
.sig-name { font-size: 11px; color: var(--muted); }
.sig-value { font-size: 15px; font-weight: 600; }
.sig-tag { margin-left: auto; font-size: 11px; color: var(--muted); }
.signal.fear .sig-tag { color: var(--fear); }
.signal.greed .sig-tag { color: var(--greed); }
.signal.near .sig-tag { color: #d29922; }
.src.fear-on { color: #3fb950; font-weight: 600; }
.src.greed-on { color: var(--extreme-greed); font-weight: 600; }
.src.fear-lean { color: var(--fear); }
.src.greed-lean { color: var(--greed); }

.loading-mask {
  position: absolute; inset: 0; background: rgba(13,17,23,.55);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(1px); z-index: 5;
}
.loading-mask[hidden] { display: none; }
.spinner {
  width: 28px; height: 28px; border: 3px solid var(--border);
  border-top-color: var(--muted); border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.unavailable {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; color: var(--muted); text-align: center; padding: 20px;
}
.unavailable[hidden] { display: none; }
.unavail-icon { font-size: 26px; color: #d29922; }
.unavailable .hint { font-size: 12px; opacity: .7; }

.footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 6px 16px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 11px;
}

.tooltip {
  position: fixed; z-index: 99; max-width: 280px;
  background: #1c2128; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 12px; line-height: 1.6; color: var(--text);
  pointer-events: none; box-shadow: 0 6px 20px rgba(0,0,0,.5);
}
.tooltip .tt-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-muted { color: var(--muted); }

.panel-error {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px;
  background: rgba(13,17,23,.8); z-index: 6; color: var(--muted);
  font-size: 13px; text-align: center; padding: 20px;
}

/* 矮屏：仪表盘与右侧读数改为左右排，避免表盘被压扁 */
@media (max-height: 880px) {
  .gauge-wrap { flex-direction: row; align-items: stretch; }
  #gauge-chart { flex: 1; min-width: 140px; }
  .gauge-side { flex: 0 0 42%; display: flex; flex-direction: column; gap: 6px; }
}

/* 中等宽度：两列排布，放弃一屏锁定，整页可滚 */
@media (max-width: 1080px) {
  html, body { height: auto; overflow: auto; }
  body { height: auto; min-height: 100vh; }
  main {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
    overflow: visible;
  }
  #panel-verdict, #panel-fg-history { grid-column: 1 / -1; }
  #panel-fg, #panel-indicators, #panel-aaii, #panel-vix { grid-column: span 1; }
  .panel { min-height: 300px; }
  .chart-box { min-height: 210px; }
}

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  #panel-fg, #panel-indicators, #panel-aaii, #panel-vix { grid-column: 1 / -1; }
  .gauge-wrap { flex-direction: column; }
  #gauge-chart { height: 220px; }
  .verdict-grid { flex-direction: column; }
  .action-scale, .signal-row { min-width: 100%; width: 100%; }
}