:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-us: #2a78d6;
  --series-jp: #eb6834;
  --series-fund: #1baf7a;
  --gain: #006300;
  --loss: #d03b3b;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-us: #3987e5;
    --series-jp: #d95926;
    --series-fund: #199e70;
    --gain: #0ca30c;
    --loss: #d03b3b;
    --accent: #3987e5;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
main { max-width: 1080px; margin: 0 auto; padding: 16px 20px 48px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0 16px; flex-wrap: wrap; }
.topbar h1 { font-size: 20px; margin: 0; letter-spacing: 0.02em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.summary { display: grid; grid-template-columns: 320px 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 760px) { .summary { grid-template-columns: 1fr; } }

.donut-card { position: relative; display: flex; flex-direction: column; align-items: center; }
#donut { width: 220px; height: 220px; }
.donut-center {
  position: absolute; top: 16px; width: 220px; height: 220px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none; text-align: center;
}
.hero { font-size: 26px; font-weight: 700; }
.legend { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; align-self: stretch; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend .chip { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .pct { margin-left: auto; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-content: start; }
@media (max-width: 760px) { .tiles { grid-template-columns: 1fr; } }
.tile-value { font-size: 22px; font-weight: 700; margin-top: 4px; }

.table-card { padding: 8px 0 4px; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 12px; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--baseline); }
td { border-bottom: 1px solid var(--grid); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: color-mix(in oklab, var(--text-primary) 4%, transparent); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sym { font-weight: 600; }
.sub { color: var(--muted); font-size: 12px; }
.class-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.class-chip::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--chip-color); }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; padding: 16px; }

.btn {
  font: inherit; border-radius: 8px; padding: 7px 14px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
}
.btn:hover { filter: brightness(0.96); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.icon { padding: 4px 8px; border: none; background: transparent; color: var(--muted); }
.btn.icon:hover { color: var(--text-primary); filter: none; }

.banner {
  margin: 4px 12px 8px; padding: 8px 12px; border-radius: 8px; font-size: 13px;
  background: color-mix(in oklab, var(--loss) 12%, var(--surface-1)); color: var(--text-primary);
}

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: min(320px, 90vw); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card input { font: inherit; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--baseline); background: var(--page); color: var(--text-primary); }
.error { color: var(--loss); font-size: 13px; margin: 0; }

dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 20px;
  background: var(--surface-1); color: var(--text-primary); width: min(440px, 92vw);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin: 0 0 12px; font-size: 17px; }
dialog label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 13px; color: var(--text-secondary); }
dialog input, dialog select {
  font: inherit; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--baseline); background: var(--page); color: var(--text-primary);
}
.hint { font-size: 11px; color: var(--muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.import-preview {
  margin: 12px 0; padding: 10px 12px; border: 1px solid var(--grid); border-radius: 8px;
  max-height: 240px; overflow-y: auto; font-size: 12px;
}
.import-preview .row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.import-preview .row .r-qty { color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
.tooltip .t-title { font-weight: 600; }
.tooltip .t-sub { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
