/* ผจญภัยสีเราะฮ์ — สไตล์ (มือถือก่อน, 3 โหมดสี: สว่าง / มืด / ถนอมสายตา) */
:root {
  --bg: #f6f1e4; --bg2: #fffaf0; --ink: #1e2a28; --muted: #5d6b66; --primary: #0f5a52; --primary-ink: #fff;
  --accent: #b8892a; --card: #ffffff; --line: #e2d8bf; --ok: #1f7a4d; --okbg: #e3f4ea; --bad: #a8372a; --badbg: #fbe8e4; --shadow: 0 6px 20px rgba(40, 30, 10, .12);
  --ar: 'Amiri', 'Noto Naskh Arabic', 'Scheherazade New', 'Traditional Arabic', serif;
  --th: 'Noto Sans Thai', 'Sarabun', 'Thonburi', 'Leelawadee UI', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
[data-theme="night"] {
  --bg: #0b1026; --bg2: #121a38; --ink: #e8ecf7; --muted: #9aa6c6; --primary: #2fa89a; --primary-ink: #04201c;
  --accent: #e8c66a; --card: #161f42; --line: #2a3566; --ok: #6fe0a6; --okbg: #12372c; --bad: #ff9a8a; --badbg: #3d1f24; --shadow: 0 6px 20px rgba(0, 0, 0, .45);
}
[data-theme="eye"] {
  --bg: #efe3c2; --bg2: #f5ebd0; --ink: #3a2f1c; --muted: #6b5a3a; --primary: #5f7138; --primary-ink: #fffbea;
  --accent: #9a6b1f; --card: #f8efd6; --line: #d6c597; --ok: #3f6a2c; --okbg: #e3ecc9; --bad: #94452a; --badbg: #f1dccb; --shadow: 0 4px 14px rgba(70, 50, 10, .12);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--th); font-size: 1.05rem; line-height: 1.75;
  min-height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-text-size-adjust: 100%; transition: background .3s, color .3s;
}
/* ฟิลเตอร์สีอุ่นลดแสงสีฟ้าในโหมดถนอมสายตา */
[data-theme="eye"] body::after { content: ''; position: fixed; inset: 0; background: rgba(255, 160, 50, .08); mix-blend-mode: multiply; pointer-events: none; z-index: 99; }
[data-theme="eye"] .scenery { filter: sepia(.4) saturate(.75) brightness(.88); }
[data-motion="off"] *, [data-motion="off"] *::before, [data-motion="off"] *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
#app { max-width: 600px; margin: 0 auto; min-height: 100dvh; }
h1, h2, h3 { line-height: 1.35; margin: .2em 0 .4em; }
.ar { font-family: var(--ar); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.pad { padding: 1rem 1rem 3rem; } .center { text-align: center; } .small { font-size: .88rem; color: var(--muted); } .hint { font-size: .85rem; color: var(--muted); text-align: center; }
.ok { color: var(--ok); font-weight: 600; }

/* แถบบน */
.topbar { display: flex; align-items: center; gap: .5rem; padding: .6rem .8rem; position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
.topbar.glass { background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(8px); border-bottom-color: transparent; }
.tb-title { flex: 1; margin: 0; font-size: 1.02rem; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 1.2rem; display: grid; place-items: center; }
.sp { width: 44px; }

/* ปุ่ม */
.btn { display: flex; align-items: center; justify-content: center; gap: .5rem; width: 100%; min-height: 52px; padding: .65rem 1rem; margin: .5rem 0; border-radius: 16px; border: 1.5px solid var(--line); background: var(--card); box-shadow: var(--shadow); font-weight: 600; text-align: center; transition: transform .1s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.accent { background: var(--accent); color: #fff; border-color: transparent; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.big { min-height: 72px; flex-direction: column; gap: 0; font-size: 1.2rem; }
.btn.big small { font-weight: 400; font-size: .85rem; opacity: .9; }
.btn.small { width: auto; min-height: 44px; padding: .4rem 1rem; display: inline-flex; font-size: .95rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.grid2 .btn { flex-direction: column; min-height: 88px; gap: .1rem; margin: 0; font-size: 1.7rem; line-height: 1.2; }
.grid2 .btn span { font-size: .92rem; }

/* หน้าแรก */
.home { padding: 1rem; }
.hero { text-align: center; padding: 1.2rem .5rem .6rem; }
.hero h1 { font-size: 2rem; margin: .4rem 0 0; color: var(--primary); }
[data-theme="night"] .hero h1 { color: var(--accent); }
.hero .sub { margin: .1rem 0; font-size: 1.1rem; } .hero .tag { margin: .2rem 0; color: var(--muted); font-size: .95rem; }
.logo { width: 92px; height: 92px; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .25)); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; margin: .8rem 0; }
.pill { background: var(--card); border: 1px solid var(--line); border-radius: 14px; text-align: center; padding: .35rem .2rem; line-height: 1.25; }
.pill b { display: block; font-size: 1.02rem; } .pill span { font-size: .72rem; color: var(--muted); } .pill.big b { color: var(--accent); font-size: 1.2rem; }
.foot { text-align: center; font-size: .78rem; color: var(--muted); padding: 0 1rem 2rem; }

/* แผนที่บท */
.map { list-style: none; margin: 0; padding: 0; position: relative; }
.map li { margin: .55rem 0; } .map li button { width: 100%; display: flex; gap: .8rem; align-items: center; text-align: left; padding: .7rem .9rem; border-radius: 18px; border: 1.5px solid var(--line); background: var(--card); box-shadow: var(--shadow); }
.map li.done button { border-color: var(--ok); } .map li.locked button { opacity: .55; }
.map .no { font-size: 1.7rem; width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; background: var(--bg2); flex: none; }
.map .tx { flex: 1; display: flex; flex-direction: column; line-height: 1.35; } .map .tx small { color: var(--muted); } .map .st { color: var(--accent); letter-spacing: 2px; font-size: .9rem; }

/* ฉาก */
.scene { position: relative; min-height: 100dvh; display: flex; flex-direction: column; overflow: hidden; background: #0b1026; }
.scenery { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }
.scene .topbar, .scene .prog, .scene .panel { position: relative; z-index: 2; }
.scene .topbar { position: sticky; }
.scene .tb-title { color: var(--ink); }
.prog { height: 5px; background: rgba(255, 255, 255, .25); } .prog i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.panel { margin: auto 0 0; max-height: 72dvh; overflow-y: auto; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(10px); border-radius: 26px 26px 0 0; padding: 1rem 1.1rem 1.6rem; box-shadow: 0 -8px 30px rgba(0, 0, 0, .35); max-width: 600px; width: 100%; align-self: center; }
.scene-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .3rem; } .scene-head h2 { margin: 0; font-size: 1.2rem; }
.chip { font-size: .75rem; background: var(--primary); color: var(--primary-ink); border-radius: 999px; padding: .1rem .6rem; white-space: nowrap; }
.era { font-size: .85rem; color: var(--accent); font-weight: 700; margin-bottom: .3rem; }
.story { font-size: 1.12rem; line-height: 1.9; margin: .3rem 0 .6rem; min-height: 5em; }
.next { margin-top: .8rem; }
.ayah { text-align: center; padding: .4rem 0; } .ayah .ar { font-size: 1.9rem; line-height: 2.3; color: var(--primary); } [data-theme="night"] .ayah .ar { color: var(--accent); }
.ayah .th { margin: .2rem 0; } .ayah .ref { font-size: .85rem; color: var(--muted); margin-bottom: .4rem; }
.kcard { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: .8rem 1rem; margin: .5rem 0; position: relative; }
.panel .kcard { background: var(--bg2); }
.kcard h3 { margin: 0 0 .3rem; font-size: 1.1rem; } .kcard p { margin: .3rem 0; }
.kcard summary { font-weight: 700; cursor: pointer; padding: .3rem 0; min-height: 44px; display: flex; align-items: center; }
.badge { position: absolute; top: -10px; right: 12px; background: var(--accent); color: #fff; font-size: .72rem; padding: .1rem .6rem; border-radius: 999px; animation: pop .5s; }
.refs { font-size: .85rem; color: var(--muted); } .refs ul, .refs ol { margin: .2rem 0; padding-left: 1.2rem; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.15); } 100% { transform: scale(1); opacity: 1; } }

/* ควิซและตัวเลือก */
.q { font-weight: 700; font-size: 1.08rem; margin: .3rem 0 .6rem; line-height: 1.6; }
.opt { display: block; width: 100%; text-align: left; margin: .45rem 0; padding: .75rem .9rem; min-height: 52px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); line-height: 1.5; }
.panel .opt { background: var(--bg2); }
.opt:not(:disabled):active { transform: scale(.99); } .opt:disabled { cursor: default; }
.opt.ok { border-color: var(--ok); background: var(--okbg); } .opt.bad { border-color: var(--bad); background: var(--badbg); }
.fb { border-radius: 14px; padding: .6rem .9rem; margin-top: .6rem; } .fb p { margin: .2rem 0 0; }
.fb.good { background: var(--okbg); border-left: 5px solid var(--ok); } .fb.try { background: var(--badbg); border-left: 5px solid var(--bad); }
.qhead { display: flex; justify-content: space-between; color: var(--muted); font-size: .9rem; margin-bottom: .4rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: .9rem 1rem; margin: .8rem 0; box-shadow: var(--shadow); }
.card.warn { border-color: var(--accent); }
.card h3 { margin-top: 0; }
.big-stars { font-size: 3rem; color: var(--accent); letter-spacing: 6px; margin: 1rem 0 0; }
.cert { border: 3px double var(--accent); border-radius: 20px; padding: 1.2rem 1rem; margin: 1rem 0; background: var(--card); }
.cert .ar.big { font-size: 1.6rem; color: var(--primary); } .cert .nm { font-size: 1.5rem; font-weight: 700; margin: .2rem 0; }
.lessons { text-align: left; padding-left: 1.2rem; }

/* สมุดความรู้ / ฟอร์ม / ออนไลน์ */
.grp { margin: 1.2rem 0 .2rem; font-size: 1rem; color: var(--primary); } [data-theme="night"] .grp { color: var(--accent); }
.search { width: 100%; padding: .7rem .9rem; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); font: inherit; margin: .4rem 0; min-height: 48px; }
.empty { text-align: center; color: var(--muted); padding: 2rem 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .45rem 0; min-height: 48px; }
.row select { max-width: 60%; padding: .45rem; border-radius: 10px; border: 1.5px solid var(--line); background: var(--bg2); color: var(--ink); font: inherit; }
.row input[type=checkbox] { width: 26px; height: 26px; accent-color: var(--primary); } .row input[type=range] { flex: 1; accent-color: var(--primary); }
.row .search { flex: 1; margin: 0; }
.lb ol { list-style: none; margin: 0; padding: 0; counter-reset: r; } .lb li { counter-increment: r; display: flex; align-items: center; gap: .6rem; padding: .4rem 0; border-bottom: 1px dashed var(--line); }
.lb li::before { content: counter(r); width: 28px; height: 28px; border-radius: 50%; background: var(--bg2); display: grid; place-items: center; font-size: .85rem; font-weight: 700; flex: none; }
.lb li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .lb li b { color: var(--accent); } .lb li small { color: var(--muted); }
.code { font-size: 3rem; font-weight: 800; letter-spacing: .3em; color: var(--primary); font-family: ui-monospace, monospace; } [data-theme="night"] .code { color: var(--accent); }

/* toast และแอนิเมชันฉาก */
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px); background: #222; color: #fff; padding: .6rem 1.1rem; border-radius: 999px; opacity: 0; pointer-events: none; transition: .3s; z-index: 100; max-width: 90vw; font-size: .92rem; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.tw { animation: tw 3.2s ease-in-out infinite; } @keyframes tw { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
.dust { animation: dust 20s linear infinite; } @keyframes dust { from { transform: translateX(-30px); } to { transform: translateX(430px); } }
@media (min-width: 700px) { .panel { border-radius: 26px; margin-bottom: 2rem; } body { font-size: 1.1rem; } }
@media print { .topbar, .btn, #toast { display: none !important; } }
