/* スマートフォン基準（320px〜）。PC では中央に 560px 幅で表示する。 */

:root {
  --bg: #f3f4f8;
  --surface: #ffffff;
  --surface-2: #eceef4;
  --text: #171a22;
  --muted: #5f6675;
  --line: #dde0e8;
  --accent: #4338ca;
  --accent-ink: #ffffff;
  --accent-soft: #e6e5fb;
  --gold: #b7860b;
  --pos: #0f7a3d;
  --neg: #c81e1e;
  --warn-bg: #fff4e0;
  --warn: #8a5300;
  --hero-1: #3b2fc0;
  --hero-2: #5b4fe0;
  --shadow: 0 1px 2px rgb(16 20 40 / 6%), 0 2px 10px rgb(16 20 40 / 5%);
  --radius: 16px;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1015;
    --surface: #181b23;
    --surface-2: #232733;
    --text: #eceef3;
    --muted: #9aa1b2;
    --line: #2c3140;
    --accent: #8f88ff;
    --accent-ink: #0e1015;
    --accent-soft: #272552;
    --gold: #f0c04a;
    --pos: #4ade80;
    --neg: #ff7a7a;
    --warn-bg: #3a2a0c;
    --warn: #ffcf7a;
    --hero-1: #2b2394;
    --hero-2: #463cc4;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1015;
  --surface: #181b23;
  --surface-2: #232733;
  --text: #eceef3;
  --muted: #9aa1b2;
  --line: #2c3140;
  --accent: #8f88ff;
  --accent-ink: #0e1015;
  --accent-soft: #272552;
  --gold: #f0c04a;
  --pos: #4ade80;
  --neg: #ff7a7a;
  --warn-bg: #3a2a0c;
  --warn: #ffcf7a;
  --hero-1: #2b2394;
  --hero-2: #463cc4;
  --shadow: none;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

#main {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 24px);
}

a { color: var(--accent); }
h1, h2 { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.pad { padding: 4px 4px 0; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.zero { color: var(--muted); }

.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.fav { width: 16px; height: 16px; fill: var(--gold); stroke: var(--gold); stroke-width: 1.2; margin-right: 4px; vertical-align: -2px; }

/* ---- スプラッシュ ---- */
#splash {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-content: center; justify-items: center; gap: 14px;
  background: var(--bg); color: var(--text); font-weight: 700; font-size: 18px;
  transition: opacity .3s;
}
#splash img { border-radius: 22px; }
#splash.hide { opacity: 0; pointer-events: none; }

/* ---- 上部バー ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 6px;
  min-height: 56px;
  padding: env(safe-area-inset-top, 0px) 16px 0;
  padding-top: max(env(safe-area-inset-top, 0px), 0px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
}
.topbar h1 { font-size: 20px; font-weight: 800; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-date { color: var(--muted); font-size: 14px; white-space: nowrap; }
.topbar .icon-btn { margin-left: -10px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn:disabled { opacity: .3; }
.icon-btn.flip .icon { transform: scaleX(-1); }

.content { padding: 4px 16px 16px; display: flex; flex-direction: column; gap: 14px; }

/* ---- カード ---- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.card.list { padding: 4px 0; }
.card.stack { display: flex; flex-direction: column; gap: 10px; }
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.card.empty { text-align: center; padding: 28px 18px; }
.card.empty p { color: var(--muted); margin: 8px 0 20px; }

.section { display: flex; flex-direction: column; gap: 8px; }
.section > h2, .section-head h2 { font-size: 15px; font-weight: 700; color: var(--muted); padding: 0 4px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; }
.section-head a { font-size: 14px; font-weight: 600; text-decoration: none; padding: 8px 4px; }

/* ---- ホーム ---- */
.hero {
  border-radius: 22px;
  padding: 20px 20px 18px;
  color: #fff;
  background: linear-gradient(140deg, var(--hero-1), var(--hero-2));
  box-shadow: 0 6px 20px rgb(59 47 192 / 25%);
}
.hero-label { font-size: 14px; opacity: .85; font-weight: 600; }
.hero-num { font-size: clamp(38px, 12vw, 52px); font-weight: 800; line-height: 1.15; letter-spacing: -.01em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hero-num small, .tile-val small, .store-medals small { font-size: .45em; font-weight: 700; margin-left: 3px; }
.hero-yen { margin-top: 6px; font-size: 15px; opacity: .95; }
.hero-yen strong { font-size: 22px; font-weight: 800; margin-left: 4px; font-variant-numeric: tabular-nums; }
.hero.small .hero-num { font-size: clamp(30px, 9vw, 38px); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.tile-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.tile-val { font-size: clamp(21px, 6.4vw, 26px); font-weight: 800; line-height: 1.25; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-sub { font-size: 12px; color: var(--muted); }

.btn-record {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 64px; border-radius: 18px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 20px; font-weight: 800; text-decoration: none;
  box-shadow: 0 6px 16px rgb(67 56 202 / 30%);
  transition: transform .08s;
}
.btn-record .icon { width: 28px; height: 28px; stroke-width: 2.2; }
.btn-record:active { transform: scale(.97); }

.notice { border-radius: 12px; padding: 10px 14px; font-size: 14px; background: var(--accent-soft); }
.notice.good { background: color-mix(in srgb, var(--pos) 16%, var(--surface)); }

.asset-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  min-height: 56px; padding: 8px 16px; text-decoration: none; color: var(--text);
}
.asset-row + .asset-row { border-top: 1px solid var(--line); }
.asset-row:active { background: var(--surface-2); }
.asset-name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.asset-nums { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.asset-nums span { font-size: 13px; color: var(--muted); }

/* ---- 目標 ---- */
.goal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.goal-rate { font-size: 22px; font-weight: 800; color: var(--accent); }
.progress { height: 12px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin: 6px 0 8px; }
.progress span { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--accent), var(--gold)); }
.goal-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; flex-wrap: wrap; }

/* ---- 記録カード ---- */
.tx-date { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; color: var(--muted); padding: 6px 4px 0; }
.tx-card {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 12px 14px; min-height: 60px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  text-decoration: none; color: var(--text);
  transition: transform .08s;
}
.tx-card:active { transform: scale(.985); background: var(--surface-2); }
.tx-main { min-width: 0; }
.tx-store { font-weight: 700; overflow-wrap: anywhere; }
.tx-sub, .tx-memo { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.tx-memo { white-space: pre-line; }
.tx-nums { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx-medals { font-size: 18px; font-weight: 800; }
.tx-yen, .tx-cash { font-size: 13px; color: var(--muted); }
.tx-cash.pos, .tx-cash.neg { font-weight: 600; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); vertical-align: 2px; }

/* ---- フォーム ---- */
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 14px; font-weight: 700; color: var(--muted); padding: 0; margin-bottom: 6px; }
.field .field-label { margin-bottom: 0; }

input[type="text"], input[type="number"], input[type="date"], input[type="time"], textarea, .select {
  width: 100%; min-height: 48px;
  padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font-size: 16px; /* 16px 未満だと iPhone で入力時に拡大される */
  appearance: none; -webkit-appearance: none;
}
input[type="date"], input[type="time"] { display: block; min-width: 0; }
textarea { resize: vertical; min-height: 64px; }
input:focus, textarea:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.unit-input { position: relative; }
.unit-input input { padding-right: 64px; }
.unit-input span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; pointer-events: none; }

.hint { font-size: 13px; color: var(--muted); margin: 0; }
.warn { font-size: 13px; color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 6px 10px; margin-top: 6px; }
.disclaimer { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.center { justify-content: center; }
.chip {
  display: inline-flex; align-items: center;
  min-height: 44px; padding: 8px 16px;
  border-radius: 99px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--text);
  font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: transform .08s;
}
.chips.small .chip { min-height: 40px; padding: 6px 12px; font-size: 14px; }
.chip:active { transform: scale(.95); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.on .icon.fav { fill: currentColor; stroke: currentColor; }
.chip.ghost { border-style: dashed; color: var(--muted); }

.amount-row { display: flex; align-items: center; gap: 8px; }
.amount-input { flex: 1; min-width: 0; font-size: 34px !important; font-weight: 800; text-align: right; min-height: 64px !important; font-variant-numeric: tabular-nums; }
.unit { font-weight: 700; font-size: 18px; }
.sign-btn {
  width: 56px; height: 64px; flex: none;
  border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface-2);
  font-size: 24px; font-weight: 800; cursor: pointer;
}
.sign-btn:disabled { opacity: .35; }
.sign-btn:active { transform: scale(.95); }
.preview { min-height: 22px; font-size: 14px; }
.preview-yen { font-size: 18px; font-weight: 800; }
.preview-bal { color: var(--muted); }
.preview-bal strong { color: var(--text); }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.qbtn {
  min-height: 52px; border-radius: 12px; border: 0;
  font-size: 16px; font-weight: 800; cursor: pointer; padding: 0 2px;
  font-variant-numeric: tabular-nums;
  transition: transform .08s, filter .08s;
}
.qbtn.pos { background: color-mix(in srgb, var(--pos) 14%, var(--surface)); color: var(--pos); }
.qbtn.neg { background: color-mix(in srgb, var(--neg) 12%, var(--surface)); color: var(--neg); }
.qbtn:active { transform: scale(.94); filter: brightness(.92); }
.label-row { display: flex; justify-content: space-between; align-items: center; margin: -10px 0 -6px; }
.link-btn { border: 0; background: none; color: var(--muted); font-size: 14px; min-height: 44px; padding: 0 4px; cursor: pointer; text-decoration: underline; }

.more { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 14px; }
.more summary { min-height: 52px; display: flex; align-items: center; font-weight: 700; font-size: 15px; cursor: pointer; list-style: none; }
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: "＋"; margin-left: auto; color: var(--muted); }
.more[open] summary::after { content: "－"; }
.more[open] { padding-bottom: 14px; }
.more[open] > :not(summary) { margin-top: 12px; }

.switch { display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; font-size: 15px; }
.switch input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }

.btn-primary, .btn, .btn-danger {
  display: flex; align-items: center; justify-content: center;
  min-height: 52px; padding: 10px 18px; border-radius: 14px;
  font-size: 17px; font-weight: 700; text-decoration: none; cursor: pointer; text-align: center;
  transition: transform .08s, filter .08s;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); border: 0; }
.btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); font-size: 16px; }
.btn-danger { background: transparent; color: var(--neg); border: 1.5px solid color-mix(in srgb, var(--neg) 40%, transparent); font-size: 15px; margin-top: 4px; }
.btn-primary:active, .btn:active, .btn-danger:active { transform: scale(.97); filter: brightness(.94); }
.btn-save { min-height: 60px; font-size: 20px; font-weight: 800; position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + 10px); z-index: 5; box-shadow: 0 6px 18px rgb(67 56 202 / 30%); }

.inline-form { display: flex; gap: 8px; margin-top: 12px; }
.inline-form input { flex: 1; min-width: 0; }
.inline-form .btn { flex: none; white-space: nowrap; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); margin-bottom: 14px; }
.seg-opt { position: relative; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-opt span { display: grid; place-items: center; min-height: 44px; border-radius: 10px; font-size: 14px; font-weight: 700; text-align: center; line-height: 1.25; padding: 4px; }
.seg-opt input:checked + span { background: var(--surface); box-shadow: var(--shadow); color: var(--accent); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--accent); }

/* ---- 履歴 ---- */
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.segmented a { display: grid; place-items: center; min-height: 44px; border-radius: 10px; font-size: 15px; font-weight: 700; color: var(--muted); text-decoration: none; }
.segmented a[aria-current] { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.month-nav { display: flex; align-items: center; justify-content: space-between; }
.month-nav strong { font-size: 18px; }

.chart { position: relative; width: 100%; touch-action: pan-y; }
.chart-svg { display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-zero { stroke: var(--muted); stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 11px; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--accent); opacity: .12; }
.chart-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-guide { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart-bar.pos { fill: var(--pos); }
.chart-bar.neg { fill: var(--neg); }
.chart-hit { fill: transparent; }
.chart-tip {
  position: absolute; top: -6px; z-index: 2;
  background: var(--text); color: var(--bg);
  font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 8px;
  white-space: nowrap; pointer-events: none; font-variant-numeric: tabular-nums;
}

.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 10px 4px; border-bottom: 1px solid var(--line); text-align: right; font-size: 15px; }
.table th:first-child { text-align: left; }
.table thead th { font-size: 12px; color: var(--muted); font-weight: 700; padding-top: 0; }
.table tbody th { font-weight: 600; overflow-wrap: anywhere; }
.table tbody th small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.table tbody tr:last-child > * { border-bottom: 0; }
.fc-basis { margin: 0 0 6px; font-size: 15px; }
.fc-basis span { font-size: 13px; }

/* ---- 店舗 ---- */
.store-card { display: block; text-decoration: none; color: var(--text); transition: transform .08s; }
.store-card:active { transform: scale(.985); }
.store-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.store-head .muted { font-size: 13px; }
.store-name { font-size: 18px; font-weight: 800; overflow-wrap: anywhere; }
.store-nums { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 4px; font-variant-numeric: tabular-nums; }
.store-medals { font-size: 28px; font-weight: 800; }
.store-yen { font-weight: 700; color: var(--muted); }
.share { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.share span { display: block; height: 100%; background: var(--gold); }
.store-memo { font-size: 13px; color: var(--muted); margin: 8px 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.locked { text-align: center; }

.info dl { margin: 0 0 12px; }
.info dl div { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.info dt { color: var(--muted); flex: none; width: 5.5em; }
.info dd { margin: 0; overflow-wrap: anywhere; }

/* ---- トースト ---- */
.toast {
  position: fixed; z-index: 50;
  left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  transform: translate(-50%, 20px);
  width: min(528px, calc(100% - 24px));
  display: flex; align-items: center; gap: 8px;
  padding: 10px 10px 10px 16px; min-height: 52px; border-radius: 14px;
  background: #1f2330; color: #fff; font-size: 15px; font-weight: 600;
  box-shadow: 0 8px 24px rgb(0 0 0 / 25%);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast.error { background: #a61b1b; }
.toast-msg { flex: 1; min-width: 0; }
.toast-action { flex: none; min-height: 40px; padding: 0 12px; border: 0; border-radius: 10px; background: rgb(255 255 255 / 16%); color: #fff; font-weight: 700; cursor: pointer; }

/* ---- 下部ナビ ---- */
.nav {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-top: 1px solid var(--line);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--nav-h); min-width: 0;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 700;
}
.nav a:active { background: var(--surface-2); }
.nav a[aria-current] { color: var(--accent); }
.nav a[aria-current] .icon { stroke-width: 2.4; }
@media (min-width: 600px) {
  .nav { left: 50%; right: auto; width: 560px; transform: translateX(-50%); border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; }
}

@media (max-width: 359px) {
  .content { padding-left: 12px; padding-right: 12px; }
  .qbtn { font-size: 14px; }
  .grid2 { gap: 8px; }
  .tile { padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.card > p:first-child { margin-top: 0; }

.kv { margin: 0 0 8px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv div:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); white-space: nowrap; }
.kv dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.work-preview { font-size: 14px; background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }

/* ---- v1.2：診断・実戦カウンター ---- */
.btn-sub {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; margin-top: -4px; border-radius: 16px;
  background: var(--surface); border: 1.5px solid var(--accent); color: var(--accent);
  font-size: 16px; font-weight: 800; text-decoration: none; transition: transform .08s;
}
.btn-sub:active { transform: scale(.97); }
.section-title { font-size: 15px; font-weight: 700; color: var(--muted); padding: 8px 4px 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.inline-form.flush { margin-top: 0; }
.inline-form.flush .select { flex: 1; min-width: 0; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 10px; }
.stat-grid div { display: flex; flex-direction: column; min-width: 0; }
.stat-grid > div > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat-grid strong { font-size: clamp(20px, 6vw, 24px); font-weight: 800; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-grid > div > small { font-size: 12px; color: var(--muted); }

.insights { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.insights li { border-radius: 12px; padding: 10px 12px; background: var(--surface-2); display: flex; flex-direction: column; gap: 2px; }
.insights li.good { background: color-mix(in srgb, var(--pos) 13%, var(--surface)); }
.insights li.bad { background: color-mix(in srgb, var(--neg) 11%, var(--surface)); }
.insights li.info { background: var(--accent-soft); }
.insights strong { font-size: 15px; }
.insights span { font-size: 13px; color: var(--muted); }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table.compact th, .table.compact td { padding: 8px 4px; font-size: 14px; white-space: nowrap; }
.table.compact tbody th { white-space: normal; min-width: 5em; }

.counter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.counter { position: relative; }
.counter-plus {
  width: 100%; min-height: 104px; padding: 10px 10px 10px 12px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  border-radius: 16px; border: 1.5px solid var(--line); background: var(--surface); color: var(--text);
  cursor: pointer; touch-action: manipulation; text-align: left; transition: transform .06s, background .06s;
}
.counter-plus:active { transform: scale(.96); background: var(--accent-soft); }
.counter-label { font-size: 14px; font-weight: 700; color: var(--muted); }
.counter-num { font-size: 36px; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }
.counter-prob { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter-minus {
  position: absolute; top: 6px; right: 6px; width: 44px; height: 44px;
  border-radius: 12px; border: 0; background: var(--surface-2); color: var(--muted);
  font-size: 22px; font-weight: 800; cursor: pointer; touch-action: manipulation;
}
.counter-minus:active { transform: scale(.92); }
.counter-stats { display: flex; gap: 16px; justify-content: center; font-size: 15px; color: var(--muted); }
.counter-stats strong { color: var(--text); font-size: 18px; }

.high-chance { font-size: 15px; font-weight: 700; margin-bottom: 10px; text-align: center; }
.high-chance strong { display: block; font-size: 40px; font-weight: 800; color: var(--accent); line-height: 1.1; }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 3.4em 1fr 3em; align-items: center; gap: 8px; font-size: 14px; }
.bar-row strong { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 14px; border-radius: 7px; background: var(--surface-2); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 7px; background: var(--muted); }
.bar-row.high .bar span { background: var(--accent); }

.verdict { border-width: 2px; }
.verdict.go { border-color: var(--pos); }
.verdict.wait { border-color: #d39a00; }
.verdict.stop { border-color: var(--neg); }
.verdict-head { display: flex; align-items: center; gap: 10px; font-size: 24px; font-weight: 800; }
.verdict-icon { font-size: 28px; }
.verdict p { margin: 6px 0 0; font-size: 14px; }
.verdict .kv { margin-top: 10px; }
.kv dd small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.kv-note { margin: -4px 0 4px; }

/* ---- 小役カウンター（大きな色つきボタン） ---- */
.kachi { background: #15171d; border-radius: 22px; padding: 10px; display: flex; flex-direction: column; gap: 10px; box-shadow: inset 0 1px 0 rgb(255 255 255 / 6%), 0 6px 18px rgb(0 0 0 / 18%); }
.kachi.minus { box-shadow: 0 0 0 3px #ff5b5b, 0 6px 18px rgb(0 0 0 / 18%); }
.kachi-status {
  position: sticky; top: 60px; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  background: #22252e; border-radius: 14px; padding: 8px 6px; color: #fff; text-align: center;
}
.kachi-status div { display: flex; flex-direction: column; min-width: 0; }
.kachi-status span { font-size: 11px; color: #a9afbd; font-weight: 700; }
.kachi-status strong { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kachi-status .hi strong { color: #ffd34d; }
.kachi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kachi-grid.odd .kachi-btn:first-child { grid-column: 1 / -1; }
.kachi-btn {
  --c1: #555; --c2: #333;
  position: relative; min-height: 132px; padding: 10px 8px 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  border: 0; border-radius: 18px; color: #fff; cursor: pointer;
  background: linear-gradient(180deg, var(--c1), var(--c2));
  box-shadow: inset 0 2px 0 rgb(255 255 255 / 25%), inset 0 -4px 0 rgb(0 0 0 / 25%), 0 4px 0 rgb(0 0 0 / 35%);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  transition: transform .05s, box-shadow .05s, filter .05s;
}
.kachi-btn:active { transform: translateY(3px); box-shadow: inset 0 2px 0 rgb(255 255 255 / 15%), inset 0 -2px 0 rgb(0 0 0 / 25%), 0 1px 0 rgb(0 0 0 / 35%); filter: brightness(1.1); }
.kachi-grid.odd .kachi-btn:first-child { min-height: 112px; }
.k-big { --c1: #f2464b; --c2: #b8161d; }
.k-reg { --c1: #3b82f6; --c2: #1d4fc0; }
.k-creg { --c1: #8b5cf6; --c2: #5b2dc4; }
.k-grape { --c1: #7ac943; --c2: #3f8a1a; }
.k-cherry { --c1: #f2609b; --c2: #c2245f; }
.k-label { font-size: 15px; font-weight: 800; letter-spacing: .04em; text-shadow: 0 1px 0 rgb(0 0 0 / 30%); }
.k-num { font-size: 52px; line-height: 1.05; font-weight: 800; font-variant-numeric: tabular-nums; text-shadow: 0 2px 0 rgb(0 0 0 / 30%); }
.k-prob { font-size: 14px; font-weight: 700; background: rgb(0 0 0 / 22%); border-radius: 99px; padding: 1px 10px; font-variant-numeric: tabular-nums; }
.kachi.minus .kachi-btn::after { content: "−1"; position: absolute; bottom: 10px; right: 10px; font-size: 14px; font-weight: 800; background: #fff; color: #d11; border-radius: 99px; padding: 0 7px; }
.kachi-btn.bump .k-num { animation: bump .18s ease-out; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
.kachi-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.k-tool {
  min-height: 48px; border-radius: 12px; border: 0; background: #2c303b; color: #e8eaf0;
  font-size: 15px; font-weight: 800; cursor: pointer; touch-action: manipulation;
}
.k-tool:active { filter: brightness(1.2); }
.k-tool.on { background: #ff5b5b; color: #fff; }
.k-tool:disabled { opacity: .4; }
.k-minus-note { margin: -2px 0 0; text-align: center; color: #ff8a8a; font-size: 13px; font-weight: 700; }
@media (max-width: 359px) {
  .kachi-btn { min-height: 118px; }
  .k-num { font-size: 44px; }
  .k-label { font-size: 13px; letter-spacing: 0; }
  .kachi-status strong { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) { .kachi-btn.bump .k-num { animation: none; } }
.k-cbig { --c1: #ff8a3d; --c2: #c8510c; }

/* ---- 横向き（スマホを横にしたとき） ---- */
#main, .nav { padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
@media (orientation: landscape) and (max-height: 540px) {
  :root { --nav-h: 46px; }
  .nav { left: 0; right: 0; width: auto; transform: none; border-radius: 0; border-left: 0; border-right: 0; }
  .topbar { min-height: 46px; }
  .topbar h1 { font-size: 18px; }
  .nav a { flex-direction: row; gap: 6px; font-size: 12px; }
  .nav .icon { width: 20px; height: 20px; }
  .hero { padding: 14px 18px; }
  .hero-num { font-size: 40px; }
  .btn-record { min-height: 54px; }
  .chart-svg { max-height: 220px; }
  .toast { bottom: calc(var(--nav-h) + var(--safe-b) + 8px); }
  /* 実戦カウンターは横いっぱいを使い、ボタンを1列に並べる */
  body[data-route="judge"] #main { max-width: 980px; }
  .kachi-status { top: 50px; grid-template-columns: repeat(4, auto); justify-content: space-around; padding: 6px; }
  .kachi-grid { grid-template-columns: repeat(var(--cols, 4), 1fr); gap: 8px; }
  .kachi-grid.odd .kachi-btn:first-child { grid-column: auto; min-height: 0; }
  .kachi-btn { min-height: 0; height: calc(100dvh - 46px - 46px - 52px - 64px - 48px); max-height: 190px; min-height: 104px; padding: 6px 4px 8px; }
  .k-num { font-size: clamp(34px, 7vh, 52px); }
  .k-label { font-size: 13px; letter-spacing: 0; }
  .k-prob { font-size: 12px; padding: 0 8px; }
  .kachi-tools { grid-template-columns: repeat(4, 1fr); }
  .k-tool { min-height: 44px; }
}
/* 全画面で横に固定したとき */
:fullscreen body { background: var(--bg); }

/* ---- 全画面の小役カウンター（#/counter）：スクロールせず画面いっぱいに ---- */
.sub-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: -4px; }
.sub-row .btn-sub { margin-top: 0; font-size: 15px; padding: 0 6px; text-align: center; }
html[data-route="counter"], html[data-route="counter"] body { overflow: hidden; overscroll-behavior: none; height: 100%; background: #0f1115; }
body[data-route="counter"] .nav { display: none; }
body[data-route="counter"] #main { max-width: 980px; min-height: 0; height: 100dvh; padding-bottom: 0; }
body[data-route="counter"] .toast { bottom: calc(76px + var(--safe-b)); }
.cscreen {
  height: 100dvh; display: flex; flex-direction: column; gap: 8px;
  padding: max(env(safe-area-inset-top, 0px), 8px) 10px max(env(safe-area-inset-bottom, 0px), 10px);
  background: #0f1115; color: #fff;
}
.cscreen.minus { box-shadow: inset 0 0 0 3px #ff5b5b; }
.cs-head { display: flex; align-items: center; gap: 8px; flex: none; }
.cs-btn {
  flex: none; display: grid; place-items: center; min-width: 44px; height: 44px; padding: 0 10px;
  border-radius: 12px; background: #22252e; color: #e8eaf0; text-decoration: none; font-size: 16px; font-weight: 800;
}
.cs-btn.wide { padding: 0 16px; background: #3b3f9e; color: #fff; }
.cs-machine {
  flex: 1; min-width: 0; height: 44px; padding: 0 10px; border-radius: 12px; border: 0;
  background: #22252e; color: #fff; font-size: 15px; font-weight: 700;
}
.cs-bar { display: grid; grid-template-columns: 7.2em 1fr; gap: 8px; flex: none; }
.cs-games { display: flex; flex-direction: column; justify-content: center; background: #22252e; border-radius: 14px; padding: 4px 10px; }
.cs-games span { font-size: 11px; color: #a9afbd; font-weight: 700; }
.cs-games input {
  width: 100%; min-height: 0; padding: 0; border: 0; background: transparent; color: #fff;
  font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums;
}
.cs-games input:focus { outline: none; }
.cs-status { position: static; grid-template-columns: repeat(3, 1fr); }
.cs-grid { flex: 1; min-height: 0; grid-auto-rows: 1fr; }
.cs-grid .kachi-btn, .cs-grid.odd .kachi-btn:first-child { min-height: 0; height: auto; max-height: none; }
.cs-grid .k-num { font-size: clamp(40px, 9dvh, 84px); }
.cs-grid .k-label { font-size: clamp(14px, 2.4dvh, 20px); }
.cs-grid .k-prob { font-size: clamp(12px, 2dvh, 16px); }
.cscreen .kachi-tools { flex: none; }
@media (orientation: landscape) and (max-height: 540px) {
  .cscreen { gap: 6px; padding-top: max(env(safe-area-inset-top, 0px), 6px); padding-bottom: max(env(safe-area-inset-bottom, 0px), 6px); }
  .cs-head .cs-btn, .cs-machine { height: 38px; }
  .cs-grid { grid-template-columns: repeat(var(--cols, 4), 1fr); }
  .cs-grid.odd .kachi-btn:first-child { grid-column: auto; }
  .cs-grid .k-num { font-size: clamp(32px, 13dvh, 72px); }
  .cscreen .k-tool { min-height: 40px; }
}

/* ---- 使い方ガイド ---- */
.help-btn { margin-right: -8px; font-size: 18px; font-weight: 800; color: var(--accent); }
.topbar .help-btn { width: 40px; height: 40px; border: 2px solid var(--accent); }
.cs-head .cs-btn[data-action="guide"] { font-size: 18px; }
.sheet-open, .sheet-open body { overflow: hidden; }
.sheet-backdrop { position: fixed; inset: 0; z-index: 60; background: rgb(0 0 0 / 45%); animation: fade .2s; }
.sheet {
  position: fixed; z-index: 61; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(600px, 100%); max-height: 88dvh; display: flex; flex-direction: column;
  background: var(--surface); color: var(--text); border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 30px rgb(0 0 0 / 25%); animation: slideup .22s ease-out;
  padding-bottom: var(--safe-b);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 10px 8px 18px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 18px; font-weight: 800; }
.sheet-body { overflow-y: auto; padding: 6px 18px 22px; overscroll-behavior: contain; }
.guide-sec h3 { font-size: 16px; font-weight: 800; margin: 16px 0 6px; color: var(--accent); }
.guide-sec p { margin: 0 0 6px; }
.guide-sec ol, .guide-sec ul { margin: 0; padding-left: 1.4em; display: flex; flex-direction: column; gap: 6px; }
.guide-sec li { font-size: 15px; line-height: 1.6; }
.guide-link { justify-content: flex-start; text-align: left; }
@keyframes slideup { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { animation: none; } }

/* ---- v1.6：残高で入力・引き継ぎ・お知らせ・更新 ---- */
.seg2 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.seg2 button { min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 15px; font-weight: 700; cursor: pointer; }
.seg2 button.on { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.preview-diff { font-size: 15px; }
.preview-diff strong { font-size: 20px; font-weight: 800; }
.carry { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 14px; padding: 8px 12px; border-radius: 12px; background: var(--accent-soft); }
.carry .link-btn { margin-left: auto; min-height: 32px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); font-weight: 700; }
.notice.bad { background: color-mix(in srgb, var(--neg) 16%, var(--surface)); color: var(--neg); font-weight: 700; }
.store-replay { font-size: 13px; color: var(--muted); margin-top: 2px; }
#update-bar {
  position: fixed; z-index: 70; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 8px); transform: translateX(-50%);
  width: min(528px, calc(100% - 24px)); display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 16px; border-radius: 14px; background: #1f2330; color: #fff; font-weight: 700;
  box-shadow: 0 8px 24px rgb(0 0 0 / 25%); animation: fade .2s;
}
#update-bar span { flex: 1; }
#update-bar button { min-height: 40px; padding: 0 16px; border: 0; border-radius: 10px; background: #8f88ff; color: #0e1015; font-weight: 800; cursor: pointer; }
