/* Layout: 1カラムのスマホ画面。夜に開くアプリなので、結論カードだけ「夜空」の色で強調し、他は静かな紙面に置く。 */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eaeef3;
  --line: #d8dee6;
  --fg: #142030;
  --fg-2: #4a5768;
  --muted: #6b778a;
  --night: #16233a;
  --night-2: #22324f;
  --night-fg: #f2f5fb;
  --night-muted: #aab6cc;
  --sun: #e8912b;
  --accent: #1f6fbf;
  --accent-soft: #e2edf9;
  --good: #1a7f4e;
  --good-soft: #e1f3e9;
  --warn: #9a5b00;
  --warn-soft: #fbefd9;
  --bad: #b3261e;
  --bad-soft: #fbe4e2;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --grid: #e3e8ee;
  --shadow: 0 1px 2px rgba(20, 32, 48, .06), 0 4px 16px rgba(20, 32, 48, .05);
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
  --font-num: "Outfit", "Zen Kaku Gothic New", system-ui, sans-serif;
  --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1620; --surface: #17212d; --surface-2: #1f2b39; --line: #2c3a4b;
    --fg: #e8edf4; --fg-2: #b9c4d2; --muted: #8b98aa;
    --night: #1b2a45; --night-2: #26385a; --night-fg: #f2f5fb; --night-muted: #a9b6cd;
    --sun: #f0a043; --accent: #5aa2ec; --accent-soft: #1d3149;
    --good: #4cc38a; --good-soft: #163428; --warn: #f0b456; --warn-soft: #3a2c12; --bad: #f2827a; --bad-soft: #3d1c1a;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --grid: #253244;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1620; --surface: #17212d; --surface-2: #1f2b39; --line: #2c3a4b;
  --fg: #e8edf4; --fg-2: #b9c4d2; --muted: #8b98aa;
  --night: #1b2a45; --night-2: #26385a; --night-fg: #f2f5fb; --night-muted: #a9b6cd;
  --sun: #f0a043; --accent: #5aa2ec; --accent-soft: #1d3149;
  --good: #4cc38a; --good-soft: #163428; --warn: #f0b456; --warn-soft: #3a2c12; --bad: #f2827a; --bad-soft: #3d1c1a;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --grid: #253244;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 15px; line-height: 1.6; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { max-width: 560px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 12px; background: var(--bg); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.brand-mark { width: 26px; height: 26px; color: var(--fg); }
.wx-pill { cursor: pointer; font: inherit; font-size: 12px; color: var(--fg-2); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60%; }
.wx-pill.err { color: var(--bad); border-color: var(--bad); background: var(--bad-soft); }

.view { display: flex; flex-direction: column; gap: 14px; padding-top: 4px; }
.view-title { font-size: 22px; margin: 6px 0 0; text-wrap: balance; }

/* 結論カード */
.hero { background: radial-gradient(120% 90% at 100% 0%, var(--night-2) 0%, var(--night) 60%); color: var(--night-fg); border-radius: 20px; padding: 20px 20px 18px; position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; right: -28px; top: -28px; width: 110px; height: 110px; border-radius: 50%; box-shadow: inset -18px 10px 0 0 rgba(242, 245, 251, .10); transform: rotate(-20deg); pointer-events: none; }
.eyebrow { margin: 0; font-size: 12px; letter-spacing: .12em; color: var(--night-muted); }
.hero-mode { margin: 4px 0 0; font-size: 32px; line-height: 1.25; letter-spacing: .02em; text-wrap: balance; }
.hero-charge { margin: 6px 0 0; font-size: 17px; color: var(--night-muted); min-height: 1.2em; }
.hero-charge b { font-family: var(--font-num); font-size: 44px; line-height: 1; color: var(--night-fg); font-weight: 700; margin: 0 2px 0 6px; font-variant-numeric: tabular-nums; }
.hero-charge b + span { color: var(--night-fg); font-size: 20px; font-weight: 700; }
.hero-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 14px; }
.hero-save { font-size: 14px; color: var(--night-fg); }
.hero-save strong { color: var(--sun); font-family: var(--font-num); font-size: 18px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 10px; border-radius: 999px; background: rgba(255, 255, 255, .12); color: var(--night-fg); }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .9; }
.chip.c-high::before { background: #5fd39a; } .chip.c-mid::before { background: #f0b456; } .chip.c-low::before { background: #f2827a; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.panel-title { font-size: 15px; margin: 0 0 8px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; line-height: 1.6; }
.reason { margin: 0; line-height: 1.85; }

.inputs { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--fg-2); font-weight: 500; }
.soc-row { display: grid; grid-template-columns: 48px 1fr 48px; gap: 10px; align-items: center; }
.step { height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); font-size: 22px; cursor: pointer; }
.soc-val { display: flex; align-items: baseline; justify-content: center; gap: 2px; }
.soc-val input { width: 3.2ch; text-align: right; border: none; background: transparent; font-family: var(--font-num); font-size: 36px; font-weight: 700; padding: 0; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.soc-val input::-webkit-outer-spin-button, .soc-val input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.soc-val span { font-size: 18px; color: var(--fg-2); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.seg button { border: none; background: transparent; padding: 9px 4px; border-radius: 9px; font-size: 14px; cursor: pointer; color: var(--fg-2); min-height: 40px; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--fg); font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.more summary { cursor: pointer; font-size: 13.5px; color: var(--accent); padding: 4px 0; }
.more[open] summary { margin-bottom: 10px; }
.more .field + .field { margin-top: 12px; }
.row-inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-inline input { width: 6.5em; }
.row-inline select, .row-inline input, .settings input, .settings select { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 10px; min-height: 40px; }
.unit { color: var(--muted); font-size: 13px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; min-width: 0; }
.stat-label { font-size: 12px; color: var(--fg-2); display: flex; align-items: center; gap: 6px; }
.stat-label i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.stat-value { font-family: var(--font-num); font-size: 26px; font-weight: 600; line-height: 1.2; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat-value small { font-family: var(--font-body); font-size: 13px; font-weight: 500; color: var(--fg-2); margin-left: 2px; }
.stat-sub { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.stat-value.pos { color: var(--good); }

.notice-list { display: flex; flex-direction: column; gap: 8px; }
.notice-list:empty { display: none; }
.notice { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; line-height: 1.6; padding: 10px 12px; border-radius: 12px; background: var(--warn-soft); color: var(--fg); border: 1px solid transparent; }
.notice b { color: var(--warn); }
.notice.info { background: var(--accent-soft); } .notice.info b { color: var(--accent); }
.notice.err { background: var(--bad-soft); } .notice.err b { color: var(--bad); }
.notice svg { flex: none; width: 18px; height: 18px; margin-top: 2px; }

.link { background: none; border: none; color: var(--accent); font-size: 13px; cursor: pointer; padding: 4px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-weight: 500; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.file-btn { position: relative; margin-top: 6px; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.import-status { margin-top: 10px; font-size: 13px; }
.import-status:empty { display: none; }
.confirm { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--bad-soft); }
.confirm p { margin: 0 0 8px; font-size: 13.5px; }

/* グラフ */
.chart { width: 100%; min-height: 40px; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font-body); }
.chart .axis-line { stroke: var(--line); }
.chart .gridline { stroke: var(--grid); }
.chart .xhair { stroke: var(--fg-2); stroke-dasharray: 3 3; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--fg-2); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.box { height: 10px; width: 10px; border-radius: 3px; }
.legend i.band { height: 10px; width: 14px; opacity: .35; }
.tooltip { position: fixed; z-index: 20; pointer-events: none; background: var(--fg); color: var(--bg); font-size: 12px; line-height: 1.5; padding: 6px 9px; border-radius: 8px; max-width: 240px; font-variant-numeric: tabular-nums; box-shadow: 0 4px 14px rgba(0, 0, 0, .2); }

/* 表 */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.tbl { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 6px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.tbl th { color: var(--fg-2); font-weight: 500; font-size: 11.5px; position: sticky; top: 0; background: var(--surface); }
.tbl.num td:not(:first-child), .tbl.num th:not(:first-child) { text-align: right; }
.tbl tr.best td { background: var(--accent-soft); font-weight: 700; }
.tbl tr.best td:first-child::after { content: " ★"; color: var(--sun); }

/* データ画面 */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; margin: 0; }
.kv dt { color: var(--fg-2); } .kv dd { margin: 0; font-variant-numeric: tabular-nums; min-width: 0; }
.bands { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.band { background: var(--surface-2); border-radius: 10px; padding: 8px; text-align: center; }
.band .b-l { font-size: 11.5px; color: var(--fg-2); } .band .b-v { font-family: var(--font-num); font-size: 18px; font-weight: 600; }
.empty { text-align: center; padding: 20px 8px; color: var(--fg-2); font-size: 13.5px; }
.empty svg { width: 44px; height: 44px; color: var(--muted); }

/* 設定 */
.settings { display: flex; flex-direction: column; gap: 14px; }
.settings fieldset { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); padding: 12px 16px 16px; margin: 0; min-width: 0; }
.settings legend { font-weight: 700; font-size: 15px; padding: 0 6px; }
.set-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.set-row:last-child { border-bottom: none; }
.set-row label { font-size: 13.5px; }
.set-row .hint { grid-column: 1 / -1; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.set-row input[type="number"] { width: 7.5em; text-align: right; }
.set-row input[type="text"], .set-row input[type="time"] { width: 7.5em; }
.set-row .pair { display: flex; gap: 4px; align-items: center; }
.set-row .pair input { width: 5.6em; }
.set-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.about { margin: 8px 0 0; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 8; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); }
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; border: none; background: none; font-size: 11px; color: var(--muted); padding: 4px 0; cursor: pointer; min-height: 48px; }
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-current="page"] { color: var(--accent); font-weight: 700; }
@media (min-width: 720px) { .tabbar { left: 50%; transform: translateX(-50%); max-width: 560px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); border-radius: 16px 16px 0 0; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
