:root { --u: 1px; --vw: 100vw; --gold: #ffd79a; --ink: #f3ecdf; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #020309; overflow: hidden; color: var(--ink); font-family: 'Sarabun', sans-serif; }
#stage { position: fixed; inset: 0; user-select: none; -webkit-user-select: none; touch-action: manipulation; cursor: default; }
#cv { position: absolute; display: block; }
button { font: inherit; color: inherit; }

/* ---------- หน้าเรื่องย่อ ---------- */
#intro { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 0 24px; transition: opacity 1.4s ease; }
#intro.on { display: flex; }
#intro.out { opacity: 0; pointer-events: none; }
#title { font-family: 'Mitr', sans-serif; font-weight: 300; margin: 0 0 calc(70 * var(--u)); font-size: clamp(30px, calc(92 * var(--u)), 84px); letter-spacing: .04em; color: #ffe2b0;
  text-shadow: 0 0 18px rgba(255, 170, 80, .75), 0 0 46px rgba(255, 130, 50, .45); opacity: 0; transform: translateY(8px); transition: opacity 2.2s ease, transform 2.2s ease; animation: flick 3.2s ease-in-out infinite; }
#title.on { opacity: 1; transform: none; }
#title span { display: inline-block; } /* ตัดบรรทัดได้แค่ระหว่าง "ตะเกียง" กับ "ดวงสุดท้าย" */
@keyframes flick { 0%, 100% { text-shadow: 0 0 18px rgba(255,170,80,.75), 0 0 46px rgba(255,130,50,.45); } 47% { text-shadow: 0 0 14px rgba(255,170,80,.6), 0 0 36px rgba(255,130,50,.35); } 52% { text-shadow: 0 0 22px rgba(255,180,90,.85), 0 0 56px rgba(255,140,60,.5); } }
#introText { min-height: 8em; max-width: 34em; }
#introText p { margin: .7em 0; font-weight: 300; font-size: clamp(16px, calc(34 * var(--u)), 30px); line-height: 1.6; opacity: 0; transform: translateY(10px); filter: blur(4px); transition: opacity 1.6s ease, transform 1.6s ease, filter 1.6s ease; font-style: italic; color: #dfe3f2; }
#introText p.on { opacity: .92; transform: none; filter: none; }
#introHint { position: absolute; bottom: 9%; font-size: 14px; letter-spacing: .1em; opacity: 0; transition: opacity .8s; color: #b8c0dc; }
#introHint.on { opacity: .55; animation: pulse 2.4s ease-in-out infinite; }
#btnStart { margin-top: calc(40 * var(--u)); padding: .7em 2.4em; font-family: 'Mitr', sans-serif; font-weight: 300; font-size: clamp(17px, calc(32 * var(--u)), 28px); letter-spacing: .08em;
  background: rgba(255, 190, 110, .06); border: 1px solid rgba(255, 210, 150, .45); border-radius: 999px; cursor: pointer; color: #ffe6bd; opacity: 0; visibility: hidden; transform: translateY(10px);
  transition: opacity 1.4s ease, transform 1.4s ease, background .3s, box-shadow .3s; box-shadow: 0 0 30px rgba(255, 160, 70, .15); }
#btnStart.on { opacity: 1; visibility: visible; transform: none; }
#btnStart:hover, #btnStart:focus-visible { background: rgba(255, 190, 110, .14); box-shadow: 0 0 40px rgba(255, 170, 80, .35); outline: none; }
@keyframes pulse { 50% { opacity: .2; } }

/* ---------- ซับไตเติล ---------- */
#sub { position: absolute; left: 50%; bottom: max(7%, 28px); transform: translateX(-50%); width: min(92vw, calc(var(--vw) * .86), 1180px); text-align: center; pointer-events: none; opacity: 0; transition: opacity .5s ease; }
#sub.on { opacity: 1; }
#sub .who { font-family: 'Mitr', sans-serif; font-weight: 300; font-size: clamp(12px, calc(22 * var(--u)), 19px); letter-spacing: .14em; color: var(--gold); margin-bottom: .35em; opacity: .85; text-shadow: 0 0 10px rgba(0,0,0,.9); }
#sub.narr .who { display: none; }
#sub .txt { font-size: clamp(17px, calc(38 * var(--u)), 34px); line-height: 1.55; font-weight: 400; text-shadow: 0 1px 2px rgba(0,0,0,.95), 0 0 14px rgba(0,0,0,.85), 0 0 30px rgba(0,0,0,.6); }
#sub.narr .txt { font-style: italic; font-weight: 300; color: #e2e6f4; }
#sub .txt span { opacity: 0; transition: opacity .55s ease; }
#sub .txt span.on { opacity: 1; }
#sub .more { display: inline-block; margin-top: .3em; font-size: 12px; color: var(--gold); opacity: 0; }
#sub.done .more { animation: pulse 1.6s ease-in-out infinite; opacity: .6; }

/* ---------- ตัวเลือกลอยกลางอากาศ ---------- */
#choice { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; text-align: center; padding: 0 20px calc(90 * var(--u)); pointer-events: none; opacity: 0; transition: opacity .9s ease; }
#choice.on { opacity: 1; }
#choice::before { content: ''; position: absolute; inset: 0; background: linear-gradient(to top, rgba(2,4,12,.7), rgba(2,4,12,.35) 45%, rgba(2,4,12,0) 75%); z-index: -1; }
#choice .who { font-family: 'Mitr', sans-serif; font-weight: 300; font-size: clamp(12px, calc(22 * var(--u)), 19px); letter-spacing: .14em; color: var(--gold); opacity: .8; margin-bottom: .5em; }
#choice .q { font-size: clamp(19px, calc(44 * var(--u)), 40px); max-width: 26em; line-height: 1.5; margin-bottom: calc(34 * var(--u)); text-shadow: 0 0 20px rgba(0,0,0,.9);
  opacity: 0; filter: blur(6px); transform: translateY(10px); transition: opacity 1.2s ease .2s, filter 1.2s ease .2s, transform 1.2s ease .2s; }
#choice.on .q { opacity: 1; filter: none; transform: none; }
#choice .opts { display: flex; flex-direction: column; gap: calc(20 * var(--u)); align-items: center; }
#choice .opt { pointer-events: auto; cursor: pointer; font-size: clamp(16px, calc(34 * var(--u)), 30px); font-weight: 300; padding: .35em 1.2em; color: #e9e4f2; position: relative;
  opacity: 0; filter: blur(8px); text-shadow: 0 0 16px rgba(0,0,0,.95);
  animation: optIn 1.4s ease forwards var(--d), drift 6s ease-in-out infinite var(--f); transition: color .35s, text-shadow .35s, transform .35s; }
#choice .opt::after { content: ''; position: absolute; left: 50%; bottom: .1em; width: 0; height: 1px; background: linear-gradient(90deg, transparent, var(--gold), transparent); transition: width .5s ease, left .5s ease; }
#choice .opt:hover, #choice .opt:focus-visible { color: #fff3da; text-shadow: 0 0 18px rgba(255,190,100,.9), 0 0 4px rgba(0,0,0,.9); }
#choice .opt:hover::after { width: 100%; left: 0; }
#choice .opt.skip { font-size: clamp(14px, calc(27 * var(--u)), 24px); color: #b9b2cc; margin-top: calc(6 * var(--u)); }
#choice.picked .opt { animation: none; opacity: 1; filter: none; }
#choice .opt.pick { color: #fff6e2; text-shadow: 0 0 26px rgba(255,200,110,1), 0 0 60px rgba(255,170,80,.7); transform: scale(1.06); transition: all .6s ease; }
#choice .opt.gone { opacity: 0 !important; filter: blur(10px) !important; transform: translateY(-14px); transition: all 1s ease; }
#choice .hint { margin-top: calc(30 * var(--u)); font-size: clamp(12px, calc(22 * var(--u)), 17px); font-weight: 300; letter-spacing: .08em; color: var(--gold); opacity: 0; text-shadow: 0 0 10px rgba(0,0,0,.9); }
#choice.on .hint { animation: hintIn 1.2s ease forwards 2.6s, pulse 2.4s ease-in-out infinite 3.8s; }
#choice.picked .hint { animation: none; opacity: 0; transition: opacity .4s; }
@keyframes hintIn { to { opacity: .7; } }
@keyframes optIn { to { opacity: 1; filter: none; } }
@keyframes drift { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* ---------- ข้อความในกระจก ---------- */
#mirrorText { position: absolute; transform: translate(-50%, -50%); text-align: center; pointer-events: none; display: none; font-family: 'Sarabun', sans-serif; }
#mirrorText.on { display: block; }
#mirrorText p { margin: 0; line-height: 1.5; font-style: italic; font-weight: 300; color: #f4f1ff; text-shadow: 0 0 12px rgba(190,210,255,.9), 0 0 2px rgba(0,0,0,.8);
  opacity: 0; filter: blur(5px); transition: opacity 1.1s ease, filter 1.1s ease; }
#mirrorText p.on { opacity: 1; filter: none; }

/* ---------- นับถอยหลัง ---------- */
#count { position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%); font-family: 'Mitr', sans-serif; font-weight: 300; font-size: clamp(60px, calc(220 * var(--u)), 200px); color: rgba(255, 236, 205, .0); pointer-events: none; text-shadow: 0 0 40px rgba(255, 200, 120, .4); }
#count.on { animation: cnt 1s ease-out; }
@keyframes cnt { 0% { color: rgba(255,236,205,0); transform: translate(-50%,-50%) scale(1.12); } 25% { color: rgba(255,236,205,.55); } 100% { color: rgba(255,236,205,0); transform: translate(-50%,-50%) scale(.96); } }

/* ---------- ตอนจบ ---------- */
#final { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 0 28px; opacity: 0; visibility: hidden; transition: opacity 2.4s ease; color: #5a4a44; }
#final.on { opacity: 1; visibility: visible; }
#final .msg { max-width: 30em; font-size: clamp(16px, calc(32 * var(--u)), 27px); line-height: 1.8; font-weight: 300; margin: 0 0 calc(70 * var(--u)); }
#final .btns { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
#final button { font-family: 'Mitr', sans-serif; font-weight: 300; font-size: clamp(15px, calc(26 * var(--u)), 22px); padding: .65em 1.8em; border-radius: 999px; cursor: pointer; border: 1px solid rgba(150, 110, 90, .45); background: rgba(255, 255, 255, .45); color: #6a5048; transition: background .3s, box-shadow .3s; }
#final button:hover, #final button:focus-visible { background: rgba(255, 255, 255, .85); box-shadow: 0 0 30px rgba(255, 190, 120, .45); outline: none; }

/* ---------- บันทึกการเดินทาง ---------- */
#journal { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(60, 44, 40, .35); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); padding: 16px; }
#journal.on { display: flex; }
#journal .card { width: min(720px, 100%); max-height: 88vh; overflow: auto; background: #fbf6ef; color: #4a3c38; border-radius: 18px; padding: 28px 28px 22px; box-shadow: 0 20px 60px rgba(60, 30, 20, .3); user-select: text; -webkit-user-select: text; }
#journal h2 { font-family: 'Mitr', sans-serif; font-weight: 400; margin: 0 0 18px; font-size: 24px; color: #7a5640; }
.jItem { padding: 14px 0; border-top: 1px solid #eadfd2; }
.jWho { font-family: 'Mitr', sans-serif; font-weight: 300; font-size: 13px; letter-spacing: .06em; color: #b08060; }
.jQ { margin-top: 4px; font-size: 16px; color: #6a5a54; }
.jA { margin-top: 4px; font-size: 17px; font-weight: 400; color: #4a3c38; }
.jR { margin-top: 8px; font-size: 16px; line-height: 1.65; color: #5d4c46; }
.jM { margin-top: 6px; font-size: 15px; font-style: italic; color: #9a7a70; }
#jClose { margin-top: 18px; float: right; font-family: 'Mitr', sans-serif; font-weight: 300; padding: .5em 1.6em; border-radius: 999px; border: 1px solid #d8c6b4; background: #fff; cursor: pointer; color: #6a5048; }

#btnMute { position: absolute; right: max(14px, env(safe-area-inset-right)); top: max(12px, env(safe-area-inset-top)); width: 38px; height: 38px; border-radius: 50%; border: 1px solid rgba(255,255,255,.14); background: rgba(0,0,0,.18); color: rgba(255,255,255,.45); cursor: pointer; font-size: 16px; transition: opacity .3s, color .3s; }
#btnMute:hover { color: rgba(255,255,255,.85); }
#btnMute.off { text-decoration: line-through; opacity: .5; }

/* ---------- การ์ดตะเกียงของคุณ (หน้าจบ) ---------- */
#final { overflow-y: auto; justify-content: safe center; padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom)); }
#cardImg { display: none; width: auto; max-width: min(92vw, 460px); max-height: 56vh; aspect-ratio: 4 / 5; border-radius: 18px; box-shadow: 0 18px 50px rgba(90, 60, 80, .28), 0 0 0 1px rgba(150, 110, 90, .18); margin: 0 0 18px; flex: none; }
#final.hasCard #cardImg { display: block; }
#final .btns.share { display: none; margin-bottom: 18px; }
#final.hasCard .btns.share { display: flex; }
#final.hasCard .msg { font-size: clamp(14px, calc(24 * var(--u)), 19px); line-height: 1.7; margin: 0 0 18px; opacity: .85; }
#final button.main { background: linear-gradient(180deg, #ffcf8a, #f2a25e); border-color: rgba(200, 120, 60, .55); color: #4a2c1c; font-weight: 400; box-shadow: 0 6px 22px rgba(240, 150, 80, .35); }
#final button.main:hover, #final button.main:focus-visible { background: linear-gradient(180deg, #ffd99e, #f5ad6c); }
#cardToast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 12px); background: rgba(60, 44, 52, .9); color: #fff4e8; font-family: 'Sarabun', sans-serif; font-size: 15px; padding: .6em 1.2em; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s; max-width: calc(100vw - 32px); }
#cardToast.on { opacity: 1; transform: translate(-50%, 0); }
#final.hasCard { background: radial-gradient(120% 90% at 50% 30%, #fbf5ee, #efe3da); }

/* จอแนวตั้งแคบ (มือถือ): หน่วย --u อิงความสูงจอ ทำให้ตัวหนังสือใหญ่เกินความกว้าง จึงจำกัดด้วยความกว้างจอแทน */
#introNote { margin-top: 1.6em; font-family: 'Sarabun', sans-serif; font-weight: 300; font-size: clamp(12px, calc(20 * var(--u)), 15px); color: rgba(220, 226, 245, .55); opacity: 0; transition: opacity 1.2s ease; }
#btnStart.on + #introNote { opacity: 1; }
#crash { position: absolute; inset: 0; z-index: 100; display: none; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 0 24px; background: #04060f; color: #eef0fa; font-family: 'Mitr', sans-serif; font-weight: 300; }
#crash.on { display: flex; }
#crash p { margin: .3em 0; font-size: clamp(18px, 4.5vw, 26px); }
#crash p.small { font-family: 'Sarabun', sans-serif; font-size: clamp(14px, 3.6vw, 18px); opacity: .7; }
#crash button { margin-top: 1.4em; padding: .6em 2em; font: inherit; font-size: 18px; color: #2a1606; background: linear-gradient(#ffd79a, #f0a555); border: 0; border-radius: 999px; cursor: pointer; }

@media (max-aspect-ratio: 3/4) {
  #title { font-size: min(13vw, 60px); line-height: 1.25; margin-bottom: 4vh; }
  #introText { min-height: 0; }
  #introText p { font-size: clamp(15px, 4.6vw, 20px); margin: .55em 0; line-height: 1.55; text-wrap: pretty; }
  #introHint { bottom: max(4%, env(safe-area-inset-bottom)); }
  #btnStart { margin-top: 3vh; font-size: clamp(16px, 5vw, 22px); }
  #sub { bottom: 22%; width: calc(100vw - 32px); }
  #sub .txt { font-size: clamp(16px, 5.1vw, 21px); text-wrap: pretty; }
  #choice { padding-bottom: 24vh; }
  #choice .q { font-size: clamp(18px, 5.6vw, 23px); margin-bottom: 2.2vh; text-wrap: pretty; }
  #choice .opts { gap: 1.2vh; }
  #choice .opt { font-size: clamp(15px, 4.8vw, 19px); padding: .55em .9em; text-wrap: pretty; }
  #choice .opt.skip { font-size: clamp(13px, 4vw, 16px); }
  #choice .hint { margin-top: 2vh; }
  #final .btns { gap: 10px; flex-wrap: nowrap; }
  #final button { font-size: 15px; padding: .6em 1.1em; white-space: nowrap; }
  #final.hasCard .msg { font-size: 14px; margin-bottom: 14px; text-wrap: pretty; }
  #final .btns.share { margin-bottom: 14px; }
  #cardImg { max-height: 54vh; margin-bottom: 14px; }
}
