:root {
  --ink: #f6ead2;
  --ink-dim: rgba(246, 234, 210, 0.62);
  --gold: #f3c77a;
  --gold-deep: #d9913c;
  --glass: rgba(14, 14, 38, 0.46);
  --glass-strong: rgba(12, 12, 32, 0.72);
  --line: rgba(243, 199, 122, 0.22);
  --display: "Cormorant Garamond", "Charm", serif;
  --thai-display: "Charm", "Cormorant Garamond", serif;
  --body: "Noto Sans Thai", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #050714; color: var(--ink); font-family: var(--body); font-weight: 300; -webkit-font-smoothing: antialiased; }
html[lang="th"] { --display: "Charm", serif; }
button, input, textarea { font: inherit; color: inherit; }
canvas#sky, canvas#river { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; }
canvas#river { touch-action: manipulation; }

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

/* ---------- header ---------- */
.top { top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: max(14px, env(safe-area-inset-top)) 18px 0; pointer-events: none; }
.top > * { pointer-events: auto; }
.brand { font-family: var(--display); font-size: 17px; letter-spacing: 0.04em; color: var(--ink-dim); display: flex; gap: 8px; align-items: baseline; }
.brand .th { font-family: var(--thai-display); color: var(--gold); font-size: 20px; }
.controls { display: flex; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); padding: 7px 13px; border-radius: 999px; font-size: 13px; cursor: pointer; transition: border-color .3s, background .3s; }
.chip:hover { border-color: rgba(243, 199, 122, 0.5); }
.eq { display: inline-flex; gap: 2px; align-items: flex-end; height: 12px; }
.eq i { width: 2px; height: 3px; background: var(--gold); border-radius: 2px; transition: height .3s; }
#sound[aria-pressed="true"] .eq i { animation: eq 1.1s ease-in-out infinite; }
#sound[aria-pressed="true"] .eq i:nth-child(2) { animation-delay: -.4s; }
#sound[aria-pressed="true"] .eq i:nth-child(3) { animation-delay: -.8s; }
@keyframes eq { 0%,100% { height: 3px } 50% { height: 12px } }

/* ---------- buttons ---------- */
.btn { position: relative; border: 0; cursor: pointer; padding: 13px 26px; border-radius: 999px; font-size: 15px; letter-spacing: 0.02em; transition: transform .25s, box-shadow .3s, background .3s; }
.btn:active { transform: scale(0.97); }
.btn.primary { color: #2a1503; font-weight: 500; background: radial-gradient(120% 140% at 30% 20%, #ffe6b0 0%, #f3c77a 45%, #d9913c 100%); box-shadow: 0 0 0 1px rgba(255, 220, 160, .5) inset, 0 8px 30px rgba(243, 160, 70, .35), 0 0 60px rgba(243, 160, 70, .15); }
.btn.primary:hover { box-shadow: 0 0 0 1px rgba(255, 220, 160, .7) inset, 0 8px 40px rgba(243, 160, 70, .55), 0 0 80px rgba(243, 160, 70, .25); }
.btn.primary:disabled { filter: grayscale(.4) brightness(.8); cursor: progress; }
.btn.ghost { background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.btn.ghost:hover { border-color: rgba(243, 199, 122, .5); }

/* ---------- modes ---------- */
#intro, #builder, #riverbar { opacity: 0; pointer-events: none; transition: opacity .9s ease, transform .9s cubic-bezier(.2,.7,.2,1); }
[data-mode="intro"] #intro, [data-mode="build"] #builder, [data-mode="river"] #riverbar { opacity: 1; pointer-events: auto; transform: none; }

/* ---------- intro ---------- */
#intro { left: 50%; top: 13vh; transform: translate(-50%, 12px); width: min(640px, calc(100vw - 32px)); text-align: center; }
[data-mode="intro"] #intro { transform: translate(-50%, 0); }
.dedication { font-family: var(--display); font-style: italic; color: var(--gold); letter-spacing: .25em; text-transform: lowercase; font-size: 15px; margin: 0 0 6px; opacity: .9; }
h1 { margin: 0; font-family: var(--display); font-weight: 500; font-size: clamp(54px, 10vw, 104px); line-height: .95; letter-spacing: .01em; text-shadow: 0 0 40px rgba(255, 200, 120, .25); }
h1 small { display: block; font-family: var(--thai-display); font-size: .42em; color: var(--gold); margin-top: 10px; letter-spacing: .05em; }
html[lang="th"] h1 small { font-family: "Cormorant Garamond", serif; font-style: italic; }
.lede { max-width: 470px; margin: 22px auto 0; color: var(--ink-dim); line-height: 1.65; font-size: 15px; text-shadow: 0 1px 12px rgba(0,0,0,.8); }
.count { font-family: var(--display); font-size: 18px; color: var(--gold); margin: 18px 0 0; letter-spacing: .03em; min-height: 1.3em; }
.actions { display: flex; gap: 12px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }

/* ---------- builder ---------- */
#builder { inset: 0; display: grid; grid-template-columns: 1fr minmax(340px, 420px); background: radial-gradient(80% 60% at 35% 55%, rgba(5, 6, 20, 0.05), rgba(5, 6, 20, 0.6)); }
.stage { position: relative; display: grid; place-items: center; min-height: 0; }
#preview { width: min(62vh, 92%); aspect-ratio: 1 / 1.05; }
.repaint { position: absolute; bottom: 7%; left: 50%; transform: translateX(-50%); }
.dice { color: var(--gold); display: inline-block; transition: transform .6s; }
.repaint:hover .dice { transform: rotate(180deg); }
.sheet { margin: 76px 18px 18px 0; padding: 22px 22px 20px; background: var(--glass-strong); border: 1px solid var(--line); border-radius: 24px; backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2); overflow-y: auto; scrollbar-width: thin; align-self: start; max-height: calc(100dvh - 94px); }
.steps { list-style: none; display: flex; gap: 18px; padding: 0; margin: 0 0 14px; font-size: 13px; color: var(--ink-dim); }
.steps li { display: flex; align-items: center; gap: 8px; }
.steps li span { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); font-size: 11px; }
.steps li.on { color: var(--ink); }
.steps li.on span { background: var(--gold); color: #2a1503; border-color: var(--gold); }
.step h3 { font-family: var(--display); font-weight: 500; font-size: 19px; margin: 16px 0 10px; letter-spacing: .02em; }
.opts { display: grid; gap: 8px; }
.opts.bases { grid-template-columns: repeat(4, 1fr); }
.opts.swatches { grid-template-columns: repeat(6, 1fr); }
.opts.flowers { grid-template-columns: repeat(5, 1fr); }
.opt { position: relative; border: 1px solid rgba(255,255,255,.08); background: rgba(255,255,255,.03); border-radius: 14px; padding: 6px 4px 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; transition: border-color .25s, background .25s, transform .25s; }
.opt:hover { background: rgba(255,255,255,.06); transform: translateY(-1px); }
.opt[aria-pressed="true"] { border-color: var(--gold); background: rgba(243,199,122,.1); box-shadow: 0 0 24px rgba(243,199,122,.15); }
.opt canvas { width: 100%; aspect-ratio: 1; }
.opt small { font-size: 10.5px; color: var(--ink-dim); text-align: center; line-height: 1.2; min-height: 2.4em; display: flex; align-items: center; }
.swatches .opt small { display: none; }
.swatches .opt { padding: 4px; }
.hint { color: var(--ink-dim); font-size: 12px; margin: 14px 0 0; font-style: italic; }
.row { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }
.row .btn.primary { flex: 1; }
label { display: block; margin-top: 14px; font-family: var(--display); font-size: 18px; position: relative; }
input, textarea { display: block; width: 100%; margin-top: 8px; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: rgba(0,0,0,.25); font-family: var(--body); font-size: 16px; resize: none; outline: none; transition: border-color .25s, box-shadow .25s; }
input:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(243,199,122,.1); }
.left { position: absolute; right: 12px; bottom: 8px; font-size: 11px; color: var(--ink-dim); font-family: var(--body); }
.err { color: #ffb4a0; font-size: 13px; }

/* ---------- river bar ---------- */
#riverbar { left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translate(-50%, 12px); display: flex; align-items: center; gap: 18px; padding: 10px 10px 10px 22px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); width: max-content; max-width: calc(100vw - 24px); }
[data-mode="river"] #riverbar { transform: translate(-50%, 0); }
#riverbar .count { margin: 0; font-size: 17px; white-space: nowrap; }
#riverbar .hint { margin: 0; font-size: 12px; max-width: 300px; }

/* ---------- card ---------- */
#card { inset: 0; display: grid; place-items: center; background: rgba(3, 4, 14, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade .4s ease; z-index: 5; }
#card[hidden] { display: none; }
.card-inner { position: relative; width: min(440px, calc(100vw - 32px)); padding: 26px 26px 24px; border-radius: 26px; background: linear-gradient(170deg, rgba(30, 24, 52, .92), rgba(12, 12, 30, .94)); border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0,0,0,.6), 0 0 100px rgba(243, 170, 80, .12); text-align: center; animation: rise .5s cubic-bezier(.2,.7,.2,1); }
#cardArt { width: 180px; height: 189px; margin: -90px auto 0; display: block; filter: drop-shadow(0 10px 30px rgba(255, 170, 80, .3)); }
.who { font-family: var(--display); font-size: 24px; color: var(--gold); margin: 6px 0 10px; }
.wish { font-size: 16px; line-height: 1.7; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.when { font-size: 12px; color: var(--ink-dim); margin: 16px 0 0; }
.x { position: absolute; top: 10px; right: 14px; border: 0; background: none; font-size: 26px; color: var(--ink-dim); cursor: pointer; }

/* ---------- toast ---------- */
#toast { left: 50%; top: 70px; transform: translate(-50%, -10px); opacity: 0; padding: 10px 18px; border-radius: 999px; background: var(--glass-strong); border: 1px solid var(--line); font-size: 14px; transition: opacity .5s, transform .5s; pointer-events: none; max-width: calc(100vw - 32px); text-align: center; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade { from { opacity: 0 } }
@keyframes rise { from { opacity: 0; transform: translateY(20px) scale(.98) } }

/* ---------- small screens ---------- */
@media (max-width: 820px) {
  #intro { top: 18vh; }
  .lede { font-size: 14px; }
  #builder { grid-template-columns: 1fr; grid-template-rows: 38dvh 1fr; }
  #preview { width: auto; height: 34dvh; }
  .repaint { bottom: 0; }
  .sheet { margin: 6px 0 0; border-radius: 24px 24px 0 0; max-height: none; align-self: stretch; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
  .step h3 { font-size: 17px; margin: 12px 0 8px; }
  .opts.flowers { grid-template-columns: repeat(5, 1fr); }
  .opt small { font-size: 9.5px; }
  #riverbar { flex-wrap: wrap; justify-content: center; gap: 6px 14px; border-radius: 22px; padding: 12px 14px; width: calc(100vw - 24px); }
  #riverbar .hint { text-align: center; max-width: none; flex-basis: 100%; order: 3; }
}
