/* ElfHQ 2.0: global styles and theme tokens.
   Two hand-made themes:
     storybook: warm paper, pine and cranberry, a picture-book elf (default)
     midnight: night-sky navy, frosted cards and candlelight, for the 11pm elf move
   Every color in the app comes from these tokens. Text that sits on a colored surface uses that
   surface's "on" ink (--on-primary, --on-accent, --on-danger, --on-chip-active, --on-festive,
   --hero-ink), never a hardcoded #fff. Every pair is checked for at least 4.5:1 contrast.
   Theme selectors are attribute-only ([data-theme=…]), so one part of the page (e.g. Night setup
   mode) can switch to the midnight palette on its own. */

:root {
  --radius-card: 18px;
  --radius-input: 12px;
  --radius-chip: 999px;
  --sidebar-w: 256px;
  --bottom-nav-h: 74px;
  --header-h: 60px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

/* ---------- THEME: Storybook (light) ---------- */
[data-theme="storybook"], :root:not([data-theme]) {
  color-scheme: light;
  --font-display: "Young Serif", Georgia, "Times New Roman", serif;
  --font-body: "Nunito Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-hand: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  --display-style: normal;
  --display-weight: 400;
  --hand-size: 1.3em;

  --color-primary: #1E4A3B;        /* pine */
  --color-primary-dark: #163A2E;
  --color-danger: #B4232C;         /* cranberry */
  --color-accent: #E2B54F;         /* gold, takes dark ink */
  --color-festive: #B4232C;        /* the "magic" call to action: Tonight, Moved ✓ */
  --color-festive-dark: #961B23;
  --color-cream: #FBF7F0;
  --color-bg: #FBF7F0;
  --color-card: #FFFFFF;
  --color-raised: #FFFFFF;
  --color-text: #2A2320;
  --color-muted: #675B53;          /* 5.9:1 on bg */
  --color-border: #E6DAC6;
  --color-border-strong: #D3C3A8;
  --color-chip: #F2E8D8;
  --color-chip-text: #5A4A2E;
  --color-success: #2E6B4F;
  --color-warning: #9A5B0E;
  --color-error: #B4232C;
  --color-info: #2F5D8A;
  --chart-1: #1E4A3B;
  --chart-2: #B4232C;
  --chart-3: #B8862A;
  --chart-4: #5B8F7B;
  --chart-5: #8C5A3C;
  --chart-6: #2F5D8A;
  --header-bg: rgba(251, 247, 240, .9);
  --nav-bg: #FFFFFF;
  --nav-active-bg: #E5EFE8;
  --nav-active-text: #1E4A3B;
  --side-bg: #1E4A3B;
  --side-text: #D9E7DF;
  --side-heading: #A9C6B7;
  --side-active-bg: #FBF7F0;
  --side-active-text: #1E4A3B;
  --side-hover-bg: rgba(255, 255, 255, .08);
  --focus-ring: #1E4A3B;
  --banner-grad: linear-gradient(150deg, #24584A 0%, #1E4A3B 55%, #173B2F 100%);
  --chip-active-bg: #B4232C;
  --on-primary: #FFFFFF;
  --on-accent: #2A2320;
  --on-danger: #FFFFFF;
  --on-chip-active: #FFFFFF;
  --on-festive: #FFFFFF;

  --hero-bg: var(--banner-grad);
  --hero-ink: #FFFFFF;
  --hero-muted: #CFE2D8;
  --hero-chip: rgba(255, 255, 255, .14);
  --hero-ghost: rgba(255, 255, 255, .14);
  --hero-note: #F6D98D;
  --tag-bg: #E2B54F;
  --tag-ink: #2A2320;

  --good-bg: #E3EFE7; --good-ink: #1E4A3B;
  --miss-bg: #F8E0DF; --miss-ink: #9E1E27;
  --warn-bg: #FBEBCB; --warn-ink: #7A4708;
  --info-bg: #E2ECF5; --info-ink: #24486B;

  --cal-easy-bg: #DCEBDF;    --cal-easy-ink: #1E4A3B;
  --cal-medium-bg: #FBE7BF;  --cal-medium-ink: #6B4A08;
  --cal-hard-bg: #F6D6D4;    --cal-hard-ink: #8E1B22;
  --cal-rest-bg: #ECE6DC;    --cal-rest-ink: #5A4A3E;
  --cal-special-bg: #EADCF0; --cal-special-ink: #5B2A6E;
  --cal-scene-bg: #DCE8F3;   --cal-scene-ink: #24486B;

  --shadow-card: 0 1px 0 rgba(120, 90, 50, .06), 0 10px 24px -18px rgba(70, 45, 20, .35);
  --shadow-elevated: 0 18px 40px -16px rgba(50, 32, 14, .38);
  --card-border: 1px solid var(--color-border);
  --scrim: rgba(28, 22, 18, .5);
  --paper: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .32 0 0 0 0 .18 0 0 0 .06 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
  --stripe: repeating-linear-gradient(-45deg, #B4232C 0 9px, #FFFFFF 9px 18px);
  --stitch: rgba(255, 255, 255, .3);

  --elf-hat: #B4232C; --elf-fur: #FFFFFF; --elf-skin: #F5D0B5; --elf-skin-2: #E9AE90; --elf-hair: #7A4E33;
  --elf-body: #B4232C; --elf-collar: #2F6B55; --elf-line: #2A2320; --elf-sw: 2.4px; --elf-eye: #2A2320;
  --elf-halo: #F2E8D8;
}

/* ---------- THEME: Midnight Snow (dark) ---------- */
[data-theme="midnight"] {
  color-scheme: dark;
  --font-display: "Bodoni Moda", "Didot", Georgia, serif;
  --font-body: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-hand: "Bodoni Moda", Georgia, serif;
  --display-style: italic;
  --display-weight: 600;
  --hand-size: 1.08em;

  --color-primary: #F3B95F;        /* candlelight */
  --color-primary-dark: #F7CC86;
  --color-danger: #F0898F;
  --color-accent: #8FCBBB;         /* aurora mint, takes dark ink */
  --color-festive: #F3B95F;
  --color-festive-dark: #F7CC86;
  --color-cream: #14223A;
  --color-bg: #0C1626;
  --color-card: #14223A;
  --color-raised: #1A2A45;
  --color-text: #F4F7FB;
  --color-muted: #CAD4E0;          /* lighter for reading in the dark: 10.4:1 on card */
  --color-border: #263752;
  --color-border-strong: #34496A;
  --color-chip: #1E2F4B;
  --color-chip-text: #EAF0F6;
  --color-success: #7ED6B5;
  --color-warning: #F3B95F;
  --color-error: #F0898F;
  --color-info: #93BBEA;
  --chart-1: #F3B95F;
  --chart-2: #8FCBBB;
  --chart-3: #F0898F;
  --chart-4: #93BBEA;
  --chart-5: #C9A7E8;
  --chart-6: #E8D3A1;
  --header-bg: rgba(12, 22, 38, .86);
  --nav-bg: #0F1B2E;
  --nav-active-bg: rgba(243, 185, 95, .14);
  --nav-active-text: #F7CC86;
  --side-bg: #091221;
  --side-text: #DFE7F0;
  --side-heading: #AEBDD0;
  --side-active-bg: rgba(243, 185, 95, .14);
  --side-active-text: #F7CC86;
  --side-hover-bg: rgba(255, 255, 255, .05);
  --focus-ring: #F3B95F;
  --banner-grad: linear-gradient(165deg, #1F3355 0%, #15243D 58%, #101C30 100%);
  --chip-active-bg: #F3B95F;
  --on-primary: #1D1405;
  --on-accent: #0C1626;
  --on-danger: #1D1405;
  --on-chip-active: #1D1405;
  --on-festive: #1D1405;

  --hero-bg: var(--banner-grad);
  --hero-ink: #F4F7FB;
  --hero-muted: #D3DDE8;
  --hero-chip: rgba(255, 255, 255, .09);
  --hero-ghost: rgba(255, 255, 255, .1);
  --hero-note: #E3EAF2;
  --tag-bg: rgba(243, 185, 95, .16);
  --tag-ink: #F7CC86;

  --good-bg: rgba(126, 214, 181, .14); --good-ink: #9FE3C8;
  --miss-bg: rgba(240, 137, 143, .16); --miss-ink: #FFB8BD;
  --warn-bg: rgba(243, 185, 95, .14);  --warn-ink: #F7CC86;
  --info-bg: rgba(147, 187, 234, .14); --info-ink: #B9D3F2;

  --cal-easy-bg: rgba(126, 214, 181, .16);   --cal-easy-ink: #B5ECD7;
  --cal-medium-bg: rgba(243, 185, 95, .18);  --cal-medium-ink: #F7D7A2;
  --cal-hard-bg: rgba(240, 137, 143, .18);   --cal-hard-ink: #FFC4C8;
  --cal-rest-bg: rgba(169, 182, 198, .14);   --cal-rest-ink: #CBD5E1;
  --cal-special-bg: rgba(201, 167, 232, .18); --cal-special-ink: #E1CCF5;
  --cal-scene-bg: rgba(147, 187, 234, .16);  --cal-scene-ink: #C7DBF5;

  --shadow-card: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 18px 36px -24px rgba(0, 0, 0, .8);
  --shadow-elevated: 0 24px 50px -18px rgba(0, 0, 0, .75);
  --card-border: 1px solid var(--color-border);
  --scrim: rgba(3, 8, 16, .66);
  --paper: radial-gradient(1.2px 1.2px at 12% 18%, rgba(255,255,255,.55) 50%, transparent 52%),
           radial-gradient(1px 1px at 68% 8%, rgba(255,255,255,.4) 50%, transparent 52%),
           radial-gradient(1.4px 1.4px at 86% 42%, rgba(255,255,255,.35) 50%, transparent 52%),
           radial-gradient(1px 1px at 34% 64%, rgba(255,255,255,.3) 50%, transparent 52%),
           radial-gradient(1.2px 1.2px at 52% 88%, rgba(255,255,255,.3) 50%, transparent 52%);
  --stripe: repeating-linear-gradient(-45deg, rgba(243,185,95,.85) 0 9px, rgba(255,255,255,.08) 9px 18px);
  --stitch: rgba(255, 255, 255, .14);

  --elf-hat: #D9646C; --elf-fur: #F4F1EA; --elf-skin: #F1CCB2; --elf-skin-2: #DDA88C; --elf-hair: #6E4A34;
  --elf-body: #2E7566; --elf-collar: #F3B95F; --elf-line: transparent; --elf-sw: 0px; --elf-eye: #2A2320;
  --elf-halo: rgba(243, 185, 95, .12);
}

/* ---------- Reset (replaces the Tailwind preflight the pages were built on) ---------- */
*, ::before, ::after { box-sizing: border-box; border-width: 0; border-style: solid; border-color: var(--color-border); }
html { -webkit-text-size-adjust: 100%; tab-size: 4; }
body { margin: 0; }
h1, h2, h3, h4, h5, h6 { font-size: inherit; font-weight: inherit; margin: 0; }
p, blockquote, dl, dd, figure, pre, hr { margin: 0; }
hr { height: 0; border-top-width: 1px; }
a { color: inherit; text-decoration: inherit; }
b, strong { font-weight: 800; }
table { border-collapse: collapse; text-indent: 0; border-color: inherit; }
button, input, optgroup, select, textarea { font-family: inherit; font-size: 100%; font-weight: inherit; line-height: inherit; color: inherit; margin: 0; padding: 0; }
button, [type="button"], [type="reset"], [type="submit"] { -webkit-appearance: button; background-color: transparent; background-image: none; }
button, [role="button"] { cursor: pointer; }
:disabled { cursor: default; }
ol, ul, menu { list-style: none; margin: 0; padding: 0; }
fieldset { margin: 0; padding: 0; }
legend { padding: 0; }
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--color-muted); opacity: .75; }
img, svg, video, canvas, audio, iframe, embed, object { display: block; vertical-align: middle; }
img, video { max-width: 100%; height: auto; }
[hidden] { display: none !important; }

/* ---------- Base ---------- */
html { background: var(--color-bg); }
body {
  background-color: var(--color-bg);
  background-image: var(--paper);
  background-attachment: fixed;
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
[data-theme="midnight"] body {
  background-image: var(--paper), radial-gradient(120% 60% at 85% -10%, #213659 0%, rgba(33,54,89,0) 60%), radial-gradient(90% 50% at -10% 110%, #17293F 0%, rgba(23,41,63,0) 60%);
  background-size: 260px 260px, auto, auto;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-style: var(--display-style); font-weight: var(--display-weight); color: var(--color-text); text-wrap: balance; letter-spacing: -.005em; }
.display { font-family: var(--font-display); font-style: var(--display-style); font-weight: var(--display-weight); }
.hand { font-family: var(--font-hand); font-size: var(--hand-size); line-height: 1.15; font-weight: 600; }
[data-theme="midnight"] .hand { font-style: italic; font-weight: 500; }
::selection { background: var(--color-accent); color: var(--on-accent); }
/* Remove the ~350ms tap delay / double-tap-zoom on interactive elements (iOS Safari) */
button, a, label, .chip, .elf-checkbox, .cal-cell, .list-row, .photo-tile, [role="checkbox"], .tile { touch-action: manipulation; }
.lucide { flex: none; }
.muted { color: var(--color-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ---------- Layout ---------- */
#app-shell { min-height: 100vh; min-height: 100dvh; display: flex; }
#sidebar { display: none; }
#content-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#app-header { background: var(--header-bg); -webkit-backdrop-filter: saturate(1.2) blur(12px); backdrop-filter: saturate(1.2) blur(12px); border-bottom: 1px solid var(--color-border); position: sticky; top: 0; z-index: 50; padding-top: env(safe-area-inset-top, 0px); }
#main-content { flex: 1; padding: 14px 16px calc(var(--bottom-nav-h) + 36px + env(safe-area-inset-bottom, 0px)); max-width: 1180px; width: 100%; margin: 0 auto; }
#main-content:focus { outline: none; }
#bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px); background: var(--nav-bg); border-top: 1px solid var(--color-border); z-index: 40; box-shadow: 0 -10px 30px -24px rgba(0,0,0,.4); }

@media (min-width: 1024px) {
  #sidebar { display: flex; flex-direction: column; width: var(--sidebar-w); flex-shrink: 0; background: var(--side-bg); color: var(--side-text); position: sticky; top: 0; height: 100vh; overflow-y: auto; scrollbar-width: thin; }
  [data-theme="storybook"] #sidebar, :root:not([data-theme]) #sidebar { background-image: radial-gradient(rgba(255,255,255,.07) 1.2px, transparent 1.4px); background-size: 18px 18px; }
  [data-theme="midnight"] #sidebar { border-right: 1px solid var(--color-border); }
  #bottom-nav { display: none; }
  #app-header { display: none; }
  #main-content { padding: 30px 36px 48px; }
}

/* ---------- App header (phones/tablets) ---------- */
.app-header-bar { display: flex; align-items: center; gap: 10px; height: var(--header-h); padding: 0 12px 0 16px; }
.app-brand { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-display); font-style: var(--display-style); font-weight: var(--display-weight); font-size: 22px; color: var(--color-text); }
.app-brand .elf { width: 34px; height: 34px; }
.app-header-bar .route-title { flex: 1; min-width: 0; text-align: center; font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--color-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; display: inline-grid; place-items: center; color: var(--color-muted); background: transparent; transition: background .15s, color .15s; flex: none; }
.icon-btn:hover { background: var(--color-chip); color: var(--color-text); }
.icon-btn .lucide { width: 20px; height: 20px; }

/* ---------- Sidebar (desktop) ---------- */
.sidebar-brand { padding: 22px 20px 14px; display: flex; align-items: center; gap: 10px; color: #FFFFFF; }
[data-theme="midnight"] .sidebar-brand { color: var(--color-text); }
.sidebar-brand .elf { width: 40px; height: 40px; }
.sidebar-brand h1, .sidebar-brand .name { font-size: 24px; color: inherit; font-family: var(--font-display); font-style: var(--display-style); font-weight: var(--display-weight); }
.sidebar-brand .elf { --elf-line: #12302A; }
.nav-drawer-list { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.sidebar-group-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: .14em; color: var(--side-heading); padding: 16px 12px 6px; font-weight: 800; }
.sidebar-item { display: flex; align-items: center; gap: 11px; padding: 9px 12px; color: var(--side-text); text-decoration: none; font-size: 14.5px; font-weight: 700; border-radius: 11px; transition: background .15s, color .15s; }
.sidebar-item .lucide { width: 18px; height: 18px; opacity: .9; }
@media (hover: hover) { .sidebar-item:hover { background: var(--side-hover-bg); color: var(--side-active-text); } [data-theme="storybook"] .sidebar-item:hover, :root:not([data-theme]) .sidebar-item:hover { color: #FFFFFF; } }
.sidebar-item.active { background: var(--side-active-bg); color: var(--side-active-text); box-shadow: 0 6px 16px -10px rgba(0,0,0,.5); }
.sidebar-item .nav-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--color-festive); color: var(--on-festive); font-size: 11px; font-weight: 800; display: grid; place-items: center; }
.sidebar-footer { margin-top: auto; padding: 18px 22px 22px; font-size: 11.5px; color: var(--side-heading); }
/* The drawer ("More" on phones) reuses the sidebar items on a light sheet */
.drawer .sidebar-item { color: var(--color-text); }
.drawer .sidebar-item.active { background: var(--nav-active-bg); color: var(--nav-active-text); box-shadow: none; }
.drawer .sidebar-group-title { color: var(--color-muted); }
.drawer .sidebar-footer { color: var(--color-muted); }
.drawer .nav-drawer-list { padding: 0; }

/* ---------- Bottom nav ---------- */
.bnav { display: flex; height: var(--bottom-nav-h); align-items: stretch; }
.bnav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; flex: 1; color: var(--color-muted); font-size: 11px; font-weight: 800; min-height: 44px; text-decoration: none; padding: 8px 2px; transition: color .15s; letter-spacing: .01em; }
.bnav-item .lucide { width: 23px; height: 23px; }
.bnav-item.active { color: var(--color-festive); }
[data-theme="midnight"] .bnav-item.active { color: var(--nav-active-text); }
.bnav-item .label { font-weight: 800; }
.bnav-center { position: relative; }
.bnav-center .bnav-orb { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; background: var(--color-festive); color: var(--on-festive); margin-top: -30px; box-shadow: 0 0 0 5px var(--nav-bg), 0 10px 22px -6px rgba(150, 25, 35, .55); transition: transform .15s var(--ease); }
[data-theme="midnight"] .bnav-center .bnav-orb { box-shadow: 0 0 0 5px var(--nav-bg), 0 0 26px -2px rgba(243, 185, 95, .5); }
.bnav-center .bnav-orb .lucide { width: 26px; height: 26px; }
.bnav-center:active .bnav-orb { transform: scale(.94); }
.bnav-center.active { color: var(--color-festive); }
.bnav-dot { position: absolute; top: -26px; right: calc(50% - 30px); width: 14px; height: 14px; border-radius: 50%; background: var(--color-accent); border: 2px solid var(--nav-bg); }

/* ---------- Page header ---------- */
.page-header { padding: 10px 0 16px; display: grid; gap: 4px; }
.page-header .eyebrow, .eyebrow { font-size: 11.5px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--color-muted); }
.page-header h1 { font-size: 30px; line-height: 1.08; }
.page-header p { color: var(--color-muted); margin: 2px 0 0; font-size: 14.5px; }
.page-header .hand { color: var(--color-danger); }
[data-theme="midnight"] .page-header .hand { color: var(--hero-note); }
@media (min-width: 1024px) { .page-header { padding: 4px 0 22px; } .page-header h1 { font-size: 38px; } }

/* ---------- Cards ---------- */
.card { background: var(--color-card); border-radius: var(--radius-card); box-shadow: var(--shadow-card); padding: 18px; border: var(--card-border); position: relative; }
.card.flat { box-shadow: none; }
.card.tight { padding: 14px 16px; }
@media (hover: hover) { .card.interactive { transition: transform .18s var(--ease), box-shadow .18s var(--ease); } .card.interactive:hover { transform: translateY(-2px); box-shadow: var(--shadow-elevated); } }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-title h2, .card-title h3 { font-size: 19px; line-height: 1.15; }
[data-theme="storybook"] .card-title h2, [data-theme="storybook"] .card-title h3, :root:not([data-theme]) .card-title h2 { color: var(--color-primary); }
.card-title .aside { font-size: 12.5px; font-weight: 800; color: var(--color-muted); }
.card-title a.aside { color: var(--color-danger); }
[data-theme="midnight"] .card-title a.aside { color: var(--color-primary); }
.card-stitched::after { content: ""; position: absolute; inset: 6px; border: 1.5px dashed var(--color-border); border-radius: calc(var(--radius-card) - 5px); pointer-events: none; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 18px; border-radius: var(--radius-input); font-weight: 800; font-size: 14.5px; border: 1px solid transparent; transition: background .15s, color .15s, border-color .15s, transform .1s; min-height: 44px; touch-action: manipulation; line-height: 1.2; text-align: center; white-space: nowrap; }
.btn .lucide { width: 17px; height: 17px; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .55; }
.btn-primary { background: var(--color-primary); color: var(--on-primary); }
.btn-festive { background: var(--color-festive); color: var(--on-festive); }
.btn-secondary { background: var(--color-chip); color: var(--color-text); }
.btn-outline { background: var(--color-card); color: var(--color-text); border-color: var(--color-border-strong); }
.btn-danger { background: transparent; color: var(--color-danger); border-color: var(--color-danger); }
.btn-ghost { background: transparent; color: var(--color-text); }
.btn-sm { padding: 7px 13px; min-height: 38px; font-size: 13.5px; border-radius: 10px; }
.btn-sm .lucide { width: 15px; height: 15px; }
.btn-lg { padding: 15px 22px; min-height: 54px; font-size: 16px; border-radius: 14px; }
.btn-block { width: 100%; }
.btn.is-on, .btn-secondary.is-on { background: var(--color-primary); color: var(--on-primary); }
@media (hover: hover) {
  .btn-primary:hover:not(:disabled) { background: var(--color-primary-dark); }
  .btn-festive:hover:not(:disabled) { background: var(--color-festive-dark); }
  .btn-secondary:hover:not(:disabled) { background: var(--color-border); }
  .btn-outline:hover:not(:disabled) { border-color: var(--color-primary); }
  .btn-danger:hover:not(:disabled) { background: var(--color-danger); color: var(--on-danger); }
  .btn-ghost:hover:not(:disabled) { background: var(--color-chip); }
}
/* Segmented control (view switches) */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--color-chip); border-radius: 12px; }
.seg button { padding: 7px 14px; border-radius: 9px; font-size: 13.5px; font-weight: 800; color: var(--color-muted); min-height: 36px; }
.seg button.on, .seg button[aria-pressed="true"] { background: var(--color-card); color: var(--color-text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* ---------- Inputs ---------- */
.input, .textarea, .select {
  width: 100%;
  min-width: 0; /* allow date/number inputs to shrink inside grid/flex columns (iOS overlap fix) */
  padding: 12px 14px;
  border-radius: var(--radius-input);
  border: 1px solid var(--color-border-strong);
  background: var(--color-card);
  color: var(--color-text);
  font-size: 16px; /* 16px stops iOS zooming in on focus */
  min-height: 46px;
  transition: border-color .15s, box-shadow .15s;
}
[data-theme="midnight"] .input, [data-theme="midnight"] .textarea, [data-theme="midnight"] .select { background-color: #0F1B2E; }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--focus-ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus-ring) 28%, transparent); }
.select { -webkit-appearance: none; appearance: none; padding-right: 38px; background-image: linear-gradient(45deg, transparent 50%, var(--color-muted) 50%), linear-gradient(135deg, var(--color-muted) 50%, transparent 50%); background-position: calc(100% - 20px) 52%, calc(100% - 15px) 52%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
/* iOS/Safari render native date & time controls wider than their box, spilling into the next
   column. Strip the native appearance so they respect width:100% and clip to their box. */
input[type="date"], input[type="time"], input[type="month"], input[type="datetime-local"] { -webkit-appearance: none; appearance: none; }
input[type="date"]::-webkit-date-and-time-value, input[type="time"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--color-primary); width: 18px; height: 18px; }
input[type="range"] { accent-color: var(--color-festive); width: 100%; }
/* Two-up form rows (e.g. Date + Difficulty). Equal columns that never overflow, and they
   stack to a single column on phones so a wide date field can't overlap its neighbour. */
.form-grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
@media (max-width: 600px) { .form-grid-2 { grid-template-columns: 1fr; } }
.textarea { min-height: 100px; resize: vertical; line-height: 1.5; }
.label { display: block; font-size: 13px; font-weight: 800; color: var(--color-muted); margin-bottom: 6px; letter-spacing: .02em; }
.field { display: grid; gap: 6px; }
.field .label { margin: 0; }
.help { font-size: 12.5px; color: var(--color-muted); }
/* Preview of longer text: shows whole lines only (never slices through descenders like g and y)
   and ends with "…". Set --lines on the element to change how many. */
.clamp-lines { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: var(--lines, 4); line-clamp: var(--lines, 4); overflow: hidden; white-space: pre-line; line-height: 1.6; padding-bottom: .1em; }
.field-error { font-size: 13px; font-weight: 700; color: var(--miss-ink); background: var(--miss-bg); padding: 8px 12px; border-radius: 10px; margin-top: 6px; }
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--color-danger); }

/* ---------- Chips, tags & badges ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; border-radius: var(--radius-chip); background: var(--color-chip); color: var(--color-chip-text); font-size: 12.5px; font-weight: 800; letter-spacing: .01em; line-height: 1.35; white-space: nowrap; }
.chip .lucide { width: 13px; height: 13px; }
.chip-primary { background: var(--color-primary); color: var(--on-primary); }
.chip-accent { background: var(--color-accent); color: var(--on-accent); }
.chip-danger { background: var(--color-danger); color: var(--on-danger); }
.chip-good { background: var(--good-bg); color: var(--good-ink); }
.chip-miss { background: var(--miss-bg); color: var(--miss-ink); }
.chip-warn { background: var(--warn-bg); color: var(--warn-ink); }
.chip-info { background: var(--info-bg); color: var(--info-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
/* Gift-tag label, e.g. "Tonight · Sun Dec 7" */
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; padding: 5px 11px 5px 17px; background: var(--tag-bg); color: var(--tag-ink); border-radius: 3px; clip-path: polygon(10px 0, 100% 0, 100% 100%, 10px 100%, 0 50%); }
.tag .lucide { width: 13px; height: 13px; }
[data-theme="midnight"] .tag { clip-path: none; border-radius: 999px; padding-left: 11px; }

/* Filter chips wrap onto more rows at every width. (Phones and tablets used to scroll them
   sideways behind a hidden scrollbar, so most filters were never seen.) */
.chip-scroll { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0 14px; align-items: center; }
.chip-scroll .chip { flex-shrink: 1; cursor: pointer; padding: 8px 14px; font-size: 13px; border: 1px solid transparent; transition: background .15s, color .15s; }
@media (hover: hover) { .chip-scroll .chip:hover { border-color: var(--color-border-strong); } }
.chip-scroll .chip.active { background: var(--chip-active-bg); color: var(--on-chip-active); }

/* Difficulty dots */
.diff-dots { display: inline-flex; gap: 3px; }
.diff-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-border-strong); }
.diff-dot.filled { background: var(--color-primary); }

/* Long labels wrap instead of pushing past a narrow screen */
.chip, .btn { max-width: 100%; }
.chip { overflow-wrap: anywhere; }
@media (max-width: 480px) { .chip, .btn { white-space: normal; } .chip { text-align: left; } }

/* ---------- Notices (in-page banners) ---------- */
.notice { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-radius: 14px; background: var(--warn-bg); color: var(--warn-ink); font-size: 14.5px; font-weight: 600; }
.notice .lucide { width: 20px; height: 20px; margin-top: 1px; }
.notice b { font-weight: 800; }
.notice .grow { flex: 1; min-width: 0; }
.notice.good { background: var(--good-bg); color: var(--good-ink); }
.notice.info { background: var(--info-bg); color: var(--info-ink); }
.notice.miss { background: var(--miss-bg); color: var(--miss-ink); }
.notice .btn { flex: none; }

/* ---------- Page enter ---------- */
.page-enter-active { animation: pageEnter .28s var(--ease); }
@keyframes pageEnter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: calc(var(--bottom-nav-h) + 18px + env(safe-area-inset-bottom, 0px)); left: 16px; right: 16px; z-index: 300; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
@media (min-width: 1024px) { #toast-root { bottom: 24px; left: auto; right: 28px; align-items: flex-end; } }
.toast { display: inline-flex; align-items: center; gap: 10px; max-width: 420px; background: var(--color-text); color: var(--color-bg); padding: 12px 18px 12px 14px; border-radius: 14px; box-shadow: var(--shadow-elevated); animation: toastIn .3s var(--ease); pointer-events: auto; font-size: 14.5px; font-weight: 700; }
.toast::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--color-success); flex: none; box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-success) 30%, transparent); }
[data-theme="storybook"] .toast::before, :root:not([data-theme]) .toast::before { background: #7FD3A6; }
.toast.error::before { background: #FF8A8F; }
.toast.warning::before { background: #F3B95F; }
.toast.info::before { background: #93BBEA; }
@keyframes toastIn { from { transform: translateY(16px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Update banner ---------- */
#update-banner { position: fixed; top: 0; left: 0; right: 0; z-index: 10000; }
.update-bar { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px 14px; padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: var(--color-primary); color: var(--on-primary); font-weight: 700; font-size: 14.5px; text-align: center; }
.update-bar button { padding: 6px 14px; border-radius: 10px; background: var(--on-primary); color: var(--color-primary); font-weight: 800; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: var(--scrim); z-index: 200; display: flex; align-items: flex-end; justify-content: center; animation: fadeIn .2s ease; -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
@media (min-width: 768px) { .modal-backdrop { align-items: center; padding: 24px; } }
.modal { background: var(--color-card); border-radius: 22px 22px 0 0; padding: 22px 20px calc(20px + env(safe-area-inset-bottom, 0px)); width: 100%; max-height: 92vh; max-height: 92dvh; overflow-y: auto; animation: sheetUp .3s var(--ease); position: relative; box-shadow: var(--shadow-elevated); overscroll-behavior: contain; }
.modal::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 7px; background: var(--stripe); border-radius: 22px 22px 0 0; }
.modal:focus { outline: none; }
.modal .modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.modal .modal-head h2 { font-size: 23px; line-height: 1.15; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 20px; }
@media (max-width: 480px) { .modal-footer .btn { flex: 1; } }
@media (min-width: 768px) { .modal { border-radius: 22px; max-width: 600px; padding: 26px 26px 24px; } .modal::before { border-radius: 22px 22px 0 0; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: var(--scrim); z-index: 60; animation: fadeIn .2s ease; }
.drawer { position: fixed; left: 0; right: 0; bottom: 0; background: var(--color-card); z-index: 61; border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0px)); max-height: 86vh; max-height: 86dvh; overflow-y: auto; animation: sheetUp .3s var(--ease); box-shadow: var(--shadow-elevated); overscroll-behavior: contain; }
@media (min-width: 768px) { .drawer { left: auto; top: 0; bottom: 0; right: 0; width: 430px; border-radius: 22px 0 0 22px; max-height: 100vh; } }

/* ---------- Skip link & focus ---------- */
.skip-link { position: absolute; left: -9999px; top: 0; background: var(--color-primary); color: var(--on-primary); padding: 8px 12px; z-index: 999; border-radius: 8px; }
.skip-link:focus { left: 8px; top: 8px; }
:focus-visible { outline: 2.5px solid var(--focus-ring); outline-offset: 2px; }
.sidebar-item:focus-visible { outline-color: var(--side-active-bg); }

/* ---------- Progress ---------- */
.progress-track { background: var(--color-chip); border-radius: 999px; height: 8px; overflow: hidden; }
.progress-fill { background: var(--color-primary); height: 100%; transition: width .6s var(--ease); border-radius: 999px; }
.ring { display: block; }
.ring .trk { fill: none; stroke: var(--color-chip); }
.ring .val { fill: none; stroke: var(--color-festive); stroke-linecap: round; transition: stroke-dasharray .8s var(--ease); }
.ring text { font-family: var(--font-display); font-style: var(--display-style); fill: var(--color-text); }

/* ---------- Mascot ---------- */
.elf { display: block; overflow: visible; }
.elf .e-hat { fill: var(--elf-hat); }
.elf .e-fur { fill: var(--elf-fur); }
.elf .e-skin { fill: var(--elf-skin); }
.elf .e-body { fill: var(--elf-body); }
.elf .e-collar { fill: var(--elf-collar); }
.elf .e-hair { fill: var(--elf-hair); }
.elf .e-hat, .elf .e-fur, .elf .e-skin, .elf .e-body, .elf .e-collar, .elf .e-hair { stroke: var(--elf-line); stroke-width: var(--elf-sw); stroke-linejoin: round; paint-order: stroke; }
.elf .e-inner, .elf .e-nose { fill: var(--elf-skin-2); }
.elf .e-eye { fill: var(--elf-eye); }
.elf .e-glint { fill: #FFFFFF; }
.elf .e-brow { fill: none; stroke: var(--elf-hair); stroke-width: 2.2; stroke-linecap: round; }
.elf .e-lid { fill: none; stroke: var(--elf-eye); stroke-width: 2.4; stroke-linecap: round; }
.elf .e-cheek { fill: #F08F8F; opacity: .5; }
.elf .e-smile { fill: none; stroke: var(--elf-eye); stroke-width: 2.6; stroke-linecap: round; }
[data-theme="midnight"] .elf { filter: drop-shadow(0 0 16px rgba(243, 185, 95, .22)); }

/* ---------- Empty state ---------- */
.empty-state { padding: 36px 20px 30px; text-align: center; display: grid; justify-items: center; gap: 6px; }
.empty-art { width: 128px; height: 128px; border-radius: 50%; background: var(--elf-halo); display: grid; place-items: center; position: relative; margin-bottom: 10px; }
.empty-art::after { content: ""; position: absolute; inset: -9px; border-radius: 50%; border: 2px dashed var(--color-accent); opacity: .8; }
.empty-art .elf { width: 84px; height: 105px; margin-top: 6px; }
.empty-state h3 { font-size: 21px; }
.empty-state p { color: var(--color-muted); margin: 0 0 14px; font-size: 14.5px; max-width: 42ch; }
.empty-state > svg:not(.elf) { color: var(--color-muted); opacity: .6; margin-bottom: 8px; }

/* ---------- Grids ---------- */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 768px) { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.grid-4 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 768px) { .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row .grow, .grow { flex: 1; min-width: 0; }

/* ---------- FAB & speed dial ---------- */
.fab { position: fixed; right: 18px; bottom: calc(var(--bottom-nav-h) + 18px + env(safe-area-inset-bottom, 0px)); width: 56px; height: 56px; border-radius: 18px; background: var(--color-primary); color: var(--on-primary); box-shadow: var(--shadow-elevated); display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 35; transition: transform .15s var(--ease); }
.fab:active { transform: scale(.92); }
@media (min-width: 1024px) { .fab { bottom: 32px; right: 32px; } }
.speed-dial { position: fixed; right: 18px; bottom: calc(var(--bottom-nav-h) + 86px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; align-items: flex-end; gap: 10px; z-index: 36; }
@media (min-width: 1024px) { .speed-dial { bottom: 100px; right: 32px; } }
.speed-dial-item { display: flex; align-items: center; justify-content: center; padding: 10px 16px; gap: 8px; background: var(--color-raised); color: var(--color-text); border-radius: 999px; box-shadow: var(--shadow-elevated); border: 1px solid var(--color-border); font-size: 14px; font-weight: 800; cursor: pointer; animation: fanIn .2s var(--ease) backwards; min-height: 44px; }
.speed-dial-item:nth-child(2) { animation-delay: 40ms; }
.speed-dial-item:nth-child(3) { animation-delay: 80ms; }
.speed-dial-item:nth-child(4) { animation-delay: 120ms; }
@keyframes fanIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* ---------- Stat cards ---------- */
.stat-card { padding: 16px; }
.stat-card .num { font-size: 30px; line-height: 1.1; color: var(--color-primary); font-family: var(--font-display); font-style: var(--display-style); font-weight: var(--display-weight); font-variant-numeric: tabular-nums; }
.stat-card .label { font-size: 12.5px; color: var(--color-muted); margin-top: 4px; letter-spacing: .02em; font-weight: 700; }

/* ---------- Hero (dashboard "Tonight", countdowns, budget) ---------- */
.hero-card, .countdown-hero { position: relative; overflow: hidden; isolation: isolate; border-radius: calc(var(--radius-card) + 2px); background: var(--hero-bg); color: var(--hero-ink); padding: 26px 20px 20px; box-shadow: 0 18px 34px -22px rgba(20, 50, 40, .8); }
[data-theme="midnight"] .hero-card, [data-theme="midnight"] .countdown-hero { border: 1px solid rgba(255,255,255,.1); box-shadow: 0 24px 50px -26px rgba(0,0,0,.9); }
.hero-card::before, .countdown-hero::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 9px; background: var(--stripe); z-index: -1; }
.hero-card::after, .countdown-hero::after { content: ""; position: absolute; inset: 15px 7px 7px; border: 1.5px dashed var(--stitch); border-radius: 12px; pointer-events: none; z-index: -1; }
[data-theme="midnight"] .hero-card::before, [data-theme="midnight"] .countdown-hero::before { height: 0; }
[data-theme="midnight"] .hero-card::after, [data-theme="midnight"] .countdown-hero::after { inset: 0; border: 0; border-radius: 0; background-image: radial-gradient(1.5px 1.5px at 20% 30%, rgba(255,255,255,.7) 50%, transparent 52%), radial-gradient(1px 1px at 60% 20%, rgba(255,255,255,.5) 50%, transparent 52%), radial-gradient(2px 2px at 80% 70%, rgba(255,255,255,.35) 50%, transparent 52%), radial-gradient(1.2px 1.2px at 35% 80%, rgba(255,255,255,.4) 50%, transparent 52%); background-size: 220px 160px; animation: snowfall 22s linear infinite; }
@keyframes snowfall { from { background-position: 0 0; } to { background-position: 30px 160px; } }
.hero-card h2, .hero-card h3, .countdown-hero h2 { color: var(--hero-ink); }
.hero-card .hero-muted { color: var(--hero-muted); }
.hero-card .hand, .hero-note { color: var(--hero-note); }
.hero-card .chip { background: var(--hero-chip); color: var(--hero-ink); }
.hero-card .btn-ghost, .hero-card .btn-secondary { background: var(--hero-ghost); color: var(--hero-ink); }
.hero-card .btn-festive { box-shadow: 0 8px 18px -8px rgba(0,0,0,.5); }
[data-theme="storybook"] .hero-card .btn-primary, :root:not([data-theme]) .hero-card .btn-primary { background: #FFFFFF; color: var(--color-primary); }
.hero-card .hero-elf { position: absolute; z-index: 0; pointer-events: none; }
.hero-card .hero-moon { position: absolute; top: 16px; width: 52px; height: 52px; border-radius: 50%; box-shadow: inset -13px 6px 0 0 #F6E7C1; transform: rotate(-12deg); filter: drop-shadow(0 0 12px rgba(246,231,193,.45)); display: none; z-index: 0; }
[data-theme="midnight"] .hero-card .hero-moon { display: block; }
.hero-card > :not(.hero-elf):not(.hero-moon) { position: relative; z-index: 1; }
/* Legacy countdown hero (Budget page) */
.countdown-hero { text-align: center; }
.countdown-hero .num { font-family: var(--font-display); font-style: var(--display-style); font-size: 60px; line-height: 1; font-variant-numeric: tabular-nums; }
.countdown-hero .label { color: var(--hero-ink); margin-top: 6px; font-size: 14.5px; font-weight: 700; }
.countdown-hero .sub { color: var(--hero-muted); margin-top: 6px; font-size: 13px; font-weight: 600; }
/* A light button sitting on the hero (Budget → Edit budget) */
.btn-on-banner { background: #FFFFFF; color: #1E2A26; }

/* ---------- Week strip ---------- */
.day-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.day-strip .day { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 9px 2px 10px; border-radius: 14px; background: var(--color-card); border: 1px solid var(--color-border); font-size: 11px; font-weight: 800; color: var(--color-muted); cursor: pointer; text-decoration: none; min-width: 0; transition: transform .12s; }
.day-strip .day:active { transform: scale(.96); }
.day-strip .day .num { font-family: var(--font-display); font-style: var(--display-style); font-size: 19px; font-weight: var(--display-weight); color: var(--color-text); line-height: 1.2; }
.day-strip .day .what { display: none; font-size: 11.5px; font-weight: 700; line-height: 1.2; text-align: center; padding: 0 4px; min-height: 28px; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.day-strip .day .dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 4px; background: transparent; box-shadow: inset 0 0 0 1.6px var(--color-border-strong); }
.day-strip .day.has-mission .dot { background: var(--color-primary); box-shadow: none; }
.day-strip .day.done .dot { background: var(--color-success); box-shadow: none; }
.day-strip .day.has-rest .dot { background: var(--color-muted); box-shadow: none; }
.day-strip .day.unplanned { border-style: dashed; background: transparent; }
.day-strip .day.unplanned .dot { background: var(--color-warning); box-shadow: none; }
.day-strip .day.off { opacity: .55; }
.day-strip .day.today { background: var(--color-primary); border-color: var(--color-primary); color: var(--on-primary); box-shadow: 0 10px 20px -12px rgba(0,0,0,.6); }
.day-strip .day.today .num { color: var(--on-primary); }
.day-strip .day.today .dot { background: var(--on-primary); box-shadow: none; }
@media (min-width: 768px) { .day-strip.wide .day .what { display: -webkit-box; } }

/* ---------- Quick tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 768px) { .tiles.four { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { display: grid; gap: 5px; align-content: start; padding: 14px; border-radius: var(--radius-card); background: var(--color-card); border: var(--card-border); box-shadow: var(--shadow-card); text-align: left; color: var(--color-text); text-decoration: none; transition: transform .15s var(--ease); min-width: 0; }
.tile:active { transform: scale(.98); }
.tile .ti { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--color-chip); color: var(--color-primary); margin-bottom: 3px; }
.tile .ti .lucide { width: 19px; height: 19px; }
.tile b { font-size: 15px; font-weight: 800; line-height: 1.2; }
.tile span.sub { font-size: 12.5px; color: var(--color-muted); font-weight: 700; line-height: 1.3; }
.tile.festive { background: var(--color-festive); color: var(--on-festive); border-color: transparent; }
.tile.festive span.sub { color: var(--on-festive); opacity: .9; }
.tile.festive .ti { background: rgba(255,255,255,.18); color: var(--on-festive); }
[data-theme="midnight"] .tile.festive { background: rgba(240,137,143,.15); color: #FFD7DA; border: 1px solid rgba(240,137,143,.3); }
[data-theme="midnight"] .tile.festive span.sub { color: #FFD7DA; }
[data-theme="midnight"] .tile.festive .ti { background: rgba(240,137,143,.2); color: #FFD7DA; }
@media (hover: hover) { .tile:hover { transform: translateY(-2px); } }

/* ---------- Checklists (steps, supplies) ---------- */
.steps { display: grid; gap: 4px; counter-reset: step; }
.steps li { display: grid; grid-template-columns: 30px 1fr; gap: 12px; align-items: start; padding: 8px 0; font-size: 15px; cursor: pointer; }
.steps .ck { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; border: 2px solid var(--color-border-strong); font-size: 13px; font-weight: 800; color: var(--color-muted); transition: background .15s, border-color .15s; }
.steps .ck .lucide { width: 16px; height: 16px; stroke-width: 3; }
.steps li.done .ck { background: var(--color-primary); border-color: var(--color-primary); color: var(--on-primary); }
.steps li.done .txt { color: var(--color-muted); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.supply-list { display: grid; gap: 2px; }
.supply-list li { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; padding: 6px 0; flex-wrap: wrap; }
.supply-list .st { width: 24px; height: 24px; border-radius: 8px; display: grid; place-items: center; background: var(--good-bg); color: var(--good-ink); flex: none; }
.supply-list .st .lucide { width: 15px; height: 15px; stroke-width: 3; }
.supply-list li.miss .st { background: var(--miss-bg); color: var(--miss-ink); }
.supply-list .swap { flex-basis: 100%; margin-left: 34px; font-size: 13px; color: var(--color-muted); font-weight: 700; margin-top: -2px; }
.supply-list .swap a, .link { color: var(--color-danger); text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 2px; font-weight: 800; }
[data-theme="midnight"] .supply-list .swap a, [data-theme="midnight"] .link { color: var(--color-primary); }

/* ---------- Calendar ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.cal-cell { min-height: 68px; border: 1px solid var(--color-border); border-radius: 12px; padding: 5px; cursor: pointer; background: var(--color-card); position: relative; font-size: 12px; display: flex; flex-direction: column; gap: 2px; transition: transform .1s, border-color .15s; min-width: 0; overflow: hidden; }
@media (min-width: 768px) { .cal-cell { min-height: 92px; padding: 7px; } }
@media (hover: hover) { .cal-cell:hover { border-color: var(--color-primary); } }
.cal-cell.today { border-color: var(--color-festive); border-width: 2px; }
.cal-cell.past { background: var(--color-chip); }
.cal-cell.past .date-num { color: var(--color-muted); }
.cal-cell .date-num { font-weight: 800; color: var(--color-text); min-width: 0; }
.cal-cell.today .date-num { color: var(--color-festive); }
.cal-cell .mini-chip { font-size: 10.5px; font-weight: 700; padding: 2px 5px; border-radius: 5px; line-height: 1.2; white-space: normal; overflow-wrap: normal; word-break: normal; display: block; max-width: 100%; background: var(--color-chip); color: var(--color-chip-text); }
.cal-cell .mini-chip.easy, .chip.cal-easy { background: var(--cal-easy-bg); color: var(--cal-easy-ink); }
.cal-cell .mini-chip.medium, .chip.cal-medium { background: var(--cal-medium-bg); color: var(--cal-medium-ink); }
.cal-cell .mini-chip.hard, .chip.cal-hard { background: var(--cal-hard-bg); color: var(--cal-hard-ink); }
.cal-cell .mini-chip.rest, .chip.cal-rest { background: var(--cal-rest-bg); color: var(--cal-rest-ink); }
.cal-cell .mini-chip.special, .chip.cal-special { background: var(--cal-special-bg); color: var(--cal-special-ink); }
.cal-cell .mini-chip.scene, .chip.cal-scene { background: var(--cal-scene-bg); color: var(--cal-scene-ink); }
.cal-cell .mini-chip.done { text-decoration: line-through; opacity: .8; }

/* Calendar week view: 7 columns on tablet/desktop, a stacked list of days on phones */
.week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.week-grid .week-day { padding: 12px; cursor: pointer; min-height: 150px; min-width: 0; }
.week-grid .week-day.today { border-color: var(--color-festive); border-width: 2px; }
.week-grid .week-day-body { margin-top: 8px; }
@media (max-width: 600px) {
  .week-grid { grid-template-columns: minmax(0, 1fr); }
  .week-grid .week-day { display: flex; align-items: flex-start; gap: 14px; min-height: 0; }
  .week-grid .week-day-date { min-width: 44px; text-align: center; }
  .week-grid .week-day-body { margin-top: 0; flex: 1; min-width: 0; }
}

/* ---------- Photos ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 768px) { .photo-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; } }
@media (min-width: 1024px) { .photo-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.photo-tile { position: relative; aspect-ratio: 1 / 1; overflow: hidden; border-radius: 14px; background: var(--color-chip); cursor: pointer; box-shadow: var(--shadow-card); }
[data-theme="storybook"] .photo-tile, :root:not([data-theme]) .photo-tile { border: 5px solid #FFFFFF; box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 10px 18px -12px rgba(60,40,20,.5); }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; }
.photo-tile .photo-overlay { position: absolute; bottom: 0; left: 0; right: 0; padding: 18px 10px 7px; background: linear-gradient(transparent, rgba(0,0,0,.7)); color: #FFFFFF; font-size: 12px; font-weight: 700; }
.photo-fallback { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; font-size: 36px; color: var(--color-muted); }

/* ---------- Section titles & lists ---------- */
.section-title { font-family: var(--font-display); font-style: var(--display-style); font-weight: var(--display-weight); font-size: 21px; margin: 26px 0 12px; line-height: 1.2; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--color-card); border-radius: 14px; border: 1px solid var(--color-border); transition: transform .1s, border-color .15s; }
@media (hover: hover) { .list-row:hover { border-color: var(--color-border-strong); } }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 800; }
.list-row .meta { color: var(--color-muted); font-size: 12.5px; font-weight: 600; }

/* ---------- Toggle switch ---------- */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.slider { position: absolute; inset: 0; background: var(--color-border-strong); border-radius: 26px; cursor: pointer; transition: .2s; }
.slider:before { content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px; background: #FFFFFF; border-radius: 50%; transition: .2s var(--ease); box-shadow: 0 1px 3px rgba(0,0,0,.3); }
input:checked + .slider { background: var(--color-primary); }
input:checked + .slider:before { transform: translateX(20px); }
input:focus-visible + .slider { outline: 2.5px solid var(--focus-ring); outline-offset: 2px; }

/* ---------- Checkbox ---------- */
.elf-checkbox { width: 24px; height: 24px; min-width: 24px; border: 2px solid var(--color-border-strong); border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; transition: all .15s; background: var(--color-card); }
.elf-checkbox.checked { background: var(--color-primary); border-color: var(--color-primary); }
.elf-checkbox.checked svg { color: var(--on-primary); animation: checkBounce .22s ease; }
@keyframes checkBounce { 0% { transform: scale(0); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }

/* ---------- Theme picker ---------- */
.theme-preview { display: flex; gap: 6px; margin-top: 8px; }
.theme-swatch { width: 24px; height: 24px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); }
.theme-option { display: grid; gap: 8px; padding: 14px; border-radius: 16px; border: 2px solid var(--color-border); background: var(--color-card); text-align: left; min-width: 0; }
.theme-option.on { border-color: var(--color-festive); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-festive) 22%, transparent); }
.theme-option .tname { font-weight: 800; font-size: 14.5px; }
.theme-option .tdesc { font-size: 12.5px; color: var(--color-muted); }
.theme-mini { height: 56px; border-radius: 10px; overflow: hidden; display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--color-border); }

/* ---------- Settings ---------- */
.settings-grid { display: grid; gap: 14px; }
@media (min-width: 1100px) { .settings-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } }
.theme-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)) !important; }
.about { text-align: center; margin: 30px auto 8px; display: grid; justify-items: center; gap: 4px; max-width: 46ch; }
.about-elf { width: 46px; height: 50px; margin-bottom: 4px; }
.seg { flex-wrap: wrap; }

/* ---------- Letter print ---------- */
.letter-print { padding: 48px; background: #FFFDF7; color: #2A2A2A; min-height: 100vh; max-width: 720px; margin: 0 auto; font-family: "Young Serif", Georgia, serif; font-size: 18px; line-height: 1.7; border: 8px double #C99A2E; }

/* ---------- Search ---------- */
.search-wrap { display: flex; align-items: center; gap: 10px; padding: 12px 16px; }
.search-input { flex: 1; background: var(--color-chip); border: none; border-radius: 999px; padding: 11px 16px; color: var(--color-text); font-size: 16px; }
.search-input:focus { outline: 2.5px solid var(--focus-ring); }

/* ---------- Install banner ---------- */
.install-banner { position: fixed; left: 16px; right: 16px; bottom: calc(var(--bottom-nav-h) + 16px + env(safe-area-inset-bottom, 0px)); background: var(--color-raised); border: 1px solid var(--color-border); border-radius: var(--radius-card); padding: 14px 16px; box-shadow: var(--shadow-elevated); z-index: 70; animation: sheetUp .3s var(--ease); }
@media (min-width: 1024px) { .install-banner { left: auto; right: 32px; bottom: 32px; max-width: 380px; } }

/* ---------- Dashboard ---------- */
.dash-top .page-header { flex: 1 1 360px; min-width: 0; }
.dash-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.dash-actions { display: none; gap: 8px; }
@media (min-width: 1024px) { .dash-actions { display: flex; padding-bottom: 22px; } }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin-top: 16px; }
@media (min-width: 900px) { .dash-grid { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 18px; align-items: start; } }
.dash-section { margin-top: 22px; }
.dash-section > .card-title { margin-bottom: 10px; }
.hero-title { font-size: 28px; line-height: 1.06; margin: 12px 0 8px; overflow-wrap: anywhere; }
.hero-note { margin: 0 0 12px; }
.hero-supplies { margin: 14px 0 0; font-size: 14px; font-weight: 600; display: flex; gap: 8px; align-items: flex-start; color: var(--hero-ink); }
.hero-supplies .lucide { width: 18px; height: 18px; margin-top: 1px; }
.hero-supplies b { font-weight: 800; }
.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
/* The elf scales with the card, and the text keeps clear of it at every width */
.hero-card { container-type: inline-size; --elf-w: min(30cqw, 172px); }
.hero-card .hero-elf { width: var(--elf-w); height: auto; aspect-ratio: 120 / 150; right: 3.5cqw; top: 34px; }
.hero-card .hero-moon { right: calc(3.5cqw + var(--elf-w) - 16px); }
.hero-title, .hero-note, .hero-card .chips, .hero-supplies { max-width: calc(100% - var(--elf-w) - 8px); }
@media (min-width: 900px) {
  .hero-card { padding: 32px 30px 28px; min-height: 290px; }
  .hero-title { font-size: clamp(28px, 7cqw, 40px); }
  .hero-card .hero-moon { top: 26px; width: 66px; height: 66px; box-shadow: inset -16px 8px 0 0 #F6E7C1; }
}
.countdown-card { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px; align-items: center; }
.countdown-card .cd-n { font-family: var(--font-display); font-style: var(--display-style); font-weight: var(--display-weight); font-size: 21px; line-height: 1.15; }
.countdown-card .cd-s { font-size: 13px; color: var(--color-muted); font-weight: 600; margin-top: 3px; }
.supply-list a:hover { text-decoration: underline; }

/* ---------- Rescue ---------- */
.rescue-steps { counter-reset: rs; display: grid; gap: 8px; margin: 4px 0 0; max-width: calc(100% - var(--elf-w) - 8px); }
.rescue-steps li { counter-increment: rs; display: grid; grid-template-columns: 26px 1fr; gap: 10px; font-size: 15.5px; font-weight: 600; line-height: 1.4; color: var(--hero-ink); }
.rescue-steps li::before { content: counter(rs); width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 800; background: var(--hero-chip); color: var(--hero-ink); }

/* ---------- Ideas library ---------- */
.idea-card { display: flex; flex-direction: column; gap: 10px; }
.idea-title { font-size: 17.5px; line-height: 1.25; }
.icon-btn.fav .lucide { width: 21px; height: 21px; }
.icon-btn.fav.on { color: var(--color-festive); }
.icon-btn.fav.on .lucide { fill: currentColor; }

/* ---------- Season planner ---------- */
.sp-grid { display: grid; gap: 16px; }
@media (min-width: 1000px) { .sp-grid { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); align-items: start; } .sp-options { position: sticky; top: 20px; } }
.sp-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 6px; }
.sp-dot { aspect-ratio: 1; border-radius: 10px; display: grid; place-items: center; font-size: 12.5px; background: var(--color-chip); color: var(--color-muted); }
.sp-dot b { font-weight: 800; }
.sp-dot.planned, .sp-dot.moved { background: var(--color-primary); color: var(--on-primary); }
.sp-dot.rest { background: var(--cal-rest-bg); color: var(--cal-rest-ink); }
.sp-dot.unplanned { background: transparent; border: 1.5px dashed var(--color-border-strong); }
.sp-key { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; margin-right: 4px; background: var(--color-primary); }
.sp-key.rest { background: var(--cal-rest-bg); } .sp-key.unplanned { background: transparent; border: 1.5px dashed var(--color-border-strong); }
.sp-row { align-items: center; }
.sp-row.locked { border-color: var(--color-accent); box-shadow: inset 3px 0 0 var(--color-accent); }
.sp-date { width: 46px; flex: none; text-align: center; display: grid; line-height: 1.1; }
.sp-date span { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--color-muted); }
.sp-date b { font-family: var(--font-display); font-style: var(--display-style); font-weight: var(--display-weight); font-size: 22px; }
.sp-acts { display: flex; gap: 0; flex: none; }
.sp-acts .icon-btn { width: 38px; height: 38px; }
@media (max-width: 480px) { .sp-row { flex-wrap: wrap; } .sp-row .grow { flex-basis: calc(100% - 60px); } .sp-acts { margin-left: auto; } }

/* ---------- Tonight ---------- */
.t-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
@media (min-width: 900px) { .t-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 18px; align-items: start; } }
.t-actions { position: sticky; bottom: calc(var(--bottom-nav-h) + 10px + env(safe-area-inset-bottom, 0px)); z-index: 30; margin-top: 18px; padding: 10px; border-radius: 22px; background: var(--color-raised); border: 1px solid var(--color-border); box-shadow: var(--shadow-elevated); display: grid; gap: 4px; }
@media (min-width: 1024px) { .t-actions { bottom: 18px; } }
.t-actions-main { display: flex; gap: 8px; }
.t-actions-main .grow { flex: 1; }
.t-actions-more { display: flex; justify-content: space-around; flex-wrap: wrap; gap: 2px; }
.t-actions-more .btn { color: var(--color-muted); }
@media (max-width: 420px) { .t-actions-main .lbl { display: none; } }
button.link { padding: 0; font: inherit; }

/* ---------- Kids' screen lock: no navigation, no header, nothing that could spoil a surprise ---------- */
body.kids-locked #sidebar, body.kids-locked #bottom-nav, body.kids-locked #app-header, body.kids-locked #toast-root, body.kids-locked .fab { display: none !important; }
body.kids-locked #main-content { max-width: none; padding: 0; }

/* ---------- Night setup mode: always the midnight palette, screen kept awake ---------- */
.night-mode { position: fixed; inset: 0; z-index: 500; background: #060C17; color: var(--color-text); overflow-y: auto; padding: calc(16px + env(safe-area-inset-top, 0px)) 18px calc(24px + env(safe-area-inset-bottom, 0px)); animation: fadeIn .3s ease; overscroll-behavior: contain; }
.night-mode .card { background: rgba(255,255,255,.04); }

/* ---------- Scrollbars (dark) ---------- */
[data-theme="midnight"] { scrollbar-color: #2A3B57 #0A1322; }
[data-theme="midnight"] ::-webkit-scrollbar { width: 12px; height: 12px; }
[data-theme="midnight"] ::-webkit-scrollbar-track { background: #0A1322; }
[data-theme="midnight"] ::-webkit-scrollbar-thumb { background: #2A3B57; border-radius: 6px; border: 2px solid #0A1322; }

/* ---------- Print: only the page content, in ink that prints ---------- */
@media print {
  @page { margin: 14mm; }
  #sidebar, #bottom-nav, #app-header, .fab, .speed-dial, #update-banner, #toast-root, #modal-root, #drawer-root, #install-prompt-root, .install-banner, .chip-scroll, .no-print, .btn, .icon-btn, .seg { display: none !important; }
  html, body { background: #FFFFFF !important; background-image: none !important; color: #111111 !important; }
  #main-content { padding: 0 !important; max-width: 100% !important; }
  .card, .tile, .list-row { box-shadow: none !important; border: 1px solid #CCCCCC !important; background: #FFFFFF !important; break-inside: avoid; }
  .hero-card, .countdown-hero { background: #FFFFFF !important; color: #111111 !important; border: 2px solid #1E4A3B !important; box-shadow: none !important; }
  .hero-card *, .countdown-hero * { color: #111111 !important; }
  .hero-card::before, .hero-card::after, .countdown-hero::before, .countdown-hero::after { display: none !important; }
  a { text-decoration: none !important; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Device sync (Settings → Use ElfHQ on more than one device) ---------- */
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-weight: 800; color: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link-btn:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; border-radius: 4px; }
.sync-code { font-family: var(--font-display); font-size: 44px; font-weight: 700; letter-spacing: .14em; text-align: center; margin: 10px 0 4px; color: var(--color-text); font-variant-numeric: tabular-nums; }
.sync-code-input { font-size: 26px; letter-spacing: .18em; text-align: center; font-variant-numeric: tabular-nums; }
.sync-pics { display: flex; justify-content: center; gap: 22px; margin: 12px 0 14px; }
.sync-pics > span { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.sync-pic { font-size: 42px; line-height: 1; }
.sync-key { display: block; width: 100%; font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; font-size: 14px; line-height: 1.5; word-break: break-all; text-align: left; padding: 12px 14px; border-radius: 12px; border: 1.5px dashed var(--color-border-strong); background: var(--color-raised); color: var(--color-text); cursor: pointer; }
textarea.sync-key { cursor: text; border-style: solid; }
.sync-key-hidden { filter: blur(6px); user-select: none; }
.sync-more summary { cursor: pointer; font-size: 14px; font-weight: 800; color: var(--color-text); }
#sync-status .lucide { width: 13px; height: 13px; }
.toast-action { background: none; border: 0; padding: 4px 2px; font: inherit; font-weight: 800; color: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ---------- Free online demo (tools/make-demo.py sets window.ELFHQ_DEMO; inert in the app) ---------- */
html.is-demo .demo-hide { display: none !important; }
.demo-bar { position: relative; z-index: 5; display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; padding: 7px 16px; background: color-mix(in srgb, var(--color-accent) 22%, var(--color-card)); color: var(--color-text); border-bottom: 1px solid var(--color-border); font-size: 13.5px; font-weight: 700; text-align: center; }
.demo-bar .btn { min-height: 32px; padding: 5px 12px; }
.demo-bar .demo-short { display: none; }
@media (max-width: 560px) { .demo-bar { gap: 10px; padding: 6px 12px; font-size: 12.5px; } .demo-bar .demo-long { display: none; } .demo-bar .demo-short { display: inline; } }
.demo-card { border: 2px solid var(--color-accent); background: color-mix(in srgb, var(--color-accent) 8%, var(--color-card)); }
@media print { .demo-bar { display: none !important; } }
