:root {
  color-scheme: light;
  --bg: #f5f5f2;
  --surface: #fcfcfb;
  --surface-2: #efeeea;
  --border: #dddcd6;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #75746f;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #1d7a3e;
  --good-bg: #e3f3e8;
  --warn: #8a5a00;
  --warn-bg: #fbf0d6;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --neutral-bg: #ecebe6;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06);
  --gold: #8a6a2a;
  --gold-soft: rgb(138 106 42 / 0.14);
  --hero-bg: linear-gradient(160deg, #fffdf7 0%, var(--surface) 60%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #34332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #9a998f;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good: #6fcf8e;
    --good-bg: #173322;
    --warn: #f0c060;
    --warn-bg: #3a2e12;
    --bad: #ff8a80;
    --bad-bg: #3d1a18;
    --neutral-bg: #2a2a27;
    --shadow: none;
    --gold: #d4b26a;
    --gold-soft: rgb(212 178 106 / 0.14);
    --hero-bg: linear-gradient(160deg, #24221c 0%, #1a1a19 55%, #161615 100%);
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1a19;
  --surface-2: #242422;
  --border: #34332f;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #9a998f;
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --good: #6fcf8e;
  --good-bg: #173322;
  --warn: #f0c060;
  --warn-bg: #3a2e12;
  --bad: #ff8a80;
  --bad-bg: #3d1a18;
  --neutral-bg: #2a2a27;
  --shadow: none;
  --gold: #d4b26a;
  --gold-soft: rgb(212 178 106 / 0.14);
  --hero-bg: linear-gradient(160deg, #24221c 0%, #1a1a19 55%, #161615 100%);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
.num { font-variant-numeric: tabular-nums; }

/* ---------- レイアウト ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  padding: calc(env(safe-area-inset-top) + 10px) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { font-weight: 800; letter-spacing: 0.02em; font-size: 17px; }
.brand small { font-weight: 600; color: var(--text-3); font-size: 11px; margin-left: 6px; }
.paper-badge {
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: var(--warn-bg); color: var(--warn); white-space: nowrap;
}
main {
  max-width: 760px; margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  appearance: none; border: 0; background: none; color: var(--text-3);
  min-height: 60px; font: inherit; font-size: 11px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  cursor: pointer;
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button[aria-current='page'] { color: var(--accent); }

section[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 0 0 6px; }
p { margin: 0 0 8px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.xsmall { font-size: 12px; color: var(--text-3); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 520px) { .grid-3 .stat { padding: 8px; } .grid-3 .stat .value { font-size: 15px; } }
.nowrap { flex-wrap: nowrap; }
.kind { display: inline-block; font-size: 11px; font-weight: 800; padding: 1px 7px; border-radius: 6px; vertical-align: middle; margin-left: 2px; }
.kind.virtual { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.kind.estimate { background: var(--warn-bg); color: var(--warn); }
.kind.real { background: var(--good-bg); color: var(--good); }
.kind.proxy { background: var(--neutral-bg); color: var(--text-2); }
button.term { appearance: none; border: 0; background: none; padding: 0; font: inherit; color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; cursor: help; }
.tip-sheet { position: fixed; left: 12px; right: 12px; bottom: calc(68px + env(safe-area-inset-bottom)); z-index: 30; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; box-shadow: 0 8px 30px rgb(0 0 0 / 0.2); max-width: 736px; margin: 0 auto; }
input.file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
label.btn { display: inline-flex; align-items: center; justify-content: center; position: relative; }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.small-btn { min-height: 40px; font-size: 13px; padding: 0 12px; }
dd a, p a { color: var(--accent); }

/* ---------- 数値タイル ---------- */
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat .label { font-size: 12px; color: var(--text-2); }
.stat .value { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .value.big { font-size: 28px; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* ---------- 入力 ---------- */
label.field { display: block; font-size: 13px; color: var(--text-2); font-weight: 600; margin-bottom: 4px; }
input, select, button { font: inherit; }
input[type='text'], input[type='password'], select {
  width: 100%; min-height: 48px; font-size: 16px; /* iOS Safariの自動ズーム防止 */
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.amount-input { display: grid; grid-template-columns: 52px 1fr 52px; gap: 8px; align-items: center; }
.amount-input input { text-align: center; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  min-height: 48px; min-width: 48px; padding: 0 16px; border-radius: 12px; font-weight: 700; cursor: pointer;
  touch-action: manipulation;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.block { width: 100%; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); min-height: 44px; padding: 0 14px; border-radius: 999px; font-weight: 600; font-size: 14px; cursor: pointer;
}
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 4px; }
.segmented button {
  appearance: none; border: 0; background: none; min-height: 44px; border-radius: 9px;
  font-weight: 700; font-size: 14px; color: var(--text-2); cursor: pointer;
}
.segmented button[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }

/* ---------- バッジ・注意 ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 800; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warning { background: var(--warn-bg); color: var(--warn); }
.badge.critical { background: var(--bad-bg); color: var(--bad); }
.badge.neutral { background: var(--neutral-bg); color: var(--text-2); }
.notice { border-radius: 12px; padding: 12px 14px; font-size: 13px; line-height: 1.6; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.info { background: var(--surface-2); color: var(--text-2); }
.notice strong { color: inherit; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.s1 { background: var(--series-1); }
.dot.s2 { background: var(--series-2); }
.dot.s3 { background: var(--series-3); }

/* ---------- 表 ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
td .row { flex-wrap: nowrap; gap: 6px; }
th { font-size: 12px; color: var(--text-2); font-weight: 600; }

/* ---------- 比較カード ---------- */
.fund-result .head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.fund-result .head h3 { margin: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- チャート ---------- */
.chart { position: relative; width: 100%; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart .axis text { fill: var(--text-3); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.s1 { stroke: var(--series-1); }
.chart .line.s2 { stroke: var(--series-2); }
.chart .line.s3 { stroke: var(--series-3); }
.chart .line.ref { stroke: var(--text-3); stroke-dasharray: 4 4; stroke-width: 1.5; }
.chart .cross { stroke: var(--text-3); stroke-width: 1; }
.chart .marker { stroke: var(--surface); stroke-width: 2; }
.chart .marker.s1 { fill: var(--series-1); }
.chart .marker.s2 { fill: var(--series-2); }
.chart .marker.s3 { fill: var(--series-3); }
.chart .range-bar { stroke-width: 8; stroke-linecap: round; opacity: 0.35; }
.chart .range-bar.s1 { stroke: var(--series-1); }
.chart .range-bar.s2 { stroke: var(--series-2); }
.chart .range-bar.s3 { stroke: var(--series-3); }
.chart .baseline { stroke: var(--text-2); stroke-width: 1.5; }
.chart .label { fill: var(--text-2); font-size: 12px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 10px; font-size: 12px; box-shadow: 0 4px 16px rgb(0 0 0 / 0.15);
  white-space: nowrap; font-variant-numeric: tabular-nums; transform: translate(-50%, -110%);
}
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--text-2); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

details { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; }
summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--text-2); min-height: 32px; }
ul.reasons { padding-left: 18px; margin: 6px 0; font-size: 14px; }
ul.reasons li + li { margin-top: 4px; }
.log { max-height: 280px; overflow-y: auto; font-size: 13px; -webkit-overflow-scrolling: touch; }
.log div { padding: 6px 0; border-bottom: 1px solid var(--border); }
.log time { color: var(--text-3); margin-right: 8px; font-variant-numeric: tabular-nums; }
.loading { color: var(--text-3); font-size: 14px; }

/* ---------- ログイン ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left)); }
.login-card { width: 100%; max-width: 380px; }
.error-text { color: var(--bad); font-size: 14px; min-height: 22px; }

.pct-val { min-width: 3.2em; text-align: center; font-variant-numeric: tabular-nums; }
.wbtn { min-width: 48px; min-height: 44px; padding: 0; font-size: 20px; }
.steps { padding-left: 1.3em; margin: 0; }
.steps li { margin-bottom: 6px; }

/* ---------- v0.5 初心者モード ---------- */
html[data-mode='beginner'] .tabbar button[data-modes='detail'],
html[data-mode='detail'] .tabbar button[data-modes='beginner'] { display: none; }
html[data-mode='beginner'] .lbl-detail, html:not([data-mode='beginner']) .lbl-beginner { display: none; }
.brand small { color: var(--gold); }
.header-right { display: flex; align-items: center; gap: 8px; }
.mode-toggle {
  appearance: none; border: 1px solid var(--gold); background: var(--gold-soft); color: var(--gold);
  font-size: 12px; font-weight: 800; min-height: 36px; padding: 0 12px; border-radius: 999px; cursor: pointer; touch-action: manipulation;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.lead { font-size: 17px; font-weight: 700; line-height: 1.5; margin: 0; }
.plain { color: var(--text); line-height: 1.75; }
.guarantee { border-left: 3px solid var(--warn); padding-left: 8px; }
.btn.big { min-height: 56px; font-size: 17px; }

/* データの状態 */
.status-bar { border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; margin: 0 0 14px; background: var(--surface); }
.status-bar > summary { list-style: none; display: flex; flex-direction: column; gap: 4px; min-height: 44px; justify-content: center; color: var(--text); }
.status-bar > summary::-webkit-details-marker { display: none; }
.status-bar > summary::after { content: '詳しく ▾'; font-size: 11px; color: var(--text-3); align-self: flex-end; margin-top: -18px; }
.status-bar[open] > summary::after { content: '閉じる ▴'; }
.status-bar > div { margin-top: 10px; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 800; padding: 3px 10px; border-radius: 999px; align-self: flex-start; }
.status-text { font-size: 12px; color: var(--text-2); font-weight: 400; padding-right: 52px; }
.status-bar.ok { border-color: color-mix(in srgb, var(--good) 45%, var(--border)); }
.status-bar.ok .status-pill { background: var(--good-bg); color: var(--good); }
.status-bar.pending { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }
.status-bar.pending .status-pill { background: var(--warn-bg); color: var(--warn); }
.status-bar.error { border-color: color-mix(in srgb, var(--bad) 55%, var(--border)); }
.status-bar.error .status-pill { background: var(--bad-bg); color: var(--bad); }
.status-bar.loading .status-pill { background: var(--neutral-bg); color: var(--text-2); }

/* ヒーロー（ホーム・診断結果） */
.card.hero { background: var(--hero-bg); border-color: color-mix(in srgb, var(--gold) 35%, var(--border)); }
.hero-title { font-size: 22px; font-weight: 800; letter-spacing: 0.01em; }
.hero-num { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* 元本・予想利益・予想損失 */
.money3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.m-cell { background: var(--surface-2); border-radius: 12px; padding: 10px; min-width: 0; }
.m-cell .label { font-size: 11px; color: var(--text-2); line-height: 1.4; }
.m-cell .value { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.3; margin-top: 2px; }
.m-cell button.term { font-size: 11px; }
tr.hl td { background: var(--gold-soft); font-weight: 700; }

/* 診断 */
.progress { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
.progress span { height: 6px; border-radius: 3px; background: var(--surface-2); }
.progress span.on { background: var(--gold); }
.options { display: grid; gap: 10px; }
.option {
  appearance: none; text-align: left; min-height: 60px; padding: 12px 16px; border-radius: 14px; font: inherit; font-size: 16px; font-weight: 700;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; touch-action: manipulation;
}
.option[aria-pressed='true'] { border-color: var(--gold); background: var(--gold-soft); }
.option:active { transform: scale(0.99); }
.compare3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.c-col { border: 1px solid var(--border); border-radius: 12px; padding: 10px; min-width: 0; }
.c-col.pick { border-color: var(--gold); background: var(--gold-soft); }
.c-name { font-weight: 800; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
@media (max-width: 560px) {
  .compare3 { grid-template-columns: 1fr; }
}

/* グラフの帯 */
.chart .band { fill: var(--series-1); opacity: 0.16; stroke: none; }
.swatch.band { display: inline-block; width: 14px; height: 10px; border-radius: 3px; background: color-mix(in srgb, var(--series-1) 30%, transparent); }

/* もっと詳しく */
details.more { padding: 12px 16px; }
details.more > summary { min-height: 44px; display: flex; align-items: center; font-size: 15px; color: var(--text); }
details.more[open] > summary { margin-bottom: 8px; }
details.term-row summary { font-size: 14px; color: var(--text); font-weight: 400; }
table.compact { font-size: 13px; }
table.compact th, table.compact td { padding: 7px 4px; }
.money3.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
