/* =====================================================================
   トレーニング記録 共通スタイル

   狙い: ジムの薄暗さ・汗の手・片手操作に耐えること。
        つまり「暗い背景 / 大きな文字 / 下半分に操作ボタン」。
   ===================================================================== */

:root {
  --bg: #0f1115;
  --surface: #1a1e26;
  --surface-2: #232936;
  --line: #2b313c;
  --text: #e8eaed;
  --muted: #9aa4b2;
  --primary: #22d3ee;
  --primary-dark: #0e7490;
  --accent: #f97316;
  --success: #22c55e;
  --danger: #ef4444;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  line-height: 1.6;
  overscroll-behavior-y: contain;
}

a { color: var(--primary); text-decoration: none; }

.app { min-height: 100vh; display: flex; flex-direction: column; }

.main {
  flex: 1;
  padding: 16px 14px calc(var(--tabbar-h) + var(--safe-b) + 24px);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- ヘッダー ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(15, 17, 21, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 700; }

/* ---------- 下部タブ ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  background: rgba(20, 23, 30, .96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  height: var(--tabbar-h);
  color: var(--muted);
  font-size: 11px;
}
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.is-active { color: var(--primary); }

/* ---------- 共通パーツ ---------- */
.section-title {
  font-size: 13px; color: var(--muted);
  margin: 20px 0 10px; font-weight: 600;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 20px;
  border: none; border-radius: 12px;
  background: var(--surface-2); color: var(--text);
  font-size: 16px; font-weight: 700; font-family: inherit;
  cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #04222a; }
.btn-accent  { background: var(--accent); color: #24120a; }
.btn-danger  { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-ghost   { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-lg { min-height: 72px; font-size: 22px; width: 100%; border-radius: 16px; }
.btn:disabled { opacity: .45; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 52px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-size: 17px; font-family: inherit;
}
.input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

/* 選択肢ボタン列（重量・時間） */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 46px; padding: 0 16px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  color: var(--text); font-size: 16px; font-weight: 600; font-family: inherit;
  cursor: pointer;
}
.chip.is-on { background: var(--primary); color: #04222a; border-color: var(--primary); }

/* =====================================================================
   記録画面（index.php）
   ===================================================================== */
.phase { display: none; }
.phase.is-on { display: block; }

/* Phase 1: 種目選択 */
.hero {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 2px 6px;
}
.hero h1 { margin: 0; font-size: 20px; }
.hero .stat { text-align: right; font-size: 12px; color: var(--muted); }
.hero .stat b { display: block; font-size: 20px; color: var(--accent); }

.ex-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .ex-grid { grid-template-columns: repeat(3, 1fr); } }

.ex-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 10px; text-align: center; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-height: 132px; color: var(--text); font-family: inherit;
}
.ex-card:active { border-color: var(--primary); }
.ex-card img, .ex-card svg { width: 56px; height: 56px; }
.ex-card .name { font-size: 13px; font-weight: 700; line-height: 1.3; }
.ex-card .last { font-size: 11px; color: var(--muted); }

/* Phase 2: スタート前 */
.ready { text-align: center; padding-top: 8px; }
.ready img { width: 96px; height: 96px; }
.ready h2 { font-size: 22px; margin: 8px 0 4px; }
.ready .prev { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.ready .prev b { color: var(--text); }

/* Phase 3: タイマー */
.timer-wrap { text-align: center; padding-top: 12px; }
.timer-ex { font-size: 15px; color: var(--muted); }
.timer {
  font-size: min(30vw, 150px); font-weight: 800; line-height: 1.05;
  font-variant-numeric: tabular-nums; letter-spacing: -.03em;
  margin: 6px 0 2px;
}
.timer.is-warn { color: var(--accent); }
.timer-sub { color: var(--muted); font-size: 13px; }

.counter {
  margin: 18px auto 10px; max-width: 320px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px;
}
.counter .n { font-size: 56px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.counter .lbl { font-size: 11px; color: var(--muted); }
.counter-btns { display: flex; gap: 8px; margin-top: 10px; }
.counter-btns .btn { flex: 1; }
.counter-btns .plus { flex: 2; background: var(--primary); color: #04222a; min-height: 64px; font-size: 22px; }

.timer-actions { display: flex; gap: 10px; margin-top: 18px; }
.timer-actions .btn { flex: 1; }

/* Phase 4: 記録入力シート */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .6);
  display: flex; align-items: flex-end;
}
.sheet[hidden] { display: none; }
.sheet-inner {
  width: 100%; max-height: 92vh; overflow-y: auto;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  padding: 18px 16px calc(20px + var(--safe-b));
}
.sheet-title { font-size: 18px; font-weight: 700; margin: 0 0 4px; }
.sheet-sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }

.keypad-value {
  text-align: center; font-size: 64px; font-weight: 800; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.keypad button {
  min-height: 58px; font-size: 24px; font-weight: 700;
  background: var(--surface-2); color: var(--text);
  border: none; border-radius: 12px; font-family: inherit;
}
.keypad button:active { background: var(--primary); color: #04222a; }

/* 重量のステッパー（バーベル種目。刻みが大きく値の幅も広いのでボタン列にしない） */
.stepper { display: flex; align-items: stretch; gap: 8px; }
.stepper .btn { flex: 1; min-height: 60px; font-size: 20px; }
.stepper-val {
  flex: 2; min-height: 60px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  font-size: 26px; font-weight: 800; font-family: inherit;
}

/* 保存後の結果 */
.result { text-align: center; padding: 10px 0; }
.result .big { font-size: 44px; font-weight: 800; }
.result .badge {
  display: inline-block; margin: 8px 0;
  background: var(--accent); color: #24120a;
  border-radius: 999px; padding: 6px 16px; font-weight: 800; font-size: 15px;
}
.result .diff.up { color: var(--success); }
.result .diff.down { color: var(--muted); }
.progressbar { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; margin: 10px 0 6px; }
.progressbar i { display: block; height: 100%; background: var(--primary); }

/* =====================================================================
   履歴・成長・目標・設定
   ===================================================================== */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: flex; align-items: center; gap: 12px;
}
.item .body { flex: 1; min-width: 0; }
.item .t1 { font-size: 15px; font-weight: 700; }
.item .t2 { font-size: 12px; color: var(--muted); }
.item .score { font-size: 18px; font-weight: 800; white-space: nowrap; }

.filterbar { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 4px; }
.filterbar::-webkit-scrollbar { display: none; }

.goal-row { display: flex; align-items: center; gap: 10px; }
.goal-row .name { flex: 1; font-weight: 700; font-size: 14px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--primary); }
.bar i.done { background: var(--success); }

.chart-box { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; height: 260px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px);
  transform: translateX(-50%);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 20px; font-size: 14px; z-index: 90;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.is-on { opacity: 1; }

/* ログイン */
.login-wrap {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px;
}
.login-wrap h1 { font-size: 22px; margin-bottom: 4px; }
.login-wrap p { color: var(--muted); font-size: 13px; margin: 0 0 24px; }
.login-form { width: 100%; max-width: 320px; }
.error { color: var(--danger); font-size: 13px; min-height: 20px; }
