/* =====================================================================
   Little Tales design system: tokens, background, buttons, forms, sheets, tab bar.
   Warm paper, soft gingham, one olive accent. Playfair for words that matter, Inter for the interface.
   ===================================================================== */
:root {
  --paper: #FBF8F2; --card: #FFFDF9; --sand: #E9DECB; --sage: #A8BC9C; --sky: #BFD7EC; --butter: #F6E3A1; --blush: #F3C9C3;
  --olive: #5E7A53; --olive-deep: #3F5737; --olive-wash: #EEF3EA; --ink: #2E3134; --ink-2: #4F4B45; --muted: #6B6760; --faint: #9A9284;
  --link: #3D6A99; --ring: #EEE5D5; --line: #DED3C1; --line-2: #E6DCCB; --rose-ink: #7A3E35; --danger: #A3473B; --rec: #D9614E;
  --pink-wash: #F8E1DC; --butter-wash: #FDF1D8; --butter-ink: #6E4A12; --paper-2: #F1EBDF;
  --appw: min(100vw, 430px);
  --serif: 'Playfair Display', Georgia, 'Times New Roman', serif; --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'DM Mono', ui-monospace, Menlo, monospace; --hand: 'Caveat', 'Segoe Print', cursive;
  --ease: cubic-bezier(.22, .8, .3, 1);
  --shadow-card: 0 16px 34px -22px rgba(70, 55, 30, .45), 0 0 0 1px var(--ring);
  --shadow-btn: 0 12px 22px -12px rgba(60, 80, 50, .75);
  --tabh: 100px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: #F1EBDF; }
body { margin: 0; font-family: var(--sans); color: var(--ink); background: #F1EBDF; -webkit-text-size-adjust: 100%; overscroll-behavior: none; -webkit-font-smoothing: antialiased; }
#app { position: relative; width: var(--appw); min-height: 100dvh; margin: 0 auto; background: var(--paper); overflow-x: hidden; }
@media (min-width: 440px) { #app { box-shadow: 0 0 60px rgba(70, 55, 30, .14); } }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
a { color: var(--link); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: -.005em; line-height: 1.1; }
h1 em, h2 em { font-style: italic; font-weight: 600; }
p { margin: 0; }
:focus-visible { outline: 2.5px solid var(--link); outline-offset: 2px; border-radius: 8px; }
button:focus:not(:focus-visible), input:focus:not(:focus-visible), textarea:focus:not(:focus-visible) { outline: none; }

/* ---- the soft all-over background: gingham plus a small "day" of drawings around the edges ---- */
#backdrop { position: fixed; z-index: 0; top: 0; bottom: 0; left: 50%; width: var(--appw); transform: translateX(-50%); overflow: hidden; pointer-events: none; background-size: 26px 26px; transition: opacity .3s; }
#app[data-bd="sky"] #backdrop { background-image: linear-gradient(90deg, rgba(160, 195, 226, .17) 50%, transparent 50%), linear-gradient(rgba(160, 195, 226, .17) 50%, transparent 50%); }
#app[data-bd="rose"] #backdrop { background-image: linear-gradient(90deg, rgba(240, 175, 165, .15) 50%, transparent 50%), linear-gradient(rgba(210, 196, 166, .18) 50%, transparent 50%); }
#app[data-bd="none"] #backdrop { opacity: 0; }
#backdrop svg { position: absolute; display: block; }
#backdrop .bd-tulip { right: -12px; top: max(150px, calc(var(--ft, 380) * 1px - 150px)); width: 70px; transform: rotate(10deg); }
#backdrop .bd-forget { left: -12px; top: min(calc(var(--ft, 380) * 1px + 170px), calc(100% - 420px)); width: 58px; transform: rotate(14deg); }
@media (max-height: 640px) { #backdrop .bd-lower { display: none; } }

.screen { position: relative; z-index: 1; min-height: 100dvh; display: flex; flex-direction: column; padding: max(env(safe-area-inset-top), 34px) 20px 0; }
#app[data-tabs="1"] .screen { padding-bottom: calc(var(--tabh) + 12px); }
#screen { contain: layout style; }
.fade-in { animation: fade .28s ease both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.enter-fwd { animation: enterFwd .28s var(--ease) both; }
.enter-back { animation: enterBack .28s var(--ease) both; }
@keyframes enterFwd { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }
@keyframes enterBack { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }

/* ---- small type helpers ---- */
.kicker, .label { font-family: var(--mono); font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.lead { font-size: 16px; line-height: 1.5; color: var(--ink-2); }
.lead.small { font-size: 14px; }
.fine { font-size: 12px; line-height: 1.6; color: var(--muted); }
.fine a, .link { font-weight: 600; }
.muted { color: var(--muted); }

/* ---- buttons: olive pills ---- */
.btn-primary { background: var(--olive); color: #fff; font-weight: 600; font-size: 16px; height: 56px; border-radius: 999px; width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; box-shadow: var(--shadow-btn); transition: scale .16s ease, opacity .2s; }
.btn-primary.big { height: 58px; }
.btn-primary[disabled] { background: #B9C4B1; box-shadow: none; cursor: default; }
.btn-primary.busy { opacity: .7; }
.btn-secondary { height: 52px; width: 100%; border-radius: 999px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); font-weight: 600; font-size: 15px; display: flex; align-items: center; justify-content: center; gap: 10px; transition: scale .16s ease; }
.btn-secondary.done { background: var(--olive-wash); color: var(--olive-deep); border-color: var(--olive-wash); }
.btn-danger { height: 54px; width: 100%; border-radius: 999px; background: var(--danger); color: #fff; font-weight: 600; font-size: 16px; }
.btn-danger-ghost { height: 48px; width: 100%; border-radius: 999px; color: var(--danger); font-weight: 600; font-size: 14px; }
.btn-ic { display: inline-block; width: 20px; height: 20px; flex: none; }
.btn-ic svg { width: 100%; height: 100%; display: block; }
.link { color: var(--link); font-size: 15px; padding: 10px 8px; min-height: 44px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn-primary:active, .btn-secondary:active, .tile:active, .latest-card:active, .tab-item:active, .tab-new:active, .cell.has:active, .studio-item:active, .menu-item:active, .arow:active { scale: .97; }
.btn-primary:disabled:active { scale: 1; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--ink); }
.icon-btn svg { width: 24px; height: 24px; }
.bottom { margin-top: auto; padding: 14px 0 calc(22px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.bottom.tight { padding-top: 8px; }
.bottom .hint { color: var(--muted); font-size: 13px; text-align: center; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }

/* ---- top bar ---- */
.topbar { display: flex; align-items: center; height: 52px; margin: 6px -10px 0; }
.topbar-right { margin-left: auto; display: flex; align-items: center; }
.topbar-title { flex: 1; text-align: center; font-family: var(--serif); font-weight: 600; font-size: 20px; }
.topbar .skip-slot { min-width: 100px; display: flex; justify-content: flex-end; }

/* ---- pills, chips, cards ---- */
.pill { display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border-radius: 999px; background: var(--pink-wash); font-size: 12px; font-weight: 600; color: var(--rose-ink); white-space: nowrap; }
.pill.hot { background: var(--rose-ink); color: #fff; }
.glass-card, .card { background: var(--card); border-radius: 22px; box-shadow: var(--shadow-card); }
.chip { display: inline-flex; align-items: center; height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid #DED3C1; font-size: 13px; font-weight: 500; background: transparent; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 600; }
.dots { display: flex; justify-content: center; gap: 3px; }
.dot { width: 4px; height: 4px; border-radius: 50%; background: #D9CDB8; }
.dot.on { background: var(--olive); }

/* ---- forms ---- */
input, textarea { font: inherit; color: var(--ink); }
.title-input, .date-input, .signin-card input, .pay-fields input { width: 100%; height: 54px; padding: 0 16px; border-radius: 16px; background: var(--card); border: 1.5px solid var(--line-2); font-size: 16px; }
.title-input { font-family: var(--serif); font-size: 18px; border-color: var(--olive); }
.title-input:focus, .date-input:focus, .signin-card input:focus, .pay-fields input:focus { outline: none; border-color: var(--olive); box-shadow: 0 0 0 3px rgba(94, 122, 83, .16); }
.signin-card label, .pay-fields label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.pay-err { color: var(--danger); font-size: 13px; line-height: 1.45; min-height: 0; }
.pay-err:empty { display: none; }

/* ---- bottom sheet, toast ---- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(46, 49, 52, .38); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s ease both; width: var(--appw); margin: 0 auto; }
.sheet-backdrop.out { opacity: 0; transition: opacity .2s; }
.sheet { position: relative; width: 100%; background: var(--card); border-radius: 28px 28px 0 0; padding: 30px 22px calc(24px + env(safe-area-inset-bottom)); animation: rise .28s var(--ease) both; max-height: 88dvh; overflow: auto; box-shadow: 0 -12px 30px -18px rgba(70, 55, 30, .35); }
.sheet::before { content: ""; position: absolute; left: 50%; top: 8px; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: var(--line); }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-x { position: absolute; right: 8px; top: 12px; width: 44px; height: 44px; display: grid; place-items: center; color: var(--muted); }
.sheet-x svg { width: 20px; height: 20px; }
.sheet h2 { font-size: 24px; margin-bottom: 8px; padding-right: 36px; }
.sheet p { color: var(--ink-2); line-height: 1.5; margin-bottom: 16px; }
.sheet .btn-primary, .sheet .btn-danger { margin-top: 4px; }
.sheet-msg { color: var(--danger); font-size: 13px; margin: 8px 0; }
.sheet-msg:empty { display: none; }
.limit { text-align: center; }
.limit-stamps { display: flex; justify-content: center; gap: 4px; margin: 6px 0 18px; }
.limit h2 { padding: 0; }
.menu { display: flex; flex-direction: column; }
.menu h2 { margin-bottom: 10px; }
.menu-item { display: flex; align-items: center; justify-content: space-between; height: 54px; border-bottom: 1px solid #F0E8DA; font-size: 16px; font-weight: 500; text-align: left; width: 100%; }
.menu-item span { width: 18px; height: 18px; color: var(--faint); display: grid; }
.menu-item span svg { width: 100%; height: 100%; }
.menu-item.danger { color: var(--danger); border-bottom: 0; }
.date-input { margin: 6px 0; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 60; background: var(--ink); color: #FBF8F2; padding: 12px 20px; border-radius: 999px; font-size: 14px; font-weight: 500; box-shadow: 0 12px 30px rgba(46, 49, 52, .35); animation: fade .25s ease both; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; }
.toast.out { opacity: 0; transition: opacity .4s; }
#app[data-tabs="1"] .toast { bottom: calc(var(--tabh) + 8px); }

/* ---- bottom tab bar ---- */
#tabbar { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: min(var(--appw), 100%); z-index: 30; height: var(--tabh); padding: 10px 14px calc(28px + env(safe-area-inset-bottom) - 28px); padding-bottom: max(18px, calc(env(safe-area-inset-bottom) + 6px)); background: rgba(255, 253, 249, .96); border-top: 1px solid #ECE3D3; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center; }
#tabbar .tab-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 48px; font-size: 11px; font-weight: 600; color: #7A756D; transition: scale .16s ease; }
#tabbar .tab-item .ti { width: 24px; height: 24px; display: block; }
#tabbar .tab-item .ti svg { width: 100%; height: 100%; display: block; }
#tabbar .tab-item.on { color: var(--ink); }
#tabbar .tab-new { justify-self: center; width: 60px; height: 60px; margin-top: -26px; border-radius: 50%; background: var(--olive); color: #fff; display: grid; place-items: center; box-shadow: 0 0 0 6px var(--paper), 0 12px 22px -10px rgba(60, 80, 50, .8); transition: scale .16s ease; }
#tabbar .tab-new svg { width: 26px; height: 26px; }

/* ---- splash ---- */
#splash { position: fixed; inset: 0; z-index: 100; background: var(--paper); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; transition: opacity .4s; }
#splash.gone { opacity: 0; pointer-events: none; }
.splash-mark { width: 54px; height: 62px; background: url(../assets/icons/icon.svg) center / contain no-repeat; }
.splash-name { font-family: var(--serif); font-weight: 600; font-size: 28px; }

/* ---- loading placeholders ---- */
@keyframes shimmer { 0% { background-position: 120% 0; } 100% { background-position: -120% 0; } }
.sk-stamp { flex: 0 0 auto; width: 76px; height: 99px; border-radius: 6px; background: linear-gradient(100deg, rgba(255, 255, 255, .6) 30%, rgba(255, 255, 255, 1) 50%, rgba(255, 255, 255, .6) 70%) #F1E6D6; background-size: 220% 100%; animation: shimmer 1.4s linear infinite; box-shadow: 0 6px 14px rgba(70, 55, 30, .12); margin: 6px 4px; }
.stamp-photo.loading { background: linear-gradient(100deg, #EADFD0 30%, #F7EFE3 50%, #EADFD0 70%); background-size: 220% 100%; animation: shimmer 1.4s linear infinite; }
.stamp-photo .photo { transition: opacity .3s ease; }
.stamp-photo.loading .photo { opacity: 0; }

/* ---- confetti and the little celebration card ---- */
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 80; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } .sk-stamp, .stamp-photo.loading { animation: none; } }
