:root {
  --bg: #f4f6f5; --card: #ffffff; --ink: #14211c; --sub: #5d6b65; --line: #e3e8e5;
  --brand: #0f7a5c; --brand-soft: #e3f3ed;
  --add: #12805c; --add-bg: #e1f4ec;
  --hold: #2563a8; --hold-bg: #e5eef9;
  --watch: #a06a00; --watch-bg: #fbf1dc;
  --trim: #c2540a; --trim-bg: #fdeadb;
  --exit: #c0262d; --exit-bg: #fbe3e4;
  --up: #12805c; --down: #c0262d;
  --shadow: 0 1px 2px rgba(20,33,28,.06), 0 2px 8px rgba(20,33,28,.04);
  --r: 14px;
  --font: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1513; --card: #16201d; --ink: #e6efeb; --sub: #93a39c; --line: #26332f;
    --brand: #3cc79a; --brand-soft: #173a2f;
    --add: #46c99a; --add-bg: #153a2d; --hold: #6ea8ec; --hold-bg: #172b44;
    --watch: #e2b14a; --watch-bg: #3a2e12; --trim: #f08a45; --trim-bg: #40240f;
    --exit: #f06a70; --exit-bg: #431a1d; --up: #46c99a; --down: #f06a70;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1513; --card: #16201d; --ink: #e6efeb; --sub: #93a39c; --line: #26332f;
  --brand: #3cc79a; --brand-soft: #173a2f;
  --add: #46c99a; --add-bg: #153a2d; --hold: #6ea8ec; --hold-bg: #172b44;
  --watch: #e2b14a; --watch-bg: #3a2e12; --trim: #f08a45; --trim-bg: #40240f;
  --exit: #f06a70; --exit-bg: #431a1d; --up: #46c99a; --down: #f06a70;
  --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); padding: 14px 16px 10px; display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 20px; margin: 0; font-weight: 700; flex: 1; letter-spacing: -.01em; }
.top .logo { width: 28px; height: 28px; border-radius: 8px; }
.back { border: 0; background: var(--card); width: 36px; height: 36px; border-radius: 10px; box-shadow: var(--shadow); font-size: 18px; }
.iconbtn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 7px 12px; font-size: 14px; font-weight: 500; }
.iconbtn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
:root[data-theme="dark"] .iconbtn.primary, .dark-ink { color: #08201a; }

.wrap { padding: 0 16px; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--sub); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--sub); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); } .down { color: var(--down); }

/* summary */
.sum { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.sum .big { font-size: 26px; font-weight: 700; letter-spacing: -.02em; grid-column: 1 / -1; line-height: 1.1; }
.sum .lab { font-size: 12px; color: var(--sub); }
.counts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* run bar */
.runbar { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--sub); margin: 2px 0 12px; }
.runbar .grow { flex: 1; min-width: 0; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--sub); margin-right: 6px; vertical-align: 1px; }
.dot.on { background: var(--brand); }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: sp 0.8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes sp { to { transform: rotate(360deg); } }

/* verdict chip */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.v-ADD { color: var(--add); background: var(--add-bg); }
.v-HOLD { color: var(--hold); background: var(--hold-bg); }
.v-WATCH { color: var(--watch); background: var(--watch-bg); }
.v-TRIM { color: var(--trim); background: var(--trim-bg); }
.v-EXIT { color: var(--exit); background: var(--exit-bg); }
.bar-ADD { background: var(--add); } .bar-HOLD { background: var(--hold); } .bar-WATCH { background: var(--watch); } .bar-TRIM { background: var(--trim); } .bar-EXIT { background: var(--exit); }

/* alerts */
.alert { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--card); box-shadow: var(--shadow); margin-bottom: 8px; border-left: 4px solid var(--brand); }
.alert b { font-weight: 600; }

/* list */
.list { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); text-align: left; width: 100%; border-left: 0; border-right: 0; border-top: 0; background: none; }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--bg); }
.row .sym { font-weight: 700; font-size: 16px; }
.row .nm { font-size: 12px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 210px; }
.row .rt { text-align: right; }
.row .meta { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--sub); }
.row .meta .grow { flex: 1; }
.scorebar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; width: 64px; display: inline-block; vertical-align: middle; }
.scorebar i { display: block; height: 100%; border-radius: 3px; }
.err { color: var(--exit); font-size: 13px; }

.sortbar { display: flex; align-items: center; gap: 6px; margin: 4px 2px 8px; overflow-x: auto; }
.sortbar span { margin-right: 2px; }
.sortbar button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 500; color: var(--sub); white-space: nowrap; }
.sortbar button.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 18px 2px 8px; }
.section-title h2 { font-size: 15px; margin: 0; font-weight: 600; }

/* detail */
.verdict-card { border-radius: var(--r); padding: 16px; margin-bottom: 12px; }
.verdict-card .vbig { font-size: 30px; font-weight: 700; letter-spacing: -.01em; line-height: 1.1; }
.verdict-card .vsub { margin-top: 4px; font-size: 14px; opacity: .9; }
.vgrid { display: flex; gap: 18px; margin-top: 12px; font-size: 13px; }
.vgrid b { display: block; font-size: 17px; }
.reasons { margin: 0; padding-left: 18px; }
.reasons li { margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 14px; }
.kv span:nth-child(odd) { color: var(--sub); }
.parts { display: grid; gap: 8px; }
.part { display: grid; grid-template-columns: 90px 1fr 46px; align-items: center; gap: 10px; font-size: 13px; }
.part .track { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.part .track i { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--sub); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.news { list-style: none; margin: 0; padding: 0; }
.news li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; display: flex; gap: 8px; }
.news li:last-child { border-bottom: 0; }
.imp { width: 20px; flex: none; font-weight: 700; text-align: center; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }

/* picks */
.pick { position: relative; }
.pick .rank { position: absolute; top: 14px; right: 16px; font-size: 12px; color: var(--sub); }
.pick .ph { display: flex; align-items: baseline; gap: 8px; }
.pick .ph .sym { font-weight: 700; font-size: 18px; }
.zone { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; margin: 8px 0; }
.zone b { display: block; font-size: 14px; white-space: nowrap; }

/* table */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: right; font-weight: 500; color: var(--sub); font-size: 12px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
td { text-align: right; padding: 8px 4px; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }

/* settings */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; padding: 8px 4px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--sub); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sw { position: relative; width: 46px; height: 28px; border-radius: 14px; background: var(--line); border: 0; flex: none; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.sw.on { background: var(--brand); }
.sw.on::after { left: 21px; }
code { font-family: var(--mono); font-size: 13px; background: var(--bg); padding: 1px 6px; border-radius: 6px; }

/* tab bar */
.tabs { position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabs .in { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; max-width: 560px; }
.tabs button { border: 0; background: none; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--sub); font-weight: 500; }
.tabs button svg { width: 22px; height: 22px; }
.tabs button.on { color: var(--brand); }

/* sheet */
.veil { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--sub); margin-bottom: 4px; }
.field input { width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
.field input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet .go { width: 100%; padding: 12px; border: 0; border-radius: 12px; background: var(--brand); color: #fff; font-weight: 600; font-size: 16px; }
.sheet .go:disabled { opacity: .6; }
/* "New version available" bar (above the bottom tabs), same as CardPick */
.updbar { position: fixed; left: 12px; right: 12px; bottom: calc(74px + env(safe-area-inset-bottom)); z-index: 25; max-width: 536px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px; background: var(--card); color: var(--ink); border: 1px solid var(--brand); border-radius: 14px;
  padding: 10px 10px 10px 14px; box-shadow: 0 6px 20px rgba(0,0,0,.18); font-size: 13.5px; }
.updbar span { flex: 1; }
.updbar small { color: var(--sub); margin-left: 4px; }
.updbar .updx { border: 0; background: none; color: var(--sub); font-size: 16px; padding: 4px 6px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30; max-width: 90%; }
.disclaimer { font-size: 12px; color: var(--sub); text-align: center; padding: 8px 16px 18px; }
.empty { text-align: center; padding: 28px 16px; color: var(--sub); }
