:root{color-scheme:light;--ink:#36251b;--gold:#92713e;--cream:#f8f3e8}*{box-sizing:border-box}body{margin:0;background:radial-gradient(ellipse at 50% 36%,#fffdf7 0,#eee4d2 70%);color:var(--ink);font-family:Tahoma,Arial,sans-serif;min-height:100vh}header{display:flex;justify-content:space-between;align-items:center;gap:12px;padding:16px 4vw;border-bottom:1px solid #d7c7a7;background:#faf6ed}a{color:inherit;text-decoration:none}header nav{display:flex;gap:5px}header nav a{padding:8px 12px;border-radius:20px}header .active{background:var(--ink);color:#fff5df}.back{font-size:14px}.heading{text-align:center;padding:24px 14px 12px}.heading small{color:var(--gold);letter-spacing:2px}.heading h1{font-family:Georgia,Tahoma,serif;font-size:clamp(24px,3vw,36px);margin:9px 0}.heading p{font-size:13px;color:#806e59;margin:8px}#status{text-align:center;padding:20px;color:#806e59}#status:empty{display:none}#stage{display:flex;justify-content:center;align-items:center;margin:10px auto 24px;max-width:1200px;width:calc(100% - 36px);height:clamp(280px,60vh,760px)}#book{filter:drop-shadow(0 18px 20px #3a271b30)}.book-page{background:#fffdf7;overflow:hidden;box-shadow:inset 0 0 12px #8d75421a}.paper{width:100%;height:100%;display:flex;align-items:center;justify-content:center;position:relative}.paper:after{content:'';position:absolute;inset:0;pointer-events:none;background:linear-gradient(90deg,#4a321016,transparent 7%,transparent 94%,#4a321010)}.paper canvas{width:100%;height:100%;object-fit:contain}.placeholder{color:#9e8a69;font-size:13px}.toolbar{display:flex;flex-wrap:wrap;justify-content:center;align-items:center;gap:9px;padding:12px 16px 24px}.toolbar button,.toolbar>a,.toolbar form{background:#fffaf0;border:1px solid #d2c09c;border-radius:9px;padding:10px 14px;color:var(--ink);font:inherit;font-size:13px}.toolbar button{cursor:pointer;min-height:42px}.toolbar button:hover:not(:disabled),.toolbar>a:hover{background:#e9dcc2}.toolbar button:disabled{opacity:.4;cursor:default}.toolbar form{display:flex;align-items:center;gap:7px;padding:0 9px}.toolbar form button{border:0;background:none;padding:8px}input{width:58px;background:white;border:1px solid #d2c09c;border-radius:4px;padding:6px;font:inherit}button:focus-visible,a:focus-visible,input:focus-visible{outline:3px solid #ae7b30;outline-offset:3px}dialog{width:96vw;max-width:1500px;height:94dvh;padding:0;border:1px solid #bba574;border-radius:12px;background:var(--cream);color:var(--ink)}dialog::backdrop{background:#1b120cbb}.dialog-bar{height:52px;display:flex;align-items:center;justify-content:space-between;padding:8px 16px;border-bottom:1px solid #d2c09c}.dialog-bar button{padding:8px 16px;border:0;background:var(--ink);color:white;border-radius:6px;cursor:pointer}.zoom-scroll{height:calc(100% - 52px);overflow:auto;padding:16px;text-align:center}#zoomCanvas{display:block;margin:auto;width:1100px;max-width:none;height:auto}@media(max-width:600px){header{padding:12px}.heading{padding-top:18px}header nav a{padding:8px}.toolbar{gap:7px}.toolbar>button,.toolbar>a{padding:9px}#stage{width:calc(100% - 24px);height:56vh;min-height:260px}.heading small{letter-spacing:0}.back{font-size:12px}}

/* Stable reader viewport on all screen sizes. */
@media (min-width:0px){
  html{height:100%;overflow:hidden}
  body{height:100vh;height:100dvh;min-height:0;overflow:hidden;display:flex;flex-direction:column}
  header{flex:0 0 auto;min-height:38px;padding:4px 20px;gap:8px}
  .back{font-size:12px}
  header nav{gap:3px}
  header nav a{padding:5px 9px;font-size:12px}
  main{position:relative;flex:1 1 0;min-height:0;display:grid;grid-template-rows:auto minmax(0,1fr) auto;overflow:hidden}
  .heading{grid-row:1;padding:5px 12px 3px}
  .heading small,.heading p{display:none}
  .heading h1{font-size:19px;line-height:1.35;margin:0}
  #status{position:absolute;z-index:10;top:36px;left:50%;transform:translateX(-50%);max-width:90%;padding:7px 12px;border-radius:6px;background:#fffaf0;box-shadow:0 2px 12px #36251b20;font-size:12px}
  #stage{grid-row:2;align-self:stretch;justify-self:center;min-width:0;min-height:0;width:calc(100% - 32px);max-width:none;height:auto;margin:0;padding:5px 0;overflow:hidden;contain:layout size}
  #book{flex:none;filter:drop-shadow(0 5px 7px #3a271b25)}
  .toolbar{grid-row:3;flex-wrap:nowrap;gap:6px;padding:5px 12px 7px;min-height:40px}
  .toolbar button,.toolbar>a,.toolbar form{font-size:11px;border-radius:6px;padding:5px 9px;white-space:nowrap}
  .toolbar button{min-height:28px}
  .toolbar form{gap:5px;padding:0 6px}
  .toolbar form button{min-height:26px;padding:4px 5px}
  .toolbar input{width:49px;padding:3px 4px;font-size:11px}
}

/* Cream and gold controls, with no movement on hover or press. */
.toolbar{border-top:1px solid #d9c59e;background:linear-gradient(180deg,#faf5eacc,#efe3cddd);box-shadow:0 -3px 16px #62441d08}
.toolbar>button,.toolbar>a,.back,header nav a{display:inline-flex;align-items:center;justify-content:center;border:1px solid #d6bd8e;background:linear-gradient(180deg,#fffdf8,#f0e2c5);box-shadow:inset 0 1px 0 #ffffffbd,0 2px 4px #67431e10;transition:background-color .15s,border-color .15s,box-shadow .15s}
.back{border-radius:7px;padding:5px 9px}
.toolbar #prev,.toolbar #next{background:linear-gradient(180deg,#745035,#49301f);color:#fff3d8;border-color:#694a2b;box-shadow:inset 0 1px 0 #b89a6a66,0 2px 4px #49301f20}
.toolbar #zoom{color:#6c4c20;border-color:#bf9c5d;background:linear-gradient(180deg,#fff4d4,#e8d1a0)}
.toolbar form{background:#fffaf1;border-color:#d6bd8e;box-shadow:inset 0 1px 3px #6b4d1e0c}
.toolbar form button{background:#ead9b6;border-radius:4px;color:#60421d;margin:2px 0;min-height:22px}
header nav a{border-radius:6px}
header nav a.active{background:linear-gradient(180deg,#745035,#49301f);border-color:#694a2b;color:#fff3d8}
.toolbar>button:disabled{opacity:.38;box-shadow:none;cursor:default}
@media(hover:hover){
  .toolbar>button:hover:not(:disabled),.toolbar>a:hover,.back:hover,header nav a:hover{border-color:#aa8346;box-shadow:inset 0 1px 0 #fff5,0 2px 7px #67431e25}
  .toolbar #prev:hover:not(:disabled),.toolbar #next:hover:not(:disabled){background:linear-gradient(180deg,#86603f,#593922)}
}
.toolbar>button:active:not(:disabled),.toolbar>a:active{box-shadow:inset 0 2px 5px #51351525}
@media(max-width:900px){
  header{min-height:36px;padding:3px max(8px,env(safe-area-inset-right)) 3px max(8px,env(safe-area-inset-left));padding-top:max(3px,env(safe-area-inset-top));gap:6px}
  .back{font-size:11px;padding:5px 7px;white-space:nowrap}
  header nav a{font-size:11px;padding:5px 7px}
  .heading{padding:4px 8px 2px}
  .heading h1{font-size:16px;line-height:1.4}
  #stage{width:calc(100% - 16px);padding:5px 0;min-height:0}
  .toolbar{display:grid;grid-template-columns:minmax(0,1fr) auto minmax(0,1fr);gap:5px;padding:5px max(8px,env(safe-area-inset-right)) max(6px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left));min-height:0}
  .toolbar>button,.toolbar>a{font-size:10px;padding:4px 6px;min-height:30px;line-height:1.3;border-radius:6px}
  .toolbar #prev{grid-column:1;grid-row:1}
  .toolbar form{grid-column:2;grid-row:1;padding:0 4px;gap:3px;font-size:10px;min-width:0;justify-content:center}
  .toolbar form button{font-size:10px;padding:3px 4px;min-height:24px}
  .toolbar input{width:43px;font-size:16px;line-height:1;padding:2px;border-radius:4px}
  .toolbar #next{grid-column:3;grid-row:1}
  .toolbar #zoom{grid-column:1;grid-row:2}
  .toolbar>a{grid-column:3;grid-row:2}
  .dialog-bar{height:40px;padding:5px 10px;font-size:12px}
  .dialog-bar button{padding:5px 10px;font-size:12px}
  .zoom-scroll{height:calc(100% - 40px);padding:8px;overscroll-behavior:contain}
}
@media(max-width:900px) and (orientation:landscape){
  .heading{display:none}
  .toolbar{display:flex;gap:5px;justify-content:center;flex-wrap:nowrap}
  .toolbar>button,.toolbar>a{min-height:28px}
}
@media(prefers-reduced-motion:reduce){.toolbar button,.toolbar>a,.back,header nav a{transition:none}}

/* Softer line icons and quieter colors; existing control geometry is retained. */
.reader-icon{display:inline-block;width:12px;height:12px;flex:0 0 12px;vertical-align:middle;pointer-events:none}
.toolbar>button,.toolbar>a,.back{gap:4px}
.toolbar>button,.toolbar>a,.back,header nav a{border-color:#d9c8aa;background:linear-gradient(180deg,#fffdf8,#f7efdf);box-shadow:0 1px 2px #67431e0a}
.toolbar #prev,.toolbar #next{background:linear-gradient(180deg,#927153,#7e5f44);border-color:#927454;color:#fffaf0;box-shadow:0 1px 3px #62431e14}
.toolbar #zoom{color:#7a5c31;border-color:#dcc79c;background:linear-gradient(180deg,#fff9ea,#f4e7c9)}
header nav a.active{background:#8a6b4e;border-color:#947656;color:#fffaf0;box-shadow:none}
.toolbar form button{background:#f0e5ce;color:#826239}
.toolbar input{border-color:#ddcdb0}
.dialog-bar button{display:inline-flex;align-items:center;gap:4px;background:#8a6b4e}
@media(hover:hover){
  .toolbar>button:hover:not(:disabled),.toolbar>a:hover,.back:hover,header nav a:hover{border-color:#b89c73;box-shadow:0 1px 4px #67431e14}
  .toolbar #prev:hover:not(:disabled),.toolbar #next:hover:not(:disabled){background:linear-gradient(180deg,#9b7959,#89694c)}
}

/* Match the homepage typography and add restrained blue accents. */
:root{--reader-blue:#456b8c;--reader-blue-edge:#8ca8bf}
body{font-family:"Noto Sans Thai","Noto Sans SC",system-ui,sans-serif}
button,input{font-family:inherit}
.heading h1{font-family:"Chonburi","Noto Sans Thai","Noto Sans SC",serif;font-weight:400}
header{border-bottom-color:#a9bdcd}
.toolbar{border-top-color:#a9bdcd}
.toolbar>button,.toolbar>a,.back,header nav a,.toolbar form{border-color:var(--reader-blue-edge)}
.toolbar>button,.toolbar>a,.back{color:#355978}
.toolbar .reader-icon,.back .reader-icon{color:var(--reader-blue)}
.toolbar #prev,.toolbar #next{background:linear-gradient(180deg,#f5f9fc,#e6eef5);border-color:#7899b3;color:#355978;box-shadow:0 1px 3px #35597812}
.toolbar #zoom{background:linear-gradient(180deg,#fffaf0,#f4ead5);border-color:#8ca8bf;color:#355978}
header nav a.active{background:#456b8c;border-color:#456b8c;color:#fff;box-shadow:none}
.toolbar form button{background:#e6eef5;color:#355978}
.toolbar input{border-color:#a5bbcd}
.dialog-bar{border-bottom-color:#a9bdcd}
.dialog-bar button{background:#456b8c;color:#fff}
dialog{border-color:#8ca8bf}
button:focus-visible,a:focus-visible,input:focus-visible{outline-color:#547fa2}
@media(hover:hover){
  .toolbar>button:hover:not(:disabled),.toolbar>a:hover,.back:hover,header nav a:hover{border-color:#456b8c;box-shadow:0 1px 4px #35597820}
  .toolbar #prev:hover:not(:disabled),.toolbar #next:hover:not(:disabled){background:linear-gradient(180deg,#edf5fb,#dce9f3)}
}

/* Pre-rendered pages avoid PDF workers and module MIME dependencies on hosts. */
.paper img{display:block;width:100%;height:100%;object-fit:contain;user-select:none;-webkit-user-drag:none}

/* Optional share and magnification tools. */
#share{color:#355978}
#zoomDialog{overflow:hidden}
.zoom-tools{display:flex;flex-wrap:wrap;justify-content:center;align-items:center;gap:5px;padding:7px;border-bottom:1px solid #a9bdcd;flex:0 0 auto}
.zoom-tools button,.share-tools button{border:1px solid #8ca8bf;border-radius:6px;background:#f5f9fc;color:#355978;padding:5px 8px;font:inherit;font-size:12px;cursor:pointer}
.zoom-tools button:disabled{opacity:.4;cursor:default}
#zoomDialog[open]{display:flex;flex-direction:column}
#zoomScroll{flex:1;min-height:0;overflow:auto;overscroll-behavior:contain;padding:12px;touch-action:pan-x pan-y pinch-zoom}
#zoomImage{display:block;max-width:none;height:auto;margin:0 auto}
#zoomImage[hidden]{display:none}
#zoomPage,#zoomPercent{font-size:11px;white-space:nowrap}
#zoomStatus{position:absolute;top:70px;left:10%;right:10%;text-align:center;pointer-events:none}
#zoomStatus:empty{display:none}
#shareDialog{width:min(92vw,460px);height:auto;max-height:85dvh;overflow:auto}
.share-tools{padding:18px;font-size:13px}
.share-tools input{width:100%;font-size:16px;margin:12px 0;padding:9px}
.share-tools>div{display:flex;justify-content:flex-end;gap:8px}
#shareStatus{margin:8px 0 0;font-size:12px}
@media(max-width:900px){.toolbar #share{grid-column:3;grid-row:2}.zoom-tools{gap:4px;padding:6px}.zoom-tools button{padding:5px 7px;font-size:11px}}

/* Keep controls clear of mobile system navigation, including installed shortcuts. */
@media(max-width:900px){
  body{height:var(--reader-visible-height,100dvh);max-height:var(--reader-visible-height,100dvh)}
  main{min-height:0;min-width:0}
  .toolbar{position:relative;z-index:2;padding-bottom:calc(8px + env(safe-area-inset-bottom,0px));flex-shrink:0}
  #zoomDialog{max-height:calc(var(--reader-visible-height,100dvh) - 24px - env(safe-area-inset-bottom,0px))}
  #shareDialog{max-height:calc(var(--reader-visible-height,100dvh) - 24px - env(safe-area-inset-bottom,0px))}
}
/* Some installed Android shortcuts report zero safe inset despite a navigation bar. */
@media(max-width:900px) and (display-mode:standalone), (max-width:900px) and (display-mode:fullscreen){
  .toolbar{padding-bottom:calc(8px + max(48px,env(safe-area-inset-bottom,0px)))}
  #zoomDialog,#shareDialog{max-height:calc(var(--reader-visible-height,100dvh) - 24px - max(48px,env(safe-area-inset-bottom,0px)))}
}
