:root {
  --ink: #3b2417;
  --cream: #fff4dc;
  --cream2: #f6e3bd;
  --pink: #ff8fb1;
  --teal: #2e8f88;
  --gold: #f6c344;
  --exp: #d9443f;
  --inc: #2f9e5b;
  --ps: 40;        /* panel picture slice (px of the picture) */
  --pb: 14px;      /* panel border width on screen */
  --bs: 36;
  --bb: 10px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1d2b33; }
body { color: var(--ink); user-select: none; -webkit-user-select: none; }
#app { position: fixed; top: 0; bottom: 0; left: 0; right: 0; margin: 0 auto; width: min(100vw, 62vh); overflow: hidden; }
#home.under #monthbar, #home.under #summary, #home.under #listPanel, #home.under #bottombar, #home.under #bubble { visibility: hidden; }
#bg { position: absolute; inset: 0; background: #2a4d55 center / cover no-repeat; image-rendering: pixelated; transition: background-image .4s; }
#bg::after { content: ""; position: absolute; inset: 0; background: rgba(40, 24, 16, 0.08); }

.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: flex; }

.otext { color: #fff; text-shadow: -2px 0 var(--ink), 2px 0 var(--ink), 0 -2px var(--ink), 0 2px var(--ink), -2px -2px var(--ink), 2px -2px var(--ink), -2px 2px var(--ink), 2px 2px var(--ink), 0 4px 0 rgba(0,0,0,.35); font-weight: 900; }

/* ---------- title ---------- */
#title { flex-direction: column; align-items: center; cursor: pointer; background: #12303a; }
#titleArt { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; }
#titleLogo { position: absolute; top: 6%; left: 50%; width: 82%; max-height: 30%; object-fit: contain; transform: translateX(-50%); animation: logoIn .7s cubic-bezier(.2,1.6,.4,1) both, floaty 3.2s ease-in-out .7s infinite; filter: drop-shadow(0 6px 0 rgba(0,0,0,.35)); }
#titleStart { position: absolute; bottom: 9%; left: 50%; transform: translateX(-50%); padding: 10px 26px; font-size: 20px; white-space: nowrap; color: #fff; background: rgba(30, 20, 14, .55); border: 3px solid var(--ink); box-shadow: inset 0 0 0 2px var(--gold); border-radius: 4px; font-weight: 900; text-shadow: 0 2px 0 var(--ink); }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; transform: translateX(-50%) scale(1); } 50% { opacity: .65; transform: translateX(-50%) scale(.96); } }
@keyframes logoIn { 0% { transform: translateX(-50%) translateY(-60px) scale(.6); opacity: 0; } 100% { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes floaty { 0%,100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-6px); } }

/* ---------- panels & buttons ---------- */
/* the pictures have transparent margins: slice past them and push them outside with outset */
.panel {
  border: 16px solid transparent;
  border-image-source: url(assets/ui-panel.webp);
  border-image-slice: 142 74 144 72 fill;
  border-image-width: 47px 25px 48px 24px;
  border-image-outset: 31px 9px 32px 8px;
  border-image-repeat: stretch;
  image-rendering: pixelated;
}
.btn {
  appearance: none; -webkit-appearance: none; font: inherit; cursor: pointer;
  color: #fff; font-weight: 900; font-size: 16px; min-height: 44px; min-width: 44px; padding: 0 8px;
  border: 10px solid transparent; background: none;
  border-image-source: url(assets/ui-button.webp);
  border-image-slice: 150 37 158 38 fill;
  border-image-width: 60px 15px 63px 15px;
  border-image-outset: 50px 5px 53px 5px;
  border-image-repeat: stretch;
  image-rendering: pixelated;
  text-shadow: -1.5px 0 var(--ink), 1.5px 0 var(--ink), 0 -1.5px var(--ink), 0 1.5px var(--ink), 0 2.5px 0 var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  transition: transform .08s, filter .12s;
}
.btn:active, .btn.press { transform: scale(.92); }
.btn.primary { filter: hue-rotate(150deg) saturate(1.3) brightness(1.08); }
.btn.gold { filter: hue-rotate(-140deg) saturate(1.4) brightness(1.15); }
.btn.danger { filter: hue-rotate(170deg) saturate(1.8) brightness(.95); }
.btn.dim { filter: grayscale(.8) brightness(.9); }
.btn.flat { border: none; border-image: none; background: none; }
.btn:disabled { filter: grayscale(1) opacity(.55); cursor: default; }
.focus { outline: none; animation: focusGlow .9s ease-in-out infinite; z-index: 2; position: relative; }
@keyframes focusGlow { 0%,100% { filter: drop-shadow(0 0 0 #ffe27a) drop-shadow(0 0 4px #ffe27a) brightness(1.15); } 50% { filter: drop-shadow(0 0 6px #ffe27a) drop-shadow(0 0 2px #fff) brightness(1.25); } }
.btn.primary.focus { animation: none; filter: hue-rotate(150deg) saturate(1.3) brightness(1.3) drop-shadow(0 0 6px #ffe27a); }
.pxicon { width: 22px; height: 22px; image-rendering: pixelated; flex: none; }
.bicon { font-size: 20px; line-height: 1; }
.bimg { width: 24px; height: 24px; image-rendering: pixelated; }

/* ---------- home ---------- */
#home { flex-direction: column; padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); gap: 6px; }
#topbar { display: flex; gap: 6px; align-items: center; height: 48px; padding-right: 60px; flex: none; }
.chip { display: flex; align-items: center; gap: 5px; height: 36px; padding: 0 9px; background: rgba(40, 24, 16, .62); border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px rgba(246, 195, 68, .55); border-radius: 6px; font-size: 16px; }
#lvChip { flex-direction: column; align-items: stretch; justify-content: center; gap: 2px; min-width: 70px; }
#lvText { font-size: 14px; line-height: 1; }
.xpbar { height: 7px; background: #4a3020; border: 1px solid #000; }
#xpFill { height: 100%; width: 0; background: linear-gradient(#9cf0a8, #3fbf5e); transition: width .5s; }

#monthbar { display: flex; align-items: center; justify-content: center; gap: 8px; flex: none; }
#monthText { font-size: 20px; min-width: 150px; }

#stage { position: relative; flex: 1 1 26%; min-height: 120px; max-height: 30%; }
#stageCanvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; cursor: pointer; }
#bubble { position: absolute; right: 2%; top: 10%; max-width: 50%; background: var(--cream); border: 3px solid var(--ink); padding: 8px 10px; font-size: 14px; font-weight: 700; line-height: 1.35; box-shadow: 4px 4px 0 rgba(0,0,0,.25); transform-origin: 0 100%; transition: transform .2s cubic-bezier(.2,1.6,.4,1), opacity .2s; }
#bubble::before { content: ""; position: absolute; left: -12px; bottom: 12px; border: 6px solid transparent; border-right-color: var(--ink); border-right-width: 9px; }
#bubble.hide { transform: scale(.4); opacity: 0; }

#summary { flex: none; padding: 2px 4px; cursor: pointer; }
.sumrow { display: flex; }
.sumcol { flex: 1; text-align: center; min-width: 0; }
.sumlabel { font-size: 13px; font-weight: 700; opacity: .75; }
.sumval { font-size: 18px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.exp { color: var(--exp); } .inc { color: var(--inc); }
.budgetbar { height: 12px; margin: 6px 4px 2px; background: #e9d2a6; border: 2px solid var(--ink); position: relative; }
#budgetFill { height: 100%; width: 0; background: repeating-linear-gradient(90deg, #5cc8a0 0 6px, #46b48c 6px 8px); transition: width .5s, background .3s; }
#budgetFill.warn { background: repeating-linear-gradient(90deg, #f6c344 0 6px, #e4a92a 6px 8px); }
#budgetFill.over { background: repeating-linear-gradient(90deg, #e85d5d 0 6px, #c94444 6px 8px); }
.budgettext { font-size: 13px; text-align: center; font-weight: 700; }

#listPanel { flex: 1 1 40%; min-height: 0; display: flex; }
#list { flex: 1; overflow-y: auto; overflow-x: hidden; scrollbar-width: none; padding: 0 2px; }
#list::-webkit-scrollbar { display: none; }
.dayhead { display: flex; justify-content: space-between; font-size: 13px; font-weight: 900; padding: 6px 4px 2px; border-bottom: 2px dashed rgba(59,36,23,.3); color: #7a5236; }
.row { display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 4px; min-height: 48px; border: none; background: none; font: inherit; color: inherit; cursor: pointer; text-align: left; border-radius: 4px; }
.row:active { background: rgba(255, 143, 177, .2); }
.row.focus { background: rgba(255, 226, 122, .45); animation: none; }
.row img { width: 36px; height: 36px; image-rendering: pixelated; flex: none; }
.row .rtext { flex: 1; min-width: 0; }
.row .rcat { font-weight: 900; font-size: 15px; }
.row .rnote { font-size: 12px; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .ramt { font-weight: 900; font-size: 16px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row.new { animation: rowIn .45s cubic-bezier(.2,1.6,.4,1); }
@keyframes rowIn { 0% { transform: scale(.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.empty { text-align: center; padding: 24px 10px; font-weight: 700; opacity: .7; white-space: pre-line; line-height: 1.6; }

#bottombar { display: flex; gap: 8px; flex: none; align-items: stretch; }
#bottombar .btn { flex: 1; min-height: 56px; font-size: 15px; padding: 0 6px; }
#bottombar .btn.big { flex: 1.5; font-size: 18px; }

/* ---------- sheet ---------- */
.sheet { position: absolute; inset: 0; display: none; background: rgba(20, 12, 8, .55); z-index: 20; align-items: flex-end; justify-content: center; }
.sheet.open { display: flex; }
.sheet-panel { width: min(100%, 520px); max-height: 97%; margin: 0 6px calc(6px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; padding: 2px; animation: sheetIn .26s cubic-bezier(.2,1.4,.4,1); overflow: hidden; }
.sheet.closing .sheet-panel { animation: sheetOut .18s ease-in forwards; }
@keyframes sheetIn { 0% { transform: translateY(70%); opacity: .3; } 100% { transform: translateY(0); opacity: 1; } }
@keyframes sheetOut { to { transform: translateY(80%); opacity: 0; } }
.shead { display: flex; align-items: center; gap: 8px; }
.shead h2 { flex: 1; margin: 0; font-size: 20px; font-weight: 900; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 8px; }
.tabs .btn { flex: 1; }
.amountbox { display: flex; align-items: center; gap: 10px; background: #fffaf0; border: 3px solid var(--ink); padding: 4px 10px; min-height: 54px; box-shadow: inset 0 3px 0 rgba(0,0,0,.08); }
.amountbox img { width: 40px; height: 40px; image-rendering: pixelated; }
.amountbox .acat { font-weight: 900; font-size: 15px; }
.amountbox .aval { flex: 1; text-align: right; font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }
.amountbox .aval.ph { opacity: .35; }
.catgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cat { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 58px; border: 3px solid transparent; background: rgba(255,255,255,.45); border-radius: 6px; font: inherit; font-size: 12px; font-weight: 800; color: var(--ink); cursor: pointer; padding: 2px; }
.cat img { width: 34px; height: 34px; image-rendering: pixelated; }
.cat.sel { border-color: var(--ink); background: #ffe7a8; box-shadow: inset 0 0 0 2px var(--gold); }
.cat:active { transform: scale(.92); }
.cat.focus { animation: none; background: #fff2b8; border-color: #e8a400; }
.daterow { display: flex; gap: 6px; align-items: center; }
.daterow .dtext { min-width: 86px; text-align: center; font-weight: 900; font-size: 15px; }
.note { flex: 1; min-width: 0; height: 44px; font: inherit; font-size: 15px; font-weight: 700; color: var(--ink); background: #fffaf0; border: 3px solid var(--ink); padding: 0 8px; outline: none; border-radius: 0; box-shadow: inset 0 3px 0 rgba(0,0,0,.08); user-select: text; -webkit-user-select: text; }
.note:focus { box-shadow: inset 0 0 0 2px var(--gold); }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.numpad .btn { min-height: 46px; font-size: 22px; }
.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; min-height: 52px; font-size: 18px; }
.hint { font-size: 13px; font-weight: 700; opacity: .7; text-align: center; }
.scroll { overflow-y: auto; scrollbar-width: none; min-height: 0; }
.scroll::-webkit-scrollbar { display: none; }

/* stats */
.statsTop { display: flex; align-items: center; gap: 10px; }
#donut { width: 132px; height: 132px; image-rendering: pixelated; flex: none; }
.statsTotal { flex: 1; text-align: center; }
.statsTotal .big { font-size: 26px; font-weight: 900; font-variant-numeric: tabular-nums; }
.legend .lrow { display: flex; align-items: center; gap: 8px; padding: 3px 2px; font-weight: 800; font-size: 14px; }
.legend img { width: 28px; height: 28px; image-rendering: pixelated; }
.legend .lname { width: 30%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend .lbar { flex: 1; height: 12px; background: #e9d2a6; border: 2px solid var(--ink); }
.legend .lbar div { height: 100%; }
.legend .lval { min-width: 82px; text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }
#bars { width: 100%; height: 84px; image-rendering: pixelated; background: rgba(255,255,255,.35); border: 2px solid var(--ink); }
.sub { font-size: 14px; font-weight: 900; color: #7a5236; }

/* shop sheet */
.themes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme { position: relative; border: 3px solid var(--ink); background: #fffaf0; padding: 4px; display: flex; flex-direction: column; gap: 4px; }
.theme.using { box-shadow: 0 0 0 3px var(--gold); }
.theme .thumb { height: 76px; background: center / cover no-repeat; image-rendering: pixelated; border: 2px solid var(--ink); }
.theme .tname { font-weight: 900; font-size: 13px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.theme .btn { min-height: 44px; font-size: 14px; }
.itemrow { display: flex; align-items: center; gap: 8px; background: #fffaf0; border: 3px solid var(--ink); padding: 6px; }
.itemrow img { width: 44px; height: 44px; image-rendering: pixelated; flex: none; }
.itemrow .itext { flex: 1; min-width: 0; }
.itemrow .iname { font-weight: 900; font-size: 15px; }
.itemrow .idesc { font-size: 12px; opacity: .75; }
.price img { width: 18px; height: 18px; image-rendering: pixelated; }
.helptext { font-size: 15px; line-height: 1.6; font-weight: 600; white-space: pre-line; }

/* intro */
#intro { background: #12303a url(assets/cover-bg.webp) center / cover; z-index: 40; }
#introVideo { width: 100%; height: 100%; object-fit: cover; }
#skipBtn { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; }

#fxCanvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }
#toasts { position: absolute; top: 64px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 35; }
.toast { background: rgba(40, 24, 16, .88); color: #fff; border: 3px solid var(--gold); padding: 8px 16px; font-weight: 900; font-size: 16px; animation: toastIn .3s cubic-bezier(.2,1.6,.4,1); max-width: 90%; text-align: center; }
.toast.out { animation: toastOut .3s ease-in forwards; }
@keyframes toastIn { from { transform: translateY(-20px) scale(.7); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-16px); opacity: 0; } }
.floattxt { position: absolute; z-index: 36; pointer-events: none; font-size: 22px; animation: floatUp 1.1s ease-out forwards; }
@keyframes floatUp { 0% { transform: translate(-50%, 0) scale(.6); opacity: 0; } 15% { transform: translate(-50%, -8px) scale(1.15); opacity: 1; } 100% { transform: translate(-50%, -70px) scale(1); opacity: 0; } }
.shake { animation: shake .3s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
