:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f4;
  --ink: #17191c;
  --muted: #646b73;
  --line: #d8dee4;
  --teal: #0f9f8f;
  --teal-soft: #dff6f2;
  --amber: #f0a620;
  --amber-soft: #fff1d6;
  --red: #d95757;
  --red-soft: #ffe2e2;
  --green: #1c9a5a;
  --green-soft: #ddf4e7;
  --violet: #6554c0;
  --shadow: 0 14px 40px rgba(32, 38, 46, 0.08);
  --radius: 8px;
  font-family: Inter, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(15, 159, 143, 0.08), transparent 280px),
    var(--bg);
  color: var(--ink);
}

button,
select {
  font: inherit;
}

.app-shell {
  width: min(1500px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar,
.control-bar,
.panel {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px;
  border-radius: var(--radius);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--amber), #f8d06d);
  color: #23190b;
  font-weight: 900;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.15;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 99px;
  background: var(--amber);
}

.status-dot.ok {
  background: var(--green);
}

.status-dot.error {
  background: var(--red);
}

.control-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin-top: 16px;
  padding: 14px;
  border-radius: var(--radius);
}

label {
  display: grid;
  gap: 6px;
  min-width: 130px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

select {
  width: 100%;
  min-height: 38px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

select:focus,
button:focus-visible {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 159, 143, 0.16);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid #131517;
  border-radius: var(--radius);
  background: #181b1f;
  color: #fff;
  cursor: pointer;
}

.icon-button svg {
  width: 17px;
  height: 17px;
}

.icon-button:disabled {
  cursor: progress;
  opacity: 0.65;
}

.hero-grid,
.dashboard-grid {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.hero-grid {
  grid-template-columns: minmax(290px, 0.9fr) minmax(300px, 1fr) minmax(420px, 1.55fr);
}

.dashboard-grid {
  grid-template-columns: 1.15fr 0.85fr 0.9fr;
}

.panel {
  border-radius: var(--radius);
  padding: 18px;
  overflow: hidden;
}

.wide {
  grid-column: span 2;
}

.panel-head,
.price-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.pill,
.mini-meta,
.change-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.pill.high,
.change-badge.negative {
  background: var(--red-soft);
  color: #a33a3a;
}

.pill.medium {
  background: var(--amber-soft);
  color: #9a690d;
}

.pill.low,
.change-badge.positive {
  background: var(--green-soft);
  color: #167345;
}

.score-wrap {
  display: grid;
  grid-template-columns: 150px 1fr;
  align-items: center;
  gap: 18px;
}

.score-ring {
  display: grid;
  place-items: center;
  width: 148px;
  height: 148px;
  border-radius: 999px;
  background: conic-gradient(var(--amber) 0deg, var(--line) 0deg);
}

.score-ring > div {
  display: grid;
  place-items: center;
  width: 108px;
  height: 108px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.score-ring strong {
  font-size: 36px;
  line-height: 1;
}

.score-ring span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.direction-box {
  display: grid;
  gap: 6px;
}

.direction-box span {
  font-size: 28px;
  font-weight: 900;
}

.direction-box strong {
  font-size: 21px;
  color: var(--teal);
}

.direction-box small,
.notice {
  color: var(--muted);
}

.notice {
  margin-top: 16px;
  font-size: 13px;
  line-height: 1.55;
}

.market-panel {
  background:
    linear-gradient(140deg, rgba(240, 166, 32, 0.13), transparent 44%),
    linear-gradient(320deg, rgba(15, 159, 143, 0.12), transparent 52%),
    var(--surface);
}

.price-row h2 {
  margin-top: 3px;
  font-size: 34px;
}

.metric-grid {
  display: grid;
  gap: 10px;
}

.metric-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric-grid > div,
.matrix-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(244, 246, 248, 0.72);
}

.metric-grid span,
.matrix-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric-grid strong,
.matrix-item strong {
  display: block;
  margin-top: 5px;
  font-size: 17px;
}

.market-visual {
  position: relative;
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
}

.factor-list,
.alert-list,
.source-list {
  display: grid;
  gap: 10px;
}

.factor {
  display: grid;
  gap: 7px;
}

.factor-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 800;
}

.factor-top span:last-child {
  color: var(--muted);
  white-space: nowrap;
}

.factor-track {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--red-soft), var(--surface-2) 50%, var(--green-soft));
}

.factor-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 0;
  background: var(--teal);
  border-radius: 99px;
}

.factor-bar.negative {
  left: auto;
  right: 50%;
  background: var(--red);
}

.factor small {
  color: var(--muted);
  line-height: 1.35;
}

.alert {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--teal);
  border-radius: var(--radius);
  background: #fbfcfd;
}

.alert.bear {
  border-left-color: var(--red);
}

.alert.warn {
  border-left-color: var(--amber);
}

.alert.neutral {
  border-left-color: var(--violet);
}

.alert strong {
  font-size: 14px;
}

.alert span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.matrix {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.matrix-item .sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.source-panel {
  max-height: 420px;
}

.source-list {
  max-height: 330px;
  overflow: auto;
  padding-right: 2px;
}

.source {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.source:last-child {
  border-bottom: 0;
}

.source .dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--green);
}

.source.failed .dot {
  background: var(--red);
}

.source code {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  word-break: break-word;
}

.source em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.top-contracts-panel {
  margin-top: 16px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.top-table {
  width: 100%;
  min-width: 940px;
  border-collapse: collapse;
  font-size: 13px;
}

.top-table th,
.top-table td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.top-table th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.top-table tbody tr:hover {
  background: rgba(15, 159, 143, 0.06);
}

.rank-cell {
  font-weight: 900;
  color: var(--muted);
}

.contract-cell {
  display: grid;
  gap: 3px;
}

.contract-cell strong {
  font-size: 14px;
}

.contract-cell span {
  color: var(--muted);
  font-size: 12px;
}

.side-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 900;
}

.side-pill.long {
  background: var(--green-soft);
  color: var(--green);
}

.side-pill.short {
  background: var(--red-soft);
  color: var(--red);
}

.win-cell {
  font-weight: 900;
  color: var(--teal);
}

.table-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.loading .panel {
  opacity: 0.78;
}

@media (max-width: 1180px) {
  .hero-grid,
  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
  }

  .market-visual,
  .wide {
    grid-column: span 2;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: calc(100% - 20px);
    padding: 10px 0 40px;
    overflow-x: hidden;
  }

  .hero-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .status-strip {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    width: 100%;
    justify-content: initial;
    white-space: normal;
  }

  .status-strip span {
    min-width: 0;
  }

  #clockText {
    justify-self: end;
  }

  label {
    width: 100%;
  }

  .icon-button {
    width: 100%;
  }

  .control-bar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .panel-head {
    align-items: start;
  }

  .signal-panel .panel-head {
    display: grid;
    grid-template-columns: 1fr;
  }

  .signal-panel .pill {
    justify-self: start;
  }

  .hero-grid,
  .dashboard-grid {
    display: grid;
  }

  .market-visual,
  .wide {
    grid-column: span 1;
  }

  .score-wrap,
  .metric-grid.compact,
  .matrix {
    grid-template-columns: 1fr;
  }

  .score-ring {
    margin: 0 auto;
  }

  .price-row {
    align-items: start;
    flex-direction: column;
  }

  .price-row h2 {
    font-size: 30px;
  }

  .top-contracts-panel .panel-head {
    display: grid;
    grid-template-columns: 1fr;
  }

  .top-contracts-panel .mini-meta {
    justify-self: start;
  }
}

@media (max-width: 480px) {
  .status-strip {
    grid-template-columns: auto minmax(0, 1fr);
  }

  #clockText {
    display: none;
  }
}
