/* KPJ選股 家人版 — 存摺：薄荷色帳本紙、深藍墨水、紅色印章 */
:root {
  --paper: #e6efeb;
  --sheet: #f5f9f7;
  --rule: #c9dad3;
  --rule-strong: #a9c2b8;
  --ink: #1d2b4f;
  --ink-2: #52607d;
  --seal: #b8322a;
  --seal-press: #962720;
  --on-seal: #fff;
  --ok: #2c6a4e;
  --warn: #8a5d0c;
  --warn-bg: #f6ecd6;
  --focus: #2b62c9;
  --line: 1.8rem;
  --radius-s: 6px;
  --radius-l: 14px;
  --sans: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
  --serif: "Songti TC", "Noto Serif TC", "PMingLiU", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #111a22;
    --sheet: #17222c;
    --rule: #263643;
    --rule-strong: #34495a;
    --ink: #e0e9f1;
    --ink-2: #9db0c2;
    --seal: #d55247;
    --seal-press: #b8433a;
    --ok: #6cc59a;
    --warn: #e2b866;
    --warn-bg: #3a2f17;
    --focus: #7aa7ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #111a22; --sheet: #17222c; --rule: #263643; --rule-strong: #34495a; --ink: #e0e9f1; --ink-2: #9db0c2;
  --seal: #d55247; --seal-press: #b8433a; --ok: #6cc59a; --warn: #e2b866; --warn-bg: #3a2f17; --focus: #7aa7ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; font-size: 100%; }
html[data-font="l"] { font-size: 112.5%; }
html[data-font="xl"] { font-size: 125%; }
html[data-font="xxl"] { font-size: 143.75%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1.0625rem/1.6 var(--sans);
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ── 印章 ── */
.seal {
  display: inline-grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  background: var(--seal);
  color: var(--on-seal);
  font: 700 0.95rem/1 var(--serif);
  letter-spacing: 0.02em;
  box-shadow: inset 0 0 0 3px var(--seal), inset 0 0 0 5px rgba(255, 255, 255, 0.55);
  border: 0;
  padding: 0;
  cursor: pointer;
  flex: none;
}
.seal-lg { width: 5.5rem; height: 5.5rem; font-size: 1.5rem; transform: rotate(-8deg); }

.boot { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 0.5rem; color: var(--ink-2); }

/* ── 版面 ── */
.shell { max-width: 46rem; margin: 0 auto; padding: 0 16px calc(5.5rem + env(safe-area-inset-bottom)); }
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 0.75rem;
  padding: calc(0.6rem + env(safe-area-inset-top)) 0 0.6rem;
  background: var(--paper);
}
.top h1 { margin: 0; font: 700 1.35rem/1.2 var(--serif); flex: 1; }
.top .who { color: var(--ink-2); font-size: 0.9rem; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--sheet);
  border-top: 1px solid var(--rule-strong);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; max-width: 8rem;
  background: none; border: 0;
  padding: 0.55rem 0.2rem 0.5rem;
  color: var(--ink-2);
  font-size: 0.82rem;
  display: grid; justify-items: center; gap: 0.1rem;
  cursor: pointer;
}
.tabs button .ic { font-size: 1.3rem; line-height: 1.2; }
.tabs button[aria-selected="true"] { color: var(--seal); font-weight: 700; }

/* ── 帳頁（引擎的文字放在橫線紙上）── */
.page {
  background-color: var(--sheet);
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--line) - 1px), var(--rule) calc(var(--line) - 1px), var(--rule) var(--line));
  background-position: 0 0.9rem;
  border-left: 3px double var(--rule-strong);
  border-radius: 0 var(--radius-s) var(--radius-s) 0;
  padding: 0.9rem 1rem 0.9rem 1.1rem;
  margin: 0 0 1rem;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: var(--line);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}
.page.empty { color: var(--ink-2); }

.stamp-time {
  display: inline-block;
  border: 1.5px solid var(--seal);
  color: var(--seal);
  border-radius: 4px;
  padding: 0 0.45rem;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  transform: rotate(-2deg);
}

h2 { font: 700 1.2rem/1.3 var(--serif); margin: 1.2rem 0 0.6rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.4rem; }
p.hint, .hint { color: var(--ink-2); font-size: 0.92rem; margin: 0.3rem 0 0.8rem; }

/* ── 控制項 ── */
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 8rem; }
.btn {
  appearance: none;
  border: 1.5px solid var(--ink);
  background: transparent;
  color: var(--ink);
  border-radius: var(--radius-s);
  padding: 0.6rem 1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 2.9rem;
}
.btn.primary { background: var(--seal); border-color: var(--seal); color: var(--on-seal); }
.btn.primary:active { background: var(--seal-press); }
.btn.small { min-height: 2.2rem; padding: 0.25rem 0.7rem; font-size: 0.9rem; }
.btn.quiet { border-color: var(--rule-strong); color: var(--ink-2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.block { width: 100%; }

label.field { display: grid; gap: 0.25rem; margin: 0 0 0.9rem; font-size: 0.95rem; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[inputmode], select {
  width: 100%;
  min-height: 2.9rem;
  padding: 0.5rem 0.7rem;
  border: 1.5px solid var(--rule-strong);
  border-radius: var(--radius-s);
  background: var(--sheet);
}
input:focus { border-color: var(--ink); }

.seg { display: inline-flex; border: 1.5px solid var(--ink); border-radius: var(--radius-s); overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 0.45rem 1rem; min-height: 2.6rem; cursor: pointer; }
.seg button + button { border-left: 1.5px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--sheet); font-weight: 600; }

.choices { display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); margin: 0.6rem 0 1rem; }
.choice {
  text-align: left;
  border: 1.5px solid var(--rule-strong);
  background: var(--sheet);
  border-radius: var(--radius-l);
  padding: 0.8rem 0.9rem;
  cursor: pointer;
}
.choice b { display: block; font-size: 1.05rem; }
.choice span { color: var(--ink-2); font-size: 0.88rem; }
.choice[aria-pressed="true"] { border-color: var(--seal); box-shadow: inset 0 0 0 1px var(--seal); }

.note { border-radius: var(--radius-s); padding: 0.6rem 0.8rem; margin: 0 0 1rem; font-size: 0.95rem; }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.note.ok { border: 1.5px solid var(--ok); color: var(--ok); }
.note.err { border: 1.5px solid var(--seal); color: var(--seal); }

/* 進度 */
.progress { margin: 0.5rem 0 1rem; }
.bar { height: 0.55rem; border-radius: 1rem; background: var(--rule); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--seal); transition: width 0.4s; }
.progress .hint { margin: 0.35rem 0 0; }

/* 持股表 */
table.hold { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin: 0 0 0.8rem; }
table.hold th { text-align: left; font-size: 0.82rem; color: var(--ink-2); font-weight: 600; padding: 0 0.25rem 0.25rem; }
table.hold td { padding: 0.2rem 0.25rem; border-top: 1px solid var(--rule); vertical-align: middle; }
table.hold input { min-height: 2.4rem; padding: 0.3rem 0.45rem; }
table.hold td.nm { font-size: 0.8rem; color: var(--ink-2); }
table.hold .del { border: 0; background: none; color: var(--seal); font-size: 1.2rem; min-width: 2.2rem; cursor: pointer; }
.col-tk { width: 32%; } .col-sh { width: 26%; } .col-ct { width: 30%; } .col-x { width: 12%; }

.thumbs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.4rem 0 0.8rem; }
.thumbs img { width: 4.5rem; height: 6rem; object-fit: cover; border-radius: var(--radius-s); border: 1px solid var(--rule-strong); }

.quota { font-size: 0.9rem; color: var(--ink-2); }
.cash-line { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; padding: 0.5rem 0; border-bottom: 1px solid var(--rule); }
.cash-line b { font-variant-numeric: tabular-nums; }
.cash-line .btn { flex: none; }

/* 管理 */
.person { background: var(--sheet); border-radius: var(--radius-l); padding: 0.8rem 0.9rem; margin: 0 0 0.7rem; border: 1px solid var(--rule); }
.person.pending { border: 1.5px dashed var(--seal); }
.person .head { display: flex; align-items: center; gap: 0.6rem; }
.person .head .meta { flex: 1; min-width: 0; }
.person .head b { font-size: 1.05rem; }
.person .sub { color: var(--ink-2); font-size: 0.85rem; }
.person .use { margin: 0.5rem 0 0.2rem; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.badge { font-size: 0.78rem; border: 1px solid currentColor; border-radius: 1rem; padding: 0 0.45rem; white-space: nowrap; }
.badge.on { color: var(--ok); } .badge.off { color: var(--ink-2); } .badge.wait { color: var(--seal); }
.edit { margin-top: 0.7rem; border-top: 1px solid var(--rule); padding-top: 0.7rem; }
.checks { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; margin: 0.2rem 0 0.8rem; }
.checks label { display: flex; align-items: center; gap: 0.35rem; min-height: 2.2rem; }
.checks input { width: 1.2rem; height: 1.2rem; accent-color: var(--seal); }
.temp-pw { font: 700 1.3rem/1.4 ui-monospace, Menlo, monospace; letter-spacing: 0.06em; user-select: all; }
.log { font-size: 0.85rem; border-collapse: collapse; width: 100%; }
.log td { border-top: 1px solid var(--rule); padding: 0.3rem 0.25rem; vertical-align: top; }
.log td:first-child { white-space: nowrap; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* 登入 */
.gate { min-height: 100dvh; display: grid; align-content: center; max-width: 24rem; margin: 0 auto; padding: 2rem 16px; }
.gate .seal-lg { margin: 0 0 1.2rem; }
.gate h1 { font: 700 1.7rem/1.25 var(--serif); margin: 0 0 0.3rem; }
.gate .switch { background: none; border: 0; color: var(--ink); text-decoration: underline; padding: 0.6rem 0; cursor: pointer; }

/* 底部面板（我的）*/
.sheet-back { position: fixed; inset: 0; background: rgba(10, 20, 30, 0.35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-panel {
  background: var(--sheet); width: 100%; max-width: 46rem; max-height: 88dvh; overflow: auto;
  border-radius: var(--radius-l) var(--radius-l) 0 0;
  padding: 1rem 16px calc(1.2rem + env(safe-area-inset-bottom));
}
.sheet-panel h2:first-child { margin-top: 0.2rem; }

.toast {
  position: fixed; left: 50%; top: calc(0.8rem + env(safe-area-inset-top)); transform: translateX(-50%);
  background: var(--ink); color: var(--sheet); padding: 0.55rem 1rem; border-radius: var(--radius-s);
  z-index: 30; max-width: calc(100% - 32px); font-size: 0.95rem; line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (min-width: 720px) { body { font-size: 1.125rem; } }

/* 戰法說明 */
.doc h3 { font: 700 1.1rem/1.3 var(--serif); margin: 1.4rem 0 0.4rem; padding-top: 0.8rem; border-top: 1px solid var(--rule); }
.doc h3:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.doc .red { color: var(--seal); font-weight: 700; margin: 0.3rem 0; }
