:root {
  color-scheme: light;
  --paper: #e7e0d2;
  --card: #fbf7ef;
  --ink: #1c2822;
  --muted: #667069;
  --line: #e4d8c6;
  --green: #1d6b4f;
  --green-deep: #16382c;
  --red: #9c4036;
  --amber: #8a5a12;
  --ok: #e7f3ec;
  --err: #f8e8e4;
  --dup: #f8efd8;
  --shadow: 0 18px 50px rgba(48, 38, 22, 0.08);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 400px at 50% -10%, rgba(255, 255, 255, 0.7), transparent 60%),
    var(--paper);
  color: var(--ink);
}

.app {
  width: min(100%, 560px);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--card);
  box-shadow: var(--shadow);
  position: relative;
  display: flex;
  flex-direction: column;
}

.top {
  padding:
    calc(18px + env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    8px
    max(20px, env(safe-area-inset-left));
}

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--green-deep);
  font-size: 13px;
  letter-spacing: 0.14em;
}

.chop {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--red);
  color: var(--red);
  font-size: 13px;
  letter-spacing: 0;
}

h1 {
  margin: 6px 0 0;
  font-size: 32px;
  font-weight: 620;
  letter-spacing: -0.03em;
}

h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 13px; margin: 8px 0 4px; color: var(--muted); font-weight: 600; }

.main {
  flex: 1 0 auto;
  min-width: 0;
  padding:
    8px
    max(20px, env(safe-area-inset-right))
    calc(88px + env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
}

.lede, .hint, .muted { color: var(--muted); }
.lede { margin-top: 0; line-height: 1.55; }
.hint { display: block; margin-top: 4px; font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }
.ok-text { color: var(--green); margin: 0; }
.neg { color: var(--red); }
.pos { color: var(--green); }
.warn-line { color: var(--amber); }

.hero {
  background: var(--green-deep);
  color: #f6f1e6;
  border-radius: 22px;
  padding: 18px 18px 14px;
  margin-bottom: 14px;
  container-type: inline-size;
}

.hero .muted, .hero .eyebrow { color: rgba(246, 241, 230, 0.72); }
.hero-top, .row { display: flex; align-items: center; gap: 8px; }
.hero-top { justify-content: space-between; }
.eyebrow { margin: 0; font-size: 13px; }
.net {
  margin: 8px 0 12px;
  max-width: 100%;
  font-size: clamp(18px, 8.2cqi, 40px);
  letter-spacing: -0.03em;
  line-height: 1.05;
  white-space: nowrap;
}
.hero .text-btn { color: #f6f1e6; }

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px 16px;
  margin: 0;
}
.split dt { color: rgba(246, 241, 230, 0.68); font-size: 12px; }
.card .split dt { color: var(--muted); }
.split dd { margin: 2px 0 0; font-size: 16px; overflow-wrap: anywhere; }

.card {
  padding: 14px 0 6px;
  border-top: 1px solid var(--line);
}

.acct {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, max-content);
  gap: 2px 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.acct-name { margin: 0; font-weight: 600; }
.acct p { margin: 0; }
.acct .muted { margin-top: 2px; font-size: 12px; }
.acct-amt { text-align: right; min-width: 0; max-width: 62%; }
.acct-amt .num { overflow-wrap: anywhere; }
.acct-amt .num { margin: 0; }
.voided { opacity: 0.55; }
.voided .acct-name { text-decoration: line-through; }

.bars { display: grid; gap: 8px; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(0, 4.6rem) minmax(0, 1fr) minmax(0, max-content);
  gap: 8px;
  align-items: center;
  font-size: 13px;
}
.bar-row > :last-child { justify-self: end; min-width: 0; overflow-wrap: anywhere; text-align: right; }
.track { display: block; height: 8px; background: #efe6d6; border-radius: 99px; overflow: hidden; }
.fill { display: block; height: 100%; border-radius: 99px; }
.fill.expense { background: var(--red); }
.fill.income { background: var(--green); }

.plain { list-style: none; margin: 0; padding: 0; }
.plain li { padding: 8px 0; border-top: 1px solid var(--line); line-height: 1.45; }
.plain.warn li { color: var(--amber); }
.day { margin: 16px 0 0; }

.stack { display: grid; gap: 12px; }
.inset {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fffdf8;
}
.row { flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.row.tight { justify-content: flex-end; gap: 10px; margin-top: 6px; }

.field { display: grid; gap: 6px; }
.field-label { font-size: 13px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid #d9cdb8;
  background: #fffdf8;
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;
}
textarea { min-height: 88px; resize: vertical; }
input:read-only { background: #f3eee4; }

.btn, .text-btn {
  font: inherit;
  cursor: pointer;
}
.btn {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--green-deep);
  background: transparent;
  color: var(--green-deep);
  padding: 10px 14px;
}
.btn.primary { background: var(--green-deep); color: #f6f1e6; }
.btn.danger { background: var(--red); border-color: var(--red); color: white; }
.btn.ghost { border-color: transparent; }
.btn:disabled { opacity: 0.6; }
.text-btn {
  border: 0;
  background: transparent;
  color: var(--green);
  padding: 0 8px;
  min-height: 44px;
}
.text-btn.danger { color: var(--red); }
.text-btn[aria-pressed="true"] { font-weight: 700; color: var(--ink); }

.seg.two { grid-template-columns: 1fr 1fr; }
.seg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  background: #f3eee4;
  border-radius: 14px;
}
.seg button, .seg-btn {
  min-height: 44px;
  border: 0;
  background: transparent;
  border-radius: 10px;
  font: inherit;
  color: var(--muted);
}
.seg button[aria-selected="true"], .seg-btn[aria-pressed="true"] {
  background: white;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(28, 40, 34, 0.08);
}

.check { display: flex; gap: 10px; align-items: center; min-height: 44px; }
.check input { width: 22px; height: 22px; min-height: 22px; }

.preview {
  margin: 0;
  padding: 10px 12px;
  background: #f6f1e6;
  border-radius: 12px;
  min-height: 20px;
}

.banner {
  border-radius: 14px;
  padding: 12px 14px;
  display: grid;
  gap: 4px;
}
.banner p { margin: 0; }
.banner.ok { background: var(--ok); }
.banner.err { background: var(--err); }
.banner.dup { background: var(--dup); }

.offline {
  margin: 0;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--dup);
  color: var(--amber);
  text-align: center;
  font-size: 14px;
}

.quick {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 14px;
}
.quick .btn { padding: 10px 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fffdf8;
  padding: 8px 14px;
  font: inherit;
  color: var(--ink);
}

.nav {
  position: sticky;
  bottom: 0;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  background: rgba(251, 247, 239, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding:
    6px
    max(8px, env(safe-area-inset-right))
    calc(6px + env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
  z-index: 2;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  flex: 1 0 4.25rem;
  text-decoration: none;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.15;
  min-height: 48px;
  padding: 4px 2px 0;
  white-space: nowrap;
}
.nav a.on { color: var(--green-deep); font-weight: 650; }
.nav svg { width: 20px; height: 20px; }

dialog.sheet {
  width: min(560px, 100%);
  max-height: min(88dvh, 720px);
  overflow: auto;
  margin: auto auto 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  padding:
    18px
    max(18px, env(safe-area-inset-right))
    calc(18px + env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  background: var(--card);
  color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(22, 32, 28, 0.45); }

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

@media (min-width: 720px) {
  body { padding: 28px 0; }
  .app { min-height: calc(100dvh - 56px); border-radius: 28px; overflow: clip; }
  .nav { border-radius: 0 0 28px 28px; }
  dialog.sheet { margin: auto; border-radius: 20px; }
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.metric {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.metric .k { margin: 0; color: var(--muted); font-size: 12px; }
.metric .v { margin: 4px 0 0; font-size: 20px; letter-spacing: -0.03em; overflow-wrap: anywhere; }
.up { color: var(--green); }
.down { color: var(--red); }
.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 99px; margin-right: 4px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 99px;
  background: var(--dup);
  color: var(--amber);
  font-size: 12px;
}
.alloc { display: grid; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.alloc-top { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.alloc-top strong { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.alloc-track { position: relative; height: 10px; background: #efe6d6; border-radius: 99px; }
.alloc-fill { display: block; height: 100%; border-radius: 99px; background: var(--green); }
.alloc-target { position: absolute; top: -3px; width: 2px; height: 16px; background: #1f2a5c; }

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}

.tw-up { color: var(--red); }
.tw-down { color: var(--green); }
.banner.info { background: #eef2f8; }

.group-head {
  width: 100%;
  min-height: 44px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 8px;
  align-items: center;
  text-align: left;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line);
  padding: 10px 0;
  font: inherit;
  color: inherit;
}
.group-sub { grid-column: 1 / -1; font-size: 12px; overflow-wrap: anywhere; }
.group-body { padding-left: 8px; }

.quote-row {
  width: 100%;
  min-width: 0;
  display: grid;
  gap: 4px;
  text-align: left;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line);
  padding: 10px 0;
  font: inherit;
  color: inherit;
}
.quote-top, .quote-sub { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-width: 0; }
.quote-name { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; }
.tag.stale { background: var(--err); color: var(--red); flex: 0 0 auto; }
.tag.mini { min-height: 18px; padding: 0 6px; font-size: 11px; }
.tag.basis-intraday { background: #e7eaf4; color: #1f2a5c; }
.tag.basis-estimate { background: #efe6d6; color: var(--muted); }
.tag.basis-manual { background: var(--dup); color: var(--amber); }
.valuation-line { margin: 0 0 4px; font-size: 12px; line-height: 1.4; }
.hero .valuation-line { color: rgba(246, 241, 230, 0.84); }
.hero .valuation-line.estimate { color: #f6e7c3; }
.quote-stale { font-size: 12px; overflow-wrap: anywhere; }
.quote-top strong, .quote-sub span { min-width: 0; overflow-wrap: anywhere; }
.quote-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
  font-size: 12px;
}
.quote-metrics .num { overflow-wrap: anywhere; }
.spark { width: 64px; height: 24px; flex: 0 0 auto; }
.price-canvas { width: 100%; height: 220px; display: block; }
.levels { margin-top: 12px; }
.levels h3 { margin: 0 0 4px; font-size: 16px; }
.level-summary { margin: 0 0 8px; line-height: 1.45; overflow-wrap: anywhere; }
.level-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.level-table caption.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.level-table th,
.level-table td { padding: 6px 4px; text-align: left; vertical-align: baseline; }
.level-table thead th:nth-child(2),
.level-table thead th:nth-child(3),
.level-table td.num { text-align: right; white-space: nowrap; }
.level-table thead th:first-child { width: 32%; }
.level-now th,
.level-now td { background: var(--dup); }
.level-note td { color: var(--muted); font-size: 13px; line-height: 1.45; padding-top: 0; overflow-wrap: anywhere; }
.gauge {
  height: 10px;
  border-radius: 99px;
  background: #efe6d6;
  overflow: hidden;
}
.gauge-fill {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--green), var(--amber), var(--red));
}
.plan-track p, .dca-item p, .alert p, .alert strong, .rule p, .decision p, .card-row p, .paper-sleeve p { overflow-wrap: anywhere; }
.estimate { color: var(--muted); }
.swr { margin: 0 0 8px; }
.hero .day-change { margin: 0 0 8px; color: #f6f1e6; }
.hero .day-change.down { color: #f3c7c0; }
.hero .day-change.up { color: #d7f0e4; }
.path { margin: 0 0 12px; }
.path-label { margin: 0 0 4px; font-size: 12px; color: rgba(246, 241, 230, 0.84); }
.path-track { height: 10px; border-radius: 99px; background: rgba(255, 255, 255, 0.22); overflow: hidden; }
.path-fill { display: block; height: 100%; background: #f6f1e6; }
.decision { padding: 8px 0; border-top: 1px solid var(--line); min-width: 0; }
.decision p { margin: 0; }
.decision-exit_line { border-left: 3px solid var(--red); padding-left: 8px; }
.decision-dca_paused { border-left: 3px solid var(--amber); padding-left: 8px; }
.decision-stale_quote { border-left: 3px solid var(--muted); padding-left: 8px; }
.card.paper { background: #f7f1e4; border: 1px dashed #8a5a12; }
.paper-banner { margin-bottom: 8px; }
.paper-compare { margin: 8px 0; }
.paper-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; margin: 6px 0; }
.paper-metrics p { margin: 0; }
.paper-sleeve { padding: 10px 0; border-top: 1px dashed var(--line); }
.paper-sleeve h3 { margin: 0 0 4px; color: var(--ink); }
.paper-checks { margin: 6px 0; padding: 0; list-style: none; }
.paper-checks li { margin: 2px 0; }
.paper-pos { margin: 6px 0 0; }
.paper-pos summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
.dca-item { min-width: 0; }
.dca-item .btn { width: 100%; margin: 0 0 8px; }
.dca-item .acct-amt, .plan-track .acct-amt {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.alert {
  padding: 10px 0 10px 8px;
  border-top: 1px solid var(--line);
  min-width: 0;
}
.alert p { margin: 0; }
.alert-red { border-left: 3px solid var(--red); }
.alert-amber { border-left: 3px solid var(--amber); }
.alert-watch { border-left: 3px solid #1f2a5c; }
.alert-upcoming { border-left: 3px solid #3d6b8a; }
.alert-info { border-left: 3px solid var(--green); }
.tag.alert-red, .tag.dca-paused_by_brake { background: var(--err); color: var(--red); }
.tag.alert-amber, .tag.dca-pending { background: var(--dup); color: var(--amber); }
.tag.alert-watch { background: #e7eaf4; color: #1f2a5c; }
.tag.alert-upcoming { background: #e5f0f5; color: #24566e; }
.tag.alert-info, .tag.dca-debited { background: var(--ok); color: var(--green-deep); }
.rule { padding: 8px 0; border-top: 1px solid var(--line); min-width: 0; }
.rule p { margin: 0; }

.fund-card, .look-row { border-top: 1px solid var(--line); padding: 4px 0; }
.fund-card summary, .look-row summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  cursor: pointer;
}
.fund-name { font-weight: 650; }
.weight-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 4px 8px;
  align-items: center;
  margin: 6px 0;
}
.weight-name { min-width: 0; overflow-wrap: anywhere; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.weight-track {
  grid-column: 1 / -1;
  height: 8px;
  background: #efe6d6;
  border-radius: 99px;
  overflow: hidden;
}
.weight-fill { display: block; height: 100%; background: var(--green); }
.hscroll, .md-table { overflow-x: auto; max-width: 100%; width: 100%; min-width: 0; }
.rotation { width: 100%; border-collapse: collapse; min-width: 36rem; }
.rotation th, .rotation td { padding: 8px 6px; text-align: left; vertical-align: top; border-top: 1px solid var(--line); }
.rotation-week th { background: #f6f1e6; }
.rotation-current { background: var(--dup); }
.rotation tr { cursor: pointer; }
.report-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.report-list h3 { flex: 1 0 100%; margin: 8px 0 0; }
.md { overflow-wrap: anywhere; line-height: 1.55; }
.md table { border-collapse: collapse; min-width: 28rem; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.md pre { overflow-x: auto; }
.research-foot {
  position: sticky;
  bottom: calc(64px + env(safe-area-inset-bottom));
  margin: 12px 0 0;
  padding: 8px 10px;
  background: rgba(251, 247, 239, 0.96);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  z-index: 1;
}
.cross-row { padding: 8px 0; border-top: 1px solid var(--line); }
.cross-row h3, .fund-card h3, .look-row + h3 { margin: 8px 0 4px; font-size: 16px; }
