/* ════════════════════════════════════════════════════════
   DOPA WELFARE LINK — Kiosk app
   Theme: "แสงแห่งสิทธิ์" — deep-navy night map, amber light
   ════════════════════════════════════════════════════════ */

/* ---------- Fonts (local, offline) ---------- */
@font-face {
  font-family: 'Noto Sans Thai L';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('../assets/fonts/NotoSansThai-thai.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'Noto Sans Thai L';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('../assets/fonts/NotoSansThai-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+2000-206F, U+2212, U+FEFF;
}

:root {
  --navy-0: #08133d;
  --navy-1: #001c52;
  --navy-2: #01275c;
  --orange: #cc5c0a;
  --amber: #ffb92b;
  --brown: #391501;
  --cream: #edddc0;
  --white: #ffffff;
  --paper: #f0f0ef;
  --ink: #000000;

  --card: rgba(255, 255, 255, 0.055);
  --card-line: rgba(237, 221, 192, 0.16);
  --txt: rgba(255, 255, 255, 0.94);
  --txt-dim: rgba(237, 221, 192, 0.62);
  --radius: 22px;
  --ease: cubic-bezier(.22, .8, .28, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--navy-0);
  color: var(--txt);
  font-family: 'Sukhumvit Set', 'Noto Sans Thai L', 'Noto Sans Thai', 'IBM Plex Sans Thai', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}
img, video { max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* Touch target + instant feedback */
.touch { min-width: 48px; min-height: 48px; transition: transform .12s var(--ease), filter .12s; }
.touch:active { transform: scale(.94); filter: brightness(1.25); }

/* ---------- Ambient background ---------- */
.ambient { position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% -10%, var(--navy-2) 0%, var(--navy-1) 46%, var(--navy-0) 100%);
}
.glow { position: absolute; border-radius: 50%; filter: blur(90px); opacity: .5;
  animation: drift 18s ease-in-out infinite alternate; }
.glow-a { width: 55vw; height: 55vw; left: -18vw; top: -10vh;
  background: radial-gradient(circle, rgba(1, 60, 130, .55), transparent 70%); }
.glow-b { width: 48vw; height: 48vw; right: -16vw; top: 34vh;
  background: radial-gradient(circle, rgba(204, 92, 10, .16), transparent 70%);
  animation-delay: -6s; }
.glow-c { width: 40vw; height: 40vw; left: 18vw; bottom: -14vh;
  background: radial-gradient(circle, rgba(255, 185, 43, .10), transparent 70%);
  animation-delay: -12s; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(4vw, 3vh) scale(1.12); }
}
.stars { position: absolute; inset: 0; }
.star { position: absolute; width: 4px; height: 4px; border-radius: 50%;
  background: var(--amber); opacity: 0;
  animation: twinkle var(--dur, 7s) ease-in-out var(--delay, 0s) infinite; }
@keyframes twinkle {
  0%, 100% { opacity: 0; transform: translateY(0) scale(.6); }
  50% { opacity: var(--peak, .5); transform: translateY(-14px) scale(1); }
}

/* ---------- State machine ---------- */
.state { position: fixed; inset: 0; z-index: 1; display: flex; flex-direction: column;
  opacity: 0; visibility: hidden; transform: scale(1.03);
  transition: opacity .55s var(--ease), transform .55s var(--ease), visibility 0s .55s; }
.state.active { opacity: 1; visibility: visible; transform: scale(1);
  transition: opacity .55s var(--ease), transform .55s var(--ease), visibility 0s; }

/* ════════════════ STATE 1 · IDLE ════════════════ */
.state-idle { text-align: center; }
.idle-head { display: flex; align-items: center; justify-content: space-between;
  padding: max(18px, env(safe-area-inset-top)) 26px 0; }
.logo-lockup { display: flex; gap: 14px; align-items: center; }
.logo-img { height: 58px; width: auto; object-fit: contain;
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, .5)); }
.logo-img.sm { height: 48px; }
.head-spacer { width: 48px; flex: 0 0 48px; }
.idle-brand { text-align: right; display: flex; flex-direction: column; gap: 2px; }
.brand-line { font-size: 21px; letter-spacing: .14em; color: var(--cream); font-weight: 500; }
.brand-line b { color: var(--amber); font-weight: 800; }
.brand-sub { font-size: 14px; color: var(--txt-dim); }

.idle-map-zone { flex: 1; position: relative; display: flex; flex-direction: column;
  align-items: center; justify-content: center; min-height: 0; padding: 8px 0; }
.idle-map-halo { position: absolute; width: min(78vw, 66vh); aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 185, 43, .13) 0%, rgba(204, 92, 10, .07) 42%, transparent 70%);
  animation: haloPulse 5s ease-in-out infinite; }
@keyframes haloPulse {
  0%, 100% { transform: scale(1); opacity: .8; }
  50% { transform: scale(1.09); opacity: 1; }
}
.idle-map { height: 56%; min-height: 0; position: relative; z-index: 1;
  animation: mapBreath 7s ease-in-out infinite;
  filter: drop-shadow(0 0 34px rgba(255, 170, 40, .28)); }
.idle-map svg { height: 100%; width: auto; display: block; }
@keyframes mapBreath {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.025); }
}
.idle-title { font-size: clamp(30px, 5.4vw, 52px); font-weight: 800; line-height: 1.25;
  margin-top: 26px; text-shadow: 0 6px 30px rgba(0, 0, 0, .55); padding: 0 20px; }
.grad-text { background: linear-gradient(100deg, var(--amber), #ff8a3c);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

.idle-cta { margin-top: 26px; display: inline-flex; align-items: center; gap: 16px;
  padding: 18px 34px; border-radius: 999px; position: relative;
  background: linear-gradient(120deg, rgba(204, 92, 10, .92), rgba(255, 152, 33, .92));
  box-shadow: 0 12px 40px rgba(204, 92, 10, .45), inset 0 1px 0 rgba(255, 255, 255, .35);
  font-size: 22px; font-weight: 700; color: #fff; }
.cta-ring { position: absolute; inset: -3px; border-radius: inherit;
  border: 2px solid rgba(255, 185, 43, .9);
  animation: ctaRing 2.2s var(--ease) infinite; }
@keyframes ctaRing {
  0% { transform: scale(1); opacity: .9; }
  70%, 100% { transform: scale(1.28); opacity: 0; }
}
.cta-hand { font-size: 26px; animation: hand 1.6s ease-in-out infinite; }
@keyframes hand { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

.idle-media { padding: 18px 0 max(20px, env(safe-area-inset-bottom)); }
.idle-media-head { display: flex; align-items: baseline; justify-content: space-between;
  padding: 0 26px 12px; }
.media-badge { font-size: 19px; font-weight: 700; color: var(--cream);
  display: inline-flex; align-items: center; gap: 10px; }
.media-badge::before { content: ''; width: 10px; height: 10px; border-radius: 3px;
  background: linear-gradient(135deg, var(--amber), var(--orange));
  box-shadow: 0 0 12px rgba(255, 185, 43, .8); }
.media-hint { font-size: 14px; color: var(--txt-dim); }
.media-marquee { overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent); }
.media-track { display: flex; gap: 16px; width: max-content; padding: 4px 0;
  animation: marquee var(--marquee-dur, 40s) linear infinite; }
/* marquee หน้า Idle โชว์แค่รูป — caption แสดงเฉพาะในหน้า Gallery/lightbox */
.media-track .mc-label { display: none; }
@keyframes marquee { to { transform: translateX(calc(-50% - 8px)); } }
.media-card { width: 230px; height: 148px; border-radius: 18px; overflow: hidden;
  position: relative; flex: none; border: 1px solid var(--card-line);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .4); background: var(--navy-2); }
.media-card img, .media-card video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-card .mc-label { position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 12px 9px;
  font-size: 13.5px; font-weight: 600; text-align: left; color: #fff;
  background: linear-gradient(transparent, rgba(0, 10, 40, .88)); }
.media-card .mc-play { position: absolute; inset: 0; display: grid; place-items: center; }
.media-card .mc-play span { width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  background: rgba(204, 92, 10, .88); backdrop-filter: blur(4px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .45); }
.media-ph { width: 100%; height: 100%; display: grid; place-items: center;
  background:
    radial-gradient(80% 120% at 20% 0%, rgba(255, 185, 43, .18), transparent 60%),
    linear-gradient(150deg, var(--navy-1), var(--navy-2)); }
.media-ph svg { opacity: .45; }

/* ════════════════ STATE 2 · HOME ════════════════ */
.home-head { display: flex; align-items: center; gap: 16px;
  padding: max(14px, env(safe-area-inset-top)) 22px 10px; }
.home-titles { flex: 1; text-align: center; min-width: 0; }
.home-titles h1 { font-size: clamp(21px, 3.4vw, 30px); font-weight: 800; line-height: 1.3; }
.home-titles p { font-size: 13.5px; color: var(--txt-dim); margin-top: 2px; }

.region-bar { display: flex; gap: 10px; padding: 8px 22px 10px; overflow-x: auto;
  scrollbar-width: none; justify-content: safe center; }
.region-bar::-webkit-scrollbar { display: none; }
.region-chip { flex: none; padding: 11px 20px; min-height: 48px; border-radius: 999px;
  font-size: 16.5px; font-weight: 600; color: var(--cream);
  background: var(--card); border: 1px solid var(--card-line);
  backdrop-filter: blur(8px); transition: all .25s var(--ease); }
.region-chip:active { transform: scale(.94); }
.region-chip.on { color: #14203f; background: linear-gradient(120deg, var(--amber), #ffce62);
  border-color: transparent; font-weight: 800;
  box-shadow: 0 8px 24px rgba(255, 185, 43, .38); }

.map-stage { flex: 1; position: relative; min-height: 0; }
.map-host { position: absolute; inset: 6px 10px; display: grid;
  grid-template: 100% / 100%; place-items: center;
  transition: bottom .45s var(--ease); }
/* เมื่อมีจังหวัดถูกเลือก → เบียดแผนที่ขึ้น กันแถบล่างไว้ให้ปุ่ม pill (ไม่ทับแผนที่)
   และย่อ legend เหลือแค่แถบสี กันชนกับปุ่มบนจอแคบ */
.map-stage.has-pill .map-host { bottom: 80px; }
.map-stage.has-pill .map-legend em { display: none; }
.map-host svg { width: 100%; height: 100%; overflow: visible; }

/* Province paths */
.prov { stroke: #061033; stroke-width: 1.1; vector-effect: non-scaling-stroke;
  transition: filter .3s, opacity .3s; cursor: pointer; }
.prov.dim { opacity: .16; pointer-events: none; }

/* ชื่อจังหวัดบนแผนที่ — โผล่เมื่อซูมเข้าภาค (ตอนดูทั้งประเทศซ่อนไว้กันรก) */
.prov-labels { pointer-events: none; }
.prov-label { fill: var(--cream); font-weight: 700;
  text-anchor: middle; dominant-baseline: middle;
  paint-order: stroke; stroke: rgba(4, 12, 40, .85); stroke-width: 3px;
  opacity: 0; transition: opacity .45s var(--ease); }
svg.zoomed .prov-label:not(.dim) { opacity: 1; transition-delay: .3s; }
.prov.sel { stroke: var(--amber); stroke-width: 2.4;
  filter: drop-shadow(0 0 14px rgba(255, 185, 43, .9)) brightness(1.28); }
.prov-burst { pointer-events: none; fill: none; stroke: var(--amber);
  transform-box: fill-box; transform-origin: center;
  animation: burst .7s var(--ease) forwards; }
@keyframes burst {
  from { stroke-width: 1; opacity: .95; transform: scale(1); }
  to { stroke-width: 0; opacity: 0; transform: scale(1.06); }
}

.map-reset { position: absolute; top: 12px; left: 14px; z-index: 3;
  display: inline-flex; align-items: center; gap: 8px; min-height: 48px;
  padding: 11px 18px; border-radius: 999px; font-size: 15.5px; font-weight: 700;
  color: var(--cream); background: rgba(1, 39, 92, .82); border: 1px solid var(--card-line);
  backdrop-filter: blur(10px); box-shadow: 0 8px 22px rgba(0, 0, 0, .4); }
.map-reset:active { transform: scale(.94); }

.map-tip { position: absolute; top: 12px; right: 14px; z-index: 2;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 999px; font-size: 14px; color: var(--txt-dim);
  background: rgba(0, 12, 40, .5); border: 1px solid rgba(237, 221, 192, .1);
  backdrop-filter: blur(8px); animation: tipFloat 3s ease-in-out infinite; }
@keyframes tipFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* กลางล่างในแถบที่กันไว้ (แผนที่ถูกเบียดขึ้นด้วย .has-pill) — เด่นและไม่ทับแผนที่ */
.province-pill { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  z-index: 4; display: inline-flex; align-items: center; gap: 12px;
  padding: 15px 26px; min-height: 54px; border-radius: 999px;
  font-size: 19px; font-weight: 800; color: #fff;
  max-width: calc(100% - 32px); white-space: nowrap;
  background: linear-gradient(120deg, var(--orange), #f08424);
  box-shadow: 0 14px 38px rgba(204, 92, 10, .5), inset 0 1px 0 rgba(255, 255, 255, .3);
  animation: pillIn .4s var(--ease); }
.province-pill::after { content: '›'; font-size: 24px; font-weight: 700; margin-left: 2px; }
.province-pill:active { transform: translateX(-50%) scale(.94); }
@keyframes pillIn { from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); } }

.map-legend { position: absolute; left: 16px; bottom: 10px; z-index: 2;
  display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--txt-dim); }
.legend-scale { width: 110px; height: 10px; border-radius: 6px;
  background: linear-gradient(90deg, #152f66, #2b5cae, #ffb92b, #f07f1a, #e84e0a);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .12) inset; }
.map-legend em { font-style: normal; opacity: .8; margin-left: 4px; }

.home-foot { display: flex; align-items: stretch; gap: 12px;
  padding: 6px 20px max(16px, env(safe-area-inset-bottom)); }
.stat-ribbon { flex: 1; display: flex; gap: 12px; min-width: 0; }
.stat-mini { flex: 1; min-width: 0; padding: 12px 16px; border-radius: 18px;
  background: var(--card); border: 1px solid var(--card-line); backdrop-filter: blur(10px);
  display: flex; flex-direction: column; gap: 1px; }
.stat-mini .k { font-size: 12.5px; color: var(--txt-dim); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.stat-mini .v { font-size: clamp(18px, 2.6vw, 25px); font-weight: 800; color: var(--amber);
  font-variant-numeric: tabular-nums; }
.stat-mini .v.cream { color: var(--cream); }
.list-btn { display: inline-flex; align-items: center; gap: 10px; padding: 0 22px;
  border-radius: 18px; font-size: 16.5px; font-weight: 700; color: #14203f;
  background: linear-gradient(120deg, var(--amber), #ffce62);
  box-shadow: 0 10px 26px rgba(255, 185, 43, .32); }

/* ════════════════ STATE 3 · DETAIL ════════════════ */
.state-detail { background: rgba(4, 12, 38, .35); }
.detail-head { display: flex; align-items: center; gap: 14px;
  padding: max(12px, env(safe-area-inset-top)) 18px 10px; }
.icon-btn { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center;
  color: var(--cream); background: var(--card); border: 1px solid var(--card-line);
  backdrop-filter: blur(10px); }
.icon-btn.close { color: #ffd9a8; background: rgba(204, 92, 10, .22);
  border-color: rgba(255, 185, 43, .35); }
.crumb { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0;
  font-size: 16px; color: var(--txt-dim); }
.crumb svg { flex: none; opacity: .5; }
.crumb-province { color: var(--amber); font-weight: 800; font-size: 18px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.detail-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 4px 20px 30px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.detail-scroll::-webkit-scrollbar { display: none; }

.detail-hero { display: flex; align-items: center; gap: 16px; padding: 6px 4px 16px; }
.hero-left { flex: 1; min-width: 0; }
.detail-hero h2 { font-size: clamp(32px, 6vw, 46px); font-weight: 800; line-height: 1.15;
  background: linear-gradient(100deg, #fff 30%, var(--cream));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.district-btn { margin-top: 12px; display: inline-flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-radius: 999px; font-size: 17px; font-weight: 700;
  color: var(--cream); background: var(--card); border: 1.5px solid rgba(255, 185, 43, .45);
  backdrop-filter: blur(8px); max-width: 100%; }
.district-btn svg:first-child { color: var(--amber); flex: none; }
.district-btn .chev { opacity: .6; flex: none; }
.district-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hero-map { width: 118px; height: 130px; flex: none; position: relative;
  order: -1; /* เงาจังหวัดอยู่ฝั่งซ้าย หน้าชื่อจังหวัด — ไม่ทับปุ่มปิด/การ์ดฝั่งขวา */
  filter: drop-shadow(0 0 18px rgba(255, 185, 43, .5)); }
/* absolute + inset 0 บังคับ svg เท่ากล่องพอดี (height:100% เฉยๆ ถูก browser ตีเป็น auto
   ตาม aspect ratio ของ viewBox → จังหวัดทรงสูงเคยล้นลงไปทับการ์ดข้างล่าง) */
.hero-map svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.hero-map path { fill: rgba(255, 185, 43, .16); stroke: var(--amber); stroke-width: 2;
  vector-effect: non-scaling-stroke;
  stroke-dasharray: 1400; stroke-dashoffset: 1400; animation: draw 1.4s var(--ease) .15s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

.glass { background: var(--card); border: 1px solid var(--card-line); border-radius: var(--radius);
  backdrop-filter: blur(12px); box-shadow: 0 14px 40px rgba(0, 0, 0, .3); }

.summary-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px; }
.sum-card { padding: 16px 18px; border-radius: 20px; text-align: center;
  background: var(--card); border: 1px solid var(--card-line); backdrop-filter: blur(10px);
  animation: rise .5s var(--ease) both; }
.sum-card:nth-child(2) { animation-delay: .07s; }
.sum-card:nth-child(3) { animation-delay: .14s; }
.sum-card .k { font-size: 13.5px; color: var(--txt-dim); }
.sum-card .v { font-size: clamp(22px, 4.2vw, 34px); font-weight: 800; margin-top: 3px;
  font-variant-numeric: tabular-nums; color: var(--cream); }
.sum-card.hl .v { color: var(--amber); text-shadow: 0 0 24px rgba(255, 185, 43, .45); }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

.group-cards { display: flex; flex-direction: column; gap: 14px; margin-bottom: 14px; }
.gcard { padding: 20px 22px; border-radius: var(--radius); position: relative; overflow: hidden;
  background: var(--card); border: 1px solid var(--card-line); backdrop-filter: blur(12px);
  animation: rise .55s var(--ease) both; }
.gcard::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
  background: linear-gradient(180deg, var(--amber), var(--orange)); opacity: .9; }
.gcard-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.gcard-tag { flex: none; font-size: 13px; font-weight: 800; letter-spacing: .04em;
  padding: 6px 13px; border-radius: 999px; color: #14203f;
  background: linear-gradient(120deg, var(--amber), #ffd061); }
.gcard-name { font-size: 17.5px; font-weight: 700; line-height: 1.3; }
.gcard-rate { margin-left: auto; text-align: right; flex: none; }
.gcard-rate .pct { font-size: clamp(26px, 4.6vw, 36px); font-weight: 800; color: var(--amber);
  font-variant-numeric: tabular-nums; line-height: 1; }
.gcard-rate .lbl { font-size: 12px; color: var(--txt-dim); margin-top: 2px; }
.gcard-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; }
.gm { min-width: 0; }
.gm .k { font-size: 13.5px; color: var(--txt-dim); display: flex; align-items: center; gap: 7px; }
.gm .k i { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.gm .v { font-size: clamp(21px, 3.8vw, 30px); font-weight: 800; margin-top: 2px;
  font-variant-numeric: tabular-nums; }
.gm.reg .k i { background: var(--cream); }
.gm.pass .k i { background: var(--amber); box-shadow: 0 0 8px rgba(255, 185, 43, .8); }
.gm.pass .v { color: var(--amber); }
.gbar { grid-column: 1 / -1; height: 14px; border-radius: 8px; margin-top: 4px;
  background: rgba(237, 221, 192, .14); overflow: hidden; position: relative; }
.gbar > i { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 8px;
  background: linear-gradient(90deg, var(--orange), var(--amber));
  box-shadow: 0 0 16px rgba(255, 185, 43, .55);
  transition: width 1.1s var(--ease) .2s; }

/* Group 1 — distinct amber "notice" styling */
.gcard.g1 { background: linear-gradient(140deg, rgba(204, 92, 10, .13), rgba(57, 21, 1, .3));
  border: 1.5px dashed rgba(255, 185, 43, .4); }
.gcard.g1::before { background: linear-gradient(180deg, var(--orange), var(--brown)); }
.gcard.g1 .gcard-tag { background: linear-gradient(120deg, var(--orange), #a34a08); color: #ffe6c4; }
.g1-body { display: flex; align-items: center; gap: 18px; }
.g1-num .v { font-size: clamp(26px, 5vw, 38px); font-weight: 800; color: #ffc46a;
  font-variant-numeric: tabular-nums; }
.g1-num .k { font-size: 14px; color: var(--txt-dim); }
.g1-note { flex: 1; font-size: 13px; line-height: 1.55; color: rgba(237, 221, 192, .72);
  border-left: 2px solid rgba(255, 185, 43, .35); padding-left: 14px; }

.compare-card { padding: 20px 22px; margin-bottom: 14px; animation: rise .6s var(--ease) both; }
.compare-card h3 { font-size: 17.5px; font-weight: 800; display: flex; align-items: center;
  gap: 10px; margin-bottom: 16px; }
.h-accent { width: 10px; height: 22px; border-radius: 5px;
  background: linear-gradient(180deg, var(--amber), var(--orange)); flex: none; }
.cmp-row { margin-bottom: 14px; }
.cmp-row:last-child { margin-bottom: 2px; }
.cmp-label { display: flex; justify-content: space-between; align-items: baseline;
  font-size: 14.5px; margin-bottom: 6px; }
.cmp-label b { color: var(--cream); }
.cmp-label span { color: var(--txt-dim); font-size: 13px; font-variant-numeric: tabular-nums; }
.cmp-track { height: 30px; border-radius: 10px; background: rgba(237, 221, 192, .1);
  position: relative; overflow: hidden; }
.cmp-reg, .cmp-pass { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 10px;
  transition: width 1.2s var(--ease) .25s; }
.cmp-reg { background: linear-gradient(90deg, rgba(43, 92, 174, .85), rgba(90, 140, 220, .85)); }
.cmp-pass { background: linear-gradient(90deg, var(--orange), var(--amber));
  box-shadow: 0 0 18px rgba(255, 185, 43, .45); }
.cmp-pass .in-label, .cmp-in { position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font-size: 12.5px; font-weight: 800; color: #1b2a52; }
.cmp-legend { display: flex; gap: 20px; margin-top: 14px; font-size: 13px; color: var(--txt-dim); }
.cmp-legend span { display: inline-flex; align-items: center; gap: 7px; }
.cmp-legend i { width: 12px; height: 12px; border-radius: 4px; }
.cmp-legend .li-reg { background: #4a7cc9; }
.cmp-legend .li-pass { background: var(--amber); }

.detail-note { font-size: 12.5px; color: rgba(237, 221, 192, .45); line-height: 1.6;
  padding: 0 6px 10px; }

/* ════════════════ Bottom sheets ════════════════ */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(2, 8, 28, .6);
  backdrop-filter: blur(4px); opacity: 0; visibility: hidden;
  transition: opacity .35s var(--ease), visibility 0s .35s; }
.sheet-backdrop.open { opacity: 1; visibility: visible; transition-delay: 0s; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 76vh;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, #0a2058, #071640);
  border-radius: 30px 30px 0 0; border: 1px solid var(--card-line); border-bottom: 0;
  box-shadow: 0 -18px 60px rgba(0, 0, 0, .55);
  transform: translateY(100%); transition: transform .42s var(--ease); }
.sheet-backdrop.open .sheet { transform: translateY(0); }
.sheet-grip { width: 52px; height: 5px; border-radius: 3px; background: rgba(237, 221, 192, .3);
  margin: 12px auto 4px; flex: none; }
.sheet-title { text-align: center; font-size: 19px; font-weight: 800; padding: 8px 20px 14px;
  flex: none; }
.sheet-body { overflow-y: auto; padding: 0 20px max(24px, env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.sheet-body::-webkit-scrollbar { display: none; }
.sheet-region { font-size: 14.5px; font-weight: 700; color: var(--amber); margin: 16px 4px 10px;
  display: flex; align-items: center; gap: 8px; }
.sheet-region::after { content: ''; flex: 1; height: 1px; background: rgba(255, 185, 43, .2); }
.sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sheet-item { min-height: 52px; padding: 12px 10px; border-radius: 14px; font-size: 15.5px;
  font-weight: 600; color: var(--txt); text-align: center;
  background: var(--card); border: 1px solid rgba(237, 221, 192, .12);
  transition: transform .12s var(--ease); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.sheet-item:active { transform: scale(.94); background: rgba(255, 185, 43, .2); }
.sheet-item.on { background: linear-gradient(120deg, var(--amber), #ffce62); color: #14203f;
  font-weight: 800; border-color: transparent; }

/* ════════════════ STATE 5 · Lightbox ════════════════ */
.lightbox { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center;
  justify-content: center; background: rgba(2, 6, 24, .93); backdrop-filter: blur(10px);
  opacity: 0; visibility: hidden; transition: opacity .4s var(--ease), visibility 0s .4s; }
.lightbox.open { opacity: 1; visibility: visible; transition-delay: 0s; }
.lb-stage { max-width: 92vw; max-height: 78vh; display: grid; place-items: center; }
.lb-stage img, .lb-stage video { max-width: 92vw; max-height: 78vh; border-radius: 20px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .7); }
.lb-stage .media-ph { width: 74vw; height: 46vh; border-radius: 20px; }
.lb-close { position: absolute; top: max(20px, env(safe-area-inset-top)); right: 20px;
  width: 58px; height: 58px; z-index: 2; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 60px; height: 84px; border-radius: 18px; display: grid; place-items: center;
  color: var(--cream); background: rgba(255, 255, 255, .07); border: 1px solid var(--card-line);
  backdrop-filter: blur(8px); }
.lb-nav:active { transform: translateY(-50%) scale(.92); }
.lb-prev { left: 14px; } .lb-next { right: 14px; }
.lb-caption { position: absolute; left: 0; right: 0;
  bottom: max(26px, env(safe-area-inset-bottom)); text-align: center; font-size: 17px;
  font-weight: 600; color: var(--cream); padding: 0 80px; }
.lb-play-btn { position: absolute; width: 92px; height: 92px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; z-index: 2;
  background: rgba(204, 92, 10, .9); backdrop-filter: blur(6px);
  box-shadow: 0 14px 44px rgba(0, 0, 0, .5); transition: opacity .3s, transform .15s; }
.lb-play-btn:active { transform: scale(.92); }
.lb-play-btn.playing { opacity: 0; pointer-events: none; }

/* ════════════════ Timeout toast ════════════════ */
.timeout-toast { position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%) translateY(140%);
  z-index: 60; display: flex; align-items: center; gap: 14px; padding: 14px 24px;
  border-radius: 999px; font-size: 16px; color: var(--cream);
  background: rgba(6, 18, 52, .92); border: 1px solid rgba(255, 185, 43, .4);
  backdrop-filter: blur(12px); box-shadow: 0 16px 50px rgba(0, 0, 0, .5);
  opacity: 0; visibility: hidden;
  transition: transform .45s var(--ease), opacity .45s var(--ease), visibility 0s linear .45s;
  pointer-events: none; }
.timeout-toast.show { transform: translateX(-50%) translateY(0);
  opacity: 1; visibility: visible; transition-delay: 0s; }
.timeout-toast b { color: var(--amber); }
#toastRingFg { transition: stroke-dashoffset 1s linear; }

/* ════════════════ Media banner (home → gallery) ════════════════ */
.media-banner { display: flex; align-items: center; gap: 14px; margin: 0 22px 10px;
  padding: 12px 16px; border-radius: 18px; text-align: left; color: var(--cream);
  font: inherit; border: 1px solid var(--card-line);
  background: linear-gradient(120deg, rgba(255, 185, 43, .12), rgba(10, 26, 66, .55) 45%);
  backdrop-filter: blur(10px); box-shadow: 0 10px 26px rgba(0, 0, 0, .3); }
.mb-icon { width: 48px; height: 48px; flex: none; border-radius: 14px;
  display: grid; place-items: center; color: #1a2c5c;
  background: linear-gradient(135deg, var(--amber), var(--orange));
  box-shadow: 0 6px 16px rgba(255, 150, 30, .35); }
.mb-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.mb-text b { font-size: 17px; font-weight: 700; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.mb-text small { font-size: 13px; color: var(--txt-dim); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.mb-count { flex: none; font-size: 13.5px; font-weight: 700; color: var(--amber);
  padding: 5px 12px; border-radius: 999px;
  background: rgba(255, 185, 43, .14); border: 1px solid rgba(255, 185, 43, .3); }
.mb-chev { flex: none; color: var(--txt-dim); }

/* ════════════════ STATE · Gallery — Orbit view (ระบบดาว) ════════════════ */
.orbit-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
/* ขนาดวงโคจรคำนวณที่เดียว — ดาวเคราะห์และวงสเกลตามกันทุกขนาดจอ
   2.5D: เอียงระนาบวงโคจร (--tilt) + perspective → ดวงจันทร์อ้อมหน้า/หลังดาวจริงตามความลึก */
.orbit-sky { flex: 1; position: relative; display: grid; place-items: center; min-height: 0;
  overflow: hidden; /* ดวงอาทิตย์จมขอบ sky ไม่ล้นไปทับ header */
  --tilt: 0deg;
  --da: max(190px, min(64vmin, calc((100vh - 440px) * 1.35), 500px));
  --db: max(300px, min(92vmin, calc((100vh - 300px) * 1.35), 740px));
  perspective: 1100px; transform-style: preserve-3d; }

/* ดวงอาทิตย์กลางระบบ = วิดีโอ
   clip-path จำเป็น: ใน preserve-3d Chrome depth-sort ไม่เคารพ border-radius
   → ถ้าไม่มี ดาวเคราะห์ด้านหลังจะโดนตัดเป็นเหลี่ยมตามกรอบสี่เหลี่ยมของดวงอาทิตย์ */
.orbit-center { position: absolute; z-index: 3;
  aspect-ratio: 1; border-radius: 50%; overflow: hidden;
  clip-path: circle(50%);
  border: 3px solid rgba(255, 185, 43, .65); padding: 0; background: var(--navy-2);
  box-shadow: 0 0 60px rgba(255, 170, 40, .45), 0 0 140px rgba(255, 140, 20, .2),
    inset 0 0 30px rgba(0, 0, 0, .4);
  animation: planetBreath 6s ease-in-out infinite; }
/* รัศมีโคโรนารอบดวงอาทิตย์ (อยู่หลังดวง, หายใจตามกัน) */
.sun-halo { position: absolute; z-index: 2; pointer-events: none;
  aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle,
    rgba(255, 195, 70, .18) 0%, rgba(255, 150, 30, .08) 42%, transparent 68%);
  filter: blur(7px);
  animation: haloPulse 5s ease-in-out infinite; }
.orbit-center img { width: 100%; height: 100%; object-fit: cover; display: block; }
.orbit-center .mc-play { position: absolute; inset: 0; display: grid; place-items: center; }
.orbit-center .mc-play span { width: min(9vmin, 70px); height: min(9vmin, 70px);
  border-radius: 50%; display: grid; place-items: center; color: #fff;
  background: rgba(204, 92, 10, .88); backdrop-filter: blur(4px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, .5); }
@keyframes planetBreath {
  0%, 100% { transform: scale(1); box-shadow: 0 0 60px rgba(255, 170, 40, .45), 0 0 140px rgba(255, 140, 20, .2); }
  50% { transform: scale(1.035); box-shadow: 0 0 80px rgba(255, 170, 40, .6), 0 0 170px rgba(255, 140, 20, .3); }
}

/* โปสเตอร์ระบบสุริยะ (นิ่ง — ไม่โคจรวน): เส้นวงจุดๆ ต่อดวง + ดาวลอยเบาๆ
   ตำแหน่ง/ขนาดทั้งหมดคำนวณเป็น px ใน media.js ตามขนาดจอ */
.orbit-system { position: absolute; inset: 0; }
.orbit-path { position: absolute; aspect-ratio: 1; border-radius: 50%;
  border: 2px dotted rgba(237, 221, 192, .16); }
.planet-poster { position: absolute; transform: translate(-50%, -50%); }
.planet-poster .bob { aspect-ratio: 1; border-radius: 50%; overflow: hidden;
  border: 2.5px solid rgba(237, 221, 192, .5); background: var(--navy-2);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5), 0 0 22px rgba(255, 185, 43, .22);
  animation: floatBob var(--fd, 6s) ease-in-out var(--fdl, 0s) infinite alternate; }
.planet-poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
@keyframes floatBob {
  from { transform: translateY(-5px); }
  to { transform: translateY(5px); }
}

.orbit-hint { display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 10px 20px max(22px, env(safe-area-inset-bottom));
  font-size: 17px; font-weight: 600; color: var(--cream); }

@media (prefers-reduced-motion: reduce) {
  .planet-poster .bob, .orbit-center, .sun-halo { animation: none; }
}

/* ════════════════ STATE · Gallery ════════════════ */
.gallery-titles { flex: 1; min-width: 0; }
.gallery-titles h2 { font-size: 22px; font-weight: 800; line-height: 1.25; }
.gallery-titles p { font-size: 13px; color: var(--txt-dim); margin-top: 1px; }
.gallery-scroll { flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 8px 22px calc(30px + env(safe-area-inset-bottom));
  scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.gallery-scroll::-webkit-scrollbar { display: none; }
/* justified rows (แบบ Google Photos): ทุกแถวเต็มความกว้างพอดี ขอบเสมอกันทั้งหน้า
   ขนาดการ์ดคำนวณจากสัดส่วนจริงใน JS (media-ar.js) → รูปเต็มใบ ไม่ crop
   แต่ละแถวเป็น .g-row ของตัวเอง (ห้าม wrap — กันเศษ px ทำการ์ดตกบรรทัด) */
.gallery-grid { display: block; }
.gallery-grid .g-row { display: flex; gap: 12px; margin-bottom: 12px; }
.gallery-grid .media-card { margin: 0; aspect-ratio: auto; min-width: 0; }
.gallery-grid .media-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* หน้า Gallery โชว์แค่รูป · lightbox ก็ไม่แสดง caption เช่นกัน (ตามบรีฟลูกค้า) */
.gallery-grid .mc-label { display: none; }
.lb-caption { display: none; }

/* การ์ดวิดีโอเด่น — เต็มแถว ขอบทองเรืองแสง เล่นในหน้าเลย (16:9 ตรงสัดส่วนวิดีโอ) */
.gallery-grid .media-card.gallery-video { width: 100%; height: auto; margin-bottom: 12px;
  aspect-ratio: 16 / 9;
  border: 2px solid rgba(255, 185, 43, .6);
  box-shadow: 0 0 34px rgba(255, 170, 40, .28), 0 14px 40px rgba(0, 0, 0, .45); }
.gallery-grid .gallery-video video { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-grid .gallery-video .mc-play span { width: 76px; height: 76px; }
.gallery-video.playing .mc-play { display: none; }
.gallery-video.playing .video-chip { opacity: .55; }
.video-chip { position: absolute; top: 14px; left: 14px; z-index: 2;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 16px; border-radius: 999px; font-size: 15px; font-weight: 800; color: #fff;
  background: rgba(204, 92, 10, .92); backdrop-filter: blur(6px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .4); }
.album-head { display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; padding: 22px 2px 12px; }
.album-head:first-child { padding-top: 6px; }
.album-head h3 { font-size: 19px; font-weight: 800; color: var(--cream);
  display: inline-flex; align-items: center; gap: 10px; }
.album-head h3::before { content: ''; width: 9px; height: 9px; border-radius: 3px; flex: none;
  background: linear-gradient(135deg, var(--amber), var(--orange));
  box-shadow: 0 0 10px rgba(255, 185, 43, .7); }
.album-head span { font-size: 12.5px; color: var(--txt-dim); flex: none; }

/* ════════════════ Ripple ════════════════ */
.ripple { position: fixed; width: 14px; height: 14px; border-radius: 50%; z-index: 100;
  pointer-events: none; background: radial-gradient(circle, rgba(255, 195, 60, .8), rgba(255, 185, 43, 0) 70%);
  transform: translate(-50%, -50%) scale(1); animation: rippleGo .55s var(--ease) forwards; }
@keyframes rippleGo {
  from { opacity: .9; transform: translate(-50%, -50%) scale(1); }
  to { opacity: 0; transform: translate(-50%, -50%) scale(9); }
}

/* ════════════════ Landscape adjustments ════════════════ */
@media (orientation: landscape) {
  .idle-map { height: 64%; }
  .idle-title { font-size: clamp(22px, 3.2vw, 36px); margin-top: 10px; }
  .idle-cta { margin-top: 12px; padding: 11px 24px; font-size: 17px; }
  .idle-media { padding-top: 8px; }
  .idle-media-head { padding-bottom: 8px; }
  .media-card { width: 186px; height: 116px; }
  .media-card .mc-label { font-size: 12px; padding: 20px 10px 7px; }
  .summary-strip { grid-template-columns: repeat(3, 1fr); }
  .group-cards { display: grid; grid-template-columns: 1fr 1fr; }
  .gcard.g1 { grid-column: 1 / -1; }
  .sheet-grid { grid-template-columns: repeat(5, 1fr); }
  .detail-hero h2 { font-size: clamp(26px, 4vw, 38px); }
}
@media (max-width: 620px) {
  .sheet-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-mini .v { font-size: 17px; }
  .list-btn { padding: 0 16px; font-size: 15px; }
}

/* ════════════════ Mobile (โทรศัพท์ ≤480px) ════════════════ */
@media (max-width: 480px) {
  /* — Idle — */
  .idle-head { padding-left: 16px; padding-right: 16px; }
  .logo-img { height: 44px; }
  .brand-line { font-size: 16px; }
  .brand-sub { font-size: 12px; }
  .idle-title { font-size: clamp(22px, 7vw, 28px); }
  .idle-cta { padding: 10px 18px; font-size: 15px; }
  .media-badge { font-size: 16px; }
  .media-hint { font-size: 12px; }
  .media-card { width: 172px; height: 112px; }
  .media-card .mc-label { font-size: 11.5px; padding: 18px 9px 7px; }

  /* — Home: header + region bar — */
  .home-head { gap: 10px; padding-left: 14px; padding-right: 14px; }
  .logo-img.sm { height: 38px; }
  .head-spacer { width: 38px; flex-basis: 38px; }
  .home-titles h1 { font-size: 16.5px; }
  .home-titles p { font-size: 11.5px; }
  .region-bar { gap: 8px; padding-left: 14px; padding-right: 14px; }
  .region-chip { padding: 9px 14px; min-height: 44px; font-size: 14px; }
  .map-legend { font-size: 11px; }
  .province-pill { font-size: 16px; padding: 12px 18px; min-height: 48px; }
  .map-stage.has-pill .map-host { bottom: 70px; }

  /* — Home: banner + footer (เรียงเป็น 2 แถว กันเบียด) — */
  .media-banner { margin: 0 14px 8px; padding: 10px 12px; gap: 10px; }
  .mb-icon { width: 40px; height: 40px; border-radius: 12px; }
  .mb-text b { font-size: 14.5px; }
  .mb-text small { font-size: 11.5px; }
  .mb-count { font-size: 12px; padding: 4px 9px; }
  .home-foot { flex-wrap: wrap; gap: 8px; padding-left: 14px; padding-right: 14px; }
  .stat-ribbon { flex: 1 1 100%; gap: 8px; }
  .stat-mini { padding: 9px 10px; border-radius: 14px; }
  .stat-mini .k { font-size: 10.5px; white-space: normal; line-height: 1.35; }
  .stat-mini .v { font-size: 15.5px; }
  .list-btn { flex: 1 1 100%; justify-content: center; padding: 13px 0; font-size: 15.5px; }

  /* — Detail — */
  .detail-head { padding-left: 12px; padding-right: 12px; }
  .icon-btn { width: 46px; height: 46px; }
  .detail-hero h2 { font-size: clamp(24px, 8vw, 32px); }
  .hero-map { width: 84px; height: 96px; }
  .district-btn { padding: 10px 14px; font-size: 15px; }
  .summary-strip { grid-template-columns: 1fr; gap: 8px; }
  .gcard { padding: 16px; }

  /* — Gallery — */
  .gallery-titles h2 { font-size: 17px; }
  .gallery-titles p { font-size: 11.5px; }
  .orbit-hint { font-size: 14px; }
  .gallery-scroll { padding-left: 14px; padding-right: 14px; }
  .gallery-grid .g-row { gap: 8px; margin-bottom: 8px; }

  /* — Toast — */
  .timeout-toast { font-size: 13.5px; padding: 11px 16px; gap: 10px;
    max-width: calc(100vw - 24px); }
}
