:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --baseline: #c3c2b7;
  --accent: #1c5cab;
  --accent-ink: #ffffff;
  --pos: #006300;
  --neg: #c22f2f;
  --buy-bg: #e3f1e3;
  --sell-bg: #fbe5e3;
  --warn-bg: #fff3d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --ring: rgba(11, 11, 11, 0.10);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --line: #2c2c2a;
    --baseline: #383835;
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --pos: #0ca30c;
    --neg: #e66767;
    --buy-bg: #12301a;
    --sell-bg: #3a1a1a;
    --warn-bg: #3a2f10;
    --series-1: #3987e5;
    --series-2: #d95926;
    --ring: rgba(255, 255, 255, 0.10);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #262624; --ink: #ffffff; --ink-2: #c3c2b7;
  --line: #2c2c2a; --baseline: #383835; --accent: #3987e5; --pos: #0ca30c; --neg: #e66767;
  --buy-bg: #12301a; --sell-bg: #3a1a1a; --warn-bg: #3a2f10; --series-1: #3987e5; --series-2: #d95926;
  --ring: rgba(255, 255, 255, 0.10);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Leelawadee UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 22px; margin: 0; font-weight: 650; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.pad { padding: 16px; }
.err { color: var(--neg); margin: 8px 0; }

.view { max-width: 640px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; gap: 10px; padding: calc(14px + env(safe-area-inset-top)) 0 12px; position: sticky; top: 0; background: var(--page); z-index: 5; }
.top h1 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { font-size: 30px; line-height: 1; padding: 0 8px 4px 0; color: var(--accent); }

.card { background: var(--surface); border-radius: 16px; box-shadow: 0 0 0 1px var(--ring); padding: 16px; margin: 0 0 12px; }
.card-h { font-weight: 650; margin-bottom: 8px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.kicker { color: var(--ink-2); font-size: 14px; }
.hero { font-size: 34px; font-weight: 650; line-height: 1.2; margin: 2px 0; overflow-wrap: anywhere; }
.hero small { font-size: 15px; color: var(--muted); font-weight: 400; }
.sub { color: var(--ink-2); font-size: 14px; }
.badge { font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--ink-2); border-radius: 99px; padding: 1px 8px; }
.badge.neg { background: var(--sell-bg); color: var(--neg); }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.foot { text-align: center; font-size: 13px; }

.banner { display: block; border-radius: 12px; padding: 10px 14px; margin: 0 0 12px; font-size: 14px; }
.banner.warn { background: var(--warn-bg); }
.banner.neg { background: var(--sell-bg); color: var(--neg); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.chip { flex: none; padding: 6px 16px; border-radius: 99px; background: var(--surface); box-shadow: 0 0 0 1px var(--ring); font-size: 15px; }
.chip.on { background: var(--ink); color: var(--page); box-shadow: none; }

.mrow { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: baseline; padding: 10px 0; border-top: 1px solid var(--line); }
.mrow .num { color: var(--muted); font-size: 13px; }
.mrow .lbl { color: var(--ink-2); }
.mrow .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 550; }
.mrow .val small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.mrow.strong .lbl { color: var(--ink); font-weight: 600; }
.mrow.strong .val { font-weight: 700; }
.mrow.minor { font-size: 14px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.stats div { display: flex; flex-direction: column; min-width: 0; }
.stats span { font-size: 13px; color: var(--ink-2); }
.stats b { font-size: 18px; font-weight: 650; overflow-wrap: anywhere; }
.stats.compact { grid-template-columns: 1fr 1fr 1fr; margin-bottom: 12px; }
.stats.compact b { font-size: 16px; }

.list-h { display: flex; justify-content: space-between; font-weight: 600; margin: 16px 2px 8px; font-size: 15px; }
.list-h .muted { font-weight: 400; font-size: 13px; }
.list { padding: 0 16px; }
.list > .item, .list > .stock { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 0; border-top: 1px solid var(--line); min-height: 56px; }
.list > :first-child { border-top: 0; }
.card.list > .item:active, .card.list > .stock:active { background: var(--surface-2); }
.sym { font-weight: 650; font-size: 17px; }
.right { text-align: right; font-variant-numeric: tabular-nums; flex: none; }
.small { font-size: 13px; }
.item .muted, .stock .muted { font-size: 13px; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 6px; padding: 0 6px; margin-right: 4px; }
.tag.buy { background: var(--buy-bg); color: var(--pos); }
.tag.sell { background: var(--sell-bg); color: var(--neg); }
details.sold summary { cursor: pointer; padding: 12px 2px; color: var(--ink-2); font-weight: 600; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; margin: 4px 0 12px; }
.seg a { flex: 1; text-align: center; padding: 8px; border-radius: 10px; font-size: 15px; color: var(--ink-2); }
.seg a.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--ring); }

.btn { display: inline-flex; justify-content: center; align-items: center; gap: 6px; min-height: 46px; padding: 10px 16px; border-radius: 12px; border: 0;
  background: var(--surface-2); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-align: center; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--neg); box-shadow: inset 0 0 0 1px var(--line); }
.btn.buy { background: var(--buy-bg); color: var(--pos); }
.btn.sell { background: var(--sell-bg); color: var(--neg); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; background: var(--surface); box-shadow: 0 0 0 1px var(--ring); }
.btn.block { display: flex; width: 100%; margin-top: 10px; }
.btn:active { filter: brightness(0.94); }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 12px; }
.row-btns > * { flex: 1 1 0; }
.row-btns.three > * { min-width: 0; }
.card .row-btns { margin-bottom: 0; }
.filebtn { cursor: pointer; }

.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu-btn { background: var(--surface); box-shadow: 0 0 0 1px var(--ring); border-radius: 16px; padding: 18px 14px; min-height: 96px; display: flex; flex-direction: column; justify-content: flex-end; }
.menu-btn b { font-size: 17px; }
.menu-btn span { font-size: 13px; color: var(--muted); }
.menu-btn.buy { background: var(--buy-bg); box-shadow: none; }
.menu-btn.buy b { color: var(--pos); }
.menu-btn.sell { background: var(--sell-bg); box-shadow: none; }
.menu-btn.sell b { color: var(--neg); }

.form .fld { display: block; margin-bottom: 14px; }
.form .fld > span { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 4px; }
.form input { width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--page); color: var(--ink); font: inherit; font-size: 17px; }
.form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.hint { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.infobox { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; color: var(--ink-2); }
.infobox[hidden] { display: none; }
.infobox b { color: var(--ink); }
.infobox b.pos { color: var(--pos); }
.infobox b.neg { color: var(--neg); }
.warns { margin: 0; padding-left: 18px; font-size: 14px; color: var(--ink-2); }
.warns li { margin-bottom: 4px; }

.table-wrap { overflow-x: auto; margin: 8px -16px 0; padding: 0 16px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl th { text-align: right; font-weight: 500; color: var(--muted); padding: 6px 4px; border-bottom: 1px solid var(--line); }
.tbl td { text-align: right; padding: 7px 4px; border-bottom: 1px solid var(--line); }
.tbl th:first-child, .tbl td:first-child { text-align: left; }

/* chart */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .s1 { fill: var(--series-1); }
.chart .s2 { fill: var(--series-2); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .grp.dim path { opacity: 0.35; }
.chart .base { stroke: var(--baseline); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.legend .muted { font-size: 12px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.sw.s1 { background: var(--series-1); }
.sw.s2 { background: var(--series-2); }
.tip { display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: 13px; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; margin-top: 6px; color: var(--ink-2); }
.tip[hidden] { display: none; }
.tip b { color: var(--ink); }

/* bottom tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; background: var(--surface);
  box-shadow: 0 -1px 0 var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 10; }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); padding: 4px 0; max-width: 120px; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on { color: var(--accent); }
.tabbar a.add svg { background: var(--accent); color: var(--accent-ink); border-radius: 10px; width: 36px; height: 28px; padding: 3px 9px; }

#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 12px; font-size: 14px; transition: 0.2s; max-width: calc(100% - 32px); z-index: 20; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.lock { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.lock .card { width: 100%; max-width: 340px; text-align: center; }
.lock input { width: 100%; font-size: 28px; text-align: center; letter-spacing: 8px; min-height: 56px; border-radius: 12px; border: 1px solid var(--line); background: var(--page); color: var(--ink); margin: 8px 0; }
.empty .big { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
