/* =========================================================
   トレーニング記録
   ダーク基調。iOS のホーム画面アプリとして見る時間がいちばん長いので、
   片手で押せる大きさと、屋外でも読める明暗差を優先している。
   ========================================================= */

:root {
  color-scheme: dark;

  /* 面（奥から手前へ） */
  --bg:        #090b11;
  --surface:   #141926;
  --surface-2: #1b2130;
  --surface-3: #242c3e;
  --line:      rgba(255, 255, 255, .075);
  --line-2:    rgba(255, 255, 255, .15);
  --hairline:  rgba(255, 255, 255, .055);

  /* 文字 */
  --text:  #eaeef7;
  --muted: #8b94aa;
  --faint: #626c82;

  /* 役割色 */
  --accent:     #5aa9ff;
  --accent-2:   #4189ff;
  --accent-dim: rgba(90, 169, 255, .14);
  --accent-ink: #04121f;
  --danger:     #ff6b7a;
  --ok:         #3ddc84;

  /* カテゴリ */
  --c-run:      #3ddc84;
  --c-bike:     #5aa9ff;
  --c-swim:     #35d6d6;
  --c-strength: #ffa54d;
  --c-bjj:      #b78cff;
  --c-other:    #8b94aa;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-pill: 999px;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-2: 0 10px 32px rgba(0, 0, 0, .5);

  --tabbar-h: 66px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Hiragino Sans",
               "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

/* 上端のほのかな光。のっぺりした真っ黒を避けるためだけのもの */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 420px at 50% -12%, rgba(90, 169, 255, .11), transparent 68%),
    radial-gradient(680px 360px at 108% -4%, rgba(183, 140, 255, .07), transparent 70%);
}

/* 数値は桁が揺れないように等幅で */
.stat .v, .day-head .d, .item .meta, .trend-value, .num,
input[type="number"], input[type="date"], input[type="time"] {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ---------- ヘッダ ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(9, 11, 17, .72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
  padding: 12px 16px 11px;
  padding-top: calc(12px + env(safe-area-inset-top));
}
header h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .01em;
  line-height: 1.25;
}
header .sub {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}
header .sub:empty { display: none; }

/* ---------- レイアウト ---------- */
main { padding: 16px 16px 28px; max-width: 720px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; animation: viewIn .24s cubic-bezier(.2, .7, .3, 1) both; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .view.active, .sheet, .sheet-bg.open { animation: none; }
}

section { margin-bottom: 24px; }
section:last-child { margin-bottom: 0; }

h2 {
  font-size: 11px;
  color: var(--faint);
  font-weight: 700;
  letter-spacing: .12em;
  margin: 0 0 10px 2px;
}

.card {
  background: linear-gradient(180deg, var(--surface), #11151f);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-1), inset 0 1px 0 rgba(255, 255, 255, .035);
}
.card:last-child { margin-bottom: 0; }

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 週の切り替え ---------- */
.weeknav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 4px;
  margin-bottom: 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .035);
}
.weeknav button {
  border: 0;
  background: transparent;
  border-radius: var(--r-pill);
  color: var(--muted);
  padding: 8px 0;
  font-size: 13px;
  font-weight: 600;
}
.weeknav .arrow { flex: 0 0 52px; display: grid; place-items: center; }
.weeknav .arrow svg { width: 18px; height: 18px; }
.weeknav .now { flex: 1; color: var(--text); }
.weeknav button:active { background: var(--surface-3); transform: none; }

/* ---------- 週の集計 ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  background: linear-gradient(180deg, var(--surface), #11151f);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 8px 10px;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .035);
}
.stat .v {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.02em;
}
.stat .v .small { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 1px; }
.card .stat {
  background: rgba(255, 255, 255, .035);
  border-color: var(--hairline);
  box-shadow: none;
}
.stat .k {
  font-size: 10px;
  color: var(--faint);
  letter-spacing: .08em;
  margin-top: 5px;
}

/* ---------- 週ビュー：日ごと ---------- */
.day { margin-bottom: 16px; }
.day:last-child { margin-bottom: 4px; }

.day-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}
.day-head .d { font-weight: 700; font-size: 14px; letter-spacing: -.01em; }
.day-head .w { color: var(--faint); font-size: 11px; font-weight: 600; }
.day-head .rule { flex: 1; height: 1px; background: var(--hairline); }
.day-head .none { color: var(--faint); font-size: 11px; }

.badge-today {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(90, 169, 255, .3);
  padding: 1px 7px;
  border-radius: var(--r-pill);
  line-height: 1.5;
}
.day.today .d { color: var(--accent); }

/* ---------- 行（実績・予定） ---------- */
.item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(180deg, var(--surface), #11151f);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 11px 10px 11px 15px;
  margin-bottom: 7px;
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.item::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--cat, var(--c-other));
}
.item:last-child { margin-bottom: 0; }
.item.plan {
  background: transparent;
  border-style: dashed;
  border-color: var(--line-2);
  box-shadow: none;
}
.item.plan::before { opacity: .4; }
.item.skipped { opacity: .42; }

.item .title { font-weight: 600; font-size: 14.5px; letter-spacing: -.01em; }
.item .meta { color: var(--muted); font-size: 11.5px; line-height: 1.45; }
.item .meta:empty { display: none; }
.item .act { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }

/* 旧マークアップ用の色ドット（互換のため残す） */
.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }

/* ---------- ボタン ---------- */
button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 13px;
  transition: background .15s, border-color .15s, opacity .15s, transform .08s;
}
button:active { transform: scale(.975); }
button:disabled { opacity: .4; cursor: default; transform: none; }

button.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: var(--accent-ink);
  font-weight: 700;
  letter-spacing: .02em;
  box-shadow: 0 6px 18px rgba(65, 137, 255, .28);
}
button.ghost { background: transparent; }
button.ghost:active { background: var(--surface-2); }
button.danger { color: var(--danger); border-color: transparent; background: transparent; }
button.wide { width: 100%; padding: 14px; font-size: 15px; }
button.icon { padding: 6px 11px; font-size: 12.5px; }

/* 行内の小さなボタン */
.pill {
  border-radius: var(--r-pill);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(90, 169, 255, .26);
}
.iconbtn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  padding: 0;
  border-radius: var(--r-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--faint);
}
.iconbtn svg { width: 16px; height: 16px; }
.iconbtn:active { background: var(--surface-3); color: var(--danger); }

/* 「＋ 予定を追加」「＋ 種目を追加」 */
button.add {
  width: 100%;
  padding: 13px;
  background: transparent;
  border: 1px dashed var(--line-2);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--r-md);
}
button.add:active { background: var(--surface); color: var(--text); }

/* ---------- フォーム ---------- */
label {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: .03em;
  font-weight: 600;
}
input, select, textarea {
  font: inherit;
  font-size: 16px;            /* 16px 未満だと iOS がフォーカスで勝手に拡大する */
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 11px 12px;
  appearance: none;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: rgba(90, 169, 255, .55);
  background: var(--surface-3);
  box-shadow: 0 0 0 3px rgba(90, 169, 255, .13);
}
textarea { min-height: 76px; resize: vertical; line-height: 1.6; }
.field { margin-bottom: 14px; }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fields-2.one-col { grid-template-columns: 1fr; }
.fields-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

/* カテゴリ選択 */
.cats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 11px 4px 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  transition: background .16s, border-color .16s, color .16s;
}
.cat-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--cat, var(--c-other));
  opacity: .5;
  transition: opacity .16s, box-shadow .16s;
}
.cat[aria-pressed="true"] {
  color: var(--text);
  background: color-mix(in srgb, var(--cat) 15%, var(--surface));
  border-color: color-mix(in srgb, var(--cat) 52%, transparent);
}
.cat[aria-pressed="true"] .cat-dot {
  opacity: 1;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--cat) 22%, transparent);
}

/* セット入力 */
.exercise-block {
  background: linear-gradient(180deg, var(--surface), #11151f);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 13px;
  margin-bottom: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .035);
}
.set-row {
  display: grid;
  grid-template-columns: 1fr 1fr 36px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.set-label {
  font-size: 10.5px;
  color: var(--faint);
  letter-spacing: .06em;
  margin-bottom: 7px;
}
.set-row .iconbtn { justify-self: center; }
.ex-last {
  color: var(--muted);
  font-size: 11.5px;
  background: rgba(255, 255, 255, .03);
  border-left: 2px solid var(--line-2);
  border-radius: 0 6px 6px 0;
  padding: 6px 9px;
}
.ex-last:empty { display: none; }

/* ---------- タブバー ---------- */
nav.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(12, 15, 23, .82);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  position: relative;
  border: 0;
  background: none;
  border-radius: 0;
  padding: 10px 0 9px;
  color: var(--faint);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .03em;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: color .18s;
}
nav.tabs button:active { transform: none; }
nav.tabs button svg { width: 22px; height: 22px; display: block; }
nav.tabs button::before {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  width: 26px; height: 2px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
  transform: translateX(-50%) scaleX(0);
  transition: transform .22s cubic-bezier(.2, .7, .3, 1);
}
nav.tabs button[aria-selected="true"] { color: var(--accent); }
nav.tabs button[aria-selected="true"]::before { transform: translateX(-50%) scaleX(1); }

/* ---------- グラフ ---------- */
.chart { width: 100%; height: 190px; display: block; }
.chart-legend {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 3px 10px 3px 8px;
}
.chart-legend i { width: 7px; height: 7px; border-radius: 2px; background: currentColor; }

/* 体組成のスパークライン3行 */
.trend-row { padding: 14px 0; border-bottom: 1px solid var(--hairline); }
.trend-row:last-child { border-bottom: 0; padding-bottom: 2px; }
.trend-row:first-child { padding-top: 2px; }
.trend-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.trend-label { font-size: 12.5px; color: var(--muted); font-weight: 600; letter-spacing: .03em; }
.trend-value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.trend-value .small { font-size: 12px; font-weight: 600; margin-left: 1px; }
.trend-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.spark { width: 100%; height: 42px; display: block; }
.spark-empty { padding: 12px 0; color: var(--faint); }

/* ---------- トースト ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(14px) scale(.96);
  background: rgba(36, 44, 62, .96);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 11px 20px;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s cubic-bezier(.2, .7, .3, 1);
  z-index: 50;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--shadow-2);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
#toast.err { border-color: rgba(255, 107, 122, .5); color: var(--danger); }

/* ---------- ボトムシート ---------- */
.sheet-bg {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .58);
  backdrop-filter: blur(3px);
  z-index: 40;
  display: none;
}
.sheet-bg.open { display: block; animation: fadeIn .2s ease both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, #171d2b, var(--bg) 220px);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--line-2);
  padding: 10px 16px calc(22px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
  animation: sheetUp .3s cubic-bezier(.2, .8, .25, 1) both;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .5);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
.sheet::before {
  content: "";
  display: block;
  width: 38px; height: 4px;
  border-radius: 2px;
  background: var(--line-2);
  margin: 0 auto 14px;
}
.sheet h3 { margin: 0 0 16px; font-size: 17px; font-weight: 700; }
.sheet-actions { gap: 10px; margin-top: 4px; }
.sheet-actions button { padding: 14px; font-size: 15px; }

.empty {
  color: var(--faint);
  text-align: center;
  padding: 30px 12px;
  font-size: 13px;
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}

/* ---------- セットアップ画面 ---------- */
#setup {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
}
#setup[hidden] { display: none; }
.setup-box {
  width: 100%;
  max-width: 380px;
  background: linear-gradient(180deg, var(--surface), #11151f);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px;
  box-shadow: var(--shadow-2);
}
.setup-box h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  margin: 0 0 10px;
}
.setup-box p { margin: 0 0 12px; }
.setup-box input { margin-bottom: 14px; }

/* ---------- 広い画面 ---------- */
@media (min-width: 640px) {
  main { padding: 22px 20px 32px; }
  .stats { gap: 10px; }
}
