/* ยามชีวิตผลิบานในดินแดนแห่งนักหลอม · หน้าตาแบบหนังสือเขียนมือยุคกลางตะวันตก
   แผ่นหนังลูกวัว (vellum) เส้นคู่สีทอง ตราครั่งแดง ตัวอักษรนำแบบคัมภีร์ และเส้นวงเวทเรืองจาง ๆ
   ฟอนต์: Chonburi (หัวเรื่องไทย) · Maitree (หัวข้อรองและคำเลือก) · Cinzel (อักษรละติน) · Trirong (เนื้อความ) · Sarabun (ป้ายเล็ก)
   Layout: ภาพวาดเต็มจอเป็นเวที · ซ้าย = ป้ายประวัติ · ขวา = ม้วนบันทึกชีวิต · ทางแยกโผล่ท้ายม้วน */
:root {
  --paper: rgba(252, 250, 245, .93);
  --paper-2: rgba(246, 242, 232, .97);
  --paper-solid: #f8f5ee;
  --vellum: #fdfbf7;
  --ink: #2a1d12;
  --ink-2: #5a4632;
  --ink-3: #85705a;
  --line: rgba(120, 92, 40, .17);
  --rule: #b08d48;
  --gold: #94702a;
  --gilt: #c9a24c;
  --seal: #8e2a22;
  --seal-ink: #fbeee0;
  --jade: #3a6652;
  --azure: #2c5274;
  --veil: rgba(28, 18, 8, .5);
  --shadow: 0 18px 50px rgba(40, 24, 8, .28);
  --magic: #7fd2f2;
  --stain: rgba(190, 160, 90, .07);
  --wash-bg: transparent; --wash-pad: 0px;
  --f-body: "Trirong", "Taviraj", "Leelawadee UI", serif;
  --f-disp: "Chonburi", "Trirong", serif;
  --f-script: "Maitree", "Trirong", serif;
  --f-latin: "Cinzel", "Trirong", serif;
  --f-ui: "Sarabun", "Leelawadee UI", sans-serif;
  --f-sym: "Segoe UI Symbol", "Noto Sans Symbols 2", "Noto Sans Symbols", "Cinzel", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: rgba(31, 23, 17, .88); --paper-2: rgba(40, 30, 22, .95); --paper-solid: #1c1510; --vellum: #231a13;
    --ink: #eee0c4; --ink-2: #c6b393; --ink-3: #8f7c62; --line: rgba(238, 224, 196, .14); --rule: #a8844a;
    --gold: #d8b468; --gilt: #d2ad5e; --seal: #b23a2e; --seal-ink: #fff0e0; --jade: #7cc0a6; --azure: #7fb0d8;
    --veil: rgba(0, 0, 0, .6); --shadow: 0 18px 50px rgba(0, 0, 0, .55); --magic: #9fe2ff; --stain: rgba(0, 0, 0, .18); --wash-bg: #e9dcc0; --wash-pad: 5px; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: rgba(31, 23, 17, .88); --paper-2: rgba(40, 30, 22, .95); --paper-solid: #1c1510; --vellum: #231a13;
  --ink: #eee0c4; --ink-2: #c6b393; --ink-3: #8f7c62; --line: rgba(238, 224, 196, .14); --rule: #a8844a;
  --gold: #d8b468; --gilt: #d2ad5e; --seal: #b23a2e; --seal-ink: #fff0e0; --jade: #7cc0a6; --azure: #7fb0d8;
  --veil: rgba(0, 0, 0, .6); --shadow: 0 18px 50px rgba(0, 0, 0, .55); --magic: #9fe2ff; --stain: rgba(0, 0, 0, .18); --wash-bg: #e9dcc0; --wash-pad: 5px; color-scheme: dark;
}

[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body.splashing #char, body.splashing #story, body.splashing #inscr, body.splashing .ctrl { visibility: hidden; }
body { margin: 0; overflow: hidden; background: var(--paper-solid); color: var(--ink); font: 400 16px/1.85 var(--f-body); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, .opt:focus-visible { outline: 2px solid var(--gilt); outline-offset: 2px; }
#scene { position: fixed; inset: 0; z-index: 0; display: block; }

/* ---------- วัสดุ: แผ่นหนังพร้อมเส้นคู่สีทอง ---------- */
#char, #story, .endcard, .bookcard, .mpcard, .spl {
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse at 12% 8%, rgba(255, 250, 235, .28), transparent 55%),
    radial-gradient(ellipse at 92% 96%, var(--stain), transparent 55%),
    radial-gradient(ellipse at 70% 30%, var(--stain), transparent 40%);
  box-shadow: var(--shadow), inset 0 0 0 1px color-mix(in srgb, var(--rule) 70%, transparent), inset 0 0 0 5px transparent, inset 0 0 0 6px color-mix(in srgb, var(--gilt) 45%, transparent), inset 0 0 40px var(--stain);
}
.endcard, .bookcard, .mpcard, .spl {
  background-color: var(--vellum);
  background-image:
    linear-gradient(var(--gilt), var(--gilt)), linear-gradient(var(--gilt), var(--gilt)),
    linear-gradient(var(--gilt), var(--gilt)), linear-gradient(var(--gilt), var(--gilt)),
    linear-gradient(var(--gilt), var(--gilt)), linear-gradient(var(--gilt), var(--gilt)),
    linear-gradient(var(--gilt), var(--gilt)), linear-gradient(var(--gilt), var(--gilt)),
    radial-gradient(ellipse at 12% 8%, rgba(255, 250, 235, .3), transparent 55%),
    radial-gradient(ellipse at 92% 96%, var(--stain), transparent 55%);
  background-repeat: no-repeat;
  background-size: 26px 2px, 2px 26px, 26px 2px, 2px 26px, 26px 2px, 2px 26px, 26px 2px, 2px 26px, auto, auto;
  background-position: 12px 12px, 12px 12px, right 12px top 12px, right 12px top 12px, 12px bottom 12px, 12px bottom 12px, right 12px bottom 12px, right 12px bottom 12px, 0 0, 0 0;
}

/* ---------- ตราครั่ง ---------- */
.wax, .brand .seal, #inscr .sealsm, .stamp, .eseal, .achseal, #mini b {
  --wax: var(--seal);
  position: relative; display: grid; place-items: center; flex: none;
  background: radial-gradient(circle at 34% 28%, color-mix(in srgb, var(--wax) 55%, #ffe8d0) 0 7%, color-mix(in srgb, var(--wax) 88%, #fff) 20%, var(--wax) 46%, color-mix(in srgb, var(--wax) 66%, #000) 100%);
  border-radius: 49% 51% 46% 54% / 53% 47% 53% 47%;
  box-shadow: 0 1.5px 0 color-mix(in srgb, var(--wax) 55%, #000), 0 4px 10px rgba(0, 0, 0, .28), inset 0 0 0 2px color-mix(in srgb, var(--wax) 80%, #000), inset 0 0 0 4px rgba(255, 235, 210, .1);
  color: color-mix(in srgb, var(--wax) 35%, #000); font-family: var(--f-sym); font-weight: 700;
  text-shadow: 0 1px 0 rgba(255, 230, 205, .32), 0 -1px 0 rgba(0, 0, 0, .3);
}
.wax::before, .brand .seal::before, #inscr .sealsm::before, .stamp::before, .eseal::before, .achseal::before {
  content: ""; position: absolute; inset: 17%; border-radius: 50%; border: 1.5px solid color-mix(in srgb, var(--wax) 55%, #000); box-shadow: 0 1px 0 rgba(255, 230, 205, .2), inset 0 1px 0 rgba(0, 0, 0, .15); opacity: .7; pointer-events: none;
}
.t0 { --wax: #5e5048; } .t1 { --wax: #8a4a2a; } .t2 { --wax: var(--seal); } .t3 { --wax: var(--seal); } .t4 { --wax: #b8892e; }
.stamp.t3, .ecell.got.t3 .eseal { box-shadow: 0 1.5px 0 color-mix(in srgb, var(--wax) 55%, #000), 0 0 0 3px color-mix(in srgb, var(--gilt) 70%, transparent), 0 0 30px rgba(214, 170, 70, .55), inset 0 0 0 2px color-mix(in srgb, var(--wax) 80%, #000); }
.stamp.t4, .ecell.got.t4 .eseal { box-shadow: 0 0 34px rgba(230, 190, 90, .75), inset 0 0 0 2px color-mix(in srgb, var(--wax) 70%, #000); }

/* ---------- วงเวทเรืองจาง ๆ ---------- */
.mc { position: absolute; pointer-events: none; aspect-ratio: 1; border-radius: 50%; border: 1px solid color-mix(in srgb, var(--magic) 55%, transparent); box-shadow: 0 0 22px color-mix(in srgb, var(--magic) 30%, transparent), inset 0 0 22px color-mix(in srgb, var(--magic) 20%, transparent); opacity: .7; }
.mc::before, .mc::after { content: ""; position: absolute; border-radius: 50%; }
.mc::before { inset: 9%; border: 1px dashed color-mix(in srgb, var(--magic) 60%, transparent); animation: spin 90s linear infinite; }
.mc::after { inset: 20%; background: repeating-conic-gradient(from 0deg, color-mix(in srgb, var(--magic) 55%, transparent) 0 .6deg, transparent .6deg 30deg); -webkit-mask: radial-gradient(circle, transparent 62%, #000 63% 99%, transparent 100%); mask: radial-gradient(circle, transparent 62%, #000 63% 99%, transparent 100%); border: 1px solid color-mix(in srgb, var(--magic) 45%, transparent); animation: spin 140s linear infinite reverse; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- header ---------- */
#top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-top: max(12px, env(safe-area-inset-top, 0px)); padding-bottom: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  pointer-events: none;
}
#top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 5px 16px 5px 6px; border-radius: 999px; background: var(--paper); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow), inset 0 0 0 1px color-mix(in srgb, var(--gilt) 50%, transparent); }
.brand .seal { width: 38px; height: 38px; font: 700 20px/1 var(--f-latin); }
.brand b { display: block; font: 400 16px/1.45 var(--f-disp); letter-spacing: .01em; }
.brand small { display: block; font: 12px/1.2 var(--f-ui); color: var(--ink-3); }
.ctrl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.ctrl > button, .seg { height: 38px; border: 0; border-radius: 999px; background: var(--paper); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow), inset 0 0 0 1px color-mix(in srgb, var(--gilt) 40%, transparent); }
.ctrl > button { padding: 0 14px; font: 14px var(--f-ui); display: inline-flex; align-items: center; gap: 6px; }
.ctrl > button:hover { background: var(--paper-2); }
.seg { display: flex; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; border-radius: 999px; min-width: 38px; padding: 0 8px; font: 13px var(--f-ui); font-variant-numeric: tabular-nums; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper-solid); }
#bAuto[aria-pressed="true"], #bMusic[aria-pressed="true"] { background: var(--seal); color: var(--seal-ink); }
/* ปุ่มเพลงกับแถบระดับเสียงอยู่ในเม็ดเดียวกัน */
.volbox { height: 38px; display: inline-flex; align-items: center; gap: 4px; padding: 0 12px 0 0; border-radius: 999px; background: var(--paper); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow), inset 0 0 0 1px color-mix(in srgb, var(--gilt) 40%, transparent); }
.volbox #bMusic { height: 38px; border: 0; border-radius: 999px; padding: 0 12px; font: 14px var(--f-ui); display: inline-flex; align-items: center; gap: 6px; background: transparent; }
.volbox #bMusic[aria-pressed="true"] { background: var(--seal); color: var(--seal-ink); }
.volrange { --v: 60%; -webkit-appearance: none; appearance: none; width: 74px; height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--gilt) var(--v), var(--line) var(--v)); outline: none; cursor: pointer; }
.volrange::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--seal); box-shadow: 0 0 0 2px var(--paper-solid), 0 1px 3px rgba(0,0,0,.3); }
.volrange::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--seal); box-shadow: 0 0 0 2px var(--paper-solid); }
.volrange:focus-visible { outline: 2px solid var(--gilt); outline-offset: 4px; }
.volrange.wide { display: block; width: 100%; margin: 10px 0 4px; }
#bAuto[aria-pressed="true"] .die { fill: var(--seal-ink); }
.die { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.die circle { fill: currentColor; stroke: none; }
#bChar[aria-pressed="true"] { background: var(--ink); color: var(--paper-solid); }

/* ---------- จารึกบนภาพ ---------- */
#inscr { position: fixed; z-index: 1; top: 88px; left: max(24px, 2.6vw, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; align-items: flex-start; gap: 2px; pointer-events: none; color: rgba(28, 18, 10, .82); text-shadow: 0 0 16px rgba(255, 250, 238, .7), 0 0 2px rgba(255, 250, 238, .6); }
#inscr .v { font: 600 21px/1.15 var(--f-latin); letter-spacing: .14em; text-transform: uppercase; display: flex; align-items: center; gap: 10px; }
#inscr .v::before, #inscr .v::after { content: ""; width: 26px; height: 1px; background: currentColor; opacity: .55; }
#inscr .vt { font: 600 14px/1.4 var(--f-body); letter-spacing: .04em; }
#inscr .sealsm { width: 30px; height: 30px; margin-top: 6px; font-size: 15px; text-shadow: none; transform: rotate(-6deg); }

/* ---------- panels ---------- */
#char, #story { position: fixed; z-index: 3; backdrop-filter: blur(14px) saturate(1.1); -webkit-backdrop-filter: blur(14px) saturate(1.1); border-radius: 14px; }
/* ภาพคือเวที: แถบบันทึกอยู่ล่าง ข้อมูลตัวละครเป็นลิ้นชักซ้ายที่ปิดไว้ก่อน */
body { --band: max(240px, 36vh); }
body.band0 { --band: max(170px, 24vh); }
body.band2 { --band: max(320px, 62vh); }
#char { top: 76px; bottom: 16px; left: max(16px, env(safe-area-inset-left, 0px)); width: 340px; overflow: auto; padding: 20px 20px 22px; display: flex; flex-direction: column; gap: 16px; scrollbar-width: thin; z-index: 6; background-color: var(--paper-solid); transform: translateX(calc(-100% - 32px)); transition: transform .4s ease; }
body.showchar #char { transform: none; }
.charx { position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; border: 0; border-radius: 50%; background: var(--line); font: 18px/1 var(--f-ui); color: var(--ink-2); }
.charx:hover { background: color-mix(in srgb, var(--seal) 18%, transparent); color: var(--seal); }
/* แถบบันทึกเต็มความกว้างที่ขอบล่าง ภาพฉากใหญ่ถูกวาดในพื้นที่เหนือแถบเท่านั้น (scene.js) จึงไม่มีส่วนใดของภาพถูกบัง */
#story { left: 0; right: 0; bottom: 0; height: var(--band); border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); display: flex; flex-direction: column; overflow: hidden; }
#bandbar { flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 14px 7px max(18px, env(safe-area-inset-left, 0px)); border-bottom: 1px solid color-mix(in srgb, var(--gilt) 40%, transparent); }
#mini { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; font-size: 13px; cursor: pointer; border-radius: 8px; }
#mini span { font: 400 15px/1.5 var(--f-disp); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#mini em { font: normal 13px var(--f-ui); color: var(--ink-3); white-space: nowrap; }
#mini .minihint { margin-left: 6px; font: 600 12px/1 var(--f-ui); font-style: normal; color: var(--seal); padding: 5px 10px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--seal) 35%, transparent); white-space: nowrap; }
#mini:hover .minihint { background: color-mix(in srgb, var(--seal) 10%, transparent); }
#bandctl { flex: none; display: flex; gap: 4px; }
#bandctl button { width: 30px; height: 28px; border: 1px solid var(--line); border-radius: 8px; background: var(--vellum); font: 13px/1 var(--f-sym); color: var(--ink-2); }
#bandctl button:hover:not(:disabled) { border-color: var(--gilt); color: var(--seal); }
#bandctl button:disabled { opacity: .35; cursor: default; }
#log .step { max-width: 1000px; margin-inline: auto; }

.who { display: flex; gap: 14px; align-items: center; padding-right: 28px; }
.whotx { min-width: 0; }
.whotx h2 { margin: 0; font: 400 20px/1.45 var(--f-disp); word-break: keep-all; overflow-wrap: anywhere; }
.whotx p { margin: 0; font-size: 13.5px; color: var(--ink-2); line-height: 1.55; }
.whotx .ttl { color: var(--gold); font-weight: 600; }
.bar { display: inline-block; flex: 1; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; vertical-align: middle; }
.bar b { display: block; height: 100%; background: var(--ink-2); border-radius: 3px; transition: width .8s ease; }
.hp { display: flex; align-items: center; gap: 10px; font: 13px var(--f-ui); color: var(--ink-2); }
.hp .bar b { background: var(--jade); }
.hp em { font-style: normal; font-variant-numeric: tabular-nums; min-width: 26px; text-align: right; }
.stats { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.stats div { min-width: 0; }
.stats dt { font: 12.5px/1.3 var(--f-ui); color: var(--ink-3); }
.stats dd { margin: 0; display: flex; align-items: center; gap: 8px; }
.stats em { font-style: normal; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 18px; text-align: right; font-size: 14px; }
.res { margin: 0; display: grid; gap: 4px; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.res div { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; }
.res dt { color: var(--ink-3); font-family: var(--f-ui); }
.res dd { margin: 0; text-align: right; }
#char section h3 { margin: 0 0 8px; font: 400 15px/1.5 var(--f-disp); color: var(--ink); display: flex; align-items: center; gap: 8px; }
#char section h3::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, color-mix(in srgb, var(--gilt) 70%, transparent), transparent); }
.ladder { list-style: none; margin: 0; padding: 0 0 0 12px; border-left: 1px dashed var(--line); display: grid; gap: 2px; }
.ladder li { position: relative; font-size: 13.5px; color: var(--ink-3); line-height: 1.6; }
.ladder li::before { content: ""; position: absolute; left: -16px; top: 9px; width: 7px; height: 7px; transform: rotate(45deg); background: var(--paper-solid); border: 1px solid var(--ink-3); }
.ladder li.done { color: var(--ink-2); }
.ladder li.done::before { background: var(--ink-2); border-color: var(--ink-2); }
.ladder li.now { color: var(--seal); font-weight: 700; }
.ladder li.now::before { background: var(--gilt); border-color: var(--seal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gilt) 30%, transparent); }
.meritbar { margin-top: 8px; display: flex; }
.meritbar .bar b { background: var(--gilt); }
ul.ppl { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
ul.ppl li { display: flex; gap: 8px; align-items: baseline; font-size: 13.5px; line-height: 1.55; }
ul.ppl li span { color: var(--ink-3); font: 12px var(--f-ui); flex: none; min-width: 84px; }
ul.ppl li.gone b { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--ink-3); }
ul.ppl li i { font-style: normal; font-size: 11px; color: var(--ink-3); }
.muted { color: var(--ink-3); font: 13.5px/1.6 var(--f-ui); margin: 0; }

/* ---------- ม้วนบันทึกชีวิต ---------- */
#log { flex: 1; position: relative; overflow-y: auto; padding: 24px 32px 26px; scroll-behavior: smooth; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--rule) 50%, transparent) transparent; }
#log::-webkit-scrollbar { width: 8px; }
#log::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--rule) 40%, transparent); border-radius: 4px; }
.yr { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin: 24px 0 8px; padding-top: 14px; position: relative; }
.yr::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 1px; background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--gilt) 75%, transparent) 15%, color-mix(in srgb, var(--gilt) 75%, transparent) 85%, transparent); }
.yr::after { content: ""; position: absolute; top: -3px; left: 50%; width: 7px; height: 7px; transform: translateX(-50%) rotate(45deg); background: var(--gilt); box-shadow: 0 0 0 2px var(--paper-solid); }
.step { display: flow-root; }
#log > .step:first-child > .yr { margin-top: 0; padding-top: 0; }
#log > .step:first-child > .yr::before, #log > .step:first-child > .yr::after { display: none; }
.yr b { font: 600 17px/1.6 var(--f-script); color: var(--seal); letter-spacing: .01em; }
.yr span:not(.chips) { font: 13px var(--f-ui); color: var(--ink-3); }
.yr .chips { margin: 0; }
.ln { margin: 0 0 10px; font-size: 16.5px; line-height: 1.95; text-wrap: pretty; }
.ln.dim { color: var(--ink-2); font-size: 15.5px; }
.ln.em { font-weight: 600; color: var(--ink); }
.ln.em::before { content: ""; display: inline-block; width: 7px; height: 7px; transform: rotate(45deg); background: var(--seal); margin-right: 10px; vertical-align: 3px; box-shadow: 0 0 0 2px color-mix(in srgb, var(--gilt) 45%, transparent); }
.ln.pick { font: 500 16px/1.8 var(--f-script); color: var(--seal); padding-left: 20px; position: relative; }
.ln.pick::before { content: "❧"; position: absolute; left: 0; top: 1px; font-family: var(--f-sym); color: var(--gilt); }
.ln.pick .fate { font: 600 11px/1 var(--f-ui); color: var(--seal-ink); background: var(--seal); padding: 3px 8px; border-radius: 999px; margin-left: 8px; vertical-align: 3px; font-style: normal; }
.ln.dice { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font: 14px var(--f-ui); color: var(--ink-2); }
.d20 { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 7px; background: linear-gradient(145deg, color-mix(in srgb, var(--ink) 80%, #fff), var(--ink)); color: var(--paper-solid); font: 700 14px/1 var(--f-ui); font-variant-numeric: tabular-nums; transform: rotate(-6deg); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--gilt) 60%, transparent); }
.d20.land { animation: land .35s ease; }
@keyframes land { 0% { transform: rotate(40deg) scale(1.3); } 100% { transform: rotate(-6deg) scale(1); } }
.dmath { font-variant-numeric: tabular-nums; }
.dmath b { color: var(--ink); }
.verdict { font-size: 12.5px; font-weight: 700; padding: 1px 9px; border-radius: 999px; }
.verdict.ok { color: var(--jade); box-shadow: inset 0 0 0 1px var(--jade); }
.verdict.no { color: var(--seal); box-shadow: inset 0 0 0 1px var(--seal); }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-left: 8px; vertical-align: 1px; }
.chip { font: 600 11.5px/1.3 var(--f-ui); font-style: normal; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.chip.up { color: var(--jade); background: color-mix(in srgb, var(--jade) 12%, transparent); }
.chip.dn { color: var(--seal); background: color-mix(in srgb, var(--seal) 10%, transparent); }
.chip.loc, .chip.path { color: var(--gold); background: color-mix(in srgb, var(--gilt) 15%, transparent); }
.chip.npc { color: var(--ink-2); background: var(--line); }
.chip.news { color: var(--azure); background: color-mix(in srgb, var(--azure) 12%, transparent); }
#log .in { animation: inkin .9s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes inkin { from { opacity: 0; filter: blur(6px); transform: translateY(6px); } to { opacity: 1; filter: blur(0); transform: none; } }

/* ---------- ทางแยก ---------- */
#choice { flex: none; position: relative; border-top: 1px solid color-mix(in srgb, var(--gilt) 50%, transparent); background: var(--paper-2); padding: 16px 22px 18px; display: grid; gap: 12px; animation: inkin .6s ease both; max-height: 62%; overflow-y: auto; }
.cprompt { font: 400 18px/1.55 var(--f-disp); }
.opts { display: grid; gap: 8px; }
.opt { display: flex; gap: 12px; align-items: center; text-align: left; border: 1px solid var(--line); background: var(--vellum); border-radius: 10px; padding: 10px 14px; transition: border-color .2s, transform .2s, background .2s; }
.opt:hover { border-color: var(--gilt); transform: translateX(3px); }
.opt.hot { border-color: var(--seal); background: color-mix(in srgb, var(--seal) 10%, var(--vellum)); transform: translateX(6px); }
.opt .num { flex: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 4px; background: linear-gradient(145deg, color-mix(in srgb, var(--azure) 85%, #fff), var(--azure)); color: #f6e7c4; font: 700 17px/1 var(--f-body); box-shadow: inset 0 0 0 1.5px var(--gilt), inset 0 0 0 3px color-mix(in srgb, var(--azure) 60%, #000); text-shadow: 0 1px 0 rgba(0, 0, 0, .3); }
.opt.hot .num { background: linear-gradient(145deg, color-mix(in srgb, var(--seal) 80%, #fff), var(--seal)); }
.otx { font-size: 15.5px; line-height: 1.55; display: grid; gap: 2px; min-width: 0; }
.ot { display: block; }
.tip { display: inline-block; margin-left: 8px; font: 11.5px var(--f-ui); font-style: normal; color: var(--ink-3); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; vertical-align: 2px; }
.tip.hi { color: var(--jade); border-color: color-mix(in srgb, var(--jade) 45%, transparent); }
.tip.mid { color: var(--gold); border-color: color-mix(in srgb, var(--gilt) 55%, transparent); }
.tip.lo { color: var(--seal); border-color: color-mix(in srgb, var(--seal) 45%, transparent); }
.onote { display: block; font: 12.5px/1.5 var(--f-ui); color: var(--ink-3); }
.onote.danger { color: var(--seal); font-weight: 600; }
.onote.danger::before { content: "เสี่ยง · "; }
.cfoot { display: flex; align-items: center; gap: 14px; justify-content: space-between; flex-wrap: wrap; }
.fatebtn { flex: none; display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--seal); color: var(--seal); background: none; border-radius: 999px; padding: 6px 14px; font: 13.5px var(--f-ui); }
.fatebtn:hover { background: color-mix(in srgb, var(--seal) 10%, transparent); }
.fatebtn.rolling .die { animation: roll .35s linear infinite; }
@keyframes roll { to { transform: rotate(360deg); } }
.autotick { display: inline-flex; align-items: center; gap: 8px; font: 14px var(--f-ui); cursor: pointer; user-select: none; }
.autotick input { width: 18px; height: 18px; accent-color: var(--seal); margin: 0; }
.autotick b { font-weight: 600; color: var(--seal); font-variant-numeric: tabular-nums; min-width: 4.5em; }
.chead { display: grid; gap: 4px; position: relative; }
.major { justify-self: start; display: inline-flex; align-items: center; gap: 8px; font: 700 11.5px/1 var(--f-ui); color: var(--seal-ink); background: var(--seal); padding: 5px 12px 5px 6px; border-radius: 999px; letter-spacing: .04em; }
.major::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 1px solid color-mix(in srgb, var(--magic) 80%, #fff); box-shadow: 0 0 8px var(--magic), inset 0 0 0 3px transparent, inset 0 0 0 4px color-mix(in srgb, var(--magic) 60%, transparent); }
.chint { margin: 0; font-size: 13.5px; color: var(--ink-2); line-height: 1.65; }

/* ---------- ฉากจบ ---------- */
#end, #book, #guide { position: fixed; inset: 0; z-index: 8; display: grid; place-items: center; background: var(--veil); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); padding: 20px max(16px, env(safe-area-inset-left, 0px)); overflow-y: auto; }
.endcard, .bookcard { position: relative; width: min(620px, 100%); max-height: calc(100% - 20px); overflow-y: auto; border-radius: 6px; padding: 34px 38px 28px; animation: inkin 1.2s ease both; }
.endcard { text-align: center; }
.endno { font: 600 12px var(--f-latin); color: var(--ink-3); letter-spacing: .18em; text-transform: uppercase; }
.endpt { position: relative; width: 150px; height: 150px; margin: 14px auto 24px; }
.endpt::before { content: ""; position: absolute; inset: -22px; border-radius: 50%; border: 1px solid color-mix(in srgb, var(--magic) 50%, transparent); box-shadow: 0 0 24px color-mix(in srgb, var(--magic) 25%, transparent); background: repeating-conic-gradient(from 0deg, color-mix(in srgb, var(--magic) 45%, transparent) 0 .5deg, transparent .5deg 20deg); -webkit-mask: radial-gradient(circle, transparent 88%, #000 89%); mask: radial-gradient(circle, transparent 88%, #000 89%); animation: spin 120s linear infinite; }
.ptend { width: 150px; height: 150px; display: block; border-radius: 4px; box-shadow: 0 0 0 1px var(--gilt), 0 0 0 5px var(--vellum), 0 0 0 6px color-mix(in srgb, var(--gilt) 60%, transparent); }
.stamp { margin: 14px auto 24px; width: 112px; height: 112px; font-size: 56px; transform: rotate(-8deg); animation: stamp .9s cubic-bezier(.3, 1.4, .5, 1) .3s both; }
.endpt .stamp { position: absolute; right: -36px; bottom: -16px; width: 76px; height: 76px; margin: 0; font-size: 34px; }
@keyframes stamp { from { opacity: 0; transform: rotate(-24deg) scale(2.4); } to { opacity: 1; transform: rotate(-8deg) scale(1); } }
.endcard h2 { margin: 6px 0 2px; font: 400 30px/1.5 var(--f-disp); text-wrap: balance; color: var(--seal); }
.endwho { margin: 0; color: var(--gold); font-weight: 600; font-size: 14.5px; }
.epi { margin: 16px 0; text-align: left; font-size: 16px; line-height: 1.95; }
.hist { list-style: none; margin: 0 0 14px; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); display: grid; gap: 2px; text-align: left; }
.hist li { display: grid; grid-template-columns: 48px 1fr; gap: 10px; font-size: 14px; line-height: 1.6; }
.hist b { color: var(--seal); font-variant-numeric: tabular-nums; text-align: right; font-family: var(--f-latin); }
p.ppl { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; font: 13px var(--f-ui); color: var(--ink-3); margin: 0 0 18px; }
p.ppl b { color: var(--ink-2); font-weight: 600; }
.endact { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.endact button, .splbtn button { border: 1px solid var(--ink); background: none; border-radius: 999px; padding: 10px 22px; font: 15px var(--f-ui); }
.endact button.primary, .splbtn button.primary { background: var(--seal); border-color: var(--seal); color: var(--seal-ink); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--seal) 70%, #000), inset 0 0 0 3px color-mix(in srgb, var(--gilt) 55%, transparent), 0 6px 18px rgba(0, 0, 0, .2); }

/* ---------- การ์ดแชร์ชีวิต (sharecard.js) ---------- */
.endshare { margin: 6px 0 -8px; }
.endshare button { border: 0; background: none; min-height: 44px; padding: 8px 14px; font: 13.5px var(--f-ui); color: var(--ink-2); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--gilt) 70%, transparent); text-underline-offset: 3px; }
.endshare button:hover { color: var(--seal); text-decoration-color: var(--seal); }
#share { position: fixed; inset: 0; z-index: 9; display: grid; place-items: center; background: var(--veil); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); padding: 16px max(16px, env(safe-area-inset-left, 0px)); overflow-y: auto; }
.sharecard { position: relative; width: min(480px, 100%); margin-top: 12px; padding: 16px 16px 18px; border-radius: 6px; background: var(--vellum); box-shadow: var(--shadow), inset 0 0 0 1px color-mix(in srgb, var(--rule) 70%, transparent); text-align: center; }
.sharecard .x { top: -12px; right: -8px; z-index: 1; box-shadow: var(--shadow); }
.sharecv canvas { display: block; width: 100%; max-width: calc((100dvh - 200px) * .8); height: auto; margin: 0 auto; border-radius: 3px; box-shadow: 0 6px 22px rgba(40, 24, 8, .3); }
.shnote { margin: 12px 4px 12px; }
.shnote.shtext { white-space: pre-line; user-select: all; -webkit-user-select: all; color: var(--ink-2); text-align: left; }
.offscreen { position: fixed; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; }

/* ---------- สมุดแห่งชีวิต ---------- */
.bookcard { width: min(760px, 100%); }
.bookcard h2 { margin: 0; font: 400 28px/1.5 var(--f-disp); color: var(--seal); }
.bookcard h3 { margin: 22px 0 8px; font: 400 18px/1.5 var(--f-disp); display: flex; align-items: center; gap: 10px; }
.bookcard h3::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, color-mix(in srgb, var(--gilt) 70%, transparent), transparent); }
.x { position: absolute; top: 16px; right: 16px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid color-mix(in srgb, var(--gilt) 60%, transparent); background: var(--vellum); }
.egrid { margin-top: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.ecell { border: 1px solid var(--line); border-radius: 8px; padding: 12px 10px; display: grid; justify-items: center; text-align: center; gap: 6px; background: color-mix(in srgb, var(--vellum) 60%, transparent); }
.eseal { width: 48px; height: 48px; font-size: 22px; }
.ecell:not(.got) .eseal { --wax: #a39a8c; opacity: .45; }
.ecell.got .eseal { transform: rotate(-5deg); }
.ecell b { font-size: 13.5px; line-height: 1.4; }
.ecell:not(.got) b { color: var(--ink-3); }
.ecell small { font: 11.5px/1.45 var(--f-ui); color: var(--ink-3); }
.lives { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.lives li { display: grid; grid-template-columns: 76px 1fr auto; gap: 10px; font-size: 14px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.lives li b { color: var(--seal); font-weight: 600; }
.lives li em { font-style: normal; color: var(--gold); }
.lives li small { color: var(--ink-3); }
.lives li.alive em::after { content: " · ยังมีชีวิต"; color: var(--jade); }
.album .eseal { font-size: 20px; }

/* ---------- หน้าเปิด ---------- */
#splash { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left, 0px)); background: radial-gradient(ellipse at 50% 50%, color-mix(in srgb, var(--paper-solid) 30%, transparent), transparent 75%); transition: opacity .9s ease; overflow-y: auto; }
#splash.gone { opacity: 0; pointer-events: none; }
.spl { position: relative; width: min(640px, 100%); border-radius: 6px; padding: 38px 44px 30px; overflow: hidden; }
.spl .mc { width: 300px; top: -70px; right: -80px; }
.vtitle { font: 600 15px/1 var(--f-latin); letter-spacing: .32em; text-transform: uppercase; color: var(--gold); display: flex; align-items: center; gap: 12px; }
.vtitle::before, .vtitle::after { content: ""; height: 1px; flex: 1; max-width: 60px; background: var(--gilt); }
.spltx { min-width: 0; position: relative; }
.spltx h1 { margin: 14px 0 4px; font: 400 clamp(30px, 5vw, 44px)/1.45 var(--f-disp); color: var(--seal); text-wrap: balance; }
.spltx .tag { font: 500 17px/1.8 var(--f-script); margin: 6px 0 16px; color: var(--ink); }
.spltx p { margin: 0 0 12px; font-size: 16px; line-height: 1.9; color: var(--ink-2); max-width: 36em; }
.splbtn { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin: 22px 0 14px; }
.splbtn small { display: block; font-size: 12px; opacity: .85; }
.splbtn .wax { width: 44px; height: 44px; font: 700 18px/1 var(--f-latin); transform: rotate(-10deg); }
.fine { font: 12.5px/1.7 var(--f-ui) !important; color: var(--ink-3) !important; }

#toast { position: fixed; z-index: 10; left: 50%; bottom: max(24px, env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 30px); max-width: min(520px, calc(100% - 32px)); background: var(--ink); color: var(--paper-solid); padding: 12px 18px; border-radius: 12px; font: 14px/1.6 var(--f-ui); opacity: 0; transition: .5s ease; pointer-events: none; box-shadow: var(--shadow), inset 0 0 0 1px color-mix(in srgb, var(--gilt) 50%, transparent); }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- เลือกวิธีอ่าน ---------- */
#modepick { position: fixed; inset: 0; z-index: 11; display: grid; place-items: center; padding: 20px max(16px, env(safe-area-inset-left, 0px)); background: var(--veil); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.mpcard { width: min(640px, 100%); border-radius: 6px; padding: 32px 34px; animation: inkin .8s ease both; }
.mpcard h2 { margin: 0 0 4px; font: 400 26px/1.5 var(--f-disp); color: var(--seal); text-wrap: balance; }
.mpopts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.mpopts button { display: grid; gap: 6px; text-align: left; padding: 16px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper-2); transition: border-color .2s, transform .2s; }
.mpopts button:hover, .mpopts button:focus-visible { border-color: var(--gilt); transform: translateY(-2px); }
.mpopts b { font: 400 17px/1.5 var(--f-disp); color: var(--ink); }
.mpopts span { font-size: 14px; line-height: 1.65; color: var(--ink-2); }

/* ---------- ภาพเหมือน ยุคสมัย ข่าว ---------- */
.pt { flex: none; width: 104px; height: 104px; display: block; border-radius: 4px; box-shadow: 0 0 0 1px var(--gilt), 0 0 0 4px var(--vellum), 0 0 0 5px color-mix(in srgb, var(--gilt) 55%, transparent), 0 6px 16px rgba(0, 0, 0, .2); }
.ptm { flex: none; width: 34px; height: 34px; border-radius: 3px; box-shadow: 0 0 0 1px var(--gilt); }
.whotx .looks { color: var(--jade); font-size: 12.5px; }
.charbody { display: flex; flex-direction: column; gap: 16px; }
.ln.news { display: flow-root; position: relative; padding: 8px 12px 8px 14px; border-left: 3px solid var(--gilt); border-radius: 0 8px 8px 0; background: color-mix(in srgb, var(--gilt) 9%, transparent); }
.ln.news .via { display: inline-block; margin-right: 8px; padding: 1px 9px; border-radius: 10px; font: 600 12px/1.6 var(--f-ui); color: var(--ink-2); background: var(--line); }
.ln.news.rumor { font-style: italic; border-left-style: dashed; }
.ln .book { font: 12.5px var(--f-ui); font-style: normal; color: var(--seal); margin-left: 6px; }
.yr.beat b { color: var(--azure); }
.world h3, .town h3 { margin-top: 4px; }
.lastnews { font-size: 12.5px; color: var(--ink-2); margin: 6px 0 0; line-height: 1.55; }
.filebtn { position: relative; display: inline-grid; place-items: center; cursor: pointer; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.filebtn span { display: inline-block; padding: 10px 18px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper-2); font: 600 15px var(--f-ui); color: var(--ink); }
.savecard p { line-height: 1.75; }
/* ทางออกเมื่อเซฟมีปัญหา: ปุ่มเงียบ ๆ ท้ายการ์ด ล้างเฉพาะเซฟของเกมนี้ */
.savecard .wipe { margin: 14px 0 0; text-align: center; }
.savecard .wipe button { background: none; border: 0; padding: 4px 6px; font: 12.5px var(--f-ui); color: var(--ink-3); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.savecard .wipe button:hover, .savecard .wipe button[data-arm="1"] { color: var(--seal); }
.savelbl { display: block; margin-top: 14px; font: 600 13px var(--f-ui); color: var(--ink-2); }
.savetxt { width: 100%; margin-top: 6px; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--paper-solid); color: var(--ink); font: 12px/1.4 ui-monospace, Consolas, monospace; resize: vertical; }

/* ---------- ความสำเร็จระหว่างทาง ---------- */
.ln.achv { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-radius: 10px; background: color-mix(in srgb, var(--seal) 8%, transparent); border: 1px solid color-mix(in srgb, var(--seal) 28%, transparent); }
.achseal { width: 54px; height: 54px; font-size: 24px; transform: rotate(-6deg); }
.achtx { display: grid; gap: 2px; }
.achtx b { font: 400 17px/1.5 var(--f-disp); color: var(--seal); }
.achtx small { font: 13px/1.6 var(--f-ui); color: var(--ink-2); }
#log .achv.in .achseal { animation: stamp .9s cubic-bezier(.3, 1.4, .5, 1) both; }

/* ---------- กรอบภาพเล็ก: ภาพสีน้ำในกรอบทองแบบหนังสือ ---------- */
#vig {
  position: fixed; z-index: 2; margin: 0;
  --gap: calc(100vw - 352px - min(600px, 46vw) - 16px);
  right: max(16px, env(safe-area-inset-right, 0px)); top: 76px;
  width: clamp(200px, min(22vw, calc((100vh - var(--band) - 150px) * 1.45)), 360px);
  padding: 9px 9px 6px; background: var(--vellum); border-radius: 4px;
  box-shadow: var(--shadow), inset 0 0 0 1px color-mix(in srgb, var(--rule) 70%, transparent), inset 0 0 0 4px var(--vellum), inset 0 0 0 5px color-mix(in srgb, var(--gilt) 60%, transparent);
}
#vig::before { content: ""; position: absolute; left: 50%; top: -11px; width: 22px; height: 22px; transform: translateX(-50%) rotate(45deg); background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--seal) 55%, #ffe8d0) 0 8%, var(--seal) 50%, color-mix(in srgb, var(--seal) 65%, #000)); border-radius: 46% 54% 50% 50%; box-shadow: 0 2px 6px rgba(0, 0, 0, .3); }
#vigc { display: block; width: 100%; aspect-ratio: 320 / 210; border-radius: 2px; background: var(--paper-2); box-shadow: 0 0 0 1px color-mix(in srgb, var(--gilt) 70%, transparent); }
#vig figcaption { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 2px 0; font: 600 13px/1.45 var(--f-body); color: var(--ink-2); }
#vigLabel { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.incense { --burn: 0; position: relative; flex: none; width: 64px; height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--ink-3) 18%, transparent); }
.incense i { position: absolute; left: 0; top: 0; bottom: 0; width: calc((1 - var(--burn)) * 100%); background: linear-gradient(90deg, #cfd6dc, #f2f4f6); border-radius: 3px; transition: width .2s linear; }
.incense i::after { content: ""; position: absolute; right: -2px; top: -2px; width: 9px; height: 9px; border-radius: 50%; background: radial-gradient(circle, #ffffff 0, rgba(220, 230, 240, .4) 70%); }
body.splashing #vig { visibility: hidden; }

/* ---------- ต้นกำเนิด: การ์ดแรกเกิด ป้ายความหายาก และบันทึกต้นกำเนิด ---------- */
.ln.origin { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-radius: 10px; background: color-mix(in srgb, var(--gilt) 9%, transparent); border: 1px solid color-mix(in srgb, var(--gilt) 34%, transparent); }
.otx small { font: 600 12px var(--f-ui); color: var(--gold); letter-spacing: .02em; }
.otx b { font: 400 17px/1.5 var(--f-disp); display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.whotx .otag { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; font-size: 12.5px; color: var(--ink-2); }

#top button, .chip, .tip, .onote, .fine, .muted { font-family: var(--f-ui); }

/* ---------- จอแคบ ---------- */
@media (max-width: 1100px) { #inscr { max-width: calc(100vw - 300px); } #bAuto span { display: none; } .brand b { white-space: nowrap; } }
@media (max-width: 900px) {
  #top { padding-bottom: 6px; }
  .brand { padding-right: 10px; }
  .brand b { font-size: 14px; }
  .ctrl { gap: 6px; }
  .ctrl > button, .seg { height: 34px; }
  .ctrl > button { padding: 0 11px; font-size: 13px; }
  #bAuto span, #bMusic span, #bBook { display: none; }
  .volbox { height: 34px; padding: 0; } .volbox #bMusic { height: 34px; } .volbox .volrange { display: none; }
  #inscr { top: 70px; left: max(16px, env(safe-area-inset-left, 0px)); right: auto; max-width: 44vw; }
  #inscr .v { font-size: 15px; }
  #inscr .v::before, #inscr .v::after { width: 14px; }
  #inscr .vt { font-size: 12px; }
  #inscr .sealsm { width: 24px; height: 24px; font-size: 12px; }
  body { --band: 54vh; } body.band0 { --band: 36vh; } body.band2 { --band: 80vh; }
  #bandbar { padding: 8px max(12px, env(safe-area-inset-right, 0px)) 7px max(18px, env(safe-area-inset-left, 0px)); }
  #log { padding: 14px max(18px, env(safe-area-inset-left, 0px)) 20px; }
  .ln { font-size: 16px; }
  #choice { padding: 14px max(16px, env(safe-area-inset-left, 0px)) 16px; }
  #char { top: 64px; bottom: 0; left: 0; width: min(340px, 88vw); border-radius: 0 14px 0 0; transform: translateX(-104%); padding-left: max(18px, env(safe-area-inset-left, 0px)); }
  .spl { padding: 30px 24px 24px; }
  .spl .mc { width: 220px; top: -60px; right: -70px; }
  .endcard, .bookcard { padding: 28px 22px 22px; }
  #vig { right: max(12px, env(safe-area-inset-right, 0px)); top: 60px; width: max(120px, min(44vw, 240px, calc((100vh - var(--band) - 110px) * 1.4))); padding: 5px 5px 4px; }
  #vig::before { display: none; }
  #vig figcaption { font-size: 11.5px; padding-top: 3px; }
  .incense { width: 40px; }
}
@media (max-width: 620px) { #mini .minihint { display: none; } .mpopts { grid-template-columns: 1fr; } .mpcard { padding: 26px 22px; } .brand { padding: 4px; } .brand > div { display: none; } #vig { top: 98px; } #inscr { top: 80px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- บันทึกเรียงใหม่สุดไว้บน · ภาพสีน้ำของเหตุการณ์สำคัญ ---------- */
.ln.pic { float: right; width: min(46%, 260px); margin: 6px 0 12px 18px; }
.ln.pic canvas { display: block; width: 100%; height: auto; aspect-ratio: 320 / 210; background: var(--wash-bg); padding: var(--wash-pad); border-radius: 3px; opacity: 0; transition: opacity 1.4s ease; }
.ln.pic.drawn canvas { opacity: 1; }
.ln.pic.nopic { display: none; }
.ln.pic figcaption { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 0 6px; margin-top: 3px; font: 12.5px/1.5 var(--f-ui); color: var(--ink-3); text-align: center; text-wrap: balance; }
.ln.pic figcaption i { font-style: normal; font-weight: 600; letter-spacing: .02em; color: var(--seal); }
.ln.pic.news figcaption i { color: var(--azure); }
.ln.pic.witness figcaption i { color: var(--jade); }
.ln.pic.wide { float: none; width: min(80%, 400px); margin: 10px auto 16px; }
.step > #choice { clear: both; margin: 14px 0 8px; max-height: none; overflow: visible; border: 1px solid color-mix(in srgb, var(--gilt) 55%, transparent); border-radius: 12px; box-shadow: 0 6px 18px color-mix(in srgb, var(--ink) 10%, transparent); }
#newer { position: absolute; z-index: 4; left: 50%; top: 56px; transform: translateX(-50%); border: 0; border-radius: 999px; padding: 8px 16px; font: 600 13px/1.2 var(--f-ui); color: var(--seal-ink); background: var(--seal); box-shadow: 0 6px 16px rgba(40, 24, 8, .3); cursor: pointer; white-space: nowrap; animation: inkin .5s ease both; }

@media (max-width: 620px) { .ln.pic { float: none; width: min(74%, 280px); margin: 6px auto 12px; } .ln.pic.wide { width: min(90%, 320px); } .step > #choice { margin-left: -6px; margin-right: -6px; } }

/* ---------- คู่มือสั้น ๆ และบรรทัดลิขสิทธิ์ ---------- */
#guide { z-index: 12; }
.guidecard { width: min(560px, 100%); }
.gsec h3 { margin: 18px 0 6px; }
.gsec p, .gsec li { font-size: 15.5px; line-height: 1.8; text-wrap: pretty; }
.gsec p { margin: 0 0 8px; }
.gsec ul { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.gsec li::marker { color: var(--gilt); }
.gsec b { color: var(--seal); font-weight: 600; }
.gsec .warn { padding: 10px 14px; border-radius: 8px; border-left: 3px solid var(--seal); background: color-mix(in srgb, var(--seal) 7%, transparent); }
.gsec .muted { font-size: 13.5px; }
.gnote { margin: 18px 0 0; font: 14px/1.7 var(--f-ui); color: var(--ink-3); text-align: center; }
.guidecard .endact { margin-top: 16px; }
#bGuide { width: 38px; padding: 0; justify-content: center; font: 700 15px/1 var(--f-ui); }
.spl .copy { margin: 10px 0 0; font: 11.5px/1.5 var(--f-ui); color: var(--ink-3); opacity: .8; }
@media (max-width: 900px) { #bGuide { width: 34px; } }
@media (max-width: 620px) { .guidecard { padding: 26px 18px 20px; } .gsec p, .gsec li { font-size: 15px; } }
a.quiet { color: inherit; text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--gilt) 70%, transparent); text-underline-offset: 3px; }
a.quiet:hover { color: var(--seal); text-decoration-color: var(--seal); }
.readon { margin: 16px 0 14px; font: 13px/1.7 var(--f-ui); color: var(--ink-3); text-wrap: balance; }

/* ---------- ลูกแก้วกลับสู่หน้านิยาย: แบบเดียวกับ tongfar.com แต่เงียบกว่า ลอยเหนือแถบบันทึกชิดซ้าย ทับแต่ภาพฉาก ไม่ทับตัวหนังสือ ---------- */
#orb { position: fixed; z-index: 7; left: max(18px, env(safe-area-inset-left, 0px)); bottom: calc(var(--band) + 24px); width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  background: url("../img/orb.webp") center / cover; border: 1px solid rgba(216, 194, 154, .65); box-shadow: 0 0 12px rgba(216, 194, 154, .25), 0 5px 14px rgba(0, 0, 0, .4);
  opacity: .5; transition: opacity .5s ease; animation: orbBob 6s ease-in-out infinite; text-decoration: none; }
#orb:hover, #orb:focus-visible { opacity: 1; }
#orb:focus-visible { outline: 2px solid var(--gilt); outline-offset: 4px; }
#orb i { width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .85) 0%, rgba(229, 193, 133, .4) 60%, transparent 100%); animation: orbPulse 3.2s ease-in-out infinite; }
#orb span { position: absolute; top: calc(100% + 5px); left: 50%; transform: translateX(-50%); font: 600 8.5px/1 var(--f-latin); letter-spacing: .24em; color: rgba(216, 194, 154, .9); white-space: nowrap; text-shadow: 0 1px 4px rgba(0, 0, 0, .8); }
@keyframes orbBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes orbPulse { 0%, 100% { transform: scale(1); opacity: .55; } 50% { transform: scale(1.25); opacity: .95; } }
body.splashing #orb { bottom: auto; top: 55%; }
body.showchar #orb { opacity: 0; pointer-events: none; }
@media (min-width: 901px) { #orb { z-index: 13; } }
@media (min-width: 901px) and (max-height: 760px) { body.band2 #orb { display: none; } }
@media (max-width: 900px) { #orb { width: 40px; height: 40px; left: max(12px, env(safe-area-inset-left, 0px)); bottom: calc(var(--band) + 20px); } body.band2 #orb, body.splashing #orb { display: none; } }
@media (prefers-reduced-motion: reduce) { #orb, #orb i { animation: none; } }
