/* iPhone での片手操作を前提にした見た目。
   ・タップ対象は最低 44px
   ・入力欄の文字は 16px 以上（これ未満だと Safari が勝手に拡大する）
   ・下端はホームバーを避けるため safe-area 分の余白を取る */

:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --text: #23252a;
  --muted: #6d7078;
  --line: #dcd8ce;
  --accent: #3b6ea5;
  --accent-soft: #e6eef7;
  --warn: #a8532b;
  --warn-soft: #f9ece3;
  --danger: #a33a33;
  --good: #2f7d5d;
  --radius: 12px;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1f2229;
    --surface-2: #272b33;
    --text: #e8e6e1;
    --muted: #9aa0aa;
    --line: #343943;
    --accent: #7aa9dd;
    --accent-soft: #23303f;
    --warn: #e0a175;
    --warn-soft: #33281f;
    --danger: #e08a83;
    --good: #7fc4a4;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

#header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 0.5rem) 1rem 0.5rem;
}

#header h1 { font-size: 1rem; margin: 0; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }

#main { padding: 0.75rem; max-width: 720px; margin: 0 auto; }

h2 { font-size: 1.3rem; margin: 0.25rem 0; }
h3 { font-size: 1.02rem; margin: 0 0 0.5rem; }
h4 { font-size: 0.95rem; margin: 0.75rem 0 0.25rem; }
p { margin: 0.4rem 0; }

.view { display: flex; flex-direction: column; gap: 0.75rem; }
.view-head { display: flex; flex-direction: column; gap: 0.25rem; }
.lead { color: var(--muted); font-size: 0.9rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem;
}

.card-title { font-size: 1rem; margin: 0 0 0.5rem; }
.card-title.warn { color: var(--warn); }
.card-title.accent { color: var(--accent); }
.muted { color: var(--muted); font-size: 0.85rem; }
.muted-inline { color: var(--muted); font-size: 0.8rem; font-weight: 400; margin-left: 0.4rem; }
.hint { color: var(--muted); font-size: 0.82rem; line-height: 1.5; margin: 0.35rem 0 0; }
.hint.center { text-align: center; }
.hint.warn, .warn { color: var(--warn); }
.disclaimer { color: var(--muted); font-size: 0.78rem; padding: 0.5rem 0 1.5rem; }

.warn-box {
  background: var(--warn-soft);
  border-left: 3px solid var(--warn);
  padding: 0.6rem 0.7rem;
  border-radius: 6px;
  font-size: 0.88rem;
}

.row { display: flex; align-items: center; gap: 0.5rem; }
.row.gap { gap: 0.6rem; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }

/* --- 日付の移動 --- */
.date-nav {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.35rem;
}
.nav-arrow {
  min-width: var(--tap); min-height: var(--tap);
  font-size: 1.5rem; background: none; border: none; color: var(--accent); cursor: pointer;
}
.date-center { text-align: center; display: flex; flex-direction: column; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 0.85rem; cursor: pointer; padding: 0; }
.date-chip {
  background: var(--surface-2); border-radius: 999px;
  padding: 0.1rem 0.6rem; font-size: 0.85rem; color: var(--muted);
}
.progress-pill {
  background: var(--surface-2); border-radius: 999px;
  padding: 0.1rem 0.6rem; font-size: 0.85rem; color: var(--muted);
}
.progress-pill.done { background: var(--accent-soft); color: var(--accent); }

/* --- ワンタップ記録 --- */
.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.quick-btn {
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  min-height: 76px; padding: 0.6rem 0.3rem;
  background: var(--accent-soft); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 0.9rem; font-family: inherit; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.quick-btn:active { transform: scale(0.97); }
.quick-icon { font-size: 1.6rem; line-height: 1.2; }

/* --- ボタン --- */
.big-btn {
  flex: 1; min-height: var(--tap);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0.6rem 0.9rem;
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius);
  font-size: 1rem; font-family: inherit; font-weight: 600; cursor: pointer;
}
.big-btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.big-btn.danger { background: var(--danger); color: #fff; }
.big-btn .sub { font-size: 0.75rem; font-weight: 400; opacity: 0.9; }
.checkin-btn { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.checkin-btn.filled { border-color: var(--accent); background: var(--accent-soft); }

.mini-btn {
  min-height: 36px; padding: 0.2rem 0.7rem;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 0.85rem; font-family: inherit; cursor: pointer;
}
.mini-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* --- 入力欄 --- */
.field { margin-bottom: 0.9rem; }
.field:last-child { margin-bottom: 0; }
.field-head { display: flex; align-items: center; gap: 0.5rem; min-height: 26px; }
.field-label { font-size: 0.95rem; font-weight: 500; flex: 1; }
.core > .field-head > .field-label { font-weight: 700; }
.unit { color: var(--muted); font-size: 0.9rem; }

.text-input {
  width: 100%; min-height: var(--tap);
  padding: 0.45rem 0.6rem;
  font-size: 16px; font-family: inherit;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px;
}
textarea.text-input { min-height: 72px; }

.scale-value {
  font-variant-numeric: tabular-nums;
  font-size: 1.25rem; font-weight: 700; min-width: 2.2rem; text-align: right;
  color: var(--accent);
}
.scale-range { width: 100%; height: var(--tap); accent-color: var(--accent); }
.scale-range.untouched { opacity: 0.4; }
.scale-ends { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); margin-top: -0.4rem; }

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
  min-height: 38px; padding: 0.25rem 0.75rem;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 0.9rem; font-family: inherit; cursor: pointer;
  touch-action: manipulation;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-group { margin-bottom: 0.6rem; }
.chip-group-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
.tabs { margin-bottom: 0.25rem; }

.sub-details { margin-top: 0.6rem; border-top: 1px solid var(--line); padding-top: 0.5rem; }
.sub-details > summary { cursor: pointer; color: var(--accent); font-size: 0.9rem; min-height: var(--tap); display: flex; align-items: center; }

/* --- 自動計算の一覧 --- */
.stat-list { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 0.75rem; }
.stat { display: contents; }
.stat dt { color: var(--muted); font-size: 0.88rem; }
.stat dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-size: 0.9rem; }

/* --- 時系列 --- */
.timeline { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.timeline-row {
  display: grid; grid-template-columns: 3.2rem 6.5rem 1fr auto;
  gap: 0.4rem; align-items: baseline;
  padding: 0.5rem 0.2rem; border-top: 1px solid var(--line);
  font-size: 0.88rem; min-height: var(--tap);
}
.timeline-row.editable { cursor: pointer; }
.timeline-row.editable:active { background: var(--surface-2); }
.tl-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-detail { color: var(--muted); overflow-wrap: anywhere; }
.tl-edit { color: var(--accent); }

/* --- グラフ --- */
.chart-wrap { width: 100%; overflow-x: auto; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .axis-title { fill: var(--muted); font-size: 12px; }
.chart .dot { fill: var(--accent); opacity: 0.75; }
.chart .tl-icon { font-size: 16px; }
.timeline-chart { max-height: 80px; }
.y-title { font-size: 0.78rem; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 0.75rem; font-size: 0.8rem; color: var(--muted); margin-top: 0.3rem; }
.legend-item { display: inline-flex; align-items: center; gap: 0.3rem; }
.legend-item i { width: 11px; height: 3px; border-radius: 2px; display: inline-block; }

/* --- 分析の結果 --- */
.result-head { display: flex; align-items: center; gap: 0.5rem; justify-content: space-between; margin-bottom: 0.4rem; }
.badge { font-size: 0.75rem; padding: 0.1rem 0.55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.lv-strong .badge { background: var(--accent); color: #fff; }
.lv-moderate .badge { background: var(--accent-soft); color: var(--accent); }
.lv-insufficient .badge { background: var(--surface-2); color: var(--muted); }
.lv-spurious .badge { background: var(--warn-soft); color: var(--warn); }
.result-headline { font-size: 0.92rem; font-weight: 600; }

.plain-list { margin: 0.3rem 0; padding-left: 1.1rem; }
.plain-list.small { font-size: 0.86rem; color: var(--muted); }
.plain-list li { margin-bottom: 0.2rem; }

.exp-priority { font-size: 0.8rem; color: var(--accent); font-weight: 600; }
.exp-title { font-size: 1.05rem; font-weight: 700; margin: 0.1rem 0 0.4rem; }

/* --- 下のタブ --- */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.1rem; min-height: 56px; text-decoration: none;
  color: var(--muted); font-size: 0.7rem;
}
.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 1.2rem; line-height: 1.1; }

/* --- シート --- */
.sheet-back {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: flex-end;
  opacity: 0; transition: opacity 0.18s ease;
}
.sheet-back.shown { opacity: 1; }
.sheet {
  width: 100%; max-height: 92vh; overflow-y: auto;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
  transform: translateY(2%); transition: transform 0.18s ease;
}
.sheet-back.shown .sheet { transform: translateY(0); }
.sheet-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; padding: 0.6rem 0.8rem;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.sheet-body { padding: 0.85rem; }
.sheet-actions { margin-top: 1rem; }

/* --- トースト --- */
.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px); z-index: 50;
  background: var(--text); color: var(--bg);
  padding: 0.5rem 1rem; border-radius: 999px; font-size: 0.9rem;
  opacity: 0; transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none; max-width: 90vw; text-align: center;
}
.toast.shown { opacity: 1; transform: translate(-50%, 0); }

/* --- 折りたたみ --- */
.section-head {
  width: 100%; display: flex; align-items: center; gap: 0.5rem;
  background: none; border: none; color: var(--text);
  font-size: 1rem; font-family: inherit; font-weight: 600;
  min-height: var(--tap); cursor: pointer; text-align: left;
}
.section-sub { color: var(--muted); font-size: 0.8rem; font-weight: 400; margin-left: auto; }
.section .caret { transition: transform 0.15s ease; color: var(--muted); }
.section.open .caret { transform: rotate(90deg); }
.section:not(.open) .section-body { display: none; }

/* --- 記録が消える状況の警告 --- */
#alerts { max-width: 720px; margin: 0 auto; padding: 0.75rem 0.75rem 0; display: flex; flex-direction: column; gap: 0.5rem; }
#alerts:empty { display: none; }
.alert {
  border-radius: var(--radius);
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  background: var(--warn-soft);
  border-left: 4px solid var(--warn);
}
.alert strong { display: block; color: var(--warn); margin-bottom: 0.2rem; }
.alert p { font-size: 0.85rem; margin: 0 0 0.5rem; }
.alert-danger { background: var(--warn-soft); border-left-color: var(--danger); }
.alert-danger strong { color: var(--danger); }
