:root {
  --bg: #ffffff;
  --surface: #f4f6f8;
  --surface-2: #eaedf1;
  --ink: #14171c;
  --muted: #5b6370;
  --line: #dde1e6;
  --line-strong: #14171c;
  --accent: #0b57a4;
  --accent-ink: #ffffff;
  --up: #d1242f;     /* 台股慣例：紅漲 */
  --down: #0f8a3c;   /* 綠跌 */
  --warn-bg: #fff6db;
  --warn-line: #e3b341;
  --font: "Noto Sans TC", -apple-system, "Segoe UI", "Microsoft JhengHei", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.6 var(--font);
  min-height: 100vh; display: flex; flex-direction: column;
}
main { flex: 1; padding-top: 20px; padding-bottom: 48px; }
a { color: var(--accent); }
.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 28px 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--ink); display: inline-block; }
h3 { font-size: 15px; margin: 0 0 8px; }

/* header */
.site-header { border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 10; }
.header-row { display: flex; align-items: center; gap: 24px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand small { font-family: var(--mono); font-weight: 400; font-size: 12px; color: var(--muted); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--ink); text-decoration: none; padding: 16px 10px 14px; border-bottom: 3px solid transparent; font-weight: 500; }
.nav a:hover { border-bottom-color: var(--line); }
.nav a.active { border-bottom-color: var(--up); }
.who { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-size: 14px; }
.who form { margin: 0; }
.status-bar { background: var(--surface); border-top: 1px solid var(--line); font-size: 13px; }
.status-bar .wrap { padding-top: 6px; padding-bottom: 6px; display: flex; gap: 6px 16px; flex-wrap: wrap; align-items: center; }
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; background: var(--muted); vertical-align: 1px; }
.dot.open { background: var(--up); }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border: 1px solid var(--ink); background: var(--ink); color: #fff;
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; border-radius: 0;
}
.btn:hover { background: #2b313a; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--surface); }
.btn.buy { background: var(--up); border-color: var(--up); }
.btn.sell { background: var(--down); border-color: var(--down); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
input[type=text], input[type=number], input[type=search], select {
  font: inherit; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 0; width: 100%;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* tabs (底線式，不用膠囊) */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); margin: 12px 0; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 14px; font: inherit; color: var(--muted); cursor: pointer; min-height: 44px; white-space: nowrap; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 700; }

/* stat grid */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 2px solid var(--ink); border-bottom: 1px solid var(--line); }
.stat { padding: 12px 14px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 600; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat .sub.up { color: var(--up); }
.stat .sub.down { color: var(--down); }

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--ink); white-space: nowrap; }
td.r, th.r { text-align: right; }
td.num, td .num { white-space: nowrap; }
tbody tr:hover { background: var(--surface); }
tr.me td { background: #eef4fb; }
.row-link { cursor: pointer; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.TIB { border-color: #8a5cf6; color: #6d3fd8; }
.tag.ESB { border-color: #d9822b; color: #a95d0e; }
.tag.TPEX { border-color: #0b57a4; color: #0b57a4; }

/* market list */
.toolbar { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin: 12px 0; }
.more { margin: 14px 0; text-align: center; }

/* stock page */
.stock-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; padding-bottom: 12px; border-bottom: 2px solid var(--ink); }
.stock-head .code { font-family: var(--mono); color: var(--muted); }
.price-big { font-family: var(--mono); font-size: 40px; font-weight: 600; line-height: 1.1; }
.stock-grid { display: grid; grid-template-columns: 1fr 380px; gap: 28px; margin-top: 18px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--muted); font-size: 14px; }
.kv dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
.panel { border: 1px solid var(--line); border-top: 3px solid var(--ink); padding: 16px; background: #fff; }
.side-switch { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 14px; }
.side-switch button { min-height: 44px; font: inherit; font-weight: 700; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; }
.side-switch button.active.buy { background: var(--up); border-color: var(--up); color: #fff; }
.side-switch button.active.sell { background: var(--down); border-color: var(--down); color: #fff; }
.qty-row { display: grid; grid-template-columns: 1fr; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.chips button { min-height: 36px; padding: 0 10px; font: inherit; font-size: 13px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.chips button:hover { border-color: var(--ink); }
.quote { margin: 12px 0; border-top: 1px dashed var(--line); padding-top: 10px; }
.quote .kv dd.total { font-weight: 700; font-size: 17px; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

/* callouts */
.callout { border-left: 4px solid var(--warn-line); background: var(--warn-bg); padding: 10px 14px; margin: 14px 0; font-size: 14px; }
.callout.info { border-left-color: var(--accent); background: #eef4fb; }
.empty { padding: 28px 0; text-align: center; color: var(--muted); }

/* ratio bars */
.bar { height: 6px; background: var(--surface-2); margin-top: 4px; }
.bar > span { display: block; height: 100%; background: var(--ink); }

/* about */
.prose { max-width: 760px; }
.prose h2 { margin-top: 30px; }
.prose li { margin: 4px 0; }

/* footer */
.site-footer { border-top: 2px solid var(--ink); background: var(--surface); font-size: 13px; color: var(--muted); }
.footer-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; padding-top: 22px; padding-bottom: 8px; }
.footer-grid strong { color: var(--ink); font-size: 14px; }
.footer-grid p { margin: 6px 0 0; }
.footer-bottom { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 12px; padding-bottom: 20px; border-top: 1px solid var(--line); }

/* modal & toast */
.modal { position: fixed; inset: 0; background: rgba(20, 23, 28, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; width: 100%; max-width: 420px; padding: 20px; border-top: 4px solid var(--ink); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; max-width: calc(100% - 32px); z-index: 60; font-size: 14px; }
.toast.error { background: var(--up); }
.toast[hidden] { display: none; }

/* responsive */
@media (max-width: 860px) {
  .stock-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(2n) { border-right: 0; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .footer-grid { grid-template-columns: 1fr; gap: 14px; }
}
@media (max-width: 640px) {
  .header-row { flex-wrap: wrap; gap: 0 12px; min-height: 0; padding-top: 10px; }
  .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; justify-content: space-between; }
  .nav a { flex: 1; text-align: center; padding: 10px 2px 9px; font-size: 14px; }
  .price-big { font-size: 34px; }
  .hide-sm { display: none; }
  th, td { padding: 8px 6px; }
  .toolbar { grid-template-columns: 1fr; }
  h1 { font-size: 20px; }
}
