@font-face { font-family: "NotoThai"; src: url("fonts/NotoSansThai-Regular.ttf"); font-weight: 400; font-display: swap; }
@font-face { font-family: "NotoThai"; src: url("fonts/NotoSansThai-Bold.ttf"); font-weight: 700; font-display: swap; }
:root {
  --paper: #f7f3ea; --card: #ffffff; --ink: #1f2633; --muted: #5f6878; --line: #e6e0d3;
  --accent: #1f5f8b; --accent-ink: #ffffff; --accent-soft: #e6f0f7;
  --warn: #8f5400; --warn-soft: #fff3df; --ok: #1e7a46; --ok-soft: #e5f5ec; --err: #b42318; --err-soft: #fdecea;
  --hl: #ffe2a8; --r: 16px;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: "NotoThai", -apple-system, sans-serif; font-size: 16px; line-height: 1.55; }
body { min-height: 100dvh; }
main { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 24px); }
h1 { font-size: 26px; line-height: 1.25; margin: 10px 0 14px; font-weight: 700; }
h2 { font-size: 17px; line-height: 1.3; margin: 22px 0 8px; font-weight: 700; }
p { margin: 6px 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 14px; line-height: 1.5; }
.card { background: var(--card); border-radius: var(--r); padding: 14px; border: 1px solid var(--line); }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; border-radius: 14px; border: 0;
  font: 700 16px "NotoThai", sans-serif; width: 100%; padding: 0 16px; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--accent); border: 1.5px dashed #b9c9d6; }
.btn.danger { background: var(--err-soft); color: var(--err); }
.btn.small { min-height: 40px; font-size: 14px; border-radius: 10px; width: auto; }
.btn:disabled { opacity: .5; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid #f0b545; outline-offset: 2px; }
.btns { display: flex; gap: 10px; }
.btns > * { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 99px; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.info { background: var(--accent-soft); color: var(--accent); }
.chip.err { background: var(--err-soft); color: var(--err); }
.cover { width: 56px; height: 80px; border-radius: 6px; flex: none; background: linear-gradient(160deg, #2f4f6f, #1b2f45); color: #fff;
  font-size: 11px; line-height: 1.3; font-weight: 700; padding: 6px; display: flex; align-items: flex-end; overflow: hidden; word-break: break-word; }
.cover.big { width: 84px; height: 120px; font-size: 13px; }
.bar { height: 6px; background: #ece6d9; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.back { color: var(--accent); font-size: 16px; text-decoration: none; display: inline-flex; align-items: center; min-height: 44px; padding-right: 12px; }
label { display: block; font-weight: 700; font-size: 14px; margin: 12px 0 6px; }
input[type=text], input[type=password], input[type=number], textarea {
  width: 100%; font: 16px "NotoThai", sans-serif; padding: 12px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; color: var(--ink); }
textarea { min-height: 220px; line-height: 1.7; resize: vertical; }
.hl { background: var(--hl); border-radius: 4px; padding: 0 2px; box-shadow: 0 0 0 1.5px #e0a030 inset; }
.voice { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; min-height: 52px; width: 100%;
  font: inherit; color: inherit; text-align: left; cursor: pointer; }
.voice.sel { border-color: var(--accent); background: var(--accent-soft); }
.play { width: 36px; height: 36px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  background: #fff; border: 1.5px solid var(--accent); color: var(--accent); cursor: pointer; padding: 0; }
.play.busy { opacity: .5; }
.radio { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #b8c2cc; flex: none; margin-left: auto; }
.sel .radio { border: 6px solid var(--accent); }
.switch { appearance: none; width: 50px; height: 30px; background: #cfd6dd; border-radius: 99px; position: relative; flex: none; margin: 0; cursor: pointer; }
.switch::after { content: ""; position: absolute; width: 26px; height: 26px; background: #fff; border-radius: 50%; top: 2px; left: 2px; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: left .2s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { left: 22px; }
.ep { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.ep:last-child { border-bottom: 0; }
audio { width: 100%; margin-top: 8px; }
.sheet { position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--line); margin: 16px -16px calc(-24px - env(safe-area-inset-bottom));
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); border-radius: 20px 20px 0 0; box-shadow: 0 -6px 20px rgba(0,0,0,.06); }
.pageimg { width: 100%; display: block; border-radius: 10px; background: #eee; }
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #1f2633; color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
#toast.on { opacity: 1; }
.center { text-align: center; }
.err-text { color: var(--err); }

/* scanner */
.scan { position: fixed; inset: 0; background: #111; color: #fff; display: flex; flex-direction: column; z-index: 10; }
.scan .top { display: flex; align-items: center; justify-content: space-between; padding: calc(env(safe-area-inset-top) + 6px) 16px 6px; min-height: 50px; }
.scan .top button { background: none; border: 0; color: #fff; font: 16px "NotoThai", sans-serif; min-height: 44px; padding: 0 4px; cursor: pointer; }
.scan .view { flex: 1; position: relative; overflow: hidden; }
.scan video { width: 100%; height: 100%; object-fit: cover; }
.scan .hint { position: absolute; top: 12px; left: 0; right: 0; display: flex; justify-content: center; pointer-events: none; }
.scan .hint span { background: rgba(0,0,0,.65); color: #fff; font-size: 14px; padding: 6px 12px; border-radius: 99px; }
.scan .flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
.scan .flash.on { opacity: .7; transition: none; }
.scan .bottom { padding: 14px 20px calc(env(safe-area-inset-bottom) + 18px); }
.scan .controls { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.shutter { width: 78px; height: 78px; border-radius: 50%; border: 4px solid #fff; background: none; padding: 0; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.shutter::before { content: ""; width: 62px; height: 62px; border-radius: 50%; background: #fff; transition: transform .1s; }
.shutter:active::before { transform: scale(.9); }
.thumb { width: 56px; height: 74px; border-radius: 6px; overflow: hidden; border: 2px solid #fff; background: #333; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.scan .side { width: 64px; text-align: center; font-size: 14px; line-height: 1.3; background: none; border: 0; color: #fff; font-family: inherit; min-height: 44px; cursor: pointer; }
.scan .nocam { padding: 24px; text-align: center; }
.scan .filebtn { color: #c8d3dc; font-size: 14px; text-decoration: underline; background: none; border: 0; font-family: inherit; margin-top: 10px; min-height: 44px; cursor: pointer; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
