:root {
  --desk: #24324f; --desk2: #1b2740; --paper: #fffdf7; --ink: #1f2430; --sub: #646b78; --line: #e4e0d4; --dash: #cfc9b8;
  --coral: #e2574c; --coral-ink: #ffffff; --mint: #1f8a6a; --sel: #24324f;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  --mono: "SF Mono", "Menlo", "Consolas", "Roboto Mono", "Hiragino Sans", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --desk: #10172a; --desk2: #0b1120; --paper: #e9e6dc; --sub: #585e6a; --line: #d3cfc2; --dash: #b9b3a2; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--desk); background-image: radial-gradient(circle at 20% 0, rgba(255, 255, 255, .08), transparent 50%); color: var(--ink); font-family: var(--font); line-height: 1.6; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #ffcf5a; outline-offset: 2px; }
[hidden] { display: none !important; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.desk { max-width: 560px; margin: 0 auto; padding: calc(20px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) calc(90px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left)); }
.top { color: #fff; margin-bottom: 16px; }
h1 { margin: 0; font-size: 28px; letter-spacing: .04em; }
.top h1::before { content: ""; display: inline-block; width: 22px; height: 28px; margin-right: 8px; vertical-align: -4px; background: var(--paper); clip-path: polygon(0 0, 100% 0, 100% 85%, 83% 100%, 66% 85%, 50% 100%, 33% 85%, 17% 100%, 0 85%); }
.lead { margin: 6px 0 0; color: #d6def0; font-size: 15px; }

/* レシートの紙 */
.paper, .new, .first, .move { position: relative; background: var(--paper); border-radius: 4px 4px 0 0; padding: 16px 16px 22px; margin: 0 0 26px; box-shadow: 0 8px 20px rgba(0, 0, 0, .25); }
.paper::after, .new::after, .first::after, .move::after { content: ""; position: absolute; left: 0; right: 0; bottom: -9px; height: 10px; background: linear-gradient(-45deg, transparent 6px, var(--paper) 6px) 0 0 / 12px 10px repeat-x, linear-gradient(45deg, transparent 6px, var(--paper) 6px) 0 0 / 12px 10px repeat-x; }
.sec { margin: 0 0 10px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.no { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: var(--paper); font-family: var(--mono); font-size: 14px; }
.sec2 { margin: 18px 0 6px; font-size: 14px; color: var(--sub); border-top: 2px dashed var(--dash); padding-top: 14px; }
.hint { margin: 6px 0; font-size: 13px; color: var(--sub); }
.none { color: var(--sub); font-size: 14px; margin: 4px 0; }
.ferr { margin: 4px 0 0; color: #c0392b; font-size: 13px; }
.ferr:empty { display: none; }

.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row input { flex: 1; min-width: 0; }
input, select, textarea { min-height: 46px; padding: 8px 10px; border: 1px solid var(--dash); border-radius: 8px; background: #fff; font-size: 16px; color: var(--ink); }
.btn { min-height: 46px; padding: 8px 16px; border: 2px solid var(--ink); border-radius: 10px; background: transparent; font-weight: 700; cursor: pointer; white-space: nowrap; }
.btn.main { background: var(--coral); border-color: var(--coral); color: var(--coral-ink); }
.btn.ghost { border-width: 1px; font-weight: 400; font-size: 14px; }
.link { background: none; border: 0; padding: 8px 4px; min-height: 44px; color: var(--desk); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link.small { font-size: 13px; }
.link.danger { color: #c0392b; }
.desk > section > .link.danger, #ev-del { color: #ffb4ab; display: block; margin: 0 auto; }

.new label { display: block; font-weight: 700; margin-bottom: 6px; }
.events { list-style: none; margin: 0 0 26px; padding: 0; display: grid; gap: 12px; }
.ev-card { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 0 10px; text-align: left; padding: 14px 16px; background: var(--paper); border: 0; border-left: 6px solid var(--coral); border-radius: 4px; cursor: pointer; box-shadow: 0 6px 14px rgba(0, 0, 0, .2); }
.ev-n { font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.ev-t { font-family: var(--mono); font-weight: 700; font-size: 17px; text-align: right; }
.ev-m, .ev-d { font-size: 13px; color: var(--sub); }
.ev-d { text-align: right; }
.first p { margin: 0 0 10px; }
.move .sec { font-size: 15px; }
.file { position: relative; display: inline-flex; align-items: center; }
.file input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.file:focus-within { outline: 3px solid #ffcf5a; }

.ev-top { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; color: #fff; margin-bottom: 14px; }
.back { min-height: 44px; padding: 4px 12px 4px 6px; border: 1px solid rgba(255, 255, 255, .4); border-radius: 999px; background: none; color: #fff; cursor: pointer; }
.ev-name { flex: 1 1 100%; order: 3; font-size: 24px; overflow-wrap: anywhere; }
.ev-top .link { color: #d6def0; margin-left: auto; }
.rename { background: var(--paper); padding: 12px; border-radius: 8px; margin-bottom: 18px; }

.members { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.mem { display: inline-flex; align-items: center; padding-left: 12px; background: #fff; border: 1px solid var(--dash); border-radius: 999px; font-weight: 700; }
.mem .x { width: 40px; height: 40px; border: 0; background: none; color: var(--sub); cursor: pointer; font-size: 16px; }

.f2 { display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px; }
.fld { display: grid; gap: 2px; font-size: 13px; color: var(--sub); min-width: 0; }
.fld input, .fld select { width: 100%; color: var(--ink); }
.yen { position: relative; display: block; }
.yen::before { content: "¥"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--sub); font-family: var(--mono); }
.yen input { padding-left: 24px; font-family: var(--mono); font-weight: 700; font-size: 18px; }
.fs { border: 0; padding: 0; margin: 12px 0 0; min-width: 0; }
.fs legend { font-size: 13px; color: var(--sub); padding: 0; margin-bottom: 4px; }
.pick { display: flex; flex-wrap: wrap; gap: 6px; }
.pk { min-height: 44px; padding: 6px 14px; border: 2px solid var(--dash); border-radius: 10px; background: #fff; font-weight: 700; cursor: pointer; }
.pk[aria-checked="true"], .pk[aria-pressed="true"] { background: var(--sel); border-color: var(--sel); color: #fff; }
.chk-pk[aria-pressed="true"]::before { content: "✓ "; }
.for-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 2px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; min-height: 44px; cursor: pointer; }
.chk input { min-height: 0; width: 20px; height: 20px; accent-color: var(--sel); }
.weights { background: #fff; border: 1px dashed var(--dash); border-radius: 10px; padding: 8px 10px; }
.wrow { display: grid; grid-template-columns: 1fr 44px 64px 44px; align-items: center; gap: 6px; padding: 2px 0; }
.wn { font-weight: 700; overflow-wrap: anywhere; }
.step { height: 44px; border: 1px solid var(--dash); border-radius: 8px; background: var(--paper); font-size: 18px; cursor: pointer; }
.wi { width: 64px; text-align: center; font-family: var(--mono); padding: 6px 4px; }
.wi[aria-invalid="true"] { border-color: #c0392b; }
.preview { margin: 10px 0; font-size: 13px; color: var(--mint); min-height: 1em; }
.preview:empty { margin: 4px 0; }

.pays { list-style: none; margin: 16px 0 0; padding: 0; border-top: 2px dashed var(--dash); }
.payrow { padding: 10px 0 4px; border-bottom: 1px dotted var(--dash); }
.payrow.editing { background: #fff6d8; }
.pr-main { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; }
.pr-what { overflow-wrap: anywhere; }
.pr-amt { font-family: var(--mono); white-space: nowrap; }
.pr-sub { display: flex; align-items: center; flex-wrap: wrap; gap: 0 4px; font-size: 13px; color: var(--sub); }
.pr-sub span { flex: 1 1 100%; }
.pr-sub .link { padding: 4px 8px 4px 0; min-height: 36px; }

.result .total { margin: 0 0 8px; font-family: var(--mono); font-weight: 700; font-size: 15px; }
.transfers { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.tr { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 12px; background: var(--ink); color: var(--paper); border-radius: 10px; font-weight: 700; }
.tf, .tt { overflow-wrap: anywhere; }
.ta { color: var(--coral); font-size: 20px; }
.tm { font-family: var(--mono); font-size: 20px; color: #ffcf5a; white-space: nowrap; }
@media (prefers-reduced-motion: no-preference) { .tr { animation: slip .3s ease-out both; } @keyframes slip { from { transform: translateY(-6px); opacity: 0; } } }
.adj { font-size: 13px; background: #fff6d8; padding: 6px 10px; border-radius: 8px; }
.bal { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 13px; }
.bal caption { text-align: left; color: var(--sub); padding-bottom: 4px; }
.bal th, .bal td { padding: 6px 4px; border-bottom: 1px dotted var(--dash); text-align: right; font-family: var(--mono); white-space: nowrap; }
.bal th[scope="row"], .bal thead th:first-child { text-align: left; font-family: var(--font); white-space: normal; overflow-wrap: anywhere; }
.bal thead th { color: var(--sub); font-weight: 400; font-family: var(--font); }
.plus { color: var(--mint); font-weight: 700; } .minus { color: #c0392b; font-weight: 700; }
.opts { margin-top: 14px; }
.opts summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-size: 14px; color: var(--desk); }
.opt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
textarea { width: 100%; font-family: var(--mono); font-size: 13px; resize: vertical; background: #fff; line-height: 1.5; }
.copied { margin: 6px 0 0; font-size: 13px; color: var(--mint); min-height: 1.4em; }

.foot { margin-top: 30px; text-align: center; font-size: 12px; color: #b9c3d8; }
.foot p { margin: 2px 0; }
.foot a { color: inherit; display: inline-block; padding: 8px; }

.toast { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translate(-50%, 0); width: min(540px, calc(100% - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px))); display: none; align-items: center; gap: 10px; padding: 12px 14px; background: #ffcf5a; color: #1f2430; border-radius: 12px; font-size: 14px; z-index: 10; box-shadow: 0 6px 20px rgba(0, 0, 0, .35); }
.toast.on { display: flex; }
.toast span { flex: 1; }
.toast button { min-height: 40px; padding: 4px 12px; border: 1px solid currentColor; border-radius: 8px; background: none; color: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
@media (prefers-reduced-motion: no-preference) { .toast.on { animation: up .2s ease-out; } @keyframes up { from { transform: translate(-50%, 30%); opacity: 0; } } }
@media (max-width: 380px) { .f2 { grid-template-columns: 1fr; } }
@media (prefers-color-scheme: dark) { input, select, textarea, .pk, .mem, .weights { background: #f6f3ea; } }

/* iPhone (WebKit) keeps a fieldset at least as wide as its content; let it shrink so nothing overflows narrow screens */
fieldset{min-width:0;min-inline-size:0}
input,select,textarea{max-width:100%}
