/* Kakeibo Hero — same 16-bit JRPG menu look as the Debt Clock and Zeni Quest.
   Type rules (Gate A, UX seat): Press Start 2P only for labels/headings at >= 0.75rem;
   numbers, body and inputs in DotGothic16 at >= 1rem; everything in rem so iOS text size applies.
   Colours checked for WCAG AA against the window and slot backgrounds. */
@font-face { font-family: "Press Start 2P"; src: url("../fonts/PressStart2P-latin.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "DotGothic16"; src: url("../fonts/DotGothic16-latin.woff2") format("woff2"); font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2190-21FF, U+2122; }
@font-face { font-family: "DotGothic16"; src: url("../fonts/DotGothic16-jp.woff2") format("woff2"); font-display: swap; unicode-range: U+3000-30FF, U+4E00-9FFF, U+FF00-FFEF, U+25A0-25FF, U+2600-26FF; }

:root {
  color-scheme: dark;
  --void: #070923;
  --win-top: #24339f;
  --win-bot: #0e1670;
  --slot: #0a0e4d;
  --frame: #f2efff;
  --frame-dim: #7f86d8;
  --ink: #f2efff;
  --muted: #b9beff;
  --gold: #ffd23f;
  --good: #45e07f;
  --bad: #ff8796;
  --mp: #5cc8ff;
  --shadow: #000000;
  --font-display: "Press Start 2P", ui-monospace, "Courier New", monospace;
  --font-body: "DotGothic16", ui-monospace, "Courier New", monospace;
  --t-label: 0.75rem;
  --t-sm: 1rem;
  --t-md: 1.0625rem;
  --t-lg: 1.35rem;
  --t-xl: 1.9rem;
  --bar-h: 84px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background-color: var(--void);
  background-image:
    radial-gradient(1px 1px at 20px 30px, var(--frame-dim) 50%, transparent 51%),
    radial-gradient(1px 1px at 140px 80px, var(--muted) 50%, transparent 51%),
    radial-gradient(2px 2px at 90px 160px, var(--frame-dim) 50%, transparent 51%),
    radial-gradient(1px 1px at 200px 220px, var(--muted) 50%, transparent 51%);
  background-size: 240px 260px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--t-md);
  line-height: 1.45;
  -webkit-font-smoothing: none;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
body::after { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 300;
  background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0,0,0,0.16) 2px 3px); }
/* Privacy veil when the app goes to the background: covers everything, toasts and banners included. */
/* Open windows live in the browser top layer, above any z-index, so they are hidden separately. */
body.veiled dialog { visibility: hidden; }
body.veiled::before { content: ""; position: fixed; inset: 0; background: var(--void); z-index: 290; }
.wrap { max-width: 640px; margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px calc(var(--bar-h) + 30px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 26px; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.good { color: var(--good); } .bad { color: var(--bad); } .goldt { color: var(--gold); } .mut { color: var(--muted); } .mpt { color: var(--mp); }
.lbl { font-family: var(--font-display); font-size: var(--t-label); color: var(--muted); letter-spacing: 0.04em; line-height: 1.6; }
.help { font-size: var(--t-sm); color: var(--muted); margin: 0; }
.panel { display: flex; flex-direction: column; gap: 26px; }

/* ---------- windows ---------- */
.win { position: relative; background: linear-gradient(180deg, var(--win-top), var(--win-bot));
  border: 3px solid var(--frame); border-radius: 8px; box-shadow: 0 0 0 3px var(--shadow), 6px 6px 0 3px var(--shadow);
  padding: 26px 14px 14px; min-width: 0; }
.win-title { position: absolute; top: -15px; left: 12px; background: var(--void); border: 3px solid var(--frame); border-radius: 6px;
  padding: 4px 8px; margin: 0; font-family: var(--font-display); font-size: var(--t-label); letter-spacing: 0.05em; font-weight: 400;
  display: flex; gap: 8px; align-items: center; white-space: nowrap; max-width: calc(100% - 24px); overflow: hidden; }
.win-title .jp { font-family: var(--font-body); font-size: 1rem; color: var(--gold); letter-spacing: 0; }
.slot { background: var(--slot); border: 2px solid var(--frame-dim); border-radius: 6px; padding: 10px 12px; min-width: 0; }

/* ---------- buttons ---------- */
.btn { background: var(--slot); border: 2px solid var(--frame); border-radius: 4px; min-height: 44px; padding: 8px 12px;
  font-family: var(--font-display); font-size: var(--t-label); letter-spacing: 0.04em; box-shadow: 3px 3px 0 var(--shadow); line-height: 1.35; }
.btn:hover { background: var(--win-top); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }
.btn.gold { border-color: var(--gold); color: var(--gold); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.big { min-height: 56px; font-size: 0.85rem; }
.btn.wide { width: 100%; }
.btn.small { min-height: 44px; padding: 6px 10px; }
.btn[aria-pressed="true"] { background: var(--gold); color: var(--slot); border-color: var(--gold); }
.btn:disabled { opacity: 0.45; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .btn { flex: 1; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- village ---------- */
.scene { position: relative; margin: 0 -4px; }
.scene canvas { display: block; width: 100%; aspect-ratio: 12 / 5; object-fit: cover; object-position: 50% 80%; image-rendering: pixelated; border: 3px solid var(--frame); border-radius: 8px;
  box-shadow: 0 0 0 3px var(--shadow), 6px 6px 0 3px var(--shadow); background: #5cc8ff; }
.scene .say-box { position: absolute; left: 8px; right: 8px; bottom: 8px; padding: 6px 8px; grid-template-columns: 36px 1fr; }
.scene .say-box img { width: 36px; height: 36px; }
.scene .say-box .say { font-size: 1rem; min-height: 0; line-height: 1.35; }
.scene .say-box { max-height: 58%; overflow: hidden; }
.scene .say-box.done { max-height: none; }
.say-box.gone { display: none; }
.say-box { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: start; cursor: pointer;
  background: rgba(10, 14, 77, 0.92); border: 2px solid var(--frame); border-radius: 6px; padding: 8px 10px; box-shadow: 3px 3px 0 var(--shadow); }
.say-box img { width: 44px; height: 44px; image-rendering: pixelated; }
.say-box .who { font-family: var(--font-display); font-size: var(--t-label); color: var(--gold); margin-bottom: 2px; }
.say-box .say { font-size: 1rem; line-height: 1.4; min-height: 2.8em; }
.say-box .say::after { content: " ▼"; color: var(--gold); font-size: 0.8rem; }
.say-box.done .say::after { content: ""; }
.status { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: var(--t-sm); }
.status b { font-weight: 400; color: var(--gold); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-display); font-size: var(--t-label); padding: 5px 8px;
  border: 2px solid currentColor; border-radius: 4px; background: var(--slot); line-height: 1.4; }
.forecast { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.forecast .chip { white-space: nowrap; flex-shrink: 0; }
.prompts { display: flex; flex-direction: column; gap: 10px; }
.prompt { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; background: var(--slot); border: 2px solid var(--gold);
  border-radius: 6px; padding: 10px 12px; text-align: left; width: 100%; min-height: 56px; }
.prompt .t { font-family: var(--font-display); font-size: var(--t-label); color: var(--gold); line-height: 1.6; }
.prompt .s { font-size: var(--t-sm); color: var(--muted); }
.prompt::after { content: "▶"; color: var(--gold); }

/* ---------- quick add ---------- */
.amount { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--shadow);
  border: 3px solid var(--frame); border-radius: 6px; padding: 6px 12px; margin-bottom: 10px; }
.amount .v { font-size: 1.9rem; line-height: 1.1; color: var(--gold); overflow-wrap: anywhere; }
.amount .v.neg { color: var(--good); }
.amount .typesw { font-family: var(--font-body); font-size: 1rem; letter-spacing: 0.06em; box-shadow: none; flex-shrink: 0; }
.strip { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: -4px 0 10px; font-size: 1rem; }
.strip-info { min-width: 0; overflow-wrap: anywhere; }
.cats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
.cat { min-height: 64px; min-width: 0; background: var(--slot); border: 2px solid var(--frame-dim); border-radius: 6px; padding: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; box-shadow: 3px 3px 0 var(--shadow); }
.cat .jp { font-size: 1.15rem; }
.cat .en { font-size: 0.85rem; letter-spacing: 0.02em; overflow-wrap: anywhere; text-align: center; }
.cat[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); background: rgba(255, 210, 63, 0.14); }
.entry { display: flex; flex-direction: column; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chips .btn { min-height: 44px; padding: 6px 9px; font-family: var(--font-body); font-size: 1rem; letter-spacing: 0.02em; }
.note-in { margin-bottom: 12px; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-bottom: 4px; }
.key { min-height: 48px; background: var(--slot); border: 2px solid var(--frame-dim); border-radius: 6px; font-size: 1.5rem;
  box-shadow: 3px 3px 0 var(--shadow); font-variant-numeric: tabular-nums; }
.key.go { background: var(--gold); color: var(--slot); border-color: var(--gold); font-family: var(--font-display); font-size: 0.85rem; }
.key:disabled { opacity: 0.45; }
.key:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); background: var(--win-top); }
.kept-note { text-align: center; font-size: var(--t-sm); color: var(--good); margin: 6px 0 0; }
.nothing { margin-top: 6px; }

/* ---------- lists & bars ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; align-items: baseline; background: var(--slot);
  border: 2px solid var(--frame-dim); border-radius: 6px; padding: 10px 12px; text-align: left; width: 100%; }
button.item:hover, button.item:focus-visible { border-color: var(--frame); }
.item .t { font-size: var(--t-md); overflow-wrap: anywhere; }
.item .r { text-align: right; white-space: nowrap; font-size: var(--t-md); }
.item .s { grid-column: 1 / -1; font-size: var(--t-sm); color: var(--muted); overflow-wrap: anywhere; }
.item .full { grid-column: 1 / -1; }
.day-h { font-family: var(--font-display); font-size: var(--t-label); color: var(--muted); margin: 8px 0 -2px; }
.bar { height: 14px; padding: 2px; background: var(--shadow); border: 2px solid var(--frame-dim); border-radius: 3px; margin-top: 6px; grid-column: 1 / -1; }
.bar i { display: block; height: 100%; border-radius: 1px; background: var(--mp); max-width: 100%; }
.bar.hp i { background: var(--bad); } .bar.exp i { background: var(--good); } .bar.gold i { background: var(--gold); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat .v { font-size: var(--t-lg); line-height: 1.2; margin-top: 4px; overflow-wrap: anywhere; }
.stat .s { font-size: var(--t-sm); color: var(--muted); }
.stat.full { grid-column: 1 / -1; }
.monthnav { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; text-align: center; }
.monthnav .m { font-family: var(--font-display); font-size: 0.8rem; color: var(--gold); line-height: 1.6; }
.empty { border: 2px dashed var(--frame-dim); border-radius: 6px; padding: 18px 14px; text-align: center; color: var(--muted); }
.counter { grid-column: 1 / -1; font-size: 1.6rem; line-height: 1.15; color: var(--bad); margin-top: 4px; overflow-wrap: anywhere; }
.payoff { grid-column: 1 / -1; font-size: var(--t-sm); overflow-wrap: anywhere; }
.cue { grid-column: 1 / -1; justify-self: end; font-family: var(--font-display); font-size: var(--t-label); color: var(--mp); margin-top: 4px; }
.visitors { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.visitor { background: var(--slot); border: 2px solid var(--frame-dim); border-radius: 6px; padding: 8px 6px; text-align: center; font-size: 1rem; }
.visitor img { width: 48px; height: 48px; image-rendering: pixelated; display: block; margin: 0 auto 4px; }
.visitor.unseen { color: var(--frame-dim); }
.visitor.unseen img { filter: brightness(0); opacity: 0.6; }
.chron { white-space: pre-wrap; }

/* ---------- command bar ---------- */
.cmdbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; padding: 0 8px calc(8px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, transparent, var(--void) 30%); }
.cmdbar .win { max-width: 640px; margin: 0 auto; padding: 6px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.tab { background: none; border: 2px solid transparent; border-radius: 4px; min-height: 60px; padding: 4px 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-family: var(--font-body); font-size: 0.85rem; letter-spacing: 0.06em; color: var(--muted); }
.tab .jp { font-family: var(--font-body); font-size: 1.25rem; letter-spacing: 0; line-height: 1; }
.tab[aria-selected="true"] { color: var(--gold); border-color: var(--gold); background: rgba(255,210,63,0.12); }
.tab .dot { width: 8px; height: 8px; background: var(--bad); border-radius: 50%; position: absolute; transform: translate(16px, -16px); }

/* ---------- sheets (dialogs) ---------- */
dialog.sheet { padding: 22px 8px 10px; border: 0; background: transparent; color: var(--ink); width: 100%;
  max-width: min(560px, calc(100vw - 8px)); max-height: calc(100dvh - 12px); overflow-y: auto; }
dialog.sheet::backdrop { background: rgba(4, 5, 20, 0.82); }
.sheet .win { padding: 28px 14px 16px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .lbl { font-family: var(--font-display); font-size: var(--t-label); color: var(--muted); letter-spacing: 0.04em; line-height: 1.6; }
.txt { background: var(--slot); border: 2px solid var(--frame-dim); border-radius: 4px; padding: 10px; min-height: 48px; font-size: 16px; width: 100%;
  min-width: 0; font-variant-numeric: tabular-nums; -webkit-appearance: none; appearance: none; }
textarea.txt { min-height: 80px; resize: vertical; }
.txt:focus { border-color: var(--gold); outline: none; }
.affix { display: flex; align-items: center; gap: 8px; }
.affix > span { color: var(--gold); font-size: var(--t-lg); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.err { color: var(--bad); font-size: var(--t-sm); margin: 0; min-height: 1.2em; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }
.sect { border-top: 2px dashed var(--frame-dim); margin-top: 14px; padding-top: 12px; }
.sect-h { font-family: var(--font-display); font-size: var(--t-label); color: var(--gold); line-height: 1.6; margin: 0 0 6px; }
dl.kv { margin: 8px 0 0; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: var(--t-sm); }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; text-align: right; }
.split { display: flex; height: 22px; padding: 3px; gap: 2px; background: var(--shadow); border: 2px solid var(--frame); border-radius: 4px; margin: 10px 0 8px; }
.split i { display: block; height: 100%; border-radius: 1px; min-width: 0; }
.split .si { background: var(--bad); } .split .sp { background: var(--good); }
.sched { display: grid; grid-template-columns: auto 1fr 1fr 1.25fr; gap: 4px 8px; font-size: 1rem; margin-top: 6px; }
.sched .h { font-family: var(--font-display); font-size: 0.75rem; color: var(--muted); padding-bottom: 4px; }
.sched .rt { text-align: right; }
.kindpick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.kindpick .btn { min-height: 48px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--bar-h) + 26px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  z-index: 260; display: flex; gap: 10px; align-items: center; font-size: 1rem; background: var(--slot); border: 2px solid var(--gold);
  color: var(--ink); padding: 8px 10px 8px 12px; border-radius: 6px; box-shadow: 3px 3px 0 var(--shadow); width: max-content; max-width: calc(100vw - 24px); }
.banner { position: fixed; top: env(safe-area-inset-top, 0px); left: 8px; right: 8px; z-index: 270; margin-top: 8px; }

@media (max-width: 400px) {
  .cat .en { font-size: 0.72rem; letter-spacing: 0; }
}
@media (max-width: 380px) {
  :root { --t-xl: 1.5rem; }
  .amount .v { font-size: 1.9rem; }
  .stats { grid-template-columns: minmax(0, 1fr); }
}
@media (max-height: 740px) {
  .wrap { gap: 20px; }
  .scene canvas { aspect-ratio: 7 / 2; }
  .key { min-height: 44px; }
  .pad { gap: 6px; }
  .cat { min-height: 56px; }
  .amount { padding: 4px 10px; margin-bottom: 8px; }
  .amount .v { font-size: 1.6rem; }
  .strip { margin-bottom: 6px; }
  .scene .say-box.done { max-height: 75%; overflow-y: auto; }
  .cats, .chips { margin-bottom: 8px; }
  /* the pad comes before the secondary chips on short screens */
  .entry > .chips, .entry > .note-in { order: 2; margin-top: 8px; }
}
/* Very narrow (or Safari text zoom at 200%): tabs keep the kanji and a short label that wraps. */
@media (max-width: 350px) {
  .cats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cat { flex-direction: row; gap: 8px; }
}
@media (max-width: 300px) {
  /* kanji only; the English name stays for screen readers */
  .tab .en { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .tab .jp { font-size: 1.6rem; }
  .win-title { position: static; display: inline-flex; margin: -14px 0 10px; white-space: normal; max-width: 100%; }
  .win { padding-top: 14px; }
  .cats { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
