:root {
  --bg: #101214;
  --surface: #1C2024;
  --raised: #343A40;
  --line: #4A5157;
  --text: #F2F4F5;
  --sub: #A6AFB6;
  --accent: #FFD23F;
  --on-accent: #101214;
  --danger: #FF9B8A;
  --font: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', system-ui, -apple-system, sans-serif;
  /* 数字は SF（-apple-system）の等幅数字を優先し、和文は Hiragino にフォールバック */
  --num: -apple-system, system-ui, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body { overscroll-behavior: none; }

button, input { font: inherit; color: inherit; }

button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

h1, h2, p { margin: 0; }

.num { font-family: var(--num); font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

svg.i { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- 画面の骨組み ---------- */
.screen {
  height: 100vh;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: max(20px, calc(env(safe-area-inset-top) + 12px)) 16px max(20px, calc(env(safe-area-inset-bottom) + 8px));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.head { display: flex; align-items: center; gap: 4px; min-height: 44px; }
.head-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.head-sub { font-size: 13px; line-height: 1.5; color: var(--sub); }
.title { font-size: 22px; line-height: 1.3; font-weight: 700; overflow-wrap: anywhere; }
.title-big { font-size: 28px; line-height: 1.3; font-weight: 800; }
.top { margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.back {
  flex: none;
  width: 44px;
  height: 44px;
  margin-left: -8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  border-radius: 10px;
}
.back:active { background: var(--surface); }

.link {
  min-width: 64px;
  height: 44px;
  margin-right: -4px;
  color: var(--accent);
  font-size: 17px;
  font-weight: 700;
  border-radius: 10px;
}
.link:active { background: var(--surface); }
.link.danger { color: var(--danger); }

.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.scroll > * { flex: none; }

.card { padding: 12px 14px; border-radius: 12px; background: var(--surface); }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.row { display: flex; gap: 12px; }
.row > .w2 { flex: 2; }
.row > .w1 { flex: 1; }

/* ---------- ボタン ---------- */
.btn {
  min-height: 64px;
  padding: 0 12px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 19px;
  font-weight: 800;
  line-height: 1.3;
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.outline { border: 2px solid var(--accent); color: var(--accent); }
.btn.raised { background: var(--raised); color: var(--text); font-size: 18px; }
.btn.danger { background: var(--danger); color: var(--on-accent); }
.btn.danger-outline { border: 1px solid var(--danger); color: var(--danger); }
.btn.sm { min-height: 52px; font-size: 16px; border-radius: 10px; }
.btn:disabled { opacity: .4; }
.btn.primary:active, .btn.danger:active { filter: brightness(.88); }
.btn.raised:active, .btn.outline:active, .btn.danger-outline:active { filter: brightness(1.25); }

.chip {
  flex: none;
  min-width: 64px;
  height: 48px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--raised);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}
.chip:active { filter: brightness(1.25); }
.chip.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }

.confirm { display: flex; flex-direction: column; gap: 10px; }
.confirm-text { font-size: 15px; line-height: 1.5; }
.confirm-text strong { color: var(--danger); font-weight: 700; }

/* ---------- マシン一覧 ---------- */
.mrow {
  min-height: 80px;
  border-radius: 12px;
  background: var(--surface);
  display: flex;
  align-items: stretch;
  overflow: hidden;
}
.mrow-main {
  flex: 1;
  min-width: 0;
  padding: 10px 8px 10px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  color: var(--text);
}
.mrow-main:active, .mrow-graph:active { background: var(--raised); }
.mname { font-size: 19px; line-height: 1.35; font-weight: 700; overflow-wrap: anywhere; }
.msum { display: flex; align-items: center; gap: 4px; font-size: 14px; line-height: 1.4; color: var(--sub); }
.msum.done { color: var(--accent); }
.mrow-graph {
  flex: none;
  width: 64px;
  border-left: 1px solid var(--raised);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.hint { font-size: 14px; line-height: 1.6; color: var(--sub); padding: 4px 2px; }

.field {
  width: 100%;
  height: 52px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
}
.field:focus { border-color: var(--accent); outline: none; }
.addform { display: flex; flex-direction: column; gap: 10px; padding: 12px; border-radius: 12px; background: var(--surface); }
.addform label { font-size: 14px; color: var(--sub); }

/* ---------- 記録 ---------- */
.sets { gap: 6px; }
.set {
  width: 100%;
  min-height: 58px;
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}
.set.on { background: var(--raised); }
.set-no { width: 22px; font-size: 15px; color: var(--sub); }
.set-body { flex: 1; display: flex; flex-direction: column; }
.set-main { font-size: 18px; line-height: 1.35; font-weight: 700; }
.set-prev { font-size: 13px; line-height: 1.4; color: var(--sub); }

.label-row { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.label-row p { font-size: 15px; line-height: 1.5; font-weight: 700; }
.small-danger {
  min-height: 44px;
  padding: 0 10px;
  margin-right: -6px;
  color: var(--danger);
  font-size: 15px;
  font-weight: 700;
  border-radius: 8px;
}
.small-danger:active { background: var(--surface); }
.label-row .chip { height: 44px; }

.tile {
  height: 124px;
  border: 2px solid var(--raised);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.tile.on { border-color: var(--accent); }
.tile-k { font-size: 14px; color: var(--sub); }
.tile-vw { display: flex; align-items: baseline; gap: 4px; }
.tile-v { font-size: 56px; line-height: 1.05; font-weight: 800; }
.tile-u { font-size: 17px; font-weight: 600; }

.steppers { display: flex; gap: 12px; }
.step {
  flex: 1;
  height: 92px;
  border-radius: 12px;
  background: var(--raised);
  color: var(--text);
  font-size: 44px;
  font-weight: 500;
  line-height: 1;
}
.step:active, .step.held { filter: brightness(1.3); }

/* バイク */
.tile.big { flex: 1; min-height: 140px; height: auto; padding: 16px; }
.tile.big .tile-v { font-size: 104px; line-height: 1; }
.tile.big .tile-u { font-size: 22px; }
.tile.mid { height: 112px; }
.tile.mid .tile-v { font-size: 44px; line-height: 1.1; }
.tile.mid .tile-u { font-size: 16px; }

/* ---------- 保存後 ---------- */
.hero { flex: 1 0 auto; min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.hero-k { font-size: 15px; line-height: 1.5; font-weight: 600; color: var(--sub); overflow-wrap: anywhere; }
.hero-v { margin-top: 2px; display: flex; align-items: baseline; gap: 5px; color: var(--accent); }
.hero-v .n { font-size: 76px; line-height: 1.05; font-weight: 800; }
.hero-v .u { font-size: 22px; font-weight: 700; }
.hero-plain { margin-top: 4px; font-size: 40px; line-height: 1.2; font-weight: 800; }
.badge {
  margin-top: 10px;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 17px;
  background: var(--accent);
  color: var(--on-accent);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 800;
}

.cmp { width: 100%; border-collapse: collapse; font-size: 15px; }
.cmp th, .cmp td { padding: 0; text-align: left; height: 34px; }
.cmp thead th { height: 32px; color: var(--sub); font-size: 13px; font-weight: 400; }
.cmp tbody th { font-weight: 400; width: 46px; }
.cmp td { font-weight: 700; }
.cmp td.prev { color: var(--sub); font-weight: 400; }
.cmp tr.sum { border-top: 1px solid var(--line); }

/* ---------- グラフ ---------- */
.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.seg button { height: 44px; border-radius: 8px; background: var(--raised); color: var(--text); font-size: 14px; font-weight: 700; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.chart { display: block; width: 100%; height: auto; margin-top: 6px; }
.chart text { font-family: var(--num); font-size: 14px; fill: var(--sub); }
.chart .strong { font-size: 16px; font-weight: 700; fill: var(--text); }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--accent); }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .blk { fill: var(--accent); }
.empty { padding: 20px 0; text-align: center; font-size: 14px; color: var(--sub); }

/* ---------- 推移 ---------- */
.gain { display: flex; flex-direction: column; align-items: center; text-align: center; }
.gain-k { font-size: 14px; line-height: 1.5; color: var(--sub); }
.gain-v { display: flex; align-items: baseline; gap: 4px; color: var(--accent); }
.gain-v .n { font-size: 58px; line-height: 1.1; font-weight: 800; }
.gain-v .u { font-size: 20px; font-weight: 700; }
.gain-none { font-size: 18px; line-height: 1.6; color: var(--sub); padding: 12px 0; }
.hist { gap: 6px; }
.hrow {
  width: 100%;
  min-height: 60px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}
.hrow:active { background: var(--raised); }
.hrow-date { flex: none; width: 66px; font-size: 15px; line-height: 1.4; font-weight: 700; }
.hrow-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hrow-main { font-size: 15px; line-height: 1.4; font-weight: 700; }
.hrow-sub { font-size: 13px; line-height: 1.4; color: var(--sub); overflow-wrap: anywhere; }
.hrow svg { color: var(--sub); }

/* ---------- 通った日 ---------- */
.stat {
  min-height: 96px;
  padding: 10px 4px;
  border-radius: 12px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.stat-k { font-size: 13px; color: var(--sub); }
.stat-vw { display: flex; align-items: baseline; gap: 2px; font-size: 13px; }
.stat-v { font-size: 34px; line-height: 1.15; font-weight: 800; }
.stat-v.acc { color: var(--accent); }
.card h2 { margin: 0 0 6px; font-size: 14px; line-height: 1.5; font-weight: 600; color: var(--sub); }
.drow {
  min-height: 52px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 12px;
}
.drow-date { flex: none; width: 66px; font-size: 15px; line-height: 1.4; font-weight: 700; }
.drow-names { flex: 1; min-width: 0; font-size: 13px; line-height: 1.45; color: var(--sub); overflow-wrap: anywhere; }
.backup-k { font-size: 13px; color: var(--sub); }

/* ---------- 編集 ---------- */
.erow {
  min-height: 72px;
  padding: 10px 6px 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform .15s ease;
  position: relative;
}
.erow.dragging { transition: none; z-index: 2; background: var(--raised); box-shadow: 0 8px 24px rgba(0,0,0,.5); }
.einput {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
}
.einput:focus { border-color: var(--accent); outline: none; }
.handle {
  flex: none;
  width: 44px;
  height: 48px;
  color: var(--sub);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: grab;
}
.sec { margin-top: 10px; font-size: 14px; line-height: 1.5; font-weight: 600; color: var(--sub); }
.hcard { padding: 10px 12px; border-radius: 12px; background: var(--surface); display: flex; flex-direction: column; gap: 10px; }
.hcard-top { min-height: 48px; display: flex; align-items: center; gap: 8px; }
.hcard-name { flex: 1; min-width: 0; font-size: 16px; font-weight: 700; color: var(--sub); overflow-wrap: anywhere; }

/* ---------- トースト ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: max(16px, calc(env(safe-area-inset-top) + 8px));
  transform: translate(-50%, -8px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--raised);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 縦が短い端末（iPhone SE など） */
@media (max-height: 720px) {
  .screen { gap: 10px; }
  .tile { height: 100px; }
  .tile-v { font-size: 46px; }
  .step { height: 76px; }
  .btn { min-height: 56px; }
  .tile.big .tile-v { font-size: 80px; }
  .tile.big { min-height: 110px; }
  .tile.mid { height: 96px; }
  .hero { min-height: 140px; }
  .hero-v .n { font-size: 64px; }
  .gain-v .n { font-size: 48px; }
}
