/* パチツール：スマホで見やすいシンプルな見た目 */
:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #17191c;
  --muted: #6b7280;
  --line: #e2e5e9;
  --field: #f8f9fa;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3f1;
  --plus: #1d4ed8;
  --minus: #dc2626;
  --warn: #b45309;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --card: #191c21;
    --text: #eceef1;
    --muted: #9aa2ad;
    --line: #2a2f37;
    --field: #111418;
    --accent: #2dd4bf;
    --accent-ink: #04201d;
    --accent-soft: #10302d;
    --plus: #60a5fa;
    --minus: #f87171;
    --warn: #fbbf24;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
h2 { margin: 0 0 10px; font-size: 16px; }
small { color: var(--muted); font-size: 13px; font-weight: 400; }

.topbar {
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { max-width: 560px; margin: 0 auto; font-size: 18px; }

main { max-width: 560px; margin: 0 auto; padding: 12px 16px 24px; }

.card {
  margin-bottom: 12px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card > :last-child { margin-bottom: 0; }

/* 入力 */
.field { display: block; margin-bottom: 12px; }
.field > span:first-child { display: block; margin-bottom: 4px; font-size: 14px; font-weight: 700; }
.hint { margin: -4px 0 12px; color: var(--muted); font-size: 13px; }

input, select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 18px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input::placeholder { color: var(--muted); opacity: 0.6; }

.input-unit { position: relative; display: flex; align-items: center; }
.input-unit input { padding-right: 44px; text-align: right; font-variant-numeric: tabular-nums; }
.input-unit em { position: absolute; right: 12px; color: var(--muted); font-style: normal; pointer-events: none; }
.input-unit.pre input { padding-right: 12px; padding-left: 40px; text-align: left; }
.input-unit.pre em { right: auto; left: 12px; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.seg { display: flex; gap: 4px; padding: 4px; background: var(--field); border: 1px solid var(--line); border-radius: 12px; }
.seg button {
  flex: 1;
  min-height: 42px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 9px;
  font: inherit;
  font-weight: 700;
}
.seg button.on { color: var(--accent-ink); background: var(--accent); }

.helper { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; margin-bottom: 8px; font-size: 14px; }

/* ボタン */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 16px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.btn.danger { color: var(--minus); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 38px; padding: 0 12px; border-radius: 10px; font-size: 14px; }
.btn.wide { width: 100%; }
.link { padding: 0 6px; color: var(--accent); background: none; border: 0; font: inherit; font-size: 14px; text-decoration: underline; }

.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: -4px 0 12px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.actions .btn { flex: 1; }

/* 結果（スクロールしても上に残す） */
.result {
  position: sticky;
  top: 0;
  z-index: 4;
  margin: 0 -4px 12px;
  padding: 12px 12px 14px;
  text-align: center;
  background: var(--accent-soft);
  border-radius: var(--radius);
  box-shadow: 0 6px 12px -10px rgba(0, 0, 0, 0.5);
}
.big { font-size: 44px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.big small { margin-left: 6px; color: var(--text); font-size: 15px; font-weight: 700; }
.result-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.result-sub b { color: var(--text); }
.diff { margin: 4px 0 0; font-size: 14px; font-weight: 700; white-space: pre-line; }
.diff:empty { display: none; }

.plus { color: var(--plus); }
.minus { color: var(--minus); }
.warn { margin: -4px 0 12px; color: var(--warn); font-size: 14px; font-weight: 700; }
.acc { margin: 0 0 10px; font-size: 14px; }
.calc-line { margin: 0 0 12px; font-size: 15px; }
.note { margin: 0 0 12px; color: var(--warn); font-size: 14px; font-weight: 700; }
.note:empty { display: none; }
.editing { margin: 0 0 8px; padding: 8px 12px; background: var(--accent-soft); border-radius: 10px; font-size: 14px; font-weight: 700; }

/* 一覧 */
.list-title { margin: 20px 0 8px; }
.slots, .records { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.slot, .rec {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.slot.current, .rec.current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.slot-body { display: grid; min-width: 0; }
.slot-body b, .slot-body small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-body span { font-size: 18px; font-weight: 800; }
.slot-btns, .rec-btns { display: flex; flex-shrink: 0; gap: 6px; }
.empty { padding: 16px; color: var(--muted); text-align: center; background: var(--card); border: 1px dashed var(--line); border-radius: 12px; }

.rec { align-items: flex-start; }
.rec-main { min-width: 0; }
.rec-top { display: flex; gap: 8px; font-weight: 700; }
.rec-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-sub { color: var(--muted); font-size: 13px; }
.rec-side { display: grid; flex-shrink: 0; gap: 6px; justify-items: end; }
.rec-side b { font-size: 17px; font-variant-numeric: tabular-nums; }
.month { display: flex; justify-content: space-between; padding: 10px 4px 0; color: var(--muted); font-size: 14px; font-weight: 700; }
.month b { font-size: 15px; }

.summary { display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; gap: 8px; margin-bottom: 12px; }
.summary > div { padding: 12px 8px; text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.summary small { display: block; }
.summary b { font-size: 17px; font-variant-numeric: tabular-nums; }

/* メニュー */
.menu { display: grid; gap: 12px; margin-bottom: 16px; }
.menu a {
  display: block;
  padding: 20px 16px;
  color: var(--text);
  text-decoration: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.menu a b { display: block; font-size: 21px; }
.menu a span { color: var(--muted); font-size: 14px; }

/* 下のタブ */
.tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}
.tabbar a.on { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

.toast {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom));
  left: 50%;
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  color: #fff;
  text-align: center;
  background: rgba(17, 24, 39, 0.92);
  border-radius: 12px;
  font-size: 14px;
  transform: translateX(-50%);
}
