/* ワークアウト記録アプリ — スマホ専用ダークUI
   コンセプト: スコアボード × 競技プレート
   - 数字はOswald(コンデンス)でスコアボード風に大きく
   - 機能色はIWFプレート色: 赤25kg=主要操作 / 黄15kg=ウォームアップ /
     緑10kg=完了 / 青20kg=データ・グラフ */

:root {
  --bg: #0B0D11;
  --surface: #14181F;
  --surface2: #1D232D;
  --border: #2A323E;
  --text: #EDEFF2;
  --muted: #96A0AE;
  --faint: #5F6A77;
  --red: #E8443A;      /* 25kgプレート: 主要アクション */
  --red-deep: #B92E27;
  --yellow: #E9B43C;   /* 15kgプレート: ウォームアップ */
  --green: #2FA968;    /* 10kgプレート: 完了 */
  --blue: #4A84E8;     /* 20kgプレート: データ・グラフ */
  --num: 'Oswald', 'Noto Sans JP', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
}

button {
  font-family: inherit;
  font-size: 16px;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* <16pxだとiOS Safariがフォーカス時に自動ズームする */
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
}

input::placeholder { color: var(--faint); }

.num { font-family: var(--num); letter-spacing: .02em; }

/* ---- レイアウト ---- */

.screen-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: linear-gradient(180deg, #12151B 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.screen-header h1 {
  /* 英字タイトルはOswald、日本語はNotoにフォールバック */
  font-family: var(--num);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .05em;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scroll-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px 28px;
}

.tab-bar {
  flex: none;
  display: flex;
  border-top: 1px solid var(--border);
  background: #12151B;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab-bar button {
  flex: 1;
  padding: 9px 0 7px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .04em;
  color: var(--faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.tab-bar button .ico { display: block; }
.tab-bar button .ico svg { width: 23px; height: 23px; display: block; }
.tab-bar button.active { color: var(--text); }
.tab-bar button.active .ico svg { stroke: var(--red); }

/* ---- 汎用部品 ---- */

.card {
  background: linear-gradient(180deg, #171C24 0%, var(--surface) 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
}

.card.tappable:active { background: var(--surface2); }

.card.active-card {
  border-color: var(--red);
  box-shadow: 0 0 22px rgba(232, 68, 58, .14);
}

.section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin: 20px 2px 8px;
  letter-spacing: .1em;
}
.section-title:first-child { margin-top: 2px; }

/* 部位見出しにプレート色のドット */
.section-title[class*="muscle-"]::before {
  content: '';
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 7px;
  background: var(--faint);
  vertical-align: 1px;
}
.muscle-胸::before { background: var(--red) !important; }
.muscle-背中::before { background: var(--blue) !important; }
.muscle-肩::before { background: var(--yellow) !important; }
.muscle-腕::before { background: #9A6AE8 !important; }
.muscle-脚::before { background: var(--green) !important; }
.muscle-カーフ::before { background: #3FB9B0 !important; }
.muscle-腹::before { background: #E87B3E !important; }

.btn {
  display: block;
  width: 100%;
  text-align: center;
  padding: 13px;
  border-radius: 13px;
  font-weight: 700;
  background: var(--surface2);
  border: 1px solid var(--border);
}
.btn:active { opacity: .75; }
.btn.primary {
  background: linear-gradient(180deg, var(--red) 0%, var(--red-deep) 100%);
  border-color: var(--red-deep);
  color: #fff;
  box-shadow: 0 3px 14px rgba(232, 68, 58, .3);
}
.btn.success { background: var(--green); border-color: var(--green); color: #06301B; }
.btn.danger { color: var(--red); }
.btn.small { padding: 9px 14px; font-size: 14px; width: auto; display: inline-block; white-space: nowrap; }
.btn.ghost { background: none; border: 1px dashed var(--border); color: var(--muted); font-weight: 500; }

.icon-btn {
  font-size: 20px;
  padding: 6px 10px;
  color: var(--muted);
  border-radius: 10px;
  flex: none;
  line-height: 1;
}
.icon-btn:active { background: var(--surface2); }
.icon-btn svg { display: block; }

.chip {
  display: inline-block;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  vertical-align: middle;
}
.chip.accent { color: var(--yellow); border-color: rgba(233, 180, 60, .4); background: rgba(233, 180, 60, .08); font-weight: 700; }

.muted { color: var(--muted); font-size: 13px; }
.faint { color: var(--faint); font-size: 12px; }
.empty-note {
  color: var(--faint);
  text-align: center;
  padding: 28px 12px;
  font-size: 14px;
  line-height: 1.8;
}

.row { display: flex; align-items: center; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

/* ---- 週チップ ---- */

.week-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.week-chips button {
  min-width: 54px;
  padding: 9px 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface2);
  font-family: var(--num);
  font-weight: 600;
  font-size: 15px;
  color: var(--muted);
}
.week-chips button.active {
  background: linear-gradient(180deg, var(--red) 0%, var(--red-deep) 100%);
  border-color: var(--red-deep);
  color: #fff;
}

/* ---- 記録中(ロギング)画面 ---- */

.log-entry { padding: 12px 12px 10px; }

.log-entry .ex-name { font-size: 16px; font-weight: 700; }
.log-entry .ex-target { font-size: 12px; color: var(--muted); margin-top: 2px; }

.set-grid { margin-top: 10px; }

.set-row {
  display: grid;
  grid-template-columns: 38px 1fr 14px 1fr 48px;
  gap: 7px;
  align-items: center;
  margin-bottom: 7px;
}

.set-row .set-no {
  height: 42px;
  border-radius: 10px;
  font-family: var(--num);
  font-size: 15px;
  font-weight: 600;
  color: var(--faint);
  background: var(--surface2);
  border: 1px solid var(--border);
}
.set-row.warm .set-no {
  color: var(--yellow);
  border-color: rgba(233, 180, 60, .5);
  background: rgba(233, 180, 60, .1);
}

.set-row input {
  text-align: center;
  padding: 9px 4px;
  height: 42px;
  font-family: var(--num);
  font-size: 18px;
  font-weight: 600;
}

.set-row .x { text-align: center; color: var(--faint); font-size: 13px; }

.set-row .done-btn {
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--faint);
  font-size: 18px;
}
.set-row.done .done-btn {
  background: var(--green);
  border-color: var(--green);
  color: #06301B;
}
.set-row.done input {
  border-color: transparent;
  background: rgba(47, 169, 104, .13);
}
.set-row.done.warm input { background: rgba(233, 180, 60, .1); }

.set-head {
  display: grid;
  grid-template-columns: 38px 1fr 14px 1fr 48px;
  gap: 7px;
  font-size: 11px;
  color: var(--faint);
  text-align: center;
  margin-bottom: 5px;
}

.entry-actions { display: flex; gap: 8px; margin-top: 6px; }
.entry-actions button {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  padding: 9px;
  border-radius: 9px;
  background: var(--surface2);
}

/* レストタイマーバー */
.rest-bar {
  position: relative;
  overflow: hidden;
  flex: none;
  background: #171C24;
  border-top: 1px solid rgba(232, 68, 58, .35);
  padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 10px);
  display: flex;
  align-items: center;
  gap: 12px;
}
.rest-bar .time {
  font-family: var(--num);
  font-size: 34px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 92px;
  line-height: 1;
}
.rest-bar .label { font-size: 11px; letter-spacing: .1em; color: var(--muted); }
.rest-bar button {
  padding: 9px 14px;
  border-radius: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.rest-bar .bar {
  position: absolute;
  left: 0; top: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--red), var(--yellow));
  transition: width 1s linear;
}

.elapsed {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ---- プログラム編集 ---- */

.day-block { margin-bottom: 14px; }

.wk-grid {
  display: grid;
  grid-template-columns: 44px 1fr 16px 1fr;
  gap: 7px;
  align-items: center;
  margin-bottom: 7px;
}
.wk-grid .wk-label {
  font-family: var(--num);
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  font-weight: 600;
}
.wk-grid input { text-align: center; padding: 9px 4px; font-family: var(--num); font-weight: 600; }
.wk-grid .x { text-align: center; color: var(--faint); font-size: 13px; }

/* ---- グラフ ---- */

.chart-wrap { margin: 4px 0 8px; }
.chart-wrap svg { display: block; width: 100%; height: auto; }

/* ---- モーダル ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, .7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 82vh;
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
  padding: 18px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
}

.modal h2 { font-size: 17px; font-weight: 700; margin-bottom: 14px; }
.modal .modal-body { overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 14px; flex: none; }
.modal .modal-actions .btn { flex: 1; }

.picker-list .picker-head {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  color: var(--faint);
  padding: 14px 2px 4px;
  position: sticky;
  top: 0;
  background: var(--surface);
}
.picker-list button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 13px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.picker-list button:active { background: var(--surface2); }
.picker-list .eq { color: var(--muted); font-size: 12px; margin-left: 8px; }
.picker-list .picker-new { color: var(--blue); border-bottom: none; font-weight: 600; }

/* ---- 部位別セット数 ---- */

.vol-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.vol-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 5px 10px;
}
.vol-chip b {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

/* ---- 履歴 ---- */

.hist-sets { font-size: 13px; color: var(--muted); line-height: 1.7; }
.hist-sets b { color: var(--text); font-weight: 600; font-family: var(--num); letter-spacing: .02em; }

.session-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.session-row:last-child { border-bottom: none; }
.session-row .date { font-size: 12px; color: var(--muted); margin-bottom: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- 履歴カレンダー ---- */

.cal-card { padding: 12px 10px 10px; margin-bottom: 14px; }
.cal-nav { margin-bottom: 8px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--faint); padding: 2px 0 6px; }
.cal-day {
  position: relative;
  aspect-ratio: 1;
  border: none;
  background: none;
  border-radius: 10px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0;
}
.cal-day .num { font-family: var(--num); font-size: 14px; line-height: 1; }
.cal-day:disabled { color: var(--faint); }
.cal-day.has { background: var(--surface2); border: 1px solid var(--border); }
.cal-day .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--red); }
.cal-day.today { box-shadow: inset 0 0 0 1px var(--blue); }
.cal-day.sel { background: linear-gradient(180deg, var(--red) 0%, var(--red-deep) 100%); border-color: var(--red-deep); color: #fff; }
.cal-day.sel .dot { background: #fff; }

/* ---- 実績ストリップ・自己ベスト(PR) ---- */

.stats-strip { display: flex; padding: 14px 6px; margin-bottom: 14px; }
.stats-strip .stat { flex: 1; text-align: center; min-width: 0; }
.stats-strip .stat b {
  display: block;
  font-family: var(--num);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--text);
  white-space: nowrap;
}
.stats-strip .stat b small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 1px; }
.stats-strip .stat span { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.stats-strip .stat + .stat { border-left: 1px solid var(--border); }

.done-btn.pr {
  background: linear-gradient(180deg, var(--yellow) 0%, #C9962F 100%);
  border-color: #C9962F;
  font-size: 16px;
  animation: pr-pop .45s ease;
}
.set-row.pr input:first-of-type { color: var(--yellow); font-weight: 700; }
@keyframes pr-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.28); }
  100% { transform: scale(1); }
}

/* ---- RIR列(セット行を6列に) ---- */

.set-row, .set-head { grid-template-columns: 34px 1fr 12px 1fr 42px 44px; gap: 6px; }
.set-row input.rir {
  font-size: 16px;
  color: var(--muted);
  padding: 9px 2px;
}
.set-row.done input.rir { color: var(--text); }

/* ---- グラフの点タップツールチップ ---- */
.chart-wrap .chart-hit { cursor: pointer; }
.chart-wrap .chart-tip rect { filter: drop-shadow(0 2px 4px rgba(0,0,0,.4)); }
