/* Night river, candlelight. Two families: Trirong (display, Thai + Latin) and Anuphan (UI, Thai + Latin).
   Body scale is locked to three steps; the hero title and the ceremony wish are display moments. */
:root {
  --bg: #050714;
  --ink: #f4eee2;
  --ink-dim: rgba(244, 238, 226, .74);
  --accent: #f4b860;
  --accent-ink: #2a1604;
  --surface: #0a0c1b;
  --r: 4px;
  --surface-hi: rgba(255, 255, 255, .06);
  --line: rgba(255, 255, 255, .13);
  --line-hi: rgba(244, 184, 96, .7);
  --display: "Trirong", Georgia, serif;
  --body: "Anuphan", system-ui, sans-serif;
  --t-sm: 13px;
  --t-body: 16px;
  --t-lg: 20px;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --fast: .18s;
  --sheet-w: 0px;
  --sheet-h: 0px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: var(--t-body); font-weight: 400; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
::selection { background: rgba(244, 184, 96, .35); color: #fff; }
input, textarea { caret-color: var(--accent); }
* { scrollbar-width: thin; scrollbar-color: rgba(244, 238, 226, .25) transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

canvas#gl { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; touch-action: none; outline: none; }
/* quiet shading so type always sits on darkness, never on a bright reflection */
.veil { position: fixed; inset: 0; pointer-events: none; z-index: 1; opacity: 0; transition: opacity 1.2s var(--ease);
  background: radial-gradient(110% 62% at 50% 16%, rgba(4, 5, 16, .55), rgba(4, 5, 16, 0) 64%), linear-gradient(rgba(4, 5, 16, .55), rgba(4, 5, 16, 0) 90px); }
[data-mode="intro"] .veil, [data-mode="build"] .veil { opacity: 1; }
[data-mode="build"] .veil { background: linear-gradient(rgba(4, 5, 16, .6), rgba(4, 5, 16, 0) 110px); }
[data-mode="river"] .veil { opacity: 1; background: linear-gradient(rgba(4, 5, 16, .45), rgba(4, 5, 16, 0) 90px), linear-gradient(0deg, rgba(4, 5, 16, .7), rgba(4, 5, 16, 0) 150px); }
[data-mode="float"] .veil { opacity: .85; }

.ui { position: fixed; z-index: 2; }

/* ---------- loader ---------- */
#loader { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 16px; z-index: 9; color: var(--ink-dim); font-size: var(--t-body); background: var(--bg); transition: opacity 1.4s var(--ease), visibility 1.4s; }
html:not([data-mode="loading"]) #loader { opacity: 0; visibility: hidden; pointer-events: none; }
.flame { width: 14px; height: 26px; border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%; background: radial-gradient(circle at 50% 70%, #fff7d6 0 22%, #ffc15a 45%, rgba(255, 120, 30, 0) 72%); animation: flick 1.6s ease-in-out infinite; }
@keyframes flick { 0%, 100% { transform: scale(1, 1) } 40% { transform: scale(.92, 1.08) } 70% { transform: scale(1.05, .95) } }

/* ---------- header ---------- */
.top { top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: max(14px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left)); pointer-events: none; z-index: 4; transition: opacity .6s var(--ease); }
.top > * { pointer-events: auto; }
[data-mode="float"] .top { opacity: 0; }
[data-mode="float"] .top > * { pointer-events: none; }
.brand { display: flex; gap: 10px; align-items: baseline; white-space: nowrap; }
.brand .th { font-family: var(--display); font-weight: 500; font-size: 24px; color: var(--ink); letter-spacing: -.01em; }
.brand .for { font-size: var(--t-sm); color: var(--ink-dim); }
.controls { display: flex; gap: 10px; align-items: center; }

/* language and sound: plain text controls on the night, no containers */
.seg { display: inline-flex; align-items: center; gap: 2px; }
.seg button, .switch { border: 0; background: none; cursor: pointer; padding: 8px 6px; font-size: var(--t-sm); color: var(--ink-dim); text-shadow: 0 1px 8px rgba(0, 0, 0, .8); text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 5px; text-decoration-thickness: 1px; transition: color var(--fast) var(--ease), text-decoration-color var(--fast) var(--ease); }
.seg button + button::before { content: "/"; margin-right: 8px; color: rgba(244, 238, 226, .3); display: inline-block; text-decoration: none; }
.seg button[aria-checked="true"] { color: var(--ink); text-decoration-color: var(--accent); }
.seg button:hover, .switch:hover { color: var(--ink); }
.controls { gap: 14px; }
.switch i { display: none; }
.switch::after { content: attr(data-state); margin-left: 5px; color: var(--ink-dim); }
.switch[aria-checked="true"] { color: var(--ink); }
.switch[aria-checked="true"]::after { color: var(--accent); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; border: 0; cursor: pointer; padding: 13px 24px; border-radius: var(--r); font-size: var(--t-body); font-weight: 500; text-decoration: none; white-space: nowrap; transition: transform var(--fast) var(--ease), background-color var(--fast) var(--ease); }
.btn:active { transform: scale(.97); }
.btn.primary { color: var(--accent-ink); background: var(--accent); }
.btn.primary:hover { background: #f8c77d; }
.btn.primary:disabled { opacity: .7; cursor: progress; }
.quiet { border: 0; background: none; cursor: pointer; padding: 12px 6px; font-size: var(--t-body); color: var(--ink-dim); text-decoration: underline; text-decoration-color: rgba(244, 238, 226, .3); text-underline-offset: 4px; transition: color var(--fast) var(--ease), text-decoration-color var(--fast) var(--ease); }
.quiet:hover { color: var(--ink); text-decoration-color: var(--ink); }

/* ---------- modes ---------- */
#intro, #builder .sheet, #builder .stagectl, #riverbar, #wishshow { opacity: 0; pointer-events: none; visibility: hidden; transition: opacity .5s var(--ease), transform .5s var(--ease), visibility 0s linear .5s; }
[data-mode="intro"] #intro,
[data-mode="build"] #builder .sheet, [data-mode="build"] #builder .stagectl,
[data-mode="river"] #riverbar,
[data-mode="float"] #wishshow.show { opacity: 1; pointer-events: auto; visibility: visible; transform: none; transition: opacity .8s var(--ease) .15s, transform .8s var(--ease) .15s, visibility 0s; }
[data-mode="float"] #wishshow.show { transition: opacity 1.4s var(--ease), transform 1.4s var(--ease), visibility 0s; }

/* ---------- intro ---------- */
#intro { left: 50%; top: 13vh; translate: -50% 0; transform: translateY(14px); width: min(900px, calc(100vw - 32px)); text-align: center; }
h1 { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(60px, 10.5vw, 132px); line-height: .92; letter-spacing: -.035em; text-shadow: 0 2px 30px rgba(0, 0, 0, .45); }
h1 small { display: block; margin-top: 14px; font-size: var(--t-lg); line-height: 1.2; letter-spacing: 0; color: var(--accent); }
html[lang="th"] h1 { letter-spacing: -.01em; line-height: 1.1; }
.lede { max-width: 30em; margin: 24px auto 0; color: var(--ink); line-height: 1.55; font-size: var(--t-body); text-shadow: 0 1px 14px rgba(0, 0, 0, .9); text-wrap: balance; }
.actions { display: flex; justify-content: center; margin-top: 22px; }
.count { margin: 8px 0 0; min-height: 1.4em; font-size: var(--t-sm); color: var(--ink-dim); font-variant-numeric: tabular-nums; text-shadow: 0 1px 10px rgba(0, 0, 0, .8); }

/* ---------- builder ---------- */
#builder { inset: 0; pointer-events: none; }
.sheet { position: absolute; top: 0; right: 0; bottom: 0; width: min(420px, 40vw); padding: 70px 26px 0; background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto; transform: translateX(24px); display: flex; flex-direction: column; }
.sheet .step { display: flex; flex-direction: column; }
.sheet .row { position: sticky; bottom: 0; margin: auto -26px 0; padding: 18px 26px 24px; background: linear-gradient(rgba(10, 12, 27, 0), var(--surface) 30%); }
.steps { list-style: none; display: flex; gap: 22px; padding: 0 0 12px; margin: 0; border-bottom: 1px solid var(--line); font-size: var(--t-sm); color: var(--ink-dim); }
.steps li { position: relative; }
.steps li.on { color: var(--ink); }
.steps li.on::after { content: ""; position: absolute; left: 0; right: 0; bottom: -13px; height: 2px; background: var(--accent); }
.step h3 { margin: 18px 0 8px; font-size: var(--t-sm); font-weight: 500; color: var(--ink-dim); }

/* choices: radio groups drawn as thumbnails, no boxes */
.opts { display: grid; gap: 8px 6px; }
.opts.bases { grid-template-columns: repeat(4, 1fr); }
.opts.petals { grid-template-columns: repeat(6, 1fr); }
.opts.flowers { grid-template-columns: repeat(5, 1fr); }
.opt { position: relative; border: 0; background: none; padding: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.opt canvas { width: 100%; aspect-ratio: 1; display: block; border-radius: var(--r); background: var(--surface-hi); box-shadow: 0 0 0 1px var(--line); transition: box-shadow var(--fast) var(--ease), transform var(--fast) var(--ease); }
.opt:hover canvas { transform: translateY(-1px); box-shadow: 0 0 0 1px rgba(255, 255, 255, .3); }
.opt[aria-checked="true"] canvas { box-shadow: 0 0 0 2px var(--accent); }
.opt canvas:not([width]) { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4 } }
.opt small { font-size: var(--t-sm); color: var(--ink-dim); text-align: center; line-height: 1.2; min-height: 2.4em; transition: color var(--fast) var(--ease); }
.opt[aria-checked="true"] small { color: var(--ink); }
.petals .opt small { display: none; }
.petals .opt::after { content: ""; width: 14px; height: 2px; background: var(--sw); opacity: .5; transition: opacity var(--fast) var(--ease); }
.petals .opt[aria-checked="true"]::after { opacity: 1; }

label { display: block; margin-top: 18px; font-size: var(--t-sm); font-weight: 500; color: var(--ink-dim); position: relative; }
input, textarea { display: block; width: 100%; margin-top: 8px; padding: 12px 14px; border-radius: var(--r); border: 1px solid var(--line); background: rgba(255, 255, 255, .03); font-family: var(--body); font-size: var(--t-body); font-weight: 400; color: var(--ink); resize: none; outline: none; transition: border-color var(--fast) var(--ease); }
textarea { padding-bottom: 28px; }
input::placeholder, textarea::placeholder { color: rgba(244, 238, 226, .45); }
input:focus, textarea:focus { border-color: var(--line-hi); }
.left { position: absolute; right: 12px; bottom: 9px; font-size: var(--t-sm); font-variant-numeric: tabular-nums; color: var(--ink-dim); font-style: normal; font-weight: 400; }
.err { color: #ffb4a0; font-size: var(--t-sm); margin: 12px 0 0; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.row .btn.primary { flex: 1; }

.stagectl { position: absolute; left: calc((100vw - var(--sheet-w)) / 2); bottom: 28px; translate: -50% 0; transform: translateY(10px); display: flex; align-items: center; gap: 18px; }
.drag { margin: 0; font-size: var(--t-sm); color: var(--ink-dim); text-shadow: 0 1px 10px rgba(0, 0, 0, .9); }
.stagectl .quiet { font-size: var(--t-sm); padding: 8px 4px; color: var(--ink); text-shadow: 0 1px 10px rgba(0, 0, 0, .9); }

/* ---------- the float: the wish, big ---------- */
#wishshow { left: 50%; top: max(9vh, 64px); translate: -50% 0; transform: translateY(18px); width: min(860px, calc(100vw - 36px)); text-align: center; cursor: pointer; }
#wishshow::before { content: ""; position: absolute; inset: -18% -14% -22%; z-index: -1; background: radial-gradient(closest-side, rgba(3, 4, 16, .72), rgba(3, 4, 16, .42) 55%, rgba(3, 4, 16, 0)); pointer-events: none; }
.ws-name { margin: 0; font-family: var(--display); font-weight: 500; font-size: clamp(22px, 2.6vw, 30px); color: var(--accent); text-shadow: 0 2px 16px rgba(0, 0, 0, .8); }
.ws-wish { margin: 14px auto 0; max-width: 22ch; font-family: var(--display); font-weight: 400; font-size: clamp(32px, 5.2vw, 64px); line-height: 1.12; letter-spacing: -.02em; color: #fffaf0; text-wrap: balance; overflow-wrap: anywhere; text-shadow: 0 2px 24px rgba(0, 0, 0, .85); }
.ws-wish.m { font-size: clamp(26px, 3.6vw, 44px); max-width: 28ch; }
.ws-wish.l { font-size: clamp(21px, 2.6vw, 32px); max-width: 36ch; line-height: 1.3; letter-spacing: -.01em; }
html[lang="th"] .ws-wish, .ws-wish.thai { line-height: 1.4; letter-spacing: 0; }
.ws-wish::before, .ws-wish::after { color: var(--accent); opacity: 0; transition: opacity 1s var(--ease) .5s; }
#wishshow.show .ws-wish::before, #wishshow.show .ws-wish::after { opacity: .8; }
.ws-wish::before { content: "“"; } .ws-wish::after { content: "”"; }
.ws-wish .w { display: inline-block; opacity: 0; filter: blur(6px); transform: translateY(10px); transition: opacity 1.1s var(--ease), filter 1.1s var(--ease), transform 1.1s var(--ease); transition-delay: calc(var(--i) * 70ms + .5s); max-width: 100%; }
#wishshow.show .ws-wish .w { opacity: 1; filter: none; transform: none; }
.ws-name, .ws-nth { opacity: 0; transform: translateY(8px); transition: opacity 1.2s var(--ease), transform 1.2s var(--ease); }
#wishshow.show .ws-name { opacity: 1; transform: none; transition-delay: .2s; }
#wishshow.show .ws-nth { opacity: 1; transform: none; transition-delay: var(--nth-delay, 2s); }
.ws-nth { margin: 24px 0 0; font-size: var(--t-body); color: var(--ink); text-shadow: 0 1px 12px rgba(0, 0, 0, .9); }
.ws-skip { margin: 18px 0 0; font-size: var(--t-sm); color: var(--ink-dim); opacity: 0; transition: opacity 1s var(--ease) 6s; text-shadow: 0 1px 10px rgba(0, 0, 0, .9); }
#wishshow.show .ws-skip { opacity: 1; }

/* ---------- names over krathongs ---------- */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
.tag { position: absolute; left: 0; top: 0; translate: -50% -100%; display: flex; flex-direction: column; align-items: center; padding: 0 0 20px; border: 0; background: none; color: var(--ink); white-space: nowrap; will-change: transform; transition: opacity .5s var(--ease); text-shadow: 0 0 6px rgba(4, 5, 16, .95), 0 1px 14px rgba(4, 5, 16, .9); }
.tag::after { content: ""; position: absolute; left: 50%; bottom: 0; width: 1px; height: 16px; background: linear-gradient(var(--accent), rgba(244, 184, 96, 0)); }
.tag b { font-family: var(--display); font-weight: 500; font-size: var(--t-lg); line-height: 1.15; color: var(--accent); max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }
.tag small { font-size: var(--t-sm); line-height: 1.3; color: var(--ink); }
.tag.mine { pointer-events: auto; cursor: pointer; animation: tagIn 1.2s var(--ease); }
.tag.mine:hover small { text-decoration: underline; text-underline-offset: 3px; }
@keyframes tagIn { from { opacity: 0; } }
[data-mode="build"] #labels, [data-mode="float"] #marks { opacity: 0; }

#marks { position: absolute; inset: 0; transition: opacity .24s var(--ease); }
.mark { position: absolute; left: 0; top: 0; padding: 0; border: 0; background: none; cursor: pointer; pointer-events: auto; transform-origin: 0 0; will-change: transform; }
.mark::before { content: ""; position: absolute; left: -.5px; top: -18px; width: 1px; height: 16px; background: linear-gradient(rgba(244, 238, 226, .5), rgba(244, 238, 226, 0)); }
.mark span { position: absolute; bottom: 18px; left: 0; translate: -50% 0; display: block; padding: 2px 0; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis;
  font-size: var(--t-sm); line-height: 18px; color: var(--ink); text-shadow: 0 0 5px rgba(4, 5, 16, .95), 0 0 12px rgba(4, 5, 16, .9);
  text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; transition: color var(--fast) var(--ease), text-decoration-color var(--fast) var(--ease); }
.mark:hover span, .mark:focus-visible span { color: var(--accent); text-decoration-color: var(--accent); }
.mark:focus-visible { outline: none; }

/* the wish, opened in place above its krathong */
#peek { position: absolute; left: 0; top: 0; width: max-content; max-width: min(320px, calc(100vw - 24px)); padding: 14px 18px 18px; border-radius: var(--r); pointer-events: auto; cursor: default;
  background: var(--surface); border: 1px solid var(--line); will-change: transform; z-index: 2000;
  opacity: 0; scale: .96; transform-origin: var(--tip, 50%) 100%; transition: opacity .24s var(--ease), scale .24s var(--ease); }
#peek::after { content: ""; position: absolute; left: var(--tip, 50%); top: 100%; width: 1px; height: 16px; background: linear-gradient(rgba(244, 238, 226, .6), rgba(244, 238, 226, 0)); }
#peek.below::after { top: auto; bottom: 100%; height: 30px; background: linear-gradient(rgba(244, 238, 226, 0), rgba(244, 238, 226, .6)); }
#peek.show { opacity: 1; scale: 1; }
#peek.leaving { opacity: 0; scale: .97; }
#peek > p { opacity: 0; translate: 0 6px; }
#peek.show > p { animation: peekIn .36s var(--ease) forwards; }
#peek.show .pk-wish { animation-delay: .06s; }
#peek.show .pk-when { animation-delay: .12s; }
@keyframes peekIn { to { opacity: 1; translate: 0 0; } }
.pk-name { margin: 0 0 4px; font-size: var(--t-sm); font-weight: 500; color: var(--accent); overflow-wrap: anywhere; }
.pk-wish { margin: 0; font-family: var(--display); font-size: var(--t-lg); line-height: 1.38; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 42dvh; overflow-y: auto; }
.pk-when { margin: 8px 0 0; font-size: var(--t-sm); color: var(--ink-dim); }
.pk-life { position: absolute; left: 18px; right: 18px; bottom: 8px; height: 1px; background: rgba(244, 238, 226, .3); transform-origin: 0 50%; animation: life var(--life, 8s) linear forwards; }
#peek.held .pk-life { animation-play-state: paused; }
@keyframes life { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ---------- river bar ---------- */
#riverbar { left: 0; right: 0; bottom: 0; transform: translateY(12px); display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 16px; padding: 0 max(22px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left)); }
#riverbar .count { margin: 0; font-family: var(--display); font-size: var(--t-lg); color: var(--ink); white-space: nowrap; min-height: 0; }
#riverbar .hint { margin: 0 0 4px; font-size: var(--t-sm); color: var(--ink-dim); text-align: center; text-shadow: 0 1px 10px rgba(0, 0, 0, .9); }
#riverbar .btn { justify-self: end; }

/* ---------- toast ---------- */
#toast { left: 50%; top: max(66px, calc(env(safe-area-inset-top) + 56px)); transform: translate(-50%, -10px); opacity: 0; padding: 10px 16px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); font-size: var(--t-sm); transition: opacity .24s var(--ease), transform .24s var(--ease); pointer-events: none; max-width: calc(100vw - 32px); text-align: center; z-index: 5; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#nogl { inset: 0; display: grid; place-content: center; justify-items: center; gap: 18px; text-align: center; padding: 24px; font-family: var(--display); font-size: var(--t-lg); z-index: 10; background: var(--bg); }

/* ---------- phones ---------- */
@media (max-width: 760px) {
  .brand .th { font-size: 21px; }
  #intro { top: 12dvh; }
  .lede { max-width: 22em; }
  .sheet { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 54dvh; padding: 14px 16px 0; transform: translateY(40px); border-left: 0; border-top: 1px solid var(--line); }
  .sheet .row { margin: auto -16px 0; padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); }
  .step h3 { margin: 12px 0 6px; }
  .opts { gap: 6px 5px; }
  .opt { gap: 4px; }
  .opt small { min-height: 2.5em; }
  label { margin-top: 12px; }
  .stagectl { left: 50%; bottom: calc(var(--sheet-h) + 12px); }
  #riverbar { grid-template-columns: 1fr auto; gap: 10px 12px; padding: 0 16px max(16px, env(safe-area-inset-bottom)); }
  #riverbar .hint { grid-column: 1 / -1; grid-row: 1; margin: 0; }
  #riverbar .count { align-self: center; font-size: var(--t-body); white-space: normal; min-width: 0; }
  #riverbar .btn { padding: 11px 18px; }
  #wishshow { top: max(8dvh, 56px); }
  .ws-wish { font-size: clamp(28px, 8.4vw, 40px); }
  .ws-wish.m { font-size: clamp(23px, 6.2vw, 30px); }
  .ws-wish.l { font-size: clamp(18px, 4.8vw, 22px); }
}
@media (prefers-reduced-motion: reduce) {
  .ws-wish .w { transition-delay: 0s !important; }
  .flame, .opt canvas:not([width]) { animation: none; }
  #peek > p { animation-duration: .01s !important; }
}
