@font-face { font-family: 'KFGQPC'; src: local('KFGQPC Uthman Taha Naskh'), local('KFGQPC HAFS Uthmanic Script'), url('fonts/UthmanicHafs.woff2') format('woff2'); font-display: swap; }

:root {
  --fs: 100%; --warmA: 0;
  --bgc: #f7f0e2; --card: #ffffff; --card2: #fffaf0; --tx: #1f2a28; --mut: #6d7a74;
  --g: #0f5a4f; --g2: #137a6b; --gold: #b88a2a; --line: #e6dcc6; --ok: #1f8a4c; --bad: #b4452f;
  --sh: 0 3px 12px rgba(80, 60, 20, .12); --sheet: rgba(255, 255, 255, .95);
}
[data-theme=eye] { --bgc: #f1e6c8; --card: #fbf3dd; --card2: #f6ebce; --tx: #3a3220; --mut: #7a6e50; --line: #dccda4; --sheet: rgba(251, 243, 221, .96); }
[data-theme=night] { --bgc: #0d1a1a; --card: #15262a; --card2: #1a3034; --tx: #ece6d2; --mut: #a4b3ab; --g: #1c9a86; --g2: #23b39d; --gold: #e0b94f; --line: #28403f; --sh: 0 3px 14px rgba(0, 0, 0, .4); --sheet: rgba(21, 38, 42, .96); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: var(--fs); }
body { margin: 0; font-family: 'Prompt', 'Sarabun', 'Noto Sans Thai', system-ui, sans-serif; color: var(--tx); background: var(--bgc); line-height: 1.7; min-height: 100vh; overflow-x: hidden; }
#bg { position: fixed; inset: 0; z-index: 0; opacity: 0; transition: opacity .8s; }
body.scene #bg { opacity: 1; }
#bg svg { width: 100%; height: 100%; display: block; }
body.scene[data-theme=night] #bg { filter: brightness(.7); }
#fx { position: fixed; inset: 0; z-index: 1; pointer-events: none; overflow: hidden; }
#warm { position: fixed; inset: 0; z-index: 90; pointer-events: none; background: rgb(255, 150, 50); opacity: var(--warmA); mix-blend-mode: multiply; }

/* ดาววิบวับ + ใบไม้ปลิว */
.sp { position: absolute; width: 14px; height: 14px; opacity: 0; animation: spk 3.4s ease-in-out infinite; }
.sp svg { width: 100%; height: 100%; fill: var(--gold); }
@keyframes spk { 0%, 100% { opacity: 0; transform: scale(.3) rotate(0); } 50% { opacity: .95; transform: scale(1) rotate(45deg); } }
.lf { position: absolute; top: -30px; width: 22px; height: 22px; opacity: .8; animation: fall linear infinite; }
.lf svg { width: 100%; height: 100%; }
@keyframes fall { 0% { transform: translate(0, -30px) rotate(0); } 25% { transform: translate(40px, 25vh) rotate(90deg); } 50% { transform: translate(-30px, 50vh) rotate(180deg); } 75% { transform: translate(50px, 75vh) rotate(270deg); } 100% { transform: translate(-10px, 108vh) rotate(360deg); } }
body.scene .lf { opacity: .55; }

/* ฉาก */
.tw { animation: tw 4s ease-in-out infinite alternate; } @keyframes tw { from { opacity: .25; } to { opacity: 1; } }
.dr { animation: dr 60s ease-in-out infinite alternate; } @keyframes dr { from { transform: translateX(-24px); } to { transform: translateX(24px); } }
.orb { animation: orb 5s ease-in-out infinite alternate; transform-origin: center; transform-box: fill-box; } @keyframes orb { from { opacity: .75; transform: scale(.94); } to { opacity: 1; transform: scale(1.06); } }
.orbg { animation: fl 7s ease-in-out infinite alternate; } @keyframes fl { from { transform: translateY(0); } to { transform: translateY(-12px); } }
.fl { animation: fl 8s ease-in-out infinite alternate; } .f1 { animation-delay: 1s; } .f2 { animation-delay: 2s; } .f3 { animation-delay: 3s; } .f4 { animation-delay: 4s; }
.beam { animation: bm 6s ease-in-out infinite alternate; } .b1 { animation-delay: 1.5s; } .b2 { animation-delay: 3s; } @keyframes bm { from { opacity: .2; } to { opacity: .6; } }
.sway { animation: sw 6s ease-in-out infinite alternate; transform-origin: bottom center; transform-box: fill-box; } @keyframes sw { from { rotate: -1.5deg; } to { rotate: 1.5deg; } }
.wv { animation: wv 10s linear infinite; } .w1 { animation-duration: 13s; } .w2 { animation-duration: 16s; animation-direction: reverse; } .w3 { animation-duration: 20s; } @keyframes wv { from { transform: translateX(0); } to { transform: translateX(-100px); } }
.wtr, .glow { animation: orb 3s ease-in-out infinite alternate; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } .sp, .lf { display: none; } }

/* โครงหน้า */
#view { position: relative; z-index: 5; max-width: 430px; margin: 0 auto; padding: 14px 14px calc(60px + env(safe-area-inset-bottom)); animation: in .45s ease; }
@keyframes in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.bar { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 8px 8px; background: var(--sheet); border-bottom: 1px solid var(--line); border-radius: 12px; box-shadow: var(--sh); position: sticky; top: 6px; z-index: 20; backdrop-filter: blur(8px); }
.bar .bt { flex: 1; text-align: center; font-weight: 600; font-size: .92rem; line-height: 1.3; }
.rb { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--tx); display: grid; place-items: center; cursor: pointer; text-decoration: none; font-size: 1.05rem; flex: none; }
.pbar { height: 4px; background: var(--line); border-radius: 4px; margin: -6px 6px 10px; overflow: hidden; } .pbar i { display: block; height: 100%; background: var(--gold); transition: width .5s; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 0 0 12px; box-shadow: var(--sh); }
.card h3, .card h2 { margin: 0 0 4px; line-height: 1.35; }
.mut { color: var(--mut); } .sm { font-size: .84rem; } .gold { color: var(--gold); font-weight: 600; }
.btn { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; padding: 12px 16px; border-radius: 12px; border: 0; background: var(--g); color: #fff; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 46px; box-shadow: var(--sh); }
.btn small { display: block; font-weight: 400; font-size: .74rem; opacity: .9; }
.btn.gold { background: var(--gold); } .btn.alt { background: var(--card); color: var(--tx); border: 1px solid var(--line); box-shadow: none; }
.btn.sm { width: auto; min-height: 36px; padding: 6px 14px; font-size: .84rem; } .btn:disabled { opacity: .45; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chip { flex: none; padding: 5px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--tx); font: inherit; font-size: .84rem; cursor: pointer; text-decoration: none; }
.chip.on { background: var(--g); color: #fff; border-color: transparent; }
.badge { display: inline-block; padding: 0 10px; border-radius: 99px; font-size: .72rem; border: 1px solid var(--line); color: var(--mut); }
.badge.s { color: var(--ok); border-color: var(--ok); } .badge.h { color: var(--gold); border-color: var(--gold); }
.hon { font-family: 'KFGQPC', 'Amiri Quran', 'Amiri', serif; color: var(--gold); font-size: 1.04em; white-space: nowrap; }
.ar { font-family: 'KFGQPC', 'Amiri Quran', 'Amiri', 'Noto Naskh Arabic', serif; direction: rtl; text-align: right; font-size: 1.6rem; line-height: 2.3; margin: 8px 0; } .ar.h { font-size: 1.3rem; line-height: 2.1; }

/* หน้าหลัก */
.home { text-align: center; padding-top: 10px; }
.logo { width: 60px; height: 60px; margin: 0 auto 8px; border-radius: 50%; background: var(--g); border: 3px solid var(--gold); display: grid; place-items: center; box-shadow: var(--sh); }
.logo svg { width: 34px; height: 34px; }
.home h1 { margin: 6px 0 2px; font-size: 1.55rem; color: var(--g); min-height: 2.2rem; }
.home .sub { font-weight: 600; min-height: 1.6em; } .home .tag { font-size: .8rem; color: var(--mut); margin: 4px 6px 14px; min-height: 2.6em; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px 2px; box-shadow: var(--sh); font-size: .7rem; color: var(--mut); line-height: 1.3; }
.tile b { display: block; font-size: 1.05rem; color: var(--tx); } .tile.sc b { color: var(--gold); font-size: 1.25rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.mn { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px; box-shadow: var(--sh); text-decoration: none; color: var(--tx); font-weight: 600; font-size: .86rem; min-height: 62px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; }
.mn span { font-size: 1.5rem; line-height: 1; }
.foot { font-size: .7rem; color: var(--mut); margin: 12px 8px 0; }

/* แผนที่บท */
.ch { display: flex; align-items: center; gap: 12px; padding: 10px 14px; margin-bottom: 8px; background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; box-shadow: var(--sh); text-decoration: none; color: var(--tx); }
.ch.done { border-color: var(--g); } .ch.lock { opacity: .55; filter: grayscale(.6); pointer-events: none; }
.ch .ic { width: 38px; height: 38px; border-radius: 50%; background: var(--card2); display: grid; place-items: center; font-size: 1.3rem; flex: none; }
.ch .tt { flex: 1; font-weight: 600; font-size: .9rem; line-height: 1.35; } .ch .tt small { display: block; font-weight: 400; color: var(--mut); font-size: .74rem; }
.ch .st { color: var(--gold); letter-spacing: 2px; font-size: .78rem; }

/* ฉากเล่าเรื่อง */
.sheet { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + env(safe-area-inset-bottom)); width: calc(100% - 28px); max-width: 402px; max-height: 64vh; overflow: auto; background: var(--sheet); border-radius: 22px; padding: 16px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); backdrop-filter: blur(8px); z-index: 30; animation: in .4s; }
.pill { display: inline-block; padding: 1px 10px; border-radius: 99px; background: var(--g); color: #fff; font-size: .7rem; font-weight: 600; }
.sheet h3 { display: inline; margin: 0 0 0 6px; font-size: 1rem; }
.at { color: var(--gold); font-size: .78rem; font-weight: 600; margin: 4px 0 6px; }
.tx { font-size: .95rem; min-height: 4.5em; }
.caret::after { content: '▍'; color: var(--gold); animation: blink .8s steps(1) infinite; margin-left: 1px; } @keyframes blink { 50% { opacity: 0; } }
.opt { display: block; width: 100%; text-align: left; margin: 7px 0; padding: 10px 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); color: var(--tx); font: inherit; font-size: .9rem; cursor: pointer; }
.opt.ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--card)); } .opt.no { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--card)); } .opt:disabled { cursor: default; }
.fb { padding: 9px 12px; border-radius: 10px; background: color-mix(in srgb, var(--gold) 12%, transparent); border-left: 4px solid var(--gold); margin: 8px 0; font-size: .88rem; animation: in .4s; }
.slots { min-height: 48px; padding: 6px; border: 2px dashed var(--line); border-radius: 12px; display: flex; flex-direction: column; gap: 6px; margin: 6px 0; } .slots .opt { margin: 0; }
.stars { color: var(--gold); letter-spacing: 3px; font-size: 1.6rem; text-align: center; }

/* ไทม์ไลน์ / เล่าก่อนนอน / สมุด */
.tl { margin-left: 8px; padding-left: 18px; border-left: 2px dashed var(--gold); } .tl .it { position: relative; margin-bottom: 12px; } .tl .it::before { content: ''; position: absolute; left: -26px; top: 18px; width: 12px; height: 12px; border-radius: 50%; background: var(--gold); }
.bed { text-align: center; min-height: 52vh; display: flex; flex-direction: column; justify-content: center; } .bed .tx { font-size: 1.15rem; line-height: 2; min-height: 8em; }
.nb { display: grid; grid-template-columns: 1fr; gap: 8px; } .nb .card { margin: 0; } .nb .lk { opacity: .5; text-align: center; }
details > summary { cursor: pointer; color: var(--g2); font-size: .85rem; }
.fab { position: fixed; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 40; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--sheet); color: var(--tx); font-size: 1.1rem; cursor: pointer; box-shadow: var(--sh); }
body.playing .fab { bottom: auto; top: 64px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 100; background: var(--g); color: #fff; padding: 9px 18px; border-radius: 99px; box-shadow: var(--sh); font-size: .88rem; max-width: 90vw; }
input, select { font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--tx); width: 100%; margin: 4px 0; } input[type=range] { padding: 0; }
a { color: var(--g2); } table.lb { width: 100%; border-collapse: collapse; font-size: .9rem; } .lb td { padding: 4px 8px; border-bottom: 1px solid var(--line); }
