:root {
  color-scheme: dark;
  --bg: #071018;
  --surface: #0b1721;
  --surface-2: #101f2b;
  --surface-3: #172a38;
  --line: rgba(148, 180, 201, .14);
  --line-strong: rgba(148, 180, 201, .28);
  --text: #eaf4fa;
  --muted: #8299a8;
  --accent: #20d4b0;
  --accent-2: #67a7ff;
  --positive: #ff6476;
  --negative: #31d4a4;
  --amber: #f6bf63;
  --violet: #a890ff;
  --shadow: 0 22px 65px rgba(0, 0, 0, .24);
  --radius: 18px;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f7f9;
  --surface: #ffffff;
  --surface-2: #f3f7fa;
  --surface-3: #e8f0f4;
  --line: rgba(23, 53, 70, .1);
  --line-strong: rgba(23, 53, 70, .2);
  --text: #102733;
  --muted: #647b88;
  --shadow: 0 18px 50px rgba(27, 58, 73, .1);
}

html[data-color="us"] { --positive: #22c997; --negative: #ff6476; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--bg); scroll-behavior: smooth; }
body { margin: 0; color: var(--text); background: var(--bg); font-family: "Noto Sans TC", sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.market-strip { min-height: 34px; display: flex; align-items: center; justify-content: center; gap: 5px; padding: 6px 20px; color: var(--muted); background: #061019; border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 600; letter-spacing: .02em; }
html[data-theme="light"] .market-strip { background: #eaf1f4; }
.market-strip #market-net { color: var(--text); }
.data-badge { margin-left: 10px; color: var(--accent); }

.topbar { position: sticky; top: 0; z-index: 20; min-height: 76px; display: grid; grid-template-columns: minmax(190px, 1fr) minmax(300px, 570px) minmax(190px, 1fr); align-items: center; gap: 24px; padding: 14px clamp(18px, 4vw, 64px); background: color-mix(in srgb, var(--bg) 88%, transparent); border-bottom: 1px solid var(--line); backdrop-filter: blur(18px); }
.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; width: max-content; }
.brand img { border-radius: 12px; box-shadow: 0 8px 20px rgba(32, 212, 176, .12); }
.brand span { display: flex; flex-direction: column; }
.brand strong { font-family: Manrope, sans-serif; font-size: 17px; letter-spacing: -.02em; }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: .08em; }
.search-wrap { position: relative; }
.search-wrap > svg { position: absolute; top: 50%; left: 15px; z-index: 1; width: 18px; fill: none; stroke: var(--muted); stroke-width: 1.8; transform: translateY(-50%); }
.search-wrap input { width: 100%; height: 44px; padding: 0 18px 0 44px; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 13px; outline: none; transition: .2s; }
.search-wrap input:focus { border-color: color-mix(in srgb, var(--accent) 65%, var(--line)); box-shadow: 0 0 0 3px rgba(32, 212, 176, .08); }
.search-results { position: absolute; top: calc(100% + 8px); right: 0; left: 0; z-index: 30; max-height: 370px; overflow: auto; padding: 7px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 14px; box-shadow: var(--shadow); }
.search-result { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px; color: var(--text); background: none; border: 0; border-radius: 9px; text-align: left; cursor: pointer; }
.search-result:hover { background: var(--surface-2); }
.search-result strong { display: block; font-size: 13px; }
.search-result small { color: var(--muted); }
.search-result em { color: var(--accent); font-size: 11px; font-style: normal; }
.header-actions { display: flex; justify-content: flex-end; gap: 8px; }
.button, .icon-button, .help-button, .text-button { border: 0; cursor: pointer; }
.button { height: 42px; padding: 0 18px; border-radius: 12px; font-weight: 700; }
.button.primary { color: #03281f; background: var(--accent); }
.button.primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.icon-button, .help-button { width: 42px; height: 42px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; font-size: 17px; }
.icon-button:hover, .help-button:hover { border-color: var(--line-strong); background: var(--surface-3); }

main { width: min(1540px, calc(100% - 40px)); margin: 0 auto; padding: 44px 0 70px; }
.hero-copy { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; margin-bottom: 26px; }
.eyebrow { margin: 0 0 6px; color: var(--accent); font-family: Manrope, sans-serif; font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.hero-copy h1 { margin: 0; font-family: Manrope, "Noto Sans TC", sans-serif; font-size: clamp(26px, 3.3vw, 46px); line-height: 1.18; letter-spacing: -.04em; }
.hero-copy > div:first-child > p:last-child { max-width: 750px; margin: 12px 0 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
.breadth { flex: 0 0 auto; display: flex; gap: 9px; }
.breadth-item { min-width: 88px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; text-align: center; }
.breadth-item strong { display: block; font-family: Manrope, sans-serif; font-size: 20px; }
.breadth-item span { color: var(--muted); font-size: 11px; }
.breadth-item.up strong { color: var(--positive); }
.breadth-item.down strong { color: var(--negative); }

.quadrants { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.quadrant { position: relative; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; min-height: 74px; padding: 13px 16px; overflow: hidden; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; text-align: left; cursor: pointer; transition: .2s; }
.quadrant::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 3px; background: var(--q-color); opacity: .75; }
.quadrant:hover, .quadrant.active { border-color: color-mix(in srgb, var(--q-color) 55%, var(--line)); transform: translateY(-1px); }
.quadrant.active { background: color-mix(in srgb, var(--q-color) 8%, var(--surface)); }
.quadrant b { min-width: 46px; color: var(--q-color); font-family: Manrope, sans-serif; font-size: 28px; line-height: 1; }
.quadrant strong { display: block; font-size: 13px; }
.quadrant small { color: var(--muted); font-size: 11px; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 14px; }
.chart-card, .watchlist-card, .ranking-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.chart-card { min-width: 0; overflow: hidden; }
.chart-toolbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 11px 15px; border-bottom: 1px solid var(--line); }
.segmented { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; }
.segmented button { min-height: 32px; padding: 0 13px; color: var(--muted); background: transparent; border: 0; border-radius: 7px; font-size: 12px; font-weight: 700; cursor: pointer; }
.segmented button.active { color: var(--text); background: var(--surface-3); box-shadow: 0 2px 7px rgba(0, 0, 0, .12); }
.toolbar-right { display: flex; align-items: center; gap: 8px; }
.select-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
select { height: 36px; padding: 0 30px 0 11px; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; outline: none; }
.help-button { width: 36px; height: 36px; border-radius: 10px; font-family: Manrope, sans-serif; font-weight: 800; }
.chart-stage { position: relative; min-height: 520px; background: radial-gradient(circle at 70% 24%, rgba(65, 142, 170, .09), transparent 34%), linear-gradient(180deg, color-mix(in srgb, var(--surface-2) 35%, transparent), transparent); }
#bubble-chart { width: 100%; height: auto; min-height: 520px; display: block; touch-action: pan-y; }
.axis-line { stroke: var(--line-strong); stroke-width: 1; }
.grid-line { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 6; }
.axis-label, .tick-label, .quadrant-label { fill: var(--muted); font-family: "Noto Sans TC", sans-serif; }
.axis-label { font-size: 12px; font-weight: 600; }
.tick-label { font-size: 10px; }
.quadrant-label { font-size: 11px; font-weight: 700; opacity: .7; letter-spacing: .08em; }
.bubble { cursor: pointer; transition: opacity .2s; }
.bubble circle { stroke-width: 1.5; transition: transform .22s cubic-bezier(.2, .8, .2, 1), filter .22s, opacity .2s; transform-box: fill-box; transform-origin: center; }
.bubble:hover circle, .bubble:focus circle { transform: scale(1.12); filter: drop-shadow(0 0 12px color-mix(in srgb, var(--bubble-color) 60%, transparent)); }
.bubble text { fill: #f8fcff; font-family: "Noto Sans TC", sans-serif; font-weight: 700; text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: rgba(4, 15, 22, .55); stroke-width: 2px; stroke-linejoin: round; }
.bubble text.value { font-family: Manrope, sans-serif; font-size: 10px; font-weight: 600; opacity: .9; }
.bubble.dimmed { opacity: .08; }
.tooltip { position: absolute; z-index: 5; min-width: 178px; padding: 11px 13px; color: var(--text); background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--line-strong); border-radius: 11px; box-shadow: var(--shadow); pointer-events: none; backdrop-filter: blur(10px); }
.tooltip strong { display: block; margin-bottom: 7px; }
.tooltip-row { display: flex; justify-content: space-between; gap: 18px; color: var(--muted); font-size: 11px; }
.tooltip-row b { color: var(--text); font-family: Manrope, sans-serif; }
.chart-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--muted); background: var(--surface); font-size: 13px; }
.chart-loading span { width: 20px; height: 20px; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.chart-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; min-height: 49px; padding: 10px 17px; color: var(--muted); border-top: 1px solid var(--line); font-size: 10px; }
.dot { width: 7px; height: 7px; display: inline-block; margin-right: 5px; border-radius: 50%; }
.dot.surge { background: var(--positive); }.dot.rotate { background: var(--amber); }.dot.watch { background: var(--violet); }.dot.ebb { background: var(--negative); }
.legend-note { margin-left: auto; }

.watchlist-card { min-height: 590px; display: flex; flex-direction: column; padding: 18px; }
.card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; margin-bottom: 14px; }
.card-heading h2 { margin: 0; font-size: 17px; }
.card-heading > span { color: var(--muted); font-size: 11px; }
.text-button { padding: 5px; color: var(--muted); background: none; font-size: 11px; }
.text-button:hover { color: var(--text); }
.watchlist { display: flex; flex-direction: column; gap: 5px; }
.empty-state { padding: 44px 15px; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: 12px; text-align: center; font-size: 12px; line-height: 1.7; }
.watch-row, .ranking-row, .suggestion-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%; padding: 10px 8px; color: var(--text); background: transparent; border: 0; border-bottom: 1px solid var(--line); text-align: left; cursor: pointer; }
.watch-row:hover, .ranking-row:hover { background: var(--surface-2); border-radius: 9px; }
.stock-title { min-width: 0; }
.stock-title strong { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.stock-title small { color: var(--muted); font-size: 10px; }
.stock-value { text-align: right; }
.stock-value strong { display: block; font-family: Manrope, sans-serif; font-size: 12px; }
.stock-value small { color: var(--muted); font-size: 10px; }
.positive { color: var(--positive) !important; }
.negative { color: var(--negative) !important; }
.watchlist-suggestions { margin-top: auto; padding-top: 25px; }
.watchlist-suggestions > p { margin: 0 0 7px; color: var(--muted); font-size: 10px; }
.suggestion-row { padding: 8px 3px; cursor: default; }
.add-button { width: 27px; height: 27px; color: var(--accent); background: rgba(32, 212, 176, .08); border: 1px solid rgba(32, 212, 176, .2); border-radius: 8px; cursor: pointer; }

.ranking-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 14px; }
.ranking-card { padding: 18px; }
.ranking-row { grid-template-columns: 30px minmax(0, 1fr) auto; }
.rank-number { color: var(--muted); font-family: Manrope, sans-serif; font-size: 11px; text-align: center; }

footer { padding: 28px max(20px, calc((100% - 1500px) / 2)); color: var(--muted); background: var(--surface); border-top: 1px solid var(--line); font-size: 11px; line-height: 1.7; }
footer > div { display: flex; gap: 18px; }
footer strong { color: var(--text); font-family: Manrope, sans-serif; }
footer p { margin: 6px 0 0; }

.dialog { width: min(650px, calc(100% - 28px)); max-height: min(82vh, 780px); padding: 0; overflow: hidden auto; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 20px; box-shadow: 0 28px 100px rgba(0, 0, 0, .45); }
.dialog::backdrop { background: rgba(1, 8, 12, .7); backdrop-filter: blur(6px); }
.compact-dialog { width: min(480px, calc(100% - 28px)); }
.dialog > div, .dialog > form { padding: 22px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; margin-bottom: 18px; }
.dialog-header h2 { margin: 0; font-size: 22px; }
.close-button { width: 34px; height: 34px; display: grid; place-items: center; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; font-size: 21px; cursor: pointer; }
.detail-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.metric { padding: 13px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; }
.metric small { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; }
.metric strong { font-family: Manrope, sans-serif; font-size: 16px; }
.dialog-list { display: flex; flex-direction: column; }
.dialog-list .ranking-row { padding-right: 4px; padding-left: 4px; }
.brief-lead { padding: 16px; margin-bottom: 14px; background: linear-gradient(135deg, rgba(32, 212, 176, .1), rgba(103, 167, 255, .08)); border: 1px solid rgba(32, 212, 176, .16); border-radius: 14px; line-height: 1.7; }
.brief-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.brief-panel { padding: 14px; background: var(--surface-2); border-radius: 12px; }
.brief-panel h3 { margin: 0 0 10px; font-size: 13px; }
.brief-panel p { margin: 5px 0; color: var(--muted); font-size: 12px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 0; border-top: 1px solid var(--line); font-size: 13px; }

@media (max-width: 1000px) {
  .topbar { grid-template-columns: auto minmax(250px, 1fr) auto; padding-right: 20px; padding-left: 20px; }
  .brand small { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .watchlist-card { min-height: 0; }
  .watchlist-suggestions { margin-top: 20px; }
}

@media (max-width: 720px) {
  .market-strip { justify-content: flex-start; overflow: auto; white-space: nowrap; }
  .data-badge { display: none; }
  .topbar { position: relative; grid-template-columns: 1fr auto; gap: 12px; padding: 12px 14px; }
  .brand { grid-column: 1; }
  .header-actions { grid-column: 2; grid-row: 1; }
  .search-wrap { grid-column: 1 / -1; grid-row: 2; }
  .header-actions .primary { padding: 0 12px; }
  main { width: min(100% - 24px, 1540px); padding-top: 28px; }
  .hero-copy { align-items: flex-start; flex-direction: column; }
  .breadth { width: 100%; }
  .breadth-item { flex: 1; min-width: 0; }
  .quadrants { grid-template-columns: repeat(2, 1fr); }
  .quadrant { min-height: 68px; padding: 11px; }
  .quadrant b { min-width: 35px; font-size: 23px; }
  .chart-toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-right { justify-content: space-between; }
  .chart-stage, #bubble-chart { min-height: 430px; }
  #bubble-chart { height: 430px; }
  .chart-legend { gap: 9px; }
  .legend-note { width: 100%; margin-left: 0; }
  .ranking-grid { grid-template-columns: 1fr; }
  .brief-grid, .detail-metrics { grid-template-columns: 1fr; }
  footer > div { flex-direction: column; gap: 2px; }
}

@media (max-width: 410px) {
  .brand strong { font-size: 14px; }
  .brand img { width: 36px; height: 36px; }
  .icon-button { width: 38px; height: 38px; }
  .header-actions .primary { height: 38px; font-size: 12px; }
  .quadrant small { display: none; }
}
