/* トレーニング記録：スマホ優先のスタイル。色は :root のトークンで管理し、ダークモードで切り替える。 */

:root {
  --c-bg: #f6f7f9;
  --c-surface: #ffffff;
  --c-surface-2: #f0f2f5;
  --c-text: #15181d;
  --c-muted: #626a75;
  --c-border: #e1e4e8;
  --c-accent: #2563eb;
  --c-accent-text: #ffffff;
  --c-accent-weak: #e7eefe;
  --c-success: #15803d;
  --c-success-bg: #e9f7ee;
  --c-warn: #a14a05;
  --c-warn-bg: #fff4e0;
  --c-danger: #b91c1c;
  --c-danger-bg: #fdecec;
  --c-series-2: #8a96a8;
  --c-series-3: #0f766e;
  --c-series-4: #c2410c;
  --radius: 14px;
  --tabbar-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --c-bg: #111317;
    --c-surface: #1a1d22;
    --c-surface-2: #23272e;
    --c-text: #e9ebee;
    --c-muted: #9ba3ad;
    --c-border: #2c3138;
    --c-accent: #6b9cff;
    --c-accent-text: #0b1220;
    --c-accent-weak: #1c2945;
    --c-success: #4ade80;
    --c-success-bg: #12291b;
    --c-warn: #fbbf24;
    --c-warn-bg: #2b2312;
    --c-danger: #f87171;
    --c-danger-bg: #2d1515;
    --c-series-2: #7d8896;
    --c-series-3: #2dd4bf;
    --c-series-4: #fb923c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --c-bg: #111317;
  --c-surface: #1a1d22;
  --c-surface-2: #23272e;
  --c-text: #e9ebee;
  --c-muted: #9ba3ad;
  --c-border: #2c3138;
  --c-accent: #6b9cff;
  --c-accent-text: #0b1220;
  --c-accent-weak: #1c2945;
  --c-success: #4ade80;
  --c-success-bg: #12291b;
  --c-warn: #fbbf24;
  --c-warn-bg: #2b2312;
  --c-danger: #f87171;
  --c-danger-bg: #2d1515;
  --c-series-2: #7d8896;
  --c-series-3: #2dd4bf;
  --c-series-4: #fb923c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", system-ui, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--c-accent); }
h1, h2, h3 { line-height: 1.3; }

/* ---- 上部バー・下部タブ ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--c-bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--c-border);
}
.topbar h1 { font-size: 18px; margin: 0; }
.back {
  border: 0; background: none; color: var(--c-accent);
  font-size: 30px; line-height: 1; padding: 0 8px 4px 0; cursor: pointer;
}
.main { max-width: 680px; margin: 0 auto; padding: 14px 16px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
}
.tabbar[hidden] { display: none; }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--c-muted); text-decoration: none; font-size: 11px;
}
.tabbar a.on { color: var(--c-accent); font-weight: 600; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- 共通レイアウト ---- */
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.gap { gap: 8px; }
.grow { flex: 1 1 auto; min-width: 0; }
.center { text-align: center; }
.muted { color: var(--c-muted); }
.small { font-size: 13px; }
.success-text { color: var(--c-success); }
.danger-text { color: var(--c-danger) !important; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.triple { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}
.card > * + * { margin-top: 10px; }
.card-title { font-size: 16px; margin: 0; }
details.card > summary { cursor: pointer; }
.card-accent { border-color: var(--c-accent); background: var(--c-accent-weak); }
.hero h1 { margin: 0; font-size: 22px; }
.eyebrow { font-size: 12px; color: var(--c-accent); font-weight: 700; letter-spacing: .04em; }
.title { font-size: 17px; font-weight: 700; }
.sub { font-size: 14px; margin: 14px 0 6px; color: var(--c-muted); }
.subsection + .subsection { border-top: 1px solid var(--c-border); padding-top: 6px; }

/* ---- 入力 ---- */
input[type="text"], input[type="date"], select, textarea {
  font: inherit; font-size: 16px;
  color: var(--c-text); background: var(--c-surface);
  border: 1px solid var(--c-border); border-radius: 10px;
  padding: 8px 10px; min-height: 42px; max-width: 100%;
}
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--c-accent); outline-offset: 0; border-color: transparent; }
.num { width: 76px; text-align: right; }
.num-sm { width: 80px; text-align: right; }
.date-input { min-width: 150px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field input, .field select { width: 100%; }
.field-label { font-size: 12px; color: var(--c-muted); font-weight: 600; }
.field-hint { font-size: 12px; color: var(--c-muted); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.check input { width: 18px; height: 18px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.error { color: var(--c-danger); font-size: 13px; min-height: 0; }
.error:empty { display: none; }

/* ---- ボタン ---- */
.btn {
  font: inherit; font-size: 15px; font-weight: 600;
  min-height: 42px; padding: 8px 14px;
  border-radius: 10px; border: 1px solid var(--c-border);
  background: var(--c-surface-2); color: var(--c-text);
  cursor: pointer; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--c-accent); border-color: var(--c-accent); color: var(--c-accent-text); }
.btn.sm { min-height: 34px; padding: 4px 10px; font-size: 13px; }
.btn.on { border-color: var(--c-accent); color: var(--c-accent); background: var(--c-accent-weak); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-icon {
  min-width: 36px; min-height: 36px; border-radius: 8px;
  border: 1px solid var(--c-border); background: var(--c-surface-2); color: var(--c-muted);
  font-size: 16px; cursor: pointer;
}
.btn-icon:disabled { opacity: .35; }

.badge {
  display: inline-block; font-size: 11px; font-weight: 700; line-height: 1;
  padding: 4px 7px; border-radius: 999px; vertical-align: middle;
  background: var(--c-surface-2); color: var(--c-muted);
}
.badge.accent { background: var(--c-accent-weak); color: var(--c-accent); }
.badge.info { background: var(--c-accent-weak); color: var(--c-accent); }
.badge.warn { background: var(--c-warn-bg); color: var(--c-warn); }
.badge.success { background: var(--c-success-bg); color: var(--c-success); }

.segmented { display: inline-flex; border: 1px solid var(--c-border); border-radius: 10px; overflow: hidden; }
.seg {
  font: inherit; font-size: 14px; font-weight: 600;
  border: 0; background: var(--c-surface); color: var(--c-muted);
  padding: 8px 12px; min-height: 42px; cursor: pointer;
  display: inline-flex; flex-direction: column; align-items: center; line-height: 1.2;
}
.seg + .seg { border-left: 1px solid var(--c-border); }
.seg.on { background: var(--c-accent); color: var(--c-accent-text); }
.seg-hint { font-size: 10px; font-weight: 500; opacity: .85; }

/* ---- 数値タイル ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat {
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px; border-radius: 12px;
  background: var(--c-surface); border: 1px solid var(--c-border);
  color: inherit; text-decoration: none; min-width: 0;
}
.card .stat { background: var(--c-surface-2); border-color: transparent; }
.stat-label { font-size: 12px; color: var(--c-muted); }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--c-muted); }
.diff { font-variant-numeric: tabular-nums; }

/* ---- メモ・注意 ---- */
.notes, .warnings { margin: 0; padding-left: 18px; font-size: 13px; }
.notes li + li, .warnings li + li { margin-top: 2px; }
.warnings { list-style: none; padding: 8px 10px; border-radius: 10px; background: var(--c-warn-bg); color: var(--c-warn); }
.warnings li::before { content: "! "; font-weight: 700; }
.reasons > summary { font-size: 13px; color: var(--c-muted); cursor: pointer; }
.reasons > ul { margin-top: 4px; }

/* ---- 次回メニュー ---- */
.plan-head { font-size: 14px; }
.plan { margin: 0; padding: 0; list-style: none; counter-reset: plan; }
.plan-item { padding: 10px 0; border-top: 1px solid var(--c-border); counter-increment: plan; }
.plan-item > * + * { margin-top: 4px; }
.plan-name { font-weight: 700; }
.plan-name::before { content: counter(plan) ". "; color: var(--c-muted); font-weight: 600; }
.plan-sets { font-variant-numeric: tabular-nums; }
.plan-item.skipped .plan-name { color: var(--c-muted); text-decoration: line-through; }

/* ---- 記録中 ---- */
.progress { height: 6px; border-radius: 3px; background: var(--c-surface-2); overflow: hidden; }
.progress-bar { height: 100%; background: var(--c-accent); transition: width .2s; }
.entry-done { border-color: var(--c-success); }
.target { font-variant-numeric: tabular-nums; }
.sets { display: flex; flex-direction: column; gap: 6px; }
.set-row {
  display: grid; align-items: center; gap: 6px;
  grid-template-columns: 18px 46px 1fr auto 1fr auto 46px;
  padding: 4px 0;
}
.set-row .num { width: 100%; min-width: 0; }
.set-row.done .num { background: var(--c-success-bg); border-color: transparent; }
.set-no { color: var(--c-muted); font-size: 13px; text-align: center; }
.unit { font-size: 13px; color: var(--c-muted); white-space: nowrap; }
.chip {
  font: inherit; font-size: 11px; font-weight: 700;
  min-height: 34px; border-radius: 8px; border: 1px solid var(--c-border);
  background: var(--c-surface-2); color: var(--c-muted); cursor: pointer; padding: 0;
}
.chip-amrap { background: var(--c-warn-bg); color: var(--c-warn); border-color: transparent; }
.chip-warmup { background: transparent; }
.check-btn {
  width: 46px; height: 42px; border-radius: 10px; cursor: pointer;
  border: 2px solid var(--c-border); background: var(--c-surface);
  color: var(--c-border); font-size: 20px; font-weight: 700;
}
.check-btn.on { background: var(--c-success); border-color: var(--c-success); color: var(--c-surface); }
.entry-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.entry-note { width: 100%; }
.set-info { margin-top: -4px; padding-left: 24px; font-size: 13px; color: var(--c-muted); }
.set-info .badge { margin-left: 2px; }

.rir-q { margin-bottom: 6px; font-size: 13px; color: var(--c-muted); }
.rir-options { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.rir-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0;
  padding: 7px 2px; border: 1px solid var(--c-border); border-radius: 10px;
  background: var(--c-surface); color: var(--c-text); font: inherit; cursor: pointer;
}
.rir-label { font-size: 13px; font-weight: 700; white-space: nowrap; }
.rir-reps { font-size: 11px; color: var(--c-muted); white-space: nowrap; }
.rir-btn.on { background: var(--c-accent); border-color: var(--c-accent); color: var(--c-surface); }
.rir-btn.on .rir-reps { color: inherit; }

/* ---- フィードバック ---- */
.feedback { list-style: none; margin: 0; padding: 0; }
.fb { position: relative; padding: 6px 0 6px 18px; font-size: 14px; }
.fb + .fb { border-top: 1px solid var(--c-border); }
.fb::before {
  content: ''; position: absolute; left: 2px; top: 13px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--c-accent);
}
.fb-good::before { background: var(--c-success); }
.fb-warn::before { background: var(--c-warn); }
.next { margin-top: 4px; color: var(--c-accent); font-weight: 600; }
.report { width: 100%; font-size: 13px; }
.panel { border: 1px solid var(--c-border); border-radius: 12px; padding: 10px; background: var(--c-surface-2); }
.panel > * + * { margin-top: 8px; }
.panel-title { font-weight: 700; font-size: 14px; }
.option { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 8px; border-radius: 10px; background: var(--c-surface); }
.sticky-actions {
  position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px);
  display: flex; gap: 8px; padding: 10px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--c-bg) 85%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}

/* ---- 結果・履歴 ---- */
.results, .history, .records, .template { list-style: none; margin: 0; padding: 0; }
.result { padding: 10px 0; border-top: 1px solid var(--c-border); }
.result:first-child { border-top: 0; }
.history li + li { border-top: 1px solid var(--c-border); }
.history-link { display: block; padding: 10px 0; color: inherit; text-decoration: none; }
.record { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--c-border); font-variant-numeric: tabular-nums; }
.record:first-child { border-top: 0; }
.template li { padding: 6px 0; }
.flag { font-size: 10px; font-weight: 700; margin-left: 4px; padding: 1px 5px; border-radius: 6px; background: var(--c-warn-bg); color: var(--c-warn); }
.exercise { border-top: 1px solid var(--c-border); padding: 8px 0; }
.exercise > summary { cursor: pointer; font-weight: 600; }
.exercise[open] > * + * { margin-top: 10px; }

/* ---- 表 ---- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 6px 6px; text-align: right; border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.table th:first-child, .table td:first-child { text-align: left; }
.table th { font-size: 12px; color: var(--c-muted); font-weight: 600; }
.table tr.avg td { font-weight: 700; border-bottom: 0; }

/* ---- 判定カード ---- */
.advice { border-left: 5px solid var(--c-border); }
.advice-ok { border-left-color: var(--c-success); }
.advice-wait, .advice-insufficient { border-left-color: var(--c-accent); }
.advice-up { border-left-color: var(--c-warn); }
.advice-down { border-left-color: var(--c-danger); }
.advice-title { font-weight: 700; }

/* ---- グラフ ---- */
.chart { width: 100%; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--c-border); stroke-width: 1; }
.chart .axis { fill: var(--c-muted); font-size: 19px; font-variant-numeric: tabular-nums; }
.chart .series { fill: none; stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart .series.dashed { stroke-dasharray: 8 6; }
.chart .goal { stroke: var(--c-success); stroke-width: 2; stroke-dasharray: 4 6; }
.chart .goal-label { fill: var(--c-success); font-size: 18px; font-weight: 700; }
.chart .dot { stroke: var(--c-surface); stroke-width: 2; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--c-muted); margin-top: 4px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 7em 1fr 2em; align-items: center; gap: 8px; font-size: 13px; }
.bar { height: 10px; border-radius: 5px; background: var(--c-surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--c-accent); border-radius: 5px; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- 通知 ---- */
#toast-host {
  position: fixed; left: 16px; right: 16px; z-index: 50;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none;
}
.toast {
  max-width: 560px; padding: 10px 14px; border-radius: 12px;
  background: var(--c-text); color: var(--c-bg); font-size: 14px;
  box-shadow: 0 6px 20px rgb(0 0 0 / .18); transition: opacity .3s, transform .3s;
}
.toast-error { background: var(--c-danger); color: #fff; }
.toast-success { background: var(--c-success); color: var(--c-surface); font-weight: 600; }
.toast.out { opacity: 0; transform: translateY(6px); }
.update-banner {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 8px); left: 16px; right: 16px; z-index: 60;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  max-width: 560px; margin: 0 auto; padding: 8px 8px 8px 14px; border-radius: 12px;
  background: var(--c-surface); border: 1px solid var(--c-accent); box-shadow: 0 6px 20px rgb(0 0 0 / .15);
}

@media (max-width: 380px) {
  .set-row { grid-template-columns: 14px 40px 1fr auto 1fr auto 42px; gap: 4px; }
  .unit { font-size: 12px; }
  .stat-value { font-size: 20px; }
}
