/* ==========================================================================
   DESIGN TOKENS & SYSTEM VARIABLES (From design-system.md & V30 Specs)
   ========================================================================== */
:root {
  --bg: #FCFCFA;
  --ink: #212026;
  --accent: #d42424;
  --accent-gold: #c89738;
  --accent-blue: #2e5e8c;

  /* Material Design 3 Ink Transparency Hierarchy */
  --ink-primary: rgba(33, 32, 38, 0.95);
  --ink-secondary: rgba(33, 32, 38, 0.70);
  --ink-tertiary: rgba(33, 32, 38, 0.45);

  /* UI Surface Tokens */
  --btn-bg: #F3F2F0;
  --track-bg: #E6E5E3;
  --faint-fill: rgba(33, 32, 38, 0.12);
  --faint-stroke: rgba(33, 32, 38, 0.35);
  --slider-track: #E6E5E3;

  /* Legacy Backward Compatibility Aliases */
  --ink-43: rgba(33, 32, 38, 0.43);
  --ink-55: rgba(33, 32, 38, 0.55);
  --ink-70: rgba(33, 32, 38, 0.70);
  --flash: rgb(37, 146, 235);

  /* Core Spacing Scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;
  --s-16: 64px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Anuphan', sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overscroll-behavior: none;
}

/* ==========================================================================
   MATERIAL DESIGN 3 SEMANTIC TYPE SCALE
   ========================================================================== */
.m3-display-large {
  font-family: 'Anuphan', sans-serif;
  font-size: 57px;
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -0.02em;
  color: var(--ink-primary);
}

.m3-display-medium {
  font-family: 'Anuphan', sans-serif;
  font-size: 50px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--ink-primary);
}

#welcome-screen .m3-display-medium {
  font-size: 100px;
}

.m3-headline-small {
  font-family: 'Anuphan', sans-serif;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ink-primary);
}

.m3-title-large {
  font-family: 'Anuphan', sans-serif;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.28;
  color: var(--ink-primary);
}

.m3-title-medium {
  font-family: 'Anuphan', sans-serif;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.50;
  color: var(--ink-primary);
}

.m3-title-small {
  font-family: 'Anuphan', sans-serif;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.43;
  color: var(--ink-primary);
}

.m3-body-large {
  font-family: 'Anuphan', sans-serif;
  font-size: 18px;
  font-weight: 500;
  line-height: 1.50;
  letter-spacing: 0.03em;
  color: var(--ink-secondary);
}

.m3-body-medium {
  font-family: 'Anuphan', sans-serif;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.43;
  color: var(--ink-secondary);
}

.m3-body-research-fluid {
  font-family: 'Anuphan', sans-serif;
  font-size: 18px;
  font-weight: 500;
  line-height: 1.85;
  letter-spacing: 0.01em;
  color: var(--ink-secondary);
}

.m3-label-overline {
  font-family: 'Anuphan', sans-serif;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.m3-label-medium {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-tertiary);
}

.m3-label-technical-metrics {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--ink-tertiary);
}

/* ==========================================================================
   REVEAL FEED SPECIALIST CLASSES (Scale-tunable for Trok Salak Hin Aesthetic)
   ========================================================================== */
.sys-f-reveal-slip-number {
  font-family: 'Anuphan', sans-serif;
  font-size: 96px;
  font-weight: 700;
  line-height: 1;
  margin: var(--s-1) 0;
  color: var(--accent);
}

.sys-f-reveal-poetry {
  font-family: 'Anuphan', sans-serif;
  font-size: 18px;
  font-weight: 500;
  line-height: 1.90;
  letter-spacing: 0.01em;
  color: var(--ink-primary);
}

.sys-f-reveal-poetry p {
  margin: 0;
}

.sys-f-advice-primary {
  font-family: 'Anuphan', sans-serif;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.75;
  color: var(--ink-secondary);
  max-width: 34ch;
  margin: 0 auto var(--s-2);
  text-align: left;
  /* คำอธิบาย = prose ชิดซ้าย (กลอนยัง center) */
}

.sys-f-advice-secondary {
  font-family: 'Anuphan', sans-serif;
  font-size: 18px;
  font-weight: 400;
  line-height: 1.80;
  color: var(--ink-secondary);
  max-width: 36ch;
  margin: 0;
}

/* ==========================================================================
   LAYOUT MANAGERS
   ========================================================================== */
.sys-layout-instrumental {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  width: 100%;
}

.sys-layout-narrative {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: 100%;
}

.sys-layout-footer-row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

/* ==========================================================================
   COMPONENT INTERFACES
   ========================================================================== */
.option-select-card {
  background: transparent;
  border: 1px solid var(--faint-fill);
  padding: 16px var(--s-5);
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--s-4);
  min-height: 54px;
  width: 100%;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
}

.option-select-card:hover {
  border-color: var(--ink-primary);
  background: rgba(33, 32, 38, 0.02);
}

.option-select-card.selected {
  border-color: var(--ink-primary);
  background: var(--ink);
}

.option-select-card.selected .m3-label-medium {
  color: rgba(252, 252, 250, 0.6);
}

.option-select-card.selected .m3-body-large {
  color: var(--bg);
}

.opt-text {
  flex: 1;
  text-align: left;
}

.opt-mark {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  border: 2px solid var(--ink-tertiary);
  display: inline-block;
  position: relative;
  transition: border-color .15s;
}

.opt-radio {
  border-radius: 50%;
}

.opt-check {
  border-radius: 6px;
}

.option-select-card:hover .opt-mark {
  border-color: var(--ink-primary);
}

.option-select-card.selected .opt-mark {
  border-color: var(--bg);
}

.opt-radio::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: var(--bg);
  transform: scale(0);
  transition: transform .15s;
}

.option-select-card.selected .opt-radio::after {
  transform: scale(1);
}

.opt-check::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 11px;
  border: solid var(--bg);
  border-width: 0 2.4px 2.4px 0;
  transform: rotate(45deg) scale(0);
  transition: transform .15s;
}

.option-select-card.selected .opt-check::after {
  transform: rotate(45deg) scale(1);
}

.btn-footer-left,
.btn-footer-right {
  display: inline-flex;
  align-items: center;
  font-family: 'Anuphan', sans-serif;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  border: none;
  background: transparent;
  color: var(--ink-tertiary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 200ms ease, opacity 200ms ease;
}

.btn-footer-left {
  padding: 10px 16px 10px 0;
  justify-content: flex-start;
}

.btn-footer-right {
  padding: 10px 0 10px 16px;
  justify-content: flex-end;
}

.btn-footer-left:hover,
.btn-footer-right:hover {
  color: var(--ink-primary);
}

.btn-footer-left:active,
.btn-footer-right:active {
  opacity: 0.6;
}

.btn-block-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'Anuphan', sans-serif;
  font-size: 15px;
  font-weight: 600;
  background: var(--ink);
  color: var(--bg);
  padding: 12px 24px;
  width: 100%;
  min-height: 48px;
  border-radius: 100px;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .15s ease;
}

.btn-block-primary:hover {
  opacity: .9;
}

.btn-block-primary:active {
  opacity: .8;
}

.btn-twin-gray {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'Anuphan', sans-serif;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  background: var(--btn-bg);
  color: var(--ink-primary);
  padding: 10px 24px;
  min-height: 40px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 200ms ease, color 200ms ease;
}

.btn-twin-gray:hover {
  background: var(--ink);
  color: #fff;
}

.btn-twin-gray:active {
  opacity: 0.85;
}

.btn-block-primary:disabled,
.btn-twin-gray:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.reveal-twin-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: var(--s-3);
}

.btn-twin-narrow {
  width: 33.33%;
  min-width: 120px;
  font-size: 11px;
  padding: 10px 12px;
}

/* ==========================================================================
   INITIALIZATION LOADING OVERLAY
   ========================================================================== */
#js-loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
  transition: opacity 0.5s ease;
}

.loader {
  width: 40px;
  height: 20px;
  background: var(--ink);
  position: relative;
  animation: l9-0 1.5s infinite linear;
}

.loader:before,
.loader:after {
  content: "";
  position: absolute;
  background: inherit;
  bottom: 100%;
  width: 50%;
  height: 100%;
  animation: inherit;
  animation-name: l9-1;
}

.loader:before {
  left: 0;
  transform-origin: bottom left;
  --s: -1;
}

.loader:after {
  right: 0;
  transform-origin: bottom right;
  --s: 1;
}

@keyframes l9-0 {

  0%,
  10% {
    transform: translateY(0%) scaleY(1);
  }

  49.99% {
    transform: translateY(-50%) scaleY(1);
  }

  50% {
    transform: translateY(-50%) scaleY(-1);
  }

  90%,
  100% {
    transform: translateY(-100%) scaleY(-1);
  }
}

@keyframes l9-1 {
  10% {
    background: var(--accent);
    border-radius: 0%;
  }

  30% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(calc(var(--s, 1) * 180deg));
  }

  90% {
    border-radius: 0%;
    background: var(--accent);
  }
}

/* ==========================================================================
   APP SHELL & SCREEN ROUTER STATES
   ========================================================================== */
#app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 360ms ease, transform 360ms ease;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* ==========================================================================
   GLOBAL PROGRESS GRAPHICS
   ========================================================================== */
#progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: rgba(33, 32, 38, 0.06);
  z-index: 50;
  pointer-events: none;
}

#progress-bar .fill {
  height: 100%;
  background: var(--ink);
  width: 0%;
  transition: width 480ms cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-counter {
  display: none !important;
  position: fixed;
  top: 14px;
  right: 22px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink-43);
  font-variant-numeric: tabular-nums;
  z-index: 50;
  opacity: 0;
  transition: opacity 360ms ease;
}

.progress-counter.show {
  opacity: 1;
}

/* ==========================================================================
   SCREEN 1: WELCOME VIEW
   ========================================================================== */
.welcome-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: var(--s-8) clamp(var(--s-6), 5vw, var(--s-12));
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

/* Welcome screen: scroll only when its content is taller than the viewport */
#welcome-screen {
  height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  scrollbar-width: none;
}

#welcome-screen::-webkit-scrollbar {
  display: none;
}

#welcome-screen .welcome-inner {
  flex: 0 0 auto !important;
  min-height: 100%;
}

/* ==========================================================================
   SCREEN 2: SURVEY QUESTION STACKING FRAMEWORK
   ========================================================================== */
.question-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: clamp(28px, 4vh, 40px) 0 var(--s-6) 0;
  padding-top: 24px !important;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  overflow: hidden;
}

.q-top-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(var(--s-5), 4vw, var(--s-8));
  flex-shrink: 0;
}

.sound-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--ink-tertiary);
  padding: 6px 2px;
}

.sound-toggle.muted {
  color: var(--faint-fill);
  opacity: .7;
}

.q-slider-window {
  width: 100%;
  overflow: hidden;
  flex: 1;
  position: relative;
}

.q-slider-track {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transition: transform 420ms ease-out;
}

.q-slide {
  position: absolute;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 0 clamp(var(--s-5), 4vw, var(--s-8));
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.q-slide::-webkit-scrollbar {
  display: none;
}

.q-cardinality {
  display: inline-block;
   font-size: 16px; 
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--accent);
  margin: var(--s-4) 0 var(--s-2);
}

.q-text {
   margin-top: 12px;    
  margin-bottom: 24px;  
  max-width: 24ch;
}

.q-hint {
  color: var(--ink-tertiary);
  margin-bottom: var(--s-6);
}

.q-auto-hint {
  color: var(--ink-tertiary);
  opacity: .7;
}

.options {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  margin-bottom: var(--s-6);
  width: 100%;
}

.q-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding: var(--s-4) clamp(var(--s-5), 4vw, var(--s-8)) 0 var(--s-8);
  flex-shrink: 0;
}

.btn-text-nav {
  background: none;
  border: none;
  font-family: 'Anuphan', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-tertiary);
  cursor: pointer;
  padding: 10px 0;
}

.btn-text-nav:hover {
  color: var(--ink-primary);
}

.btn-text-nav:disabled {
  opacity: .3;
  pointer-events: none;
}

.btn-next-filled {
  background: var(--ink);
  color: var(--bg);
  border: none;
  border-radius: 100px;
  font-family: 'Anuphan', sans-serif;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 24px;
  min-width: 160px;
  text-align: center;
  cursor: pointer;
  transition: opacity .15s;
}

.btn-next-filled:hover {
  opacity: .9;
}

.btn-next-filled:active {
  opacity: .8;
}

/* ==========================================================================
   SCREEN 3: GEOGRAPHIC DRAWING CANVAS INTERFACE
   ========================================================================== */
.map-screen {
  padding: 0;
}

.map-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: clamp(28px, 3.5vh, 40px) var(--s-6) var(--s-2);
  background: var(--bg);
  z-index: 10;
  pointer-events: none;
}

#map {
  inset: clamp(112px, 13vh, 150px) 0 clamp(64px, 8vh, 92px) 0;
  flex: 1;
  width: 100%;
  background: var(--bg);
  position: relative;
  touch-action: pinch-zoom;
  z-index: 1;
}

.leaflet-container {
  background: var(--bg) !important;
  font-family: 'Anuphan', sans-serif !important;
}

.leaflet-tile-pane {
  filter: grayscale(1) contrast(0.9) brightness(1.02);
}

#draw-overlay {
  position: absolute;
  inset: clamp(112px, 13vh, 150px) 0 clamp(64px, 8vh, 92px) 0;
  z-index: 5;
  cursor: crosshair;
  touch-action: none;
}

#draw-svg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  width: 100%;
  height: 100%;
}

/* Pencil-line Aesthetic Layers (Graphite-on-paper feeling) */
.draw-stroke-underlay {
  fill: rgba(212, 36, 36, 0.08);
  stroke: none;
}

.draw-stroke-main {
  fill: none;
  stroke: rgba(212, 36, 36, 0.88);
  stroke-width: 3.6;
  stroke-opacity: 1;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.draw-closing-chord {
  fill: none;
  stroke: rgba(33, 32, 38, 0.82);
  stroke-width: 2.0;
  stroke-dasharray: 2 5;
  stroke-linecap: round;
}

.draw-closing-chord.closing-snap {
  animation: chord-to-red 380ms cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

.map-guide-compact {
  margin-top: 10px;
  color: var(--ink-tertiary);
  font-family: 'Anuphan', sans-serif;
  font-size: 12px;
  line-height: 1.65;
}

.map-guide-compact strong {
  color: var(--ink-secondary);
  font-weight: 600;
}

@keyframes chord-to-red {
  0% {
    stroke: rgba(33, 32, 38, 0.5);
    stroke-dasharray: 6 5;
  }

  60% {
    stroke: rgba(212, 36, 36, 0.7);
    stroke-dasharray: 12 2;
  }

  100% {
    stroke: #d42424;
    stroke-dasharray: 1 0;
    stroke-opacity: 0.9;
  }
}

.live-stroke {
  fill: rgba(212, 36, 36, 0.06);
  stroke: #d42424;
  stroke-width: 2.2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.map-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--s-4) var(--s-6) clamp(var(--s-4), 3vh, var(--s-8));
  background: var(--bg);
  display: flex;
  justify-content: space-between;
  gap: var(--s-3);
  align-items: center;
  z-index: 10;
}

.map-hint {
  pointer-events: none;
}

.map-hint.has-poly {
  color: var(--accent);
}

/* ==========================================================================
   SCREEN 4: REVEAL SCREEN CONTINUOUS NARRATIVE FEED
   ========================================================================== */
.reveal-screen {
  padding: 0;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

.reveal-feed-container {
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  padding: clamp(60px, 8vh, 100px) var(--s-6) 120px var(--s-6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(48px, 6vh, 64px);
}

.reveal-widget-card {
  width: 100%;
  background: transparent;
  border: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.reveal-widget-card.with-divider {
  border-top: 1px solid rgba(33, 32, 38, 0.15);
  padding-top: clamp(40px, 5vh, 56px);
}

/* Module 1: Concentric Flower Geometry Container */
.flower-placeholder {
  width: 100%;
  aspect-ratio: 1;
  max-width: 320px;
  margin: var(--s-4) auto 0;
}

.flower-placeholder svg {
  width: 100%;
  height: 100%;
}

.flower-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px 24px;
  margin: var(--s-5) auto 0;
  max-width: 360px;
}

.flower-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.flower-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.flower-legend-label {
  font-family: 'Anuphan', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
  line-height: 1.3;
}

.slip-advice-divider {
  width: 48px;
  height: 1px;
  background: rgba(33, 32, 38, 0.15);
  margin: var(--s-6) auto;
}

/* Module 3: Radar Chart Vector Geometry Wrapper */
.radar-container {
  width: 100%;
  max-width: 300px;
  aspect-ratio: 1;
  margin: 0 auto;
}

.radar-container svg {
  width: 100%;
  height: 100%;
}

/* Module 4: Lynch Mental Map Bars Layout */
.lynch-bars {
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  text-align: left;
}

.lynch-item-block {
  width: 100%;
  margin-bottom: var(--s-5);
}

.lynch-item-block:last-child {
  margin-bottom: 0;
}

.lynch-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--s-2);
}

.lynch-bar-track {
  position: relative;
  height: 7px;
  background-color: rgba(33, 32, 38, 0.08);

}

.lynch-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background-color: var(--ink);
  border-radius: 999px;
  transition: width 800ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* Module 5: Control Hub Action Layouts */
.feed-actions-zone {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-4);
  padding-top: var(--s-4);
  border-top: 1px solid rgba(33, 32, 38, 0.15);
}

/* Module 4A: Lynch Sketch Map */
.lynch-map-container {
  width: min(100%, 620px);
  max-width: none;
  aspect-ratio: 1.5;
  margin: var(--s-2) auto 0;
}

.lynch-map-container svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.lynch-map-area {
  fill: none;
  stroke: none;
}

.lynch-map-boundary {
  fill: none;
  stroke: rgba(33, 32, 38, 0.95);
  stroke-width: 5.2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.lynch-map-edge {
  fill: none;
  stroke: rgba(33, 32, 38, 0.95);
  stroke-width: 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.lynch-map-path {
  fill: none;
  stroke: rgba(33, 32, 38, 0.95);
  stroke-width: 6.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.lynch-map-node {
  fill: var(--accent-blue);
  fill-opacity: 0.82;
  stroke: none;
}

.lynch-map-landmark {
  fill: var(--accent-gold);
  fill-opacity: 0.82;
}

.lynch-map-road {
  fill: none;
  stroke: rgba(33, 32, 38, 0.95);
  stroke-width: 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ==========================================================================
   ANIMATIONS & CAPTURED INTERSECTION TARGETS
   ========================================================================== */
.bloom-petal {
  transform-origin: 50% 50%;
  opacity: 0;
  animation: bloom 1200ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-play-state: paused;
}

.reveal-widget-card.is-visible .bloom-petal {
  animation-play-state: running;
}

.flower-dot {
  transform-origin: center;
  transform-box: fill-box;
}

@keyframes bloom {
  0% {
    opacity: 0;
    transform: scale(0.2);
  }

  60% {
    opacity: 0.85;
  }

  100% {
    opacity: var(--final-op, 0.95);
    transform: scale(1);
  }
}

/* Gallery bloom — same keyframes, shorter (700ms) and paused until card enters viewport.
   `.gallery-bloomed` is added by IntersectionObserver in gallery.js exactly once per card. */
.gallery-petal {
  transform-origin: 50% 50%;
  transform-box: fill-box;
  opacity: 0;
  animation: bloom 700ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-play-state: paused;
}

.gallery-card-item.gallery-bloomed .gallery-petal {
  animation-play-state: running;
}

.reveal-widget-card .lynch-bar-fill {
  width: 0 !important;
}

.reveal-widget-card.is-visible .lynch-bar-fill {
  width: var(--bar-width, 0) !important;
}

/* Gallery sticky footer — mobile-app-style bottom bar.
   Two-layer structure: an outer band that handles the sticky positioning and safe-area
   inset (no background, no border — it's invisible), and an inner wrapper that
   matches the gallery feed width (440px) and carries the top divider. The divider
   therefore reads as a continuation of the widget separators in the reveal screen
   (same `rgba(33, 32, 38, 0.15)` 1px line), not as a banner across the whole page.

   Why sticky, not fixed: `.screen` uses CSS transforms for its enter/exit animation,
   which creates a new containing block and breaks `position: fixed`. Sticky pins to
   the bottom of the scrollable `.reveal-screen` container, which behaves correctly. */
.gallery-sticky-footer {
  position: sticky;
  bottom: 0;
  z-index: 50;
  width: 100%;
  margin-top: auto;
  background: var(--bg-primary, #FCFCFA);
  /* Bottom padding is just enough for iOS home indicator. No top padding —
     the inner wrapper provides its own breathing room above the button. */
  padding: 0 0 env(safe-area-inset-bottom, 0px) 0;
}

.gallery-sticky-footer-inner {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 16px var(--s-5, 16px);
  border-top: 1px solid rgba(33, 32, 38, 0.15);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}

.gallery-footer-back,
.gallery-footer-more {
  flex: 0 0 auto;
  min-width: 120px;
  max-width: 180px;
}

.gallery-footer-more {
  margin-left: auto;
}

/* ==========================================================================
   RESPONSIVE MEDIA LAYER QUERIES
   ========================================================================== */
@media (max-width: 480px) {
  .welcome-inner {
    padding-left: var(--s-5);
    padding-right: var(--s-5);
  }

  .q-top-meta,
  .q-slide {
    padding-left: var(--s-5);
    padding-right: var(--s-5);
  }

  .q-footer {
    padding-left: var(--s-5);
    padding-right: var(--s-5);
  }

  .map-header {
    padding-left: var(--s-5);
    padding-right: var(--s-5);
  }

  .map-footer {
    padding-left: var(--s-5);
    padding-right: var(--s-5);
  }

  .reveal-feed-container {
    padding-left: var(--s-5);
    padding-right: var(--s-5);
    gap: 44px;
  }

  .reveal-widget-card.with-divider {
    padding-top: 40px;
  }
}

@media (min-width: 600px) {

  .welcome-inner,
  .question-inner {
    max-width: 540px;
    padding: var(--s-10) var(--s-8);
  }

  .reveal-feed-container {
    max-width: 540px;
    padding: var(--s-10) var(--s-8);
    margin: 0 auto;
  }

  .reveal-screen {
    padding: var(--s-8) var(--s-4) !important;
  }

  /* Gallery screen needs to override the vertical padding from `.reveal-screen` above so
     the sticky footer can sit flush against the browser bottom edge. The feed container
     inside still gets its own top padding, and the footer carries its own safe-area inset,
     so nothing visual is lost — we just remove the dead space the screen-level padding was
     adding below the scroll content. */
  [data-screen="gallery"].reveal-screen {
    padding: 0 !important;
  }

  .btn-welcome-fluid {
    width: 33.33% !important;
    min-width: 140px;
  }
}

/* ---- v2 app helpers (single-page flow) ---- */
.screen-fill {
  height: 100dvh;
  display: flex;
  flex-direction: column
}

.q-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0 clamp(var(--s-5), 4vw, var(--s-8))
}

.q-scroll::-webkit-scrollbar {
  width: 0
}

.ml-reveal {
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch
}

.opt-letter {
  min-width: 16px
}

/* --- district: M3 searchable dropdown --- */
.dd {
  position: relative;
  width: 100%
}

.dd-field {
  position: relative;
  display: flex;
  align-items: center;
  border: 1px solid var(--faint-fill);
  border-radius: 12px;
  background: transparent;
  transition: border-color .15s
}

.dd.open .dd-field,
.dd-field:focus-within {
  border-color: var(--ink-primary)
}

.dd-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-family: 'Anuphan', sans-serif;
  font-size: 18px;
  font-weight: 500;
  color: var(--ink-primary);
  padding: 16px var(--s-5)
}

.dd-input::placeholder {
  color: var(--ink-tertiary);
  font-weight: 400
}

.dd-caret {
  padding-right: var(--s-5);
  color: var(--ink-tertiary);
  pointer-events: none;
  transition: transform .15s
}

.dd.open .dd-caret {
  transform: rotate(180deg)
}

.dd-list {
  list-style: none;
  margin: var(--s-2) 0 0;
  padding: var(--s-2);
  max-height: 46vh;
  overflow-y: auto;
  display: none;
  border: 1px solid var(--faint-fill);
  border-radius: 12px;
  background: var(--bg);
  box-shadow: 0 8px 28px rgba(33, 32, 38, .10)
}

.dd.open .dd-list {
  display: block
}

.dd-list::-webkit-scrollbar {
  width: 0
}

.dd-item {
  padding: 14px var(--s-4);
  border-radius: 8px;
  font-family: 'Anuphan', sans-serif;
  font-size: 18px;
  font-weight: 500;
  color: var(--ink-primary);
  cursor: pointer
}

.dd-item:hover {
  background: rgba(33, 32, 38, .04)
}

.dd-item.sel {
  background: var(--ink);
  color: var(--bg)
}

/* open-text question */
.open-input {
  width: 100%;
  border: 1px solid var(--faint-fill);
  border-radius: 12px;
  background: transparent;
  outline: none;
  font-family: 'Anuphan', sans-serif;
  font-size: 18px;
  font-weight: 500;
  line-height: 1.6;
  color: var(--ink-primary);
  padding: 16px var(--s-5);
  resize: none
}

.open-input:focus {
  border-color: var(--ink-primary)
}

.open-input::placeholder {
  color: var(--ink-tertiary);
  font-weight: 400
}

/* consent notice + credits (restrained) */
.welcome-consent {
  max-width: 42ch;
  font-size: 14px;
  font-weight: 400;
  color: var(--ink);
  line-height: 1.65;
  margin: 0 0 var(--s-8)
}

.welcome-credit {
  font-size: 14px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  line-height: 1.5;
  color: rgba(33, 32, 38, .6);
  opacity: 1;
  margin: 0
}

.reveal-credit {
  color: var(--ink-tertiary);
  opacity: .7;
  margin-top: var(--s-4);
  text-align: center;
  width: 100%
}

/* legend — one row per mark: glyph + role-overline + value */
.legend-list {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 360px;
  margin-top: var(--s-6);
  text-align: left
}

.lg-row {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-3) 0;
  border-top: 1px solid var(--sys-rule, #ececea)
}

.lg-row:first-child {
  border-top: none
}

.lg-glyph {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center
}

.lg-mark {
  width: 40px;
  height: 40px;
  display: block
}

.lg-chip {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%
}

.lg-chip-lg {
  width: 22px;
  height: 22px
}

.lg-bands {
  display: flex;
  flex-direction: column;
  gap: 3px
}

.lg-bands .lg-chip {
  width: 22px;
  height: 6px;
  border-radius: 2px
}

.lg-txt {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0
}

.lg-txt .lg-k {
  color: var(--ink-tertiary);
  letter-spacing: .05em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700
}

.lg-txt .lg-v {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink-primary);
  line-height: 1.3
}

.lg-muted {
  color: var(--ink-tertiary)
}

/* reveal page header (session title first, then sub-sections) */
/* cascade: blocks rise + fade in as they scroll into view (modular) */
.reveal-block {
  transition: opacity .55s ease, transform .55s cubic-bezier(0.22, 1, 0.36, 1)
}

.reveal-block.pre-reveal {
  opacity: 0;
  transform: translateY(18px)
}

.reveal-page-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s-2);
  padding: var(--s-8) var(--s-5) var(--s-4);
  max-width: 520px;
  margin: 0 auto;
  width: 100%
}

.reveal-page-title {
  margin: 0
}

.reveal-page-sub {
  color: var(--ink-tertiary);
  margin: 0
}

.legend-head {
  margin-top: var(--s-7);
  align-self: flex-start
}

.reveal-center {
  align-self: center
}

.reveal-subhead {
  text-align: center;
  width: 100%;
  color: var(--ink-tertiary);
  margin: 0 0 var(--s-4)
}

.btn-restart {
  text-transform: none
}

.av-wrap {
  width: min(82vw, 340px);
  margin: var(--s-4) auto 0
}

.av-wrap canvas {
  width: 100%;
  height: auto;
  display: block
}

#radar-canvas {
  width: 100%;
  max-width: 420px;
  height: 380px;
  display: block;
  margin: 0 auto
}

.slip-radar {
  margin: var(--s-6) auto var(--s-4)
}