/* ไปกัน! — base + shared components (design v2: clean · minimal · violet/blue · liquid glass).
   Same class names as v1 (feature modules depend on them), new look.
   Layout rules that keep every screen inside the viewport:
   - html/body never scroll horizontally; .app-main is the only scroll container per page
   - every flex/grid child that holds text gets min-width:0
   - long words wrap (overflow-wrap:anywhere) — Thai has no spaces */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: 1.55;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
/* soft violet/blue ambient light behind everything (gives glass something to refract) */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: var(--grad-glow);
}
img, svg, canvas, video { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.25; margin: 0; font-weight: 700; letter-spacing: -0.01em; overflow-wrap: anywhere; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p { margin: 0; overflow-wrap: anywhere; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-sm); }
[hidden] { display: none !important; }

.emoji { font-family: var(--font-emoji); font-style: normal; line-height: 1; display: inline-block; }
.e3d { display: inline-block; width: 1.25em; height: 1.25em; object-fit: contain; vertical-align: -0.25em; flex: 0 0 auto; user-select: none; -webkit-user-drag: none; }
.ico { flex: 0 0 auto; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }
.bold { font-weight: 700; }
.display { font-family: var(--font-display); }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.min0 { min-width: 0; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.top { align-items: flex-start; }
.col { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }
.gap-1 { gap: var(--sp-1); } .gap-3 { gap: var(--sp-3); } .gap-4 { gap: var(--sp-4); }
.stack > * + * { margin-top: var(--sp-3); }
.stack-lg > * + * { margin-top: var(--sp-5); }
.center { text-align: center; }
.sr-only { position: absolute; top: 0; left: 0; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.text-grad { background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ======================= GLASS ======================= */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-edge), var(--shadow-glass);
}
.glass.strong { background: var(--glass-strong); }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: var(--glass-strong); }
}

/* ======================= APP SHELL ======================= */
.app {
  position: relative; z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "main";
}
.app-main {
  grid-area: main;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  position: relative;
  outline: none;
}
/* floating liquid-glass tab bar (phone): icons only, the active tab grows into a tinted pill with its label */
.app-nav {
  position: fixed; z-index: 40;
  left: max(var(--nav-gap), var(--safe-left)); right: max(var(--nav-gap), var(--safe-right));
  bottom: calc(var(--nav-gap) + var(--safe-bottom));
  height: var(--nav-h);
  max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  padding: 8px;
  border-radius: 26px;
  background: var(--glass-strong);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-edge), var(--shadow-glass);
}
.app-nav a {
  flex: 0 1 auto; min-width: 48px; height: 48px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 14px;
  border-radius: 18px;
  color: var(--ink-2);
  font-weight: 700; font-size: var(--fs-sm);
  transition: background var(--dur) var(--ease), color var(--dur), flex-grow 260ms var(--ease);
  overflow: hidden; white-space: nowrap;
}
.app-nav a .nav-label { max-width: 0; opacity: 0; overflow: hidden; transition: max-width 260ms var(--ease), opacity 200ms; }
.app-nav a svg { width: 22px; height: 22px; }
.app-nav .nav-ico { display: inline-grid; place-items: center; }
.app-nav .nav-ico-f { display: none; }
.app-nav a[aria-current="page"] .nav-ico-o { display: none; }
.app-nav a[aria-current="page"] .nav-ico-f { display: inline-grid; }
.app-nav a[aria-current="page"] { flex-grow: 1; background: var(--primary-soft); color: var(--primary); }
.app-nav a[aria-current="page"] .nav-label { max-width: 9em; opacity: 1; }
.app-nav a:active { transform: scale(.96); }
.app.nav-hidden .app-nav { display: none; }

@media (min-width: 900px) {
  .app { grid-template-columns: var(--rail-w) minmax(0, 1fr); grid-template-areas: "nav main"; }
  .app-nav {
    position: relative; grid-area: nav;
    left: auto; right: auto; bottom: auto; height: auto; max-width: none; margin: 12px 0 12px max(12px, var(--safe-left));
    flex-direction: column; justify-content: flex-start; gap: 6px;
    padding: 14px 8px;
    border-radius: 28px;
  }
  .app-nav a { flex: 0 0 auto; width: 100%; height: auto; min-height: 60px; flex-direction: column; gap: 4px; padding: 8px 4px; font-size: var(--fs-xs); }
  .app-nav a .nav-label { max-width: none; opacity: 1; }
  .app-nav a[aria-current="page"] { flex-grow: 0; }
  .app-nav .nav-logo { display: flex; }
  .app.nav-hidden { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main"; }
}
.nav-logo {
  display: none; flex-direction: column; align-items: center; gap: 4px; margin: 2px 0 10px;
  font-family: var(--font-display); font-weight: 700; font-size: var(--fs-xs); color: var(--ink);
}
.nav-logo .logo-mark {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  background: var(--grad-brand); color: #fff; box-shadow: var(--shadow-btn);
}
.nav-logo .logo-mark { overflow: hidden; background: #EEF0FB; }
.nav-logo .logo-mark img { width: 100%; height: 100%; display: block; }

/* ======================= PAGE ======================= */
.page {
  position: relative;
  min-height: 100%;
  padding: calc(var(--sp-4) + var(--safe-top)) max(var(--gutter), var(--safe-right)) calc(var(--sp-6) + var(--nav-space)) max(var(--gutter), var(--safe-left));
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
}
.page.narrow { max-width: 720px; }
.page.full { max-width: none; padding: 0; }
.page-header { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--header-h); margin-bottom: var(--sp-3); min-width: 0; }
.page-header .titles { flex: 1 1 auto; min-width: 0; }
.page-header h1 { font-size: var(--fs-xl); }
.page-header .sub { color: var(--ink-2); font-size: var(--fs-sm); }
.sticky-top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
}
.section-title {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  font-family: var(--font-display); font-weight: 700; font-size: var(--fs-lg);
  margin: var(--sp-6) 0 var(--sp-3); min-width: 0;
}
.section-title .see-all { font-family: var(--font-body); font-size: var(--fs-sm); font-weight: 700; color: var(--primary); }
.eyebrow { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .04em; color: var(--ink-3); text-transform: uppercase; }

/* ======================= BUTTONS ======================= */
.btn {
  --btn-bg: var(--surface);
  --btn-ink: var(--ink);
  --btn-border: var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 46px;
  padding: 10px 18px;
  border: 1px solid var(--btn-border);
  border-radius: var(--r-sm);
  background: var(--btn-bg);
  color: var(--btn-ink);
  font-weight: 700; font-size: var(--fs-md); line-height: 1.2;
  box-shadow: var(--shadow-1);
  transition: transform 120ms var(--ease), box-shadow var(--dur), background var(--dur), opacity var(--dur);
  user-select: none; white-space: nowrap; max-width: 100%; min-width: 0;
}
.btn > span:not(.emoji) { overflow: hidden; text-overflow: ellipsis; }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.btn.primary { --btn-ink: #fff; border-color: transparent; background: var(--grad-brand); box-shadow: var(--shadow-btn); }
.btn.mint { --btn-bg: var(--mint); --btn-ink: #fff; border-color: transparent; box-shadow: 0 8px 20px rgba(18, 180, 125, .28); }
.btn.sky { --btn-bg: var(--blue); --btn-ink: #fff; border-color: transparent; box-shadow: 0 8px 20px rgba(61, 123, 255, .28); }
.btn.danger { --btn-bg: var(--danger-soft); --btn-ink: var(--danger); border-color: transparent; box-shadow: none; }
.btn.soft { --btn-bg: var(--primary-soft); --btn-ink: var(--primary); border-color: transparent; box-shadow: none; }
.btn.ghost { --btn-bg: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:active { background: var(--surface-sunk); }
.btn.glass { background: var(--glass); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); border-color: var(--glass-border); box-shadow: var(--glass-edge), var(--shadow-glass); }
.btn.sm { min-height: 38px; padding: 6px 14px; font-size: var(--fs-sm); border-radius: 12px; }
.btn.lg { min-height: 56px; padding: 14px 24px; font-size: var(--fs-lg); border-radius: var(--r-md); }
.btn.pill { border-radius: var(--r-pill); }
.btn.block { display: flex; width: 100%; }
.btn.icon { padding: 0; width: 46px; min-width: 46px; height: 46px; border-radius: 50%; }
.btn.icon.sm { width: 38px; min-width: 38px; height: 38px; min-height: 38px; }
.btn .emoji { font-size: 1.1em; }
.btn svg { width: 20px; height: 20px; flex: 0 0 auto; }

.fab {
  position: fixed;
  right: max(var(--gutter), var(--safe-right));
  bottom: calc(var(--nav-space) + var(--sp-2));
  z-index: 25;
}
@media (min-width: 900px) { .fab { bottom: calc(var(--sp-6) + var(--safe-bottom)); } }

/* ======================= CHIPS / SEGMENTED / TABS ======================= */
.chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); min-width: 0; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; margin: 0 calc(-1 * var(--gutter)); padding-left: var(--gutter); padding-right: var(--gutter); scroll-padding-inline: var(--gutter); }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 38px; padding: 6px 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: var(--fs-sm); font-weight: 700;
  white-space: nowrap; flex: 0 0 auto;
  transition: background var(--dur), color var(--dur), border-color var(--dur), transform 100ms;
}
.chip:active { transform: scale(.96); }
.chip svg { width: 18px; height: 18px; }
.chip[aria-pressed="true"], .chip.active { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.chip .emoji { font-size: 1rem; }

.segmented, .tabbar {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface-sunk); border-radius: var(--r-sm);
  min-width: 0; overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar, .tabbar::-webkit-scrollbar { display: none; }
.segmented button, .tabbar a, .tabbar button {
  flex: 1 0 auto; min-width: 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 6px 12px;
  border: 0; border-radius: 11px;
  background: transparent; color: var(--ink-2);
  font-weight: 700; font-size: var(--fs-sm); white-space: nowrap;
  transition: background var(--dur), color var(--dur), box-shadow var(--dur);
}
.segmented button svg, .tabbar a svg, .tabbar button svg { width: 18px; height: 18px; }
.segmented button[aria-selected="true"], .tabbar [aria-selected="true"], .tabbar [aria-current="page"] {
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1);
}

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: var(--r-pill);
  background: var(--surface-sunk); color: var(--ink-2);
  font-size: var(--fs-xs); font-weight: 700; line-height: 1.6; white-space: nowrap;
}
.badge svg { width: 13px; height: 13px; }
.badge.coral, .badge.violet { background: var(--primary-soft); color: var(--primary); }
.badge.mint { background: var(--mint-soft); color: var(--mint); }
.badge.sky { background: var(--sky-soft); color: var(--sky); }
.badge.sun { background: var(--sun-soft); color: var(--sun-ink); }
.badge.berry { background: var(--berry-soft); color: var(--berry); }
.badge.grape { background: var(--grape-soft); color: var(--grape); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

/* ======================= CARDS / LISTS ======================= */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: var(--sp-4);
  min-width: 0;
}
.card.flat { box-shadow: none; }
.card.tight { padding: var(--sp-3); border-radius: var(--r-md); }
.card.sunk { background: var(--surface-2); box-shadow: none; }
.card.glass { background: var(--glass); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); border-color: var(--glass-border); box-shadow: var(--glass-edge), var(--shadow-glass); }
.card.tap { transition: transform 140ms var(--ease), box-shadow 140ms; cursor: pointer; }
.card.tap:active { transform: scale(.985); }
/* ---------- hero v3: clean white "map card" for every topic ----------
   <section class="hero" data-hero="home|plan|time|money|stamps|summary"> + heroFX(kind, {trip}) as first child
   (js/core/hero.js). A white card; behind the content a soft stylised MAP of the trip (route, pins, a tooltip
   bubble on the destination) that fades out toward the text. No orbs, no glyph art.
   Layout: the map is a band across the top (content starts on its faded lower edge); the route sits in the
   band's right half, so on wide cards the left half under the title is quiet scenery.
   The v2 "on hero" tokens (--hero-on, --on …) are re-pointed to ink here so feature CSS keeps working. */
.hero {
  --hero-pad: var(--sp-5);
  --hero-map-h: 148px;                          /* height of the top map band (narrow cards) */
  --hero-map-overlap: 40px;                     /* content starts this far above the band's bottom edge */
  --hero-accent: var(--primary);
  --hero-on: var(--ink); --hero-on-2: var(--ink-2);
  --hero-glass: var(--surface-2); --hero-glass-hi: var(--surface);
  --hero-line: var(--line); --hero-spec: transparent; --hero-inner: transparent; --hero-shade: var(--ink);
  --hero-ok: var(--ok-ink); --hero-warn: var(--sun-ink); --hero-bad: var(--danger-ink);
  --on: var(--ink); --on-2: var(--ink-2); --on-glass: var(--surface-2); --on-line: var(--line);
  --hero-par: 0; --hero-px: 0; --hero-py: 0;
  position: relative; overflow: hidden; isolation: isolate;
  container: hero / inline-size;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl); padding: var(--hero-pad);
  box-shadow: var(--shadow-hero);
  transition: transform 300ms var(--ease), box-shadow 300ms var(--ease);
}
.hero[data-hero="plan"] { --hero-accent: var(--blue); }
.hero[data-hero="time"] { --hero-accent: var(--indigo); }

/* decorative layer stack (heroFX) */
.hero-fx { position: absolute; inset: 0; z-index: -1; overflow: hidden; border-radius: inherit; pointer-events: none; }
.hero-map {
  position: absolute; top: 0; left: 0; right: 0; height: var(--hero-map-h);
  -webkit-mask-image: linear-gradient(180deg, #000 0%, #000 42%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 0%, #000 42%, transparent 100%);
}
.hero-map[data-map="corner"] {
  left: auto; width: min(58%, 340px); height: min(100%, 150px);
  -webkit-mask-image: radial-gradient(120% 110% at 100% 0%, #000 18%, transparent 70%);
  mask-image: radial-gradient(120% 110% at 100% 0%, #000 18%, transparent 70%);
  opacity: .75;
}
/* the map layer is a little larger than its box so the parallax drift never shows an edge */
.hmap-layer {
  position: absolute; inset: -14px;
  container-type: size;
  transform: translate3d(calc(var(--hero-px) * -12px), calc(var(--hero-par) * -16px + var(--hero-py) * -8px), 0);
  transition: transform 700ms var(--ease);
}
.hmap-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hmap-land { fill: var(--map-land); }
.hmap-water { fill: var(--map-water); }
.hmap-river { fill: none; stroke: var(--map-water); stroke-linecap: round; }
.hmap-park { fill: var(--map-park); }
.hmap-minor { fill: none; stroke: var(--map-minor); stroke-width: 2.4; stroke-linecap: round; }
.hmap-road-c { fill: none; stroke: var(--map-road-casing); stroke-width: 9; stroke-linecap: round; }
.hmap-road { fill: none; stroke: var(--map-road); stroke-width: 6; stroke-linecap: round; }
.hmap-route-c { fill: none; stroke: var(--map-route-casing); stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; }
.hmap-route { fill: none; stroke: var(--map-route); stroke-width: 4.6; stroke-linecap: round; stroke-linejoin: round; }
.hmap-route.is-ghost { stroke-dasharray: .012 .022; stroke-width: 4; opacity: .7; }
.hmap-start { fill: var(--map-route); stroke: var(--map-route-casing); stroke-width: 3; }
.hmap-stop { fill: var(--map-route-casing); stroke: var(--map-route); stroke-width: 2.6; }
.hmap-stop.is-done { fill: var(--map-route); }
.hmap-dest { fill: var(--map-route); stroke: var(--map-route-casing); stroke-width: 3.5; }
.hmap-dest-in { fill: var(--map-route-casing); }
.hmap-halo { fill: var(--map-route); opacity: .14; }
.hmap-pulse { fill: none; stroke: var(--map-route); stroke-width: 2; transform-box: fill-box; transform-origin: center; opacity: 0; animation: hmap-pulse 2.6s var(--ease) 1.2s infinite; }
@keyframes hmap-pulse { 0% { transform: scale(1); opacity: .55; } 80%, 100% { transform: scale(3); opacity: 0; } }
.hero.is-intro .hmap-route:not(.is-ghost) { stroke-dasharray: 1 1; animation: hmap-draw 1300ms var(--ease) both; }
.hero.is-intro .hmap-focus > * { transform-box: fill-box; transform-origin: center; animation: hmap-pop 420ms var(--ease) 1000ms both; }
@keyframes hmap-draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes hmap-pop { from { transform: scale(0); opacity: 0; } }
.hero.is-off .hmap-pulse { animation-play-state: paused; }

/* tooltip bubble pinned on the destination: viewBox (800 × 300, xMaxYMid slice) → layer px via container units */
.hero-bubble {
  --s: max(calc(100cqw / 800), calc(100cqh / 300));
  position: absolute;
  left: clamp(30px, calc(100cqw - (800 - var(--bx)) * var(--s)), calc(100cqw - 30px));   /* never under the card's rounded edge */
  top: calc(50cqh - (150 - var(--by)) * var(--s));
  transform: translate(-50%, calc(-100% - 15px));
  max-width: min(15em, 60cqw);
  padding: 5px 11px; border-radius: var(--r-pill);
  background: var(--bubble-bg); color: var(--bubble-ink);
  font-size: var(--fs-xs); font-weight: 700; line-height: 1.45; white-space: nowrap;
  box-shadow: 0 6px 16px -6px rgba(22, 20, 60, .45);
}
.hero-bubble-t { display: block; overflow: hidden; text-overflow: ellipsis; }
.hero-bubble::after {   /* tail */
  content: ""; position: absolute; left: 50%; bottom: -4px; width: 9px; height: 9px; margin-left: -4.5px;
  background: inherit; border-radius: 2px; transform: rotate(45deg);
}
.hero-bubble.is-end { transform: translate(calc(-100% + 18px), calc(-100% - 15px)); }
.hero-bubble.is-end::after { left: auto; right: 13px; }
.hero-bubble.is-start { transform: translate(-18px, calc(-100% - 15px)); }
.hero-bubble.is-start::after { left: 18px; }
.hero.is-intro .hero-bubble { animation: hero-bubble-in 420ms var(--ease) 1150ms both; }
@keyframes hero-bubble-in { from { opacity: 0; translate: 0 6px; } }

.hero-sheen {
  position: absolute; inset: 0; opacity: 0; transition: opacity 300ms var(--ease);
  background: radial-gradient(420px circle at var(--hero-mx, 30%) var(--hero-my, 0%), color-mix(in srgb, var(--hero-accent) 7%, transparent), transparent 60%);
}
.hero.is-hover .hero-sheen { opacity: 1; }
.hero.is-hover { box-shadow: var(--shadow-hero-hi); }
.hero.hero-tap { cursor: pointer; }
.hero.hero-tap:active { transform: scale(.985); transition-duration: 120ms; }

/* content starts on the band's faded lower edge (narrow cards); the first child after .hero-fx is the content */
.hero > .hero-fx:has(.hero-map[data-map="band"]) + * { margin-top: max(0px, calc(var(--hero-map-h) - var(--hero-pad) - var(--hero-map-overlap))); }
/* wide cards: a slightly taller band (the route stays in the right half, the left half is quiet scenery) */
@container hero (min-width: 620px) {
  .hero-fx, .hero > .hero-fx + * { --hero-map-h: 172px; }   /* (a container can't restyle itself: set it on the parts) */
}

/* v2 orbs / rings: gone in v3 (older markup may still render them) */
.hero .hero-orb, .hero .hero-ring { display: none !important; }

/* shared header row: eyebrow + title */
.hero-head { display: flex; align-items: flex-start; gap: var(--sp-3); min-width: 0; }
.hero-titles { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.hero-eyebrow { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .02em; color: var(--ink-3); overflow-wrap: break-word; }
.hero-title { font-size: var(--fs-xl); line-height: 1.25; letter-spacing: -0.015em; color: var(--ink); overflow-wrap: break-word; }
/* text that sits on the map band's edge gets a soft halo in the card colour so it stays crisp over roads */
.hero-halo, .hero-titles > :not(.badge):not(.chip) { text-shadow: 0 0 12px var(--surface), 0 0 3px var(--surface), 0 0 1px var(--surface); }

/* big number + small grey label above it (fintech "Total Balance" pattern) */
.hero-label { font-size: var(--fs-sm); font-weight: 400; color: var(--ink-3); }
.hero-big {
  font-family: var(--font-num); font-weight: 800; font-variant-numeric: tabular-nums;
  font-size: clamp(2.35rem, 1.5rem + 7cqi, 3.5rem); line-height: 1.04; letter-spacing: -0.035em;
  color: var(--ink); overflow-wrap: anywhere;
}

/* stat tile on a hero: light, sunk, a hair of blur so it reads over the map edge */
.hero .hero-tile {
  position: relative; min-width: 0;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--surface-2) 90%, transparent);
  border: 1px solid var(--line);
  box-shadow: none;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.hero .muted, .hero .faint { color: var(--ink-3); }
.hero .num, .hero [data-count] { font-variant-numeric: tabular-nums; }
.hero-count { display: inline-block; white-space: nowrap; text-align: end; }
.hero .progress { height: 8px; background: var(--surface-sunk); }
.hero .progress > i { background: var(--grad-brand); }
.hero.is-intro .progress > i { animation: hero-bar-in 900ms var(--ease) 200ms both; transform-origin: left center; }
@keyframes hero-bar-in { from { transform: scaleX(0); } }

/* delta chip: "▲ เหลือ ฿1,200" (green), "▼ เกิน" (red), neutral (violet) */
.delta {
  display: inline-flex; align-items: center; gap: 4px; min-width: 0; max-width: 100%;
  padding: 3px 10px 3px 8px; border-radius: var(--r-pill);
  background: var(--primary-soft); color: var(--primary-ink-soft);
  font-size: var(--fs-xs); font-weight: 700; line-height: 1.5; white-space: nowrap;
}
.delta > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.delta svg { width: 13px; height: 13px; flex: 0 0 auto; }
.delta.up { background: var(--mint-soft); color: var(--ok-ink); }
.delta.down { background: var(--danger-soft); color: var(--danger-ink); }
.delta.warn { background: var(--sun-soft); color: var(--sun-ink); }
.delta.plain { background: var(--surface-sunk); color: var(--ink-2); }
.delta .num { font-family: var(--font-num); }

/* wave bottom: a violet → blue band with a wavy top edge (money hero; reusable) */
.hero-wave {
  position: relative; isolation: isolate;
  margin: var(--sp-2) calc(-1 * var(--hero-pad)) calc(-1 * var(--hero-pad));
  padding: calc(var(--sp-5) + 18px) var(--hero-pad) calc(var(--hero-pad) + 6px);
  color: #fff;
}
.hero-wave::before, .hero-wave::after {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(110deg, var(--wave-a), var(--wave-b));
  -webkit-mask: var(--wave-mask) 0 0 / 360px 26px repeat-x, linear-gradient(#000 0 0) 0 25px / 100% calc(100% - 25px) no-repeat;
  mask: var(--wave-mask) 0 0 / 360px 26px repeat-x, linear-gradient(#000 0 0) 0 25px / 100% calc(100% - 25px) no-repeat;
}
.hero-wave::after {   /* a second, lighter wave a little higher, drifting the other way */
  opacity: .3; top: -9px;
  animation: hero-wave 13s linear infinite reverse;
}
.hero-wave::before { animation: hero-wave 19s linear infinite; }
@keyframes hero-wave { to { -webkit-mask-position: 360px 0, 0 25px; mask-position: 360px 0, 0 25px; } }
.hero.is-off .hero-wave::before, .hero.is-off .hero-wave::after { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  .hero, .hero-sheen, .hmap-layer { transition: none; }
  .hmap-layer { transform: none; }
  .hmap-pulse, .hero-wave::before, .hero-wave::after { animation: none !important; }
  .hero.is-intro .hmap-route, .hero.is-intro .hmap-focus > *, .hero.is-intro .hero-bubble, .hero.is-intro .progress > i { animation: none !important; }
}
@media print {
  .hero-fx, .hero-ring { display: none; }
  .hero { box-shadow: none; }
}

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); gap: var(--sp-4); }
.list { display: flex; flex-direction: column; gap: var(--sp-2); padding: 0; margin: 0; list-style: none; min-width: 0; }
.list-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  min-width: 0;
}
.list-item .li-body { flex: 1 1 auto; min-width: 0; }
.list-item .li-title { font-weight: 700; overflow-wrap: anywhere; }
.list-item .li-sub { color: var(--ink-2); font-size: var(--fs-sm); overflow-wrap: anywhere; }
/* grouped list (iOS settings style): rows share one card, hairline separators */
.list.grouped { gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.list.grouped > .list-item { border: 0; border-radius: 0; background: transparent; }
.list.grouped > .list-item + .list-item { border-top: 1px solid var(--line); }

/* icon tile — the main "icon" look: line icon on a soft tinted squircle */
.icon-bubble, .ico-tile {
  --tile-fg: var(--primary);
  flex: 0 0 auto;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--bubble, var(--tile-bg, var(--primary-soft)));
  color: var(--tile-fg);
  font-size: 1.3rem;
}
/* glyphs 20 / 24 / 30 in tiles 34 / 44 / 56 (our icon set has more inner padding than Lucide — docs/ICONS.md §4) */
.icon-bubble svg, .ico-tile svg { width: 24px; height: 24px; }
.icon-bubble.sm, .ico-tile.sm { width: 34px; height: 34px; border-radius: 11px; font-size: 1rem; }
.icon-bubble.sm svg, .ico-tile.sm svg { width: 20px; height: 20px; }
.icon-bubble.lg, .ico-tile.lg { width: 56px; height: 56px; border-radius: 18px; font-size: 1.75rem; }
.icon-bubble.lg svg, .ico-tile.lg svg { width: 30px; height: 30px; }
.ico-tile.solid { background: var(--tile-fg); color: #fff; }

.ticket-divider { position: relative; height: 1px; margin: var(--sp-4) calc(-1 * var(--sp-4)); border-top: 1.5px dashed var(--line-strong); }
.ticket-divider::before, .ticket-divider::after { content: ""; position: absolute; top: -10px; width: 18px; height: 18px; border-radius: 50%; background: var(--bg); }
.ticket-divider::before { left: -9px; } .ticket-divider::after { right: -9px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 130px), 1fr)); gap: var(--sp-3); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4); min-width: 0; }
.stat .stat-label { color: var(--ink-3); font-size: var(--fs-xs); font-weight: 700; display: flex; align-items: center; gap: 6px; }
.stat .stat-label svg { width: 15px; height: 15px; }
.stat .stat-value { font-family: var(--font-num); font-weight: 700; font-size: var(--fs-xl); line-height: 1.25; overflow-wrap: anywhere; }
.stat .stat-unit { font-size: var(--fs-sm); color: var(--ink-2); font-weight: 400; }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-2); padding: var(--sp-8) var(--sp-4); color: var(--ink-2); }
.empty > .emoji, .empty > .e3d { font-size: 3.2rem; width: 72px; height: 72px; }
.empty h3 { color: var(--ink); }

.callout { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); background: var(--sky-soft); color: var(--ink); font-size: var(--fs-sm); min-width: 0; }
.callout.warn { background: var(--sun-soft); }
.callout.danger { background: var(--danger-soft); }
.callout.ok { background: var(--mint-soft); }
.callout .emoji { font-size: 1.15rem; }
.callout > svg { width: 20px; height: 20px; margin-top: 1px; }
.callout > div { min-width: 0; flex: 1 1 auto; }

.progress { height: 8px; border-radius: 99px; background: var(--surface-sunk); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: var(--grad-brand); }

/* ======================= FORMS ======================= */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-weight: 700; font-size: var(--fs-sm); color: var(--ink-2); }
.field .hint { font-size: var(--fs-xs); color: var(--ink-3); }
.input, .select, .textarea {
  width: 100%; min-width: 0; min-height: 48px;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--surface-sunk);
  color: var(--ink);
  font-size: 16px; /* >=16px stops iOS zoom-on-focus */
  transition: border-color var(--dur), box-shadow var(--dur), background var(--dur);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; background: var(--surface); border-color: var(--primary); box-shadow: var(--focus-ring); }
.textarea { min-height: 92px; resize: vertical; }
.input-group { display: flex; align-items: stretch; min-width: 0; }
.input-group .input { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.input-group .addon { display: grid; place-items: center; padding: 0 14px; border-radius: 0 var(--r-sm) var(--r-sm) 0; background: var(--surface-sunk); color: var(--ink-2); font-weight: 700; white-space: nowrap; border-left: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: var(--sp-3); }
.stepper { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-sunk); border-radius: var(--r-pill); padding: 3px; }
.stepper button { width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: var(--shadow-1); display: grid; place-items: center; }
.stepper output, .stepper .val { min-width: 3.2em; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; font-size: var(--fs-sm); }
.switch { position: relative; display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; min-width: 0; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 50px; height: 30px; border-radius: 999px; background: var(--line-strong); position: relative; flex: 0 0 auto; transition: background var(--dur); }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.18); transition: transform var(--dur) var(--ease-bounce); }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { box-shadow: var(--focus-ring); }
input[type="range"] { width: 100%; accent-color: var(--primary); }

/* ======================= SHEET / DIALOG ======================= */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(16, 14, 40, 0.32);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  animation: fadeIn var(--dur) var(--ease);
}
.sheet {
  width: 100%; max-width: 640px;
  max-height: calc(100dvh - var(--safe-top) - 24px);
  display: flex; flex-direction: column;
  background: var(--glass-strong);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border); border-bottom: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--glass-edge), var(--shadow-3);
  animation: sheetUp 300ms var(--ease);
  min-width: 0;
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { .sheet { background: var(--surface); } }
.sheet-grab { width: 40px; height: 5px; border-radius: 99px; background: var(--line-strong); margin: 10px auto 0; flex: 0 0 auto; }
.sheet-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5) var(--sp-2); flex: 0 0 auto; min-width: 0; }
.sheet-head h2 { flex: 1 1 auto; min-width: 0; font-size: var(--fs-lg); }
.sheet-close { background: var(--surface-sunk) !important; border: 0 !important; box-shadow: none !important; }
.sheet-body { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: var(--sp-2) var(--sp-5) var(--sp-5); min-height: 0; overscroll-behavior: contain; }
.sheet-foot { flex: 0 0 auto; display: flex; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5) calc(var(--sp-3) + var(--safe-bottom)); border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1 1 0; }
.sheet.full { height: calc(100dvh - var(--safe-top) - 12px); }
@media (min-width: 700px) {
  .overlay { align-items: center; padding: var(--sp-6); }
  .sheet { border-radius: var(--r-xl); border-bottom: 1px solid var(--glass-border); max-height: min(86dvh, 860px); animation: popIn 240ms var(--ease-bounce); }
  .sheet.full { height: min(86dvh, 860px); }
  .sheet.wide { max-width: 920px; }
  .sheet-grab { display: none; }
  .sheet-foot { padding-bottom: var(--sp-3); }
}

/* Toasts carry no actions: they never take a tap (pointer-events none), and they appear where they cover
   nothing important — at the top like an iOS banner on phones (bottom = quick-add rows, sheet footers, tab bar)
   and whenever a sheet/dialog is open; above the floating tab bar on larger screens. */
.toast-root {
  position: fixed; left: 0; right: 0; z-index: 200; pointer-events: none;
  top: calc(var(--safe-top) + 12px); bottom: auto;
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  padding: 0 var(--gutter);
}
@media (min-width: 700px) {
  .toast-root { top: auto; bottom: calc(var(--nav-space) + 72px); }
  .app.nav-hidden ~ .toast-root { bottom: calc(96px + var(--safe-bottom)); }
  body.has-overlay .toast-root { top: calc(var(--safe-top) + 16px); bottom: auto; }
}
@media (min-width: 900px) { .toast-root { bottom: calc(var(--sp-6) + 72px + var(--safe-bottom)); } }
@media (min-width: 900px) { body.has-overlay .toast-root { bottom: auto; } }
/* full-screen navigation places its own toasts (css/features/nav.css: above the bottom card, top while a sheet is open) */
body:has(.nv-root) .toast-root { top: auto; }
.toast {
  pointer-events: none; max-width: min(520px, 100%);
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 11px 18px; border-radius: var(--r-pill);
  background: var(--toast-bg); color: var(--toast-ink);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  box-shadow: var(--shadow-2);
  font-weight: 700; font-size: var(--fs-sm);
  animation: toastIn 280ms var(--ease-bounce);
}
.toast.out { animation: fadeOut 200ms forwards; }

/* ======================= SPLIT LAYOUT (map + panel) ======================= */
.split { height: 100%; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
.split-map { position: relative; height: clamp(220px, 42dvh, 460px); min-width: 0; transition: height 280ms var(--ease); }
.split.map-collapsed .split-map { height: 0; overflow: hidden; }
.split.map-tall .split-map { height: clamp(300px, 66dvh, 760px); }
.split-panel {
  position: relative; min-width: 0; min-height: 0;
  overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: var(--bg);
  border-radius: var(--r-xl) var(--r-xl) 0 0; margin-top: -24px; z-index: 2;   /* panel slides over the map like a sheet */
  box-shadow: 0 -8px 30px rgba(22, 20, 60, 0.08);
}
.split.map-collapsed .split-panel { margin-top: 0; border-radius: 0; box-shadow: none; }
/* phones: the panel slides 24px over the map, so a MapView keeps its own chrome (OSM attribution, bottom
   buttons) above that edge instead of half under it (map.css insets its UI by --mv-sb) */
@media (max-width: 899px) {
  .split:not(.map-collapsed) .split-map .mv-host { --mv-sb: 28px; }
}
@media (min-width: 900px) {
  .split { grid-template-columns: var(--panel-w) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .split-panel { order: -1; margin-top: 0; border-radius: 0; box-shadow: none; background: transparent; }
  .split-map, .split.map-collapsed .split-map, .split.map-tall .split-map {
    height: auto; margin: 12px 12px 12px 0; border-radius: var(--r-xl); overflow: hidden; box-shadow: var(--shadow-2);
  }
}
.panel-inner { padding: calc(var(--sp-4) + var(--safe-top)) max(var(--gutter), var(--safe-right)) calc(var(--sp-6) + var(--nav-space)) max(var(--gutter), var(--safe-left)); }
.split .panel-inner { padding-top: var(--sp-5); }
@media (min-width: 900px) { .split .panel-inner { padding-top: calc(var(--sp-4) + var(--safe-top)); } }
.map-fill { position: absolute; inset: 0; }

/* ======================= MISC ======================= */
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--primary-soft); border-top-color: var(--primary); animation: spin .8s linear infinite; flex: 0 0 auto; }
.skeleton { background: linear-gradient(90deg, var(--surface-sunk), var(--surface-2), var(--surface-sunk)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--r-sm); min-height: 16px; }
.divider { height: 1px; background: var(--line); margin: var(--sp-4) 0; border: 0; }
.kbd { font-size: var(--fs-xs); padding: 1px 6px; border-radius: 6px; background: var(--surface-sunk); border: 1px solid var(--line); }
.paper { background-color: var(--bg); }
.wiggle:hover .emoji { animation: wiggle .5s var(--ease); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(6px); } }
@keyframes sheetUp { from { transform: translateY(100%); } }
@keyframes popIn { from { transform: scale(.96); opacity: 0; } }
@keyframes toastIn { from { transform: translateY(-10px) scale(.97); opacity: 0; } }
@keyframes wiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-10deg); } 75% { transform: rotate(8deg); } }
@keyframes pop { 0% { transform: scale(.7); opacity: 0; } 70% { transform: scale(1.05); } 100% { transform: scale(1); opacity: 1; } }

/* touch devices: every tappable control is at least 44px tall */
@media (pointer: coarse) {
  .btn.sm, .chip, .segmented button, .tabbar a, .tabbar button { min-height: 44px; }
  .btn.icon.sm { width: 44px; min-width: 44px; height: 44px; min-height: 44px; }
  .stepper button { width: 44px; height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
.print-root { display: none; }

/* selected segment readable in dark mode (lighter fill + hairline) */
:root[data-theme="dark"] .segmented button[aria-selected="true"], :root[data-theme="dark"] .tabbar [aria-selected="true"], :root[data-theme="dark"] .tabbar [aria-current="page"] {
  background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-strong), var(--shadow-1);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .segmented button[aria-selected="true"], :root:not([data-theme="light"]) .tabbar [aria-selected="true"], :root:not([data-theme="light"]) .tabbar [aria-current="page"] {
    background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-strong), var(--shadow-1);
  }
}
/* line-icon slots in toasts, sheet titles and sheet action buttons */
.toast-ico { display: inline-grid; place-items: center; flex: 0 0 auto; opacity: .92; }
.sheet-title-ico { display: inline-grid; place-items: center; width: 34px; height: 34px; margin-right: 10px; vertical-align: middle; border-radius: 11px; background: var(--primary-soft); color: var(--primary); }
.btn-ico { display: inline-grid; place-items: center; flex: 0 0 auto; }

/* "มีเวอร์ชันใหม่" bar (js/app.js): floating liquid-glass pill above the tab bar; hidden during navigation */
.app-update {
  position: fixed; z-index: 190; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-space) + 12px);
  display: flex; align-items: center; gap: var(--sp-2);
  width: max-content; max-width: calc(100% - 2 * var(--gutter));
  padding: 4px 4px 4px 14px; border-radius: var(--r-pill);
  box-shadow: var(--glass-edge), var(--shadow-glass);
  font-weight: 700; font-size: var(--fs-sm); color: var(--ink);
}
.app-update-ico { display: inline-grid; place-items: center; flex: 0 0 auto; color: var(--primary); }
.app-update-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-update .btn { flex: 0 0 auto; }
@media (min-width: 900px) { .app-update { bottom: calc(var(--sp-6) + var(--safe-bottom)); } }
body:has(.nv-root) .app-update { display: none; }
