:root {
  color-scheme: light;
  --ink: #202126;
  --muted: #757582;
  --line: #d9d9e1;
  --surface: #ffffff;
  --page: #f4f4fa;
  --orange: #ff9500;
  --green: #32c960;
  --red: #ff4039;
  --purple: #6158e8;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; }
.app-shell { width: min(100%, 540px); min-height: 100dvh; margin: auto; padding: max(10px, env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom)); }
.app-header, .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 5px; min-width: 0; }
.app-header { margin: 0 2px 10px; }
.eyebrow { margin: 0 0 1px; color: var(--orange); font-size: .62rem; font-weight: 800; letter-spacing: .1em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 1.3rem; white-space: nowrap; }
h2 { margin-bottom: 0; font-size: 1.05rem; }
.icon-button { width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--orange); color: white; font-size: 1.45rem; line-height: 1; }
.compact-toggle { border: 1px solid #b9b9c5; border-radius: 8px; padding: 7px 8px; background: white; color: #4b4b58; font-size: .68rem; font-weight: 700; }
.header-data-button { display: grid; place-items: center; min-height: 30px; margin: 0; padding: 5px 6px; border: 1px solid #b9b9c5; border-radius: 8px; background: white; color: #4b4b58; font-size: .66rem; font-weight: 700; white-space: nowrap; }
.import-button input { display: none; }
.machine-card, .entry-card, .backup-card, .history-section { margin-bottom: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); padding: 16px; box-shadow: 0 2px 8px rgba(24, 20, 52, .04); }
.machine-card { padding: 8px 10px; border-radius: 12px; }
.entry-card { margin-bottom: 0; padding: 9px 12px 10px; border-radius: 14px; }
.machine-card label { margin-bottom: 5px; font-size: .68rem; }
.machine-card input { margin-top: 2px; padding: 6px 8px; border-radius: 8px; font-size: .8rem; }
.machine-card .settings-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
.machine-card .hint { display: none; }
label { display: block; margin-bottom: 12px; color: #3e3e48; font-size: .86rem; font-weight: 700; }
input, select { width: 100%; margin-top: 6px; padding: 12px; border: 1px solid #babac5; border-radius: 11px; background: white; color: var(--ink); }
input:focus, select:focus { outline: 3px solid rgba(97, 88, 232, .22); border-color: var(--purple); }
.settings-grid, .hit-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.game-entry-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(72px, 1fr) minmax(72px, 1fr); align-items: end; gap: 10px; }
.game-entry-row label { margin-bottom: 12px; }
.move-machine-button, .end-session-button { min-height: 47px; margin: 0 0 12px; border: 1px solid #b8b8c2; border-radius: 11px; background: #f8f8fb; color: #3e3e4b; font-size: .82rem; font-weight: 800; }
.move-machine-button:active, .end-session-button:active { background: #e8e8ef; }
.end-session-button { border-color: #e4ab55; background: #fff6e9; color: #a25a00; }
.hint, .entry-note { margin: 0; color: var(--muted); font-size: .77rem; line-height: 1.45; }
.summary-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; margin-bottom: 11px; }
.summary-card { min-height: 76px; display: flex; flex-direction: column; justify-content: space-between; border-radius: 12px; padding: 9px 10px; background: #e9e9ef; }
.summary-card.primary { background: var(--purple); color: white; }
.total-investment-card { background: #dff3e5; }
.summary-card span { font-size: .68rem; }
.summary-card strong { font-size: .9rem; text-align: right; }
.history-section { padding: 0; overflow: hidden; }
.section-heading { padding: 8px 12px 6px; }
.section-heading h2 { font-size: .94rem; }
.history-heading-actions { display: flex; align-items: center; gap: 6px; }
.section-heading input { width: 126px; margin: 0; padding: 6px 7px; font-size: .78rem; }
.undo-button { min-height: 30px; border: 1px solid #b9b9c5; border-radius: 8px; padding: 5px 7px; background: #f8f8fb; color: #3e3e4b; font-size: .7rem; font-weight: 800; white-space: nowrap; }
.undo-button:disabled { opacity: .42; cursor: default; }
.history-wrap { display: flex; flex-direction: column; height: 365px; max-height: 365px; }
.history-rows-wrap { display: flex; flex: 1 1 auto; min-height: 0; overflow: auto; border-top: 1px solid var(--line); overscroll-behavior: contain; }
.history-table { width: 100%; table-layout: fixed; border-collapse: collapse; white-space: nowrap; font-variant-numeric: tabular-nums; }
.history-header-table { flex: 0 0 auto; }
.history-rows-table { flex: 0 0 auto; align-self: flex-end; margin-top: auto; }
th { background: var(--orange); color: white; font-size: .76rem; }
th, td { padding: 8px; text-align: center; border-bottom: 1px solid #ececf1; font-size: .77rem; }
tbody tr:last-child td { border-bottom: 0; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 7px; overflow: hidden; border: 1px solid #a8a8b2; border-radius: 9px; }
.segmented.small { margin-top: 0; grid-template-columns: repeat(5, 1fr); }
.segmented button { border: 0; border-right: 1px solid #a8a8b2; padding: 7px; background: #f4f4f7; color: #555562; font-size: .82rem; }
.segmented.small button { padding-inline: 2px; font-size: .62rem; line-height: 1.2; }
.segmented button:last-child { border-right: 0; }
.segmented button.selected { background: #dcdce4; color: #202126; font-weight: 800; }
.entry-card label { margin-bottom: 6px; font-size: .76rem; }
.entry-card input { margin-top: 3px; padding: 8px 10px; border-radius: 9px; }
.entry-card .game-entry-row { gap: 7px; }
.entry-card .game-entry-row label { margin-bottom: 6px; }
.entry-card .move-machine-button, .entry-card .end-session-button { min-height: 39px; margin-bottom: 6px; border-radius: 9px; font-size: .72rem; }
.entry-card .entry-note { display: none; }
.entry-card .hit-fields { gap: 7px; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px; margin-top: 8px; }
.button { min-height: 43px; border: 0; border-radius: 10px; color: white; font-size: .84rem; font-weight: 800; box-shadow: 0 3px 7px rgba(0,0,0,.13); }
.start { background: var(--purple); } .confirm { background: var(--green); } .danger { background: var(--red); }
.end-result { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: baseline; margin-top: 8px; padding: 8px 10px; border-radius: 9px; background: #f1f1f5; color: #3f3f4c; font-size: .72rem; }
.end-result[hidden] { display: none; }
.end-result strong { text-align: right; font-size: 1rem; }
.end-result small { grid-column: 1 / -1; color: #666672; font-size: .67rem; }
.end-result.positive { background: #e5f7ea; color: #16763a; }
.end-result.negative { background: #fff0ee; color: #b2342e; }
.backup-card { display: grid; gap: 14px; }
.backup-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.backup-actions button, .import-label { min-height: 46px; display: grid; place-items: center; border: 1px solid #b8b8c2; border-radius: 11px; background: #f8f8fb; color: var(--ink); font-size: .78rem; text-align: center; }
.import-label { margin: 0; padding: 5px; }
.import-label input { display: none; }
.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 10; transform: translate(-50%, 120px); width: min(92vw, 440px); padding: 13px 16px; border-radius: 12px; background: rgba(32, 33, 38, .93); color: white; text-align: center; font-size: .86rem; transition: transform .2s ease; }
.toast.show { transform: translate(-50%, 0); }
body.dashboard-collapsed .app-header { margin-bottom: 7px; }
body.dashboard-collapsed:not(.keyboard-open) {
  height: var(--app-height, 100dvh);
  overflow: hidden;
  overscroll-behavior: none;
}
body.dashboard-collapsed:not(.keyboard-open) .app-shell {
  height: var(--app-height, 100dvh);
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
body.dashboard-collapsed .history-section { margin-bottom: 8px; }
body.dashboard-collapsed .section-heading { padding: 8px 12px 6px; }
body.dashboard-collapsed .section-heading h2 { font-size: .94rem; }
body.dashboard-collapsed .section-heading input { width: 126px; padding: 6px 7px; font-size: .78rem; }
body.dashboard-collapsed:not(.keyboard-open) .history-section {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}
body.dashboard-collapsed:not(.keyboard-open) .history-wrap {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: none;
}
body.dashboard-collapsed:not(.keyboard-open) .history-rows-wrap {
  flex: 1 1 auto;
  min-height: 0;
}
/* 数値入力時は、操作ボタンを切り離さず入力カードごと表示位置を合わせる。 */
body.dashboard-collapsed th, body.dashboard-collapsed td { padding-block: 8px; font-size: .77rem; }
tr.machine-move-row td { padding: 7px 8px; background: #f3f3f7; color: #5c5c69; font-size: .76rem; font-weight: 800; letter-spacing: .08em; }
body.dashboard-collapsed .entry-card { margin-bottom: 0; padding: 9px 12px 10px; border-radius: 14px; }
body.dashboard-collapsed .segmented { margin-bottom: 7px; border-radius: 9px; }
body.dashboard-collapsed .segmented.small { margin-top: 0; }
body.dashboard-collapsed .segmented button { padding: 7px; font-size: .82rem; }
body.dashboard-collapsed .segmented.small button { padding-inline: 2px; font-size: .62rem; line-height: 1.2; }
body.dashboard-collapsed .entry-card label { margin-bottom: 6px; font-size: .76rem; }
body.dashboard-collapsed .entry-card input { margin-top: 3px; padding: 8px 10px; border-radius: 9px; }
body.dashboard-collapsed .game-entry-row { gap: 7px; }
body.dashboard-collapsed .game-entry-row label { margin-bottom: 6px; }
body.dashboard-collapsed .move-machine-button, body.dashboard-collapsed .end-session-button { min-height: 39px; margin-bottom: 6px; border-radius: 9px; font-size: .72rem; }
body.dashboard-collapsed .entry-note { display: none; }
body.dashboard-collapsed .hit-fields { gap: 7px; }
body.dashboard-collapsed .action-grid { margin-top: 8px; gap: 7px; }
body.dashboard-collapsed .button { min-height: 43px; border-radius: 10px; font-size: .84rem; }
.saved-header { margin-bottom: 14px; }
.chart-page .app-shell { padding-top: max(16px, env(safe-area-inset-top)); }
.chart-header { margin-bottom: 16px; }
.chart-title { margin: 0; font-size: 1.2rem; }
.chart-card { margin-bottom: 0; padding: 14px 10px 10px; }
.chart-machine-name { margin: 0 0 12px; font-size: .86rem; font-weight: 800; text-align: center; }
.chart-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px 14px; margin-bottom: 12px; font-size: .72rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend i { display: inline-block; width: 22px; height: 3px; border-radius: 4px; background: currentColor; }
.chart-legend .segment { color: #2499e8; }
.chart-legend .average { color: #ff9500; }
.chart-legend .cash-border { color: #35a854; }
.chart-legend .dashed { background: repeating-linear-gradient(90deg, currentColor 0 7px, transparent 7px 11px); }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-empty { padding: 72px 12px; color: var(--muted); text-align: center; }
.back-link { color: #4b4b58; }
.saved-intro { margin: 0 0 12px; color: var(--muted); font-size: .82rem; }
.saved-list { display: grid; gap: 9px; max-height: calc(100dvh - 225px); overflow-y: auto; padding: 1px 2px 2px; }
.saved-item { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--red); touch-action: pan-y; }
.saved-main { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 62px; padding: 12px; background: var(--surface); transition: transform .2s ease; }
.saved-item h2 { margin: 0 0 3px; font-size: .94rem; }
.saved-item p { margin: 0; color: var(--muted); font-size: .73rem; }
.open-saved-button, .restore-label { display: grid; place-items: center; min-height: 35px; padding: 6px 9px; border: 1px solid #a9a9b8; border-radius: 9px; background: #f8f8fb; color: #3e3e4b; font-size: .76rem; font-weight: 800; white-space: nowrap; }
.restore-label { margin: 16px 0 0; }
.restore-label input { display: none; }
.saved-delete { position: absolute; inset: 0 0 0 auto; width: 78px; border: 0; background: var(--red); color: white; font-size: .8rem; font-weight: 800; }
.saved-item.delete-revealed .saved-main { transform: translateX(-78px); }
.backup-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.backup-tools .restore-label { width: 100%; margin: 14px 0 0; }
.empty-saved { padding: 28px 12px; color: var(--muted); text-align: center; }
@media (max-width: 390px) { .app-shell { padding-inline: 10px; } .summary-card { padding-inline: 8px; } th, td { padding-inline: 6px; font-size: .76rem; } }
@media (max-width: 450px) {
  .eyebrow { display: none; }
  h1 { font-size: 1rem; letter-spacing: -.04em; }
  .header-actions { gap: 4px; }
  .header-data-button { min-height: 31px; padding-inline: 6px; font-size: .72rem; }
  .compact-toggle { min-height: 31px; padding-inline: 7px; font-size: .72rem; white-space: nowrap; }
  .icon-button { width: 30px; height: 30px; font-size: 1.25rem; }
}
@media (max-width: 768px) {
  input, select { font-size: 16px !important; }
}
