/* =========================================================
   Whispers of Mondstadt — Genshin-style UI
   สีและเวลาทั้งหมดอยู่ที่ :root ปรับได้ที่เดียว
   ========================================================= */
/* ฟอนต์ Kanit (SIL Open Font License 1.1 · assets/fonts/OFL-Kanit.txt) ตัดเหลือไทย+อังกฤษ
   ใช้ Medium เป็นตัวปกติ (ความหนาใกล้ฟอนต์ในเกม) และ SemiBold สำหรับหัวข้อ */
@font-face {
  font-family: 'Kanit';
  src: url('../assets/fonts/kanit-medium.woff2') format('woff2');
  font-weight: 400 500;
  font-display: block;
}
@font-face {
  font-family: 'Kanit';
  src: url('../assets/fonts/kanit-semibold.woff2') format('woff2');
  font-weight: 600 900;
  font-display: block;
}

:root {
  /* ดาว 4 แฉก (ใช้ที่ progress bar / เอฟเฟกต์ตอนแตะ / หน้าเปิดผล) */
  --star: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath fill='%23fff' d='M50 0Q55 45 100 50Q55 55 50 100Q45 55 0 50Q45 45 50 0Z'/%3E%3C/svg%3E");
  /* สีจาก UI ในเกม */
  --cream: #ece5d8;
  --cream-2: #f6f2ea;
  --ink: #3b4255;
  --ink-2: #6b7186;
  --gold: #d3bc8e;
  --gold-hi: #f2dcae;
  --gold-deep: #a88a55;
  --night: #1b2238;
  --panel: rgba(28, 33, 50, .82);
  --choice: rgba(18, 22, 34, .55);
  --choice-hi: rgba(255, 255, 255, .16);
  --text: #fff;
  --anemo: #6fd4b6;
  --accent: var(--anemo);

  /* เวลา transition */
  --t-fast: .2s;
  --t-mid: .45s;
  --t-bg: .9s;
  --ease: cubic-bezier(.22, .8, .3, 1);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--night); }
body {
  font-family: 'Kanit', 'Noto Sans Thai', system-ui, sans-serif;
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
img { -webkit-user-drag: none; }

#app { position: fixed; inset: 0; overflow: hidden; }

/* ---------- ฉากหลัง ---------- */
.bg-stack { position: absolute; inset: 0; z-index: 0; }
.bg-layer {
  position: absolute; inset: -4%;
  background: center / cover no-repeat;
  opacity: 0;
  transition: opacity var(--t-bg) ease, filter var(--t-bg) ease;
  animation: drift 40s ease-in-out infinite alternate;
}
.bg-layer.is-on { opacity: 1; }
@keyframes drift { from { transform: scale(1.02) translateX(-1%); } to { transform: scale(1.08) translateX(1%); } }
.bg-layer[data-bg="day"]   { background-image: url('../assets/backgrounds/mond-day.jpg'); }
.bg-layer[data-bg="dusk"]  { background-image: url('../assets/backgrounds/mond-dusk.jpg'); }
.bg-layer[data-bg="night"] { background-image: url('../assets/backgrounds/mond-day.jpg'); filter: brightness(.32) saturate(1.3) hue-rotate(12deg); }
.bg-layer[data-bg="snow"]  { background-image: url('../assets/backgrounds/mond-day.jpg'); filter: grayscale(.75) brightness(1.18) contrast(.85) hue-rotate(-10deg); }
.bg-layer[data-bg="night"]::after { content: ''; position: absolute; inset: 0; background: radial-gradient(120% 80% at 70% 0%, rgba(80, 110, 200, .35), rgba(8, 12, 30, .55)); }
.bg-layer[data-bg="snow"]::after  { content: ''; position: absolute; inset: 0; background: linear-gradient(rgba(225, 238, 255, .35), rgba(160, 185, 215, .25)); }
#particles { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
/* Black Opaque: ชั้นมืดให้อ่านง่าย */
.shade {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(0, 0, 0, .35), transparent 22%),
    linear-gradient(to top, rgba(0, 0, 0, .78), rgba(0, 0, 0, .35) 38%, transparent 60%);
  transition: opacity var(--t-mid);
}
[data-screen="title"] .shade { opacity: .55; }

/* ---------- หน้าจอ ---------- */
.screen {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity var(--t-mid) ease, visibility 0s linear var(--t-mid);
}
.screen.is-active { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity var(--t-mid) ease; }

/* ---------- HUD ---------- */
.hud {
  position: absolute; z-index: 10; left: 0; right: 0; top: 0;
  padding: calc(12px + var(--safe-t)) 16px 0;
  display: flex; align-items: center; gap: 14px;
}
.hud__right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
[data-screen="loading"] .hud { display: none; }
.lang {
  display: flex; padding: 3px; border-radius: 999px;
  background: rgba(20, 24, 38, .5); border: 1px solid rgba(236, 229, 216, .35);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.lang button { min-width: 40px; height: 30px; padding: 0 10px; border-radius: 999px; font-size: 13px; color: rgba(255, 255, 255, .75); transition: background var(--t-fast), color var(--t-fast); }
.lang button[aria-pressed="true"] { background: var(--cream); color: var(--ink); }
.hud__icon {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(20, 24, 38, .5); border: 1px solid rgba(236, 229, 216, .35); color: var(--cream);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.hud__icon .off { display: none; }
#app.is-locked .lang { display: none; }
.hud__icon[aria-pressed="false"] .off { display: inline; }
.hud__icon[aria-pressed="false"] { color: rgba(236, 229, 216, .55); }

/* Progress bar */
.progress { flex: 1; min-width: 0; opacity: 0; transition: opacity var(--t-mid); }
[data-screen="story"] .progress { opacity: 1; }
.progress__label { font-size: 12px; letter-spacing: .04em; color: var(--gold-hi); margin-bottom: 6px; text-shadow: 0 1px 4px rgba(0, 0, 0, .6); min-height: 1.2em; }
.progress__track {
  position: relative; height: 6px; border-radius: 6px;
  background: rgba(255, 255, 255, .18); box-shadow: inset 0 0 0 1px rgba(236, 229, 216, .25);
}
.progress__fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 6px;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold-hi));
  box-shadow: 0 0 10px rgba(242, 220, 174, .6);
  transition: width .6s var(--ease);
}
.progress__star {
  position: absolute; right: -13px; top: 50%; width: 26px; height: 26px; transform: translateY(-50%);
  background: var(--star) center / contain no-repeat;
  filter: drop-shadow(0 0 3px #fff) drop-shadow(0 0 8px rgba(255, 226, 160, .95));
  animation: starTwinkle 2.4s ease-in-out infinite;
}
@keyframes starTwinkle { 0%, 100% { transform: translateY(-50%) scale(1); } 50% { transform: translateY(-50%) scale(1.18); } }

/* ---------- Loading: แถบสัญลักษณ์ 7 ธาตุ (เติมสีจากซ้ายไปขวา) ---------- */
#screen-loading { background: #f4f2ee; color: var(--ink); align-items: center; justify-content: center; z-index: 30; transition: opacity .5s ease, visibility 0s linear .5s; }
#screen-loading.is-done { opacity: 0; }
.loader { width: min(560px, 86vw); text-align: center; }
.loader__strip { position: relative; height: 64px; }
.loader__row { position: absolute; left: 0; top: 0; height: 100%; width: min(560px, 86vw); display: flex; justify-content: space-between; align-items: center; }
.loader__row span {
  width: 13%; aspect-ratio: 1; background: #d6d1c7;
  -webkit-mask: center / contain no-repeat; mask: center / contain no-repeat;
}
.loader__row--fill span { background: #5a5f6e; }
.loader__clip { position: absolute; left: 0; top: 0; bottom: 0; width: 0; overflow: hidden; }
#screen-loading.is-done .loader__row--fill span { background: #3b4255; transition: background .3s; }
.loader__legal { position: absolute; left: 16px; right: 16px; bottom: max(22px, env(safe-area-inset-bottom)); margin: 0; text-align: center; font-size: 11px; line-height: 1.6; color: #77726a; }
.loader__legal b { font-size: 13px; font-weight: 600; color: #4a4640; }
.loader__text { font-size: 12px; letter-spacing: .1em; color: #a29c90; margin-top: 18px; font-variant-numeric: tabular-nums; }

/* ---------- Title ---------- */
#screen-title { align-items: center; justify-content: space-between; padding: calc(90px + var(--safe-t)) 16px calc(28px + var(--safe-b)); text-align: center; }
.title { max-width: 760px; }
.title__eyebrow { white-space: nowrap; display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 12px; letter-spacing: .32em; color: var(--gold-hi); margin: 0 0 14px; text-shadow: 0 1px 6px rgba(0, 0, 0, .5); }
.title__eyebrow span { width: 34px; height: 1px; background: linear-gradient(90deg, transparent, var(--gold-hi)); }
.title__eyebrow span:last-child { transform: scaleX(-1); }
.title__main {
  margin: 0; font-size: clamp(38px, 9vw, 76px); line-height: 1.25; font-weight: 600;
  color: #fff;
  text-shadow: 0 0 24px rgba(120, 220, 200, .55), 0 2px 0 rgba(60, 80, 110, .5), 0 6px 22px rgba(0, 0, 0, .45);
  animation: titleIn 1.4s var(--ease) both;
}
.title__sub { font-size: clamp(17px, 3.6vw, 24px); margin: 14px 0 6px; text-shadow: 0 2px 10px rgba(0, 0, 0, .6); animation: titleIn 1.4s .2s var(--ease) both; }
.title__desc { font-size: 14px; color: rgba(255, 255, 255, .85); margin: 0; text-shadow: 0 1px 6px rgba(0, 0, 0, .7); animation: titleIn 1.4s .35s var(--ease) both; }
@keyframes titleIn { from { opacity: 0; transform: translateY(14px); letter-spacing: .06em; } to { opacity: 1; transform: none; } }
.tap-start {
  position: relative; padding: 14px 40px; font-size: 20px; letter-spacing: .08em;
  color: #fff; text-shadow: 0 0 12px rgba(255, 255, 255, .7), 0 2px 8px rgba(0, 0, 0, .6);
  animation: pulse 2.2s ease-in-out infinite;
}
.tap-start::before, .tap-start::after { content: ''; position: absolute; top: 50%; width: 46px; height: 1px; background: linear-gradient(90deg, transparent, #fff); }
.tap-start::before { right: 100%; }
.tap-start::after { left: 100%; transform: scaleX(-1); }
@keyframes pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
.disclaimer { font-size: 11px; color: rgba(255, 255, 255, .6); margin: 8px 0 0; text-align: center; text-shadow: 0 1px 4px rgba(0, 0, 0, .8); }

/* ---------- Genshin buttons ---------- */
.g-btn {
  position: relative; display: inline-flex; align-items: center; gap: 12px;
  min-width: 168px; height: 50px; padding: 0 30px 0 8px; border-radius: 999px;
  background: var(--cream); color: var(--ink); font-size: 17px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.g-btn > span { flex: 1; text-align: center; }
.g-btn::after { content: ''; position: absolute; inset: -4px; border-radius: inherit; border: 2px solid rgba(255, 255, 255, 0); transition: border-color var(--t-fast); pointer-events: none; }
.g-btn:hover::after, .g-btn:focus-visible::after { border-color: rgba(255, 255, 255, .9); }
.g-btn:focus-visible { outline: none; }
.g-btn:active { transform: scale(.96); background: #d9d0c0; }
.g-btn__ico { position: relative; width: 34px; height: 34px; border-radius: 50%; background: #313131; flex: none; }
.g-btn--confirm .g-btn__ico::before { content: ''; position: absolute; inset: 9px; border-radius: 50%; border: 3px solid #f2c94c; }
.g-btn--cancel .g-btn__ico::before, .g-btn--cancel .g-btn__ico::after { content: ''; position: absolute; left: 50%; top: 50%; width: 18px; height: 3px; border-radius: 2px; background: #5fa8d3; }
.g-btn--cancel .g-btn__ico::before { transform: translate(-50%, -50%) rotate(45deg); }
.g-btn--cancel .g-btn__ico::after { transform: translate(-50%, -50%) rotate(-45deg); }
.g-btn--share .g-btn__ico::before { content: ''; position: absolute; inset: 0; background: center / 18px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f2c94c' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3v13M6 9l6-6 6 6M5 21h14'/%3E%3C/svg%3E"); }
.g-btn--ghost { background: rgba(236, 229, 216, .14); color: var(--cream); border: 1px solid rgba(236, 229, 216, .45); box-shadow: none; }
.g-btn--ghost .g-btn__ico { background: rgba(0, 0, 0, .35); }
.g-btn--ghost .g-btn__ico::before { content: ''; position: absolute; inset: 0; background: center / 18px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ece5d8' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12a9 9 0 1 0 3-6.7L3 8M3 3v5h5'/%3E%3C/svg%3E"); }

/* ---------- Name modal ---------- */
#screen-name { align-items: center; justify-content: center; padding: 16px; background: rgba(10, 12, 20, .45); }
.modal {
  width: min(520px, 100%); background: var(--cream-2); color: var(--ink); border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  position: relative; overflow: hidden;
  animation: modalIn .5s var(--ease) both;
}
.modal::before { content: ''; position: absolute; inset: 8px; border: 1px solid rgba(211, 188, 142, .7); border-radius: 3px; pointer-events: none; }
@keyframes modalIn { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
.modal__head { background: linear-gradient(#4a5168, #3b4255); color: var(--gold-hi); text-align: center; padding: 18px 16px; }
.modal__head h2 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: .04em; }
.modal__body { padding: 26px 28px 8px; text-align: center; }
.modal__hint { margin: 0 0 16px; font-size: 14px; color: var(--ink-2); }
.modal__input {
  width: 100%; height: 52px; border-radius: 999px; border: 2px solid #d8cfbd; background: #fff;
  font-size: 18px; text-align: center; color: var(--ink); padding: 0 18px; outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.modal__input:focus { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(211, 188, 142, .3); }
.modal__foot { display: flex; gap: 12px; justify-content: center; padding: 22px 20px 26px; flex-wrap: wrap; }
.modal__foot .g-btn { min-width: 0; flex: 1 1 120px; max-width: 210px; padding-right: 18px; }
@media (max-width: 420px) { .title__eyebrow { letter-spacing: .14em; font-size: 11px; gap: 8px; } .title__eyebrow span { width: 18px; } }

/* ---------- Story / dialog ---------- */
#screen-story { justify-content: flex-end; }
.dialog {
  position: relative; width: 100%; max-width: 980px; margin: 0 auto;
  padding: 18px 20px calc(24px + var(--safe-b));
  min-height: 190px; cursor: pointer;
}
.dialog__speaker {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
  font-size: 19px; color: var(--gold-hi); text-shadow: 0 2px 8px rgba(0, 0, 0, .6);
  min-height: 1.5em;
}
.dialog__speaker:not(:empty)::after { content: ''; flex: 1; max-width: 280px; height: 1px; background: linear-gradient(90deg, rgba(242, 220, 174, .8), transparent); }
.dialog__speaker:not(:empty)::before { content: ''; width: 8px; height: 8px; background: var(--gold-hi); transform: rotate(45deg); }
.dialog__text { margin: 0; font-size: clamp(18px, 4.4vw, 23px); line-height: 1.7; text-shadow: 0 2px 10px rgba(0, 0, 0, .75); min-height: 3.4em; overflow-wrap: anywhere; word-break: normal; }
.choice span, .title__main, .title__sub, .modal__hint, .hold p { overflow-wrap: anywhere; }
.dialog__text .q-tag { display: block; font-size: 13px; letter-spacing: .06em; color: var(--accent); margin-bottom: 4px; text-shadow: none; }
.dialog__next {
  position: absolute; right: 20px; bottom: calc(20px + var(--safe-b));
  display: flex; align-items: center; gap: 10px; padding: 8px 4px 8px 14px; font-size: 15px; color: var(--cream);
  opacity: 0; transform: translateY(6px); transition: opacity var(--t-mid), transform var(--t-mid);
}
.dialog__next.is-on { opacity: 1; transform: none; }
.dialog__next i { width: 0; height: 0; border-left: 8px solid transparent; border-right: 8px solid transparent; border-top: 11px solid var(--gold-hi); animation: bob 1s ease-in-out infinite; filter: drop-shadow(0 0 4px rgba(242, 220, 174, .8)); }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(4px); } }

/* ตัวอักษรจางเข้าทีละตัว */
.dialog__text .ch { opacity: 0; transition: opacity .32s ease; }
.dialog__text .ch.on { opacity: 1; }
/* กล่องบทสนทนา: ชื่อผู้พูดเลื่อนเข้า เส้นตกแต่งขยาย ทุกครั้งที่ขึ้นบรรทัดใหม่ */
.dialog.is-new .dialog__speaker { animation: speakerIn .45s var(--ease) both; }
.dialog.is-new .dialog__speaker::after, .dialog.is-new .dialog__speaker::before { animation: lineGrow .6s .08s var(--ease) both; }
.dialog.is-new .q-tag { animation: speakerIn .45s var(--ease) both; }
@keyframes speakerIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes lineGrow { from { opacity: 0; transform: scaleX(0); } to { opacity: 1; } }
.dialog__speaker:not(:empty)::after { transform-origin: left center; }
#screen-story.is-active .dialog { animation: dialogUp .6s var(--ease) both; }
@keyframes dialogUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }

/* ตัวเลือกบทสนทนา แบบในเกม */
.choices {
  width: 100%; max-width: 980px; margin: 0 auto; padding: 0 16px;
  display: flex; flex-direction: column; align-items: stretch; gap: 10px;
}
.choice {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 54px; padding: 10px 20px 10px 14px;
  border-radius: 999px; text-align: left; font-size: clamp(16px, 3.9vw, 19px); line-height: 1.4;
  background: var(--choice); border: 1px solid rgba(255, 255, 255, .14);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0; transform: translateX(24px);
  transition: background var(--t-fast), border-color var(--t-fast), opacity var(--t-mid) var(--ease), transform var(--t-mid) var(--ease);
}
.choice.is-in { opacity: 1; transform: none; }
/* กันแตะพลาด: ตัวเลือกยังกดไม่ได้จนกว่าจะพร้อม (app.js ใส่ .is-armed) */
.choices:not(.is-armed) .choice { pointer-events: none; }
.choice__ico {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: center / 16px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffe08a'%3E%3Cpath d='M4 5h16a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1h-9l-5 4v-4H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z'/%3E%3C/svg%3E"), rgba(0, 0, 0, .35);
}
.choice:hover, .choice:focus-visible { background: var(--choice-hi); border-color: rgba(255, 255, 255, .7); outline: none; box-shadow: 0 0 18px rgba(255, 255, 255, .18); }
.choice.is-in:hover { transform: translateX(-4px); }
.choice:active { transform: scale(.98); }
.choice.is-picked { animation: pickGlow .5s ease; }
@keyframes pickGlow { 0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, .9); } 100% { box-shadow: 0 0 0 14px rgba(255, 255, 255, 0); } }
.choice.is-picked { background: rgba(236, 229, 216, .92); color: var(--ink); border-color: #fff; }
.choice.is-dim { opacity: .25 !important; }

/* ---------- Reveal: จอดำ + แตะ + ดาวตก ---------- */
#screen-reveal { z-index: 6; }
.wish { position: absolute; inset: 0; overflow: hidden; cursor: pointer; background: #000; outline: none; }
#screen-reveal { transition-duration: 1.1s; }
.wish__canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.wish__prompt {
  position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 22px; text-align: center;
  transition: opacity .4s ease;
}
.wish__prompt p { margin: 0; font-size: clamp(18px, 4.4vw, 24px); letter-spacing: .08em; color: var(--cream); animation: pulse 2.2s ease-in-out infinite; }
.wish__star {
  width: 54px; height: 54px; background: var(--star) center / contain no-repeat;
  filter: drop-shadow(0 0 6px #fff) drop-shadow(0 0 16px rgba(242, 220, 174, .9));
  animation: starGlow 2.2s ease-in-out infinite;
}
@keyframes starGlow { 0%, 100% { transform: scale(.85); opacity: .7; } 50% { transform: scale(1.1); opacity: 1; } }
.wish.is-falling .wish__prompt { opacity: 0; pointer-events: none; }
.wish.is-falling { cursor: default; }

/* ---------- Result ----------
   สเกลขนาด: ระยะห่าง 8 / 12 / 16 / 24 / 32 · ตัวอักษร 12 (ป้าย) / 14 (รอง) / 16 (ปกติ) / 17 (ปุ่ม) / 40 (ชื่อ)
   ทุกอย่างในแผงกว้างเท่ากัน (--col) จึงไม่เกิดขนาดสะเปะสะปะ */
#screen-result {
  --col: min(400px, calc(100vw - 32px));
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: rgba(10, 13, 26, .62); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.result {
  display: flex; flex-direction: column; align-items: center; gap: 24px;
  width: var(--col); margin: 0 auto; padding: calc(64px + var(--safe-t)) 0 0;
}
.result__media { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.result__eyebrow {
  margin: 0; display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 13px; letter-spacing: .14em; color: var(--gold-hi);
}
.result__eyebrow::before, .result__eyebrow::after { content: ''; width: 28px; height: 1px; background: var(--gold-hi); opacity: .6; }
.result__card {
  width: 100%; aspect-ratio: 9 / 16; border-radius: 16px; overflow: hidden; background: #2a2f45;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55), 0 0 0 1px rgba(242, 220, 174, .35);
}
.result__card img { width: 100%; height: 100%; display: block; object-fit: cover; }

/* มือถือ: ให้ลูกของแผงเป็นแถวของ .result โดยตรง เพื่อให้แถบปุ่ม (sticky) ติดขอบล่างจอได้ตลอดหน้า */
.result__panel { display: contents; }
.result__panel > * { width: 100%; }
.result__panel > .r-btn--text { width: auto; }
.result__panel > .result__actions { width: calc(100% + 32px); }   /* ปุ่มด้านในกว้างเท่าการ์ดพอดี */
.result__credit { padding-bottom: calc(24px + var(--safe-b)); }
.result__who { display: none; }   /* มือถือ: ชื่อ/ตำแหน่งอยู่บนการ์ดแล้ว ไม่ซ้ำ */

/* ปุ่ม: หลัก (ครีมแบบในเกม) → รอง (ขอบทอง) → ตัวอักษร */
.result__actions {
  display: flex; flex-direction: column; gap: 12px;
  position: sticky; bottom: 0; z-index: 2;
  margin: 0 -16px; padding: 16px 16px calc(16px + var(--safe-b));
  background: linear-gradient(to top, rgba(10, 13, 26, .96) 70%, rgba(10, 13, 26, 0));
}
.r-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; border-radius: 999px; font-size: 17px; transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast); }
.r-btn:active { transform: scale(.98); }
.r-btn--primary { height: 54px; min-width: 0; padding: 0 20px 0 8px; }
.r-btn--primary > span { flex: 1; text-align: center; margin-right: 34px; }
.r-btn--secondary { height: 50px; color: var(--gold-hi); border: 1.5px solid rgba(242, 220, 174, .6); background: rgba(242, 220, 174, .06); }
.r-btn--secondary:hover, .r-btn--secondary:focus-visible { border-color: var(--gold-hi); background: rgba(242, 220, 174, .14); outline: none; }
.r-btn--text { height: 44px; width: auto; align-self: center; padding: 0 16px; font-size: 15px; color: var(--cream); opacity: .85; }
.r-btn--text:hover, .r-btn--text:focus-visible { opacity: 1; outline: none; text-decoration: underline; text-underline-offset: 4px; }

/* ตัวละครใกล้เคียง */
.result__section { display: flex; flex-direction: column; gap: 12px; }
.result__label { margin: 0; display: flex; align-items: center; gap: 10px; font-size: 12px; font-weight: 500; letter-spacing: .12em; color: rgba(242, 220, 174, .8); }
.result__label::after { content: ''; flex: 1; height: 1px; background: rgba(242, 220, 174, .25); }
#runners { display: flex; flex-direction: column; gap: 8px; }
.runner { display: grid; grid-template-columns: 32px 1fr auto; grid-template-rows: auto 4px; column-gap: 12px; row-gap: 6px; align-items: center; padding: 12px 14px; border-radius: 12px; background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .08); }
.runner img { grid-row: 1 / 3; width: 32px; height: 32px; }
.runner span { font-size: 16px; }
.runner b { font-weight: 500; font-size: 15px; color: var(--gold-hi); font-variant-numeric: tabular-nums; }
.runner i { grid-column: 2 / 4; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.runner i::before { content: ''; display: block; height: 100%; width: var(--pct, 50%); border-radius: inherit; background: linear-gradient(90deg, var(--gold-deep), var(--gold-hi)); }

/* ชวนติดตาม Instagram */
.follow {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px 16px; border-radius: 12px; text-decoration: none; color: var(--cream);
  background: rgba(242, 220, 174, .06); border: 1px solid rgba(242, 220, 174, .3);
  transition: background var(--t-fast), border-color var(--t-fast);
}
.follow:hover, .follow:focus-visible { border-color: var(--gold-hi); background: rgba(242, 220, 174, .12); outline: none; }
.follow__ig { flex: none; color: var(--gold-hi); }
.follow__text { flex: 1; display: flex; flex-direction: column; line-height: 1.35; font-size: 13px; color: rgba(236, 229, 216, .75); text-align: left; }
.follow__text b { font-weight: 500; font-size: 16px; color: #fff; }
.follow__go { flex: none; color: rgba(242, 220, 174, .7); }
.result__credit { margin: 0; font-size: 11px; line-height: 1.6; opacity: .8; }

/* คอมพิวเตอร์ / แท็บเล็ตแนวนอน: การ์ดซ้าย แผงข้อมูลขวา */
@media (min-width: 900px) and (min-aspect-ratio: 1/1) {
  #screen-result { display: flex; }
  .result {
    flex-direction: row; align-items: center; justify-content: center; gap: 56px;
    width: auto; max-width: 1200px; min-height: 100%; margin: 0 auto; padding: calc(72px + var(--safe-t)) 32px 32px;
  }
  .result__media { width: auto; flex: none; }
  .result__eyebrow--media { display: none; }
  .result__card { width: auto; height: min(calc(100vh - 140px), 900px); }
  .result__panel { display: flex; flex-direction: column; align-items: stretch; width: 380px; flex: none; gap: 20px; }
  .result__credit { padding-bottom: 0; }
  .result__who { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
  .result__who .result__eyebrow { justify-content: flex-start; }
  .result__who .result__eyebrow::before { display: none; }
  .result__name { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
  .result__name img { width: 44px; height: 44px; }
  .result__name h2 { margin: 0; font-size: 40px; line-height: 1.15; font-weight: 600; color: #fff; text-shadow: 0 2px 16px rgba(0, 0, 0, .4); }
  .result__stars { margin: 0; font-size: 18px; letter-spacing: 3px; color: #ffcc32; text-shadow: 0 0 8px rgba(255, 204, 50, .6); }
  .result__role { margin: 0; font-size: 15px; color: rgba(236, 229, 216, .8); }
  .result__traits { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 0; padding: 0; list-style: none; }
  .result__traits li { padding: 4px 12px; border-radius: 999px; font-size: 13px; border: 1px solid var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
  .result__actions, .result__panel > .result__actions { position: static; width: 100%; margin: 0; padding: 0; background: none; }
  .result__credit { text-align: left; }
}

/* ---------- Hold-to-save overlay ---------- */
.hold { position: fixed; inset: 0; z-index: 20; background: rgba(5, 7, 15, .92); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)); }
.hold[hidden] { display: none; }
.hold p { margin: 0; color: var(--gold-hi); text-align: center; max-width: 340px; line-height: 1.5; }
.hold img { max-width: 100%; max-height: 74vh; border-radius: 10px; -webkit-touch-callout: default; user-select: auto; }

/* ---------- Toast แจ้งเตือนสั้น ๆ (บันทึกแล้ว / คัดลอกแล้ว) ---------- */
.toast {
  position: fixed; z-index: 35; left: 50%; bottom: calc(28px + var(--safe-b)); transform: translate(-50%, 20px);
  max-width: calc(100% - 32px); padding: 12px 22px; border-radius: 999px;
  background: rgba(236, 229, 216, .96); color: var(--ink); font-size: 15px; text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35); opacity: 0; pointer-events: none;
}
.toast.is-on { animation: toastIn 2.6s var(--ease) forwards; }
@keyframes toastIn { 0% { opacity: 0; transform: translate(-50%, 20px); } 12%, 82% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, 0); } }

/* ---------- เอฟเฟกต์ตอนแตะ ---------- */
.tap-fx { position: fixed; z-index: 40; width: 0; height: 0; pointer-events: none; }
.tap-fx::before {
  content: ''; position: absolute; left: -22px; top: -22px; width: 44px; height: 44px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 240, 200, .75), rgba(255, 220, 150, 0) 70%);
  animation: tapGlow .55s ease-out forwards;
}
.tap-fx::after {
  content: ''; position: absolute; left: -16px; top: -16px; width: 32px; height: 32px;
  background: var(--star) center / contain no-repeat;
  filter: drop-shadow(0 0 4px rgba(255, 230, 170, 1)) drop-shadow(0 0 10px rgba(255, 210, 130, .8));
  animation: tapStar .6s cubic-bezier(.2, .9, .3, 1) forwards;
}
@keyframes tapGlow { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
@keyframes tapStar { 0% { transform: scale(.2) rotate(-20deg); opacity: 1; } 55% { transform: scale(1.15) rotate(0deg); opacity: 1; } 100% { transform: scale(.6) rotate(10deg); opacity: 0; } }

/* ---------- Flash ---------- */
.flash { position: absolute; inset: 0; z-index: 15; background: #fff; opacity: 0; pointer-events: none; }
.flash.is-on { animation: flash .9s ease; }
@keyframes flash { 0% { opacity: 0; } 30% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- มือถือแนวตั้ง: กันกล่องข้อความล้นจอ / ปุ่มถัดไปทับข้อความ ---------- */
@media (max-width: 899px) {
  #screen-story { padding-top: calc(64px + var(--safe-t)); }
  .choices { flex: 0 1 auto; min-height: 0; overflow-y: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
  .dialog { flex: none; min-height: 0; padding: 12px 20px calc(60px + var(--safe-b)); }
  .dialog.is-q { padding-bottom: calc(20px + var(--safe-b)); }
  .dialog__text { min-height: 0; }
  .dialog__next { bottom: calc(14px + var(--safe-b)); }
}

/* ---------- Layout ใหญ่ขึ้น ---------- */
@media (min-width: 900px) {
  #screen-story { flex-direction: row; align-items: flex-end; flex-wrap: wrap; }
  .choices { position: absolute; right: 6%; top: 50%; transform: translateY(-58%); width: 420px; max-width: 40vw; padding: 0; margin: 0; }
  .dialog { padding-bottom: calc(40px + var(--safe-b)); text-align: center; }
  .dialog__speaker { justify-content: center; }
  .dialog__speaker:not(:empty)::after { max-width: 120px; }
  .dialog__speaker:not(:empty)::before { content: ''; width: 120px; height: 1px; transform: none; background: linear-gradient(270deg, rgba(242, 220, 174, .8), transparent); }
}
/* จอเตี้ย (มือถือแนวนอน) */
@media (max-height: 520px) {
  .dialog { min-height: 0; padding-top: 8px; }
  .dialog__text { font-size: 17px; min-height: 0; }
  .choice { min-height: 42px; padding: 6px 16px 6px 10px; font-size: 15px; }
  .choices { gap: 6px; }
  #screen-title { padding-top: calc(56px + var(--safe-t)); }
  .title__main { font-size: 36px; }
}

/* มือถือแนวนอน: ตัวเลือกด้านขวา บทสนทนาด้านซ้าย */
@media (max-height: 520px) and (min-width: 600px) {
  .choices { position: absolute; right: 16px; top: calc(56px + var(--safe-t)); bottom: 16px; width: 50%; justify-content: center; padding: 0; margin: 0; }
  .dialog { margin: 0; width: 46%; padding-left: 20px; text-align: left; }
}

/* เครื่องที่ตั้งค่าลดการเคลื่อนไหว: ตัดเฉพาะการเคลื่อนที่ใหญ่ ๆ (ฉากหลังเลื่อน ป้ายเลื่อนเข้า)
   เอฟเฟกต์จาง/แสงเล็ก ๆ (ตัวอักษร วงแสงตอนแตะ) ยังคงไว้ */
@media (prefers-reduced-motion: reduce) {
  .bg-layer { animation: none; }
  .title__main, .title__sub, .title__desc, #screen-story.is-active .dialog { animation: none; }
  .choice { transform: none !important; }
}
