:root {
  color-scheme: dark;
  --bg: #08090d;
  --panel: #111827;
  --panel-2: #131c2c;
  --panel-3: #0f1726;
  --line: #233047;
  --line-soft: #1b2638;
  --text: #f7f7fb;
  --muted: #8d97aa;
  --muted-2: #657084;
  --red: #ef233c;
  --red-2: #ff3b45;
  --green: #35f125;
  --green-2: #52ff3f;
  --orange: #ff8a00;
  --blue: #1f6feb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.shell {
  width: min(1160px, calc(100% - 36px));
  margin: 0 auto;
  padding: 30px 0 48px;
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 15px;
}

h1 {
  margin: 0;
  font-size: clamp(1.55rem, 2.6vw, 2.15rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.source-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--orange);
  box-shadow: 0 0 0 5px rgb(255 138 0 / 14%);
}

.source-state.ok .pulse {
  background: var(--green);
  box-shadow: 0 0 0 5px rgb(53 241 37 / 14%);
}

.toolbar {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.category-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.category-pills button,
.intervals button {
  border: 0;
  border-radius: 6px;
  color: #d7ddea;
  background: #223047;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 900;
  transition: transform 0.15s ease, background 0.15s ease;
}

.category-pills button {
  min-height: 36px;
  padding: 0 17px;
}

.sub-pills {
  gap: 6px;
  margin-top: -2px;
}

.sub-pills button {
  min-height: 28px;
  padding: 0 12px;
  border-radius: 5px;
  font-size: 0.76rem;
}

.category-pills button:hover,
.intervals button:hover {
  transform: translateY(-1px);
}

.category-pills button.active,
.intervals button.active {
  color: white;
  background: var(--red);
}

.tools {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 190px;
  gap: 10px;
  margin-top: 2px;
}

label > span {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  color: var(--text);
  background: var(--panel);
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgb(31 111 235 / 20%);
}

.summary {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin: 4px 1px 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.summary p {
  margin: 0;
}

.market-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.quote-card {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(150px, 0.95fr) minmax(92px, auto);
  align-items: center;
  gap: 14px;
  min-height: 86px;
  padding: 15px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: inherit;
  text-align: left;
  cursor: pointer;
  background: #111827;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 3%);
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.quote-card:hover {
  border-color: #31507d;
  background: #141f31;
  transform: translateY(-2px);
}

.product-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 950;
  letter-spacing: -0.02em;
}

.spark {
  width: 100%;
  min-width: 120px;
  height: 48px;
}

.spark svg {
  display: block;
  width: 100%;
  height: 48px;
}

.quote {
  justify-self: end;
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 950;
}

.latest {
  display: block;
  font-size: 1.05rem;
  line-height: 1;
}

.latest .unit {
  margin-left: 2px;
  color: var(--muted-2);
  font-size: 0.64rem;
  font-family: inherit;
}

.quote-card.up .latest,
.quote-card.down .change {
  color: var(--red-2);
}

.quote-card.down .latest,
.quote-card.up .change {
  color: var(--green);
}

.quote-card.flat .latest {
  color: #f8fafc;
}

.change {
  display: inline-block;
  min-width: 58px;
  margin-top: 7px;
  padding: 2px 5px;
  border-radius: 2px;
  color: white;
  background: #3a4658;
  font-size: 0.78rem;
  line-height: 1.25;
}

.quote-card.up .change {
  color: white;
  background: var(--red-2);
}

.quote-card.down .change {
  color: white;
  background: #18d112;
}

.empty,
.error {
  grid-column: 1 / -1;
  padding: 44px 18px;
  border: 1px dashed var(--line);
  border-radius: 9px;
  color: var(--muted);
  text-align: center;
  background: var(--panel-3);
}

.error {
  margin: 14px 0;
  color: #fecdd3;
  border-color: #7f1d1d;
  background: #2b1218;
}

dialog {
  width: min(1100px, calc(100% - 26px));
  max-height: calc(100% - 26px);
  padding: 0;
  border: 1px solid #29364d;
  border-radius: 9px;
  color: var(--text);
  background: #08090d;
  box-shadow: 0 24px 90px rgb(0 0 0 / 72%);
}

dialog::backdrop {
  background: rgb(0 0 0 / 72%);
  backdrop-filter: blur(4px);
}

.terminal {
  padding: 14px;
}

.terminal-toolbar {
  display: grid;
  grid-template-columns: minmax(210px, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.terminal-toolbar select {
  height: 42px;
  border-radius: 5px;
  font-weight: 900;
}

.intervals {
  display: flex;
  gap: 1px;
  overflow: hidden;
  border-radius: 5px;
}

.intervals button {
  min-width: 46px;
  height: 38px;
  border-radius: 0;
  font-size: 0.78rem;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 6px;
  color: #dbe3ef;
  background: #223047;
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
}

.indicator-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 9px 0 10px;
  color: #e5e7eb;
  font-size: 0.78rem;
  font-weight: 950;
}

.days {
  margin-right: auto;
}

.quote-panel {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
  padding: 16px 14px 15px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--panel);
}

.quote-panel p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.quote-panel strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: clamp(1.75rem, 4vw, 2.35rem);
}

.quote-panel .unit {
  margin-left: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.quote-metrics {
  display: grid;
  align-content: center;
  gap: 8px;
  text-align: right;
  color: #d1d5db;
  font-size: 0.9rem;
  font-weight: 900;
}

.quote-metrics strong {
  margin-left: 6px;
  font-size: 1rem;
}

.chart {
  min-height: 560px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: crosshair;
}

.chart svg {
  display: block;
  width: 100%;
  height: 560px;
}

@media (max-width: 880px) {
  .market-grid {
    grid-template-columns: 1fr;
  }

  .quote-card {
    grid-template-columns: minmax(140px, 1fr) minmax(110px, 0.75fr) auto;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 22px, 1160px);
    padding-top: 22px;
  }

  .hero,
  .summary,
  .quote-panel {
    align-items: flex-start;
    flex-direction: column;
  }

  .tools,
  .terminal-toolbar {
    grid-template-columns: 1fr;
  }

  .indicator-row {
    justify-content: flex-start;
  }

  .days {
    margin-right: 0;
  }

  .intervals {
    width: 100%;
  }

  .intervals button {
    flex: 1;
  }

  .quote-card {
    grid-template-columns: 1fr auto;
  }

  .spark {
    grid-column: 1 / -1;
    order: 3;
  }

  .chart,
  .chart svg {
    min-height: 410px;
    height: 410px;
  }
}
