@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;
  --panel: rgba(244, 250, 252, .9); --panel2: rgba(236, 246, 249, .94);
  --tx: #12303a; --mut: #4d6a74; --ac: #0f6e8c; --ac2: #2f7d5a; --line: rgba(20, 90, 110, .24);
  --ok: #1f8a4c; --bad: #b4452f; --btn: #0f6e8c; --btnTx: #fff;
}
[data-theme=eye] {
  --panel: rgba(222, 236, 226, .92); --panel2: rgba(212, 229, 218, .95);
  --tx: #1f3a31; --mut: #52695d; --ac: #2b6f63; --ac2: #356a8a; --line: rgba(40, 90, 70, .26); --btn: #2b6f63;
}
[data-theme=night] {
  --panel: rgba(8, 16, 30, .84); --panel2: rgba(14, 26, 46, .92);
  --tx: #dfeaf0; --mut: #9fb4c0; --ac: #6fd0e6; --ac2: #8be0b5; --line: rgba(111, 208, 230, .24);
  --ok: #5fd090; --bad: #ff8f77; --btn: #6fd0e6; --btnTx: #06141c;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: var(--fs); }
body { margin: 0; font-family: 'Sarabun', 'Noto Sans Thai', system-ui, sans-serif; color: var(--tx); background: #0a1a26; line-height: 1.75; min-height: 100vh; overflow-x: hidden; }

#bg { position: fixed; inset: 0; z-index: 0; }
#bg .l { position: absolute; inset: 0; opacity: 0; transition: opacity 1.4s ease; }
#bg .l.on { opacity: 1; }
#bg svg { width: 100%; height: 100%; display: block; }
[data-theme=eye] #bg { filter: saturate(.8) brightness(.93) hue-rotate(-8deg); }
[data-theme=night] #bg { filter: brightness(.58) saturate(.9); }
#warm { position: fixed; inset: 0; z-index: 90; pointer-events: none; background: rgb(255, 150, 50); opacity: var(--warmA); mix-blend-mode: multiply; }

/* ภาพเคลื่อนไหวเล็กน้อย */
.tw { animation: tw 4s ease-in-out infinite alternate; }
@keyframes tw { from { opacity: .25; } to { opacity: 1; } }
.dr { animation: dr 46s ease-in-out infinite alternate; }
.dr.d1 { animation-duration: 38s; } .dr.d2 { animation-duration: 30s; } .dr.c1 { animation-duration: 90s; }
@keyframes dr { from { transform: translateX(-18px); } to { transform: translateX(18px); } }
.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(-14px); } }
.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.2deg; } to { rotate: 1.2deg; } }
.wv { animation: wv 9s linear infinite; } .w1 { animation-duration: 12s; } .w2 { animation-duration: 15s; animation-direction: reverse; } .w3 { animation-duration: 19s; }
@keyframes wv { from { transform: translateX(0); } to { transform: translateX(-100px); } }
.wtr { animation: orb 3s ease-in-out infinite alternate; }
.flame { animation: fm .6s ease-in-out infinite alternate; transform-origin: bottom; transform-box: fill-box; }
@keyframes fm { from { transform: scaleY(.9) skewX(-3deg); } to { transform: scaleY(1.08) skewX(3deg); } }
.glow { animation: orb 3.5s ease-in-out infinite alternate; }
.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; }
.ray { animation: bm 8s ease-in-out infinite alternate; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* โครง */
#top { position: fixed; top: 0; left: 0; right: 0; z-index: 30; display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: linear-gradient(var(--panel), transparent); backdrop-filter: blur(6px); }
#top h1 { flex: 1; font-size: 1.02rem; margin: 0; font-weight: 700; line-height: 1.2; }
#top h1 small { display: block; font-weight: 400; font-size: .72rem; color: var(--mut); }
.ib { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--tx); display: grid; place-items: center; cursor: pointer; font-size: 1.1rem; }
.ib svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ib.on { background: var(--btn); color: var(--btnTx); }

#view { position: relative; z-index: 5; max-width: 760px; margin: 0 auto; padding: calc(64px + env(safe-area-inset-top)) 14px calc(92px + env(safe-area-inset-bottom)); animation: in .5s ease; }
@keyframes in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

#nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: var(--panel); backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
#nav a { flex: 1; max-width: 110px; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 2px; color: var(--mut); text-decoration: none; font-size: .68rem; border-radius: 10px; }
#nav a svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#nav a.on { color: var(--ac); font-weight: 700; background: color-mix(in srgb, var(--ac) 12%, transparent); }
body.imm #nav { display: none; } body.imm #view { padding-bottom: 24px; max-width: 700px; }

/* องค์ประกอบ */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin: 0 0 14px; backdrop-filter: blur(8px); box-shadow: 0 6px 24px rgba(0, 0, 0, .15); }
.card h2, .card h3 { margin: 0 0 6px; line-height: 1.35; }
.mut { color: var(--mut); } .sm { font-size: .84rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border-radius: 14px; border: 0; background: var(--btn); color: var(--btnTx); font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn.alt { background: transparent; color: var(--tx); border: 1px solid var(--line); }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: .85rem; }
.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: 6px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel); color: var(--tx); font: inherit; font-size: .85rem; cursor: pointer; }
.chip.on { background: var(--btn); color: var(--btnTx); border-color: transparent; }
.badge { display: inline-block; padding: 1px 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(--ac); border-color: var(--ac); }
.hon { font-family: 'KFGQPC', 'Amiri Quran', 'Amiri', serif; color: var(--ac); 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.65rem; line-height: 2.3; margin: 8px 0; }
.ar.h { font-size: 1.35rem; line-height: 2.1; }
.hero { text-align: center; padding: 26px 16px; }
.hero .ar { text-align: center; font-size: 2.1rem; margin: 0; }
.hero h2 { font-size: 1.3rem; margin: 6px 0; }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.bar { height: 9px; border-radius: 9px; background: var(--line); overflow: hidden; } .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--ac2), var(--ac)); border-radius: 9px; transition: width .8s; }
.stat { display: grid; grid-template-columns: 1fr 44px; gap: 4px 8px; align-items: center; font-size: .84rem; margin: 6px 0; }

/* เส้นทางผจญภัย */
.path { position: relative; padding-left: 8px; }
.node { display: flex; gap: 12px; align-items: stretch; text-decoration: none; color: inherit; margin-bottom: 12px; }
.node .n { flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--panel2); border: 2px solid var(--ac); color: var(--ac); box-shadow: 0 0 16px color-mix(in srgb, var(--ac) 45%, transparent); }
.node.done .n { background: var(--ac); color: var(--btnTx); }
.node .card { flex: 1; margin: 0; padding: 12px 14px; }
.stars { letter-spacing: 2px; color: var(--ac); }

/* ฉากเล่น */
.hud { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.pill { padding: 3px 12px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); font-size: .78rem; backdrop-filter: blur(6px); }
.dots { display: flex; gap: 4px; flex: 1; justify-content: center; } .dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); } .dots i.on { background: var(--ac); } .dots i.cur { box-shadow: 0 0 8px var(--ac); background: var(--ac2); }
.stage { margin-top: 36vh; } .stage .card { background: var(--panel2); }
.story { font-size: 1.07rem; animation: in .7s ease; }
.opt { display: block; width: 100%; text-align: left; margin: 8px 0; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--panel); color: var(--tx); font: inherit; cursor: pointer; }
.opt.ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, var(--panel)); }
.opt.no { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 13%, var(--panel)); }
.opt:disabled { cursor: default; }
.fb { padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--ac) 10%, transparent); border-left: 4px solid var(--ac); margin: 10px 0; animation: in .5s; }
.slots { min-height: 52px; padding: 8px; border: 2px dashed var(--line); border-radius: 14px; display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.slots .opt { margin: 0; padding: 8px 12px; }

/* ไทม์ไลน์ */
.tl { position: relative; margin-left: 10px; padding-left: 22px; border-left: 2px solid var(--ac); }
.tl .it { position: relative; margin-bottom: 14px; }
.tl .it::before { content: ''; position: absolute; left: -30px; top: 18px; width: 14px; height: 14px; border-radius: 50%; background: var(--ac); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ac) 25%, transparent); }
details > summary { cursor: pointer; color: var(--ac); font-size: .85rem; }

/* นิทานก่อนนอน */
.bed { text-align: center; min-height: 62vh; display: flex; flex-direction: column; justify-content: center; }
.bed .tx { font-size: 1.28rem; line-height: 2.05; animation: in 1.2s; }

.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; background: var(--panel2); color: var(--tx); padding: 10px 18px; border-radius: 99px; border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0, 0, 0, .3); font-size: .9rem; max-width: 90vw; }
input, select { font: inherit; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--tx); width: 100%; margin: 4px 0; }
input[type=range] { padding: 0; }
a { color: var(--ac2); }
.lb td { padding: 4px 8px; border-bottom: 1px solid var(--line); } .lb { width: 100%; border-collapse: collapse; font-size: .9rem; }
@media (min-width: 700px) { .stage { margin-top: 32vh; } }

.rn { animation: rn 1.1s linear infinite; }
@keyframes rn { from { transform: translate(0, 0); } to { transform: translate(-30px, 680px); } }
