/* ส่วนที่ใช้ร่วมกันทุกเดโม่: แม่น้ำแควตอนกลางคืน + กระดาษแข็งสีครีมแบบตั๋วรถไฟเก่า */
:root {
  --bg: #0d1816;
  --bg-2: #14231f;
  --line: #2b3d38;
  --fg: #f0e8d8;
  --muted: #a7b2ab;
  --paper: #efe3c8;
  --paper-2: #e0cfa8;
  --ink: #1e1a16;
  --ink-2: #5a4c3c;
  --brass: #d1a84f;
  --brass-hi: #e8c77f;
  --signal: #b8392c;
  --river: #2f8f7f;
  --font-display: "Chonburi", "Trirong", Georgia, serif;
  --font-body: "IBM Plex Sans Thai", "Noto Sans Thai", "Leelawadee UI", Tahoma, system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "IBM Plex Sans Thai", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
img { max-width: 100%; }
:focus-visible { outline: 3px solid var(--brass-hi); outline-offset: 3px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; opacity: 0;
}

.app { max-width: 30rem; margin: 0 auto; }
.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  padding-top: max(18px, env(safe-area-inset-top));
  padding-bottom: max(22px, env(safe-area-inset-bottom));
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
}

h1, h2, h3 { margin: 0; font-weight: 400; text-wrap: balance; }
p { margin: 0; }
h1 { font-family: var(--font-display); font-size: clamp(2.3rem, 11vw, 3.2rem); line-height: 1.2; }
h1 span { color: var(--brass); }
h2 { font-family: var(--font-display); font-size: 1.4rem; line-height: 1.35; }
.kicker {
  font-family: var(--font-mono);
  font-size: .74rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--brass);
}
.lead { font-size: 1.05rem; max-width: 26rem; }
.hint { font-size: .9rem; color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ปุ่ม */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 56px; padding: 0 1.25rem;
  border-radius: 14px; border: 1px solid transparent;
  font-weight: 600; font-size: 1.05rem; text-align: center;
  cursor: pointer; text-decoration: none;
  transition: transform .12s ease, background-color .12s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brass); color: var(--ink); }
.btn.primary:disabled { opacity: .45; cursor: default; transform: none; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--fg); }
.btn.small { min-height: 46px; font-size: .92rem; padding: 0 .9rem; }
.btn.block { width: 100%; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.bar { display: flex; align-items: center; gap: .7rem; }
.bar h2 { flex: 1; min-width: 0; }
.icon-btn {
  flex: none; width: 46px; height: 46px; border-radius: 12px;
  border: 1px solid var(--line); background: transparent; color: var(--fg);
  display: grid; place-items: center; cursor: pointer; text-decoration: none;
}
.icon-btn svg { width: 22px; height: 22px; }

/* ตัวเลือกแบบชิป */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
  min-height: 40px; padding: 0 .9rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--fg);
  font-size: .9rem; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--brass); color: var(--ink); border-color: var(--brass); font-weight: 600; }

/* การ์ดกระดาษ */
.story {
  background: var(--paper); color: var(--ink);
  border-radius: 14px; padding: 1rem 1.1rem;
  display: grid; gap: .4rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}
.story h3 { font-family: var(--font-display); font-size: 1.08rem; line-height: 1.4; }
.story p { font-size: .93rem; line-height: 1.7; }
.story .fine { font-size: .76rem; color: var(--ink-2); }

.notice { font-size: .88rem; color: var(--ink); background: var(--brass-hi); border-radius: 10px; padding: .55rem .75rem; }
.notice-error { font-size: .9rem; color: var(--fg); border: 1px solid var(--signal); background: rgba(184, 57, 44, .15); border-radius: 10px; padding: .6rem .8rem; }

/* เวทีกล้องแบบเต็มจอ ใช้กับเดโม่ที่ใช้กล้อง */
.stage { position: relative; width: 100%; aspect-ratio: 3 / 4; border-radius: 20px; overflow: hidden; background: #000; border: 1px solid var(--line); }
.stage > canvas, .stage > video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.stage-msg {
  position: absolute; inset: 0; display: grid; place-content: center; gap: .9rem;
  padding: 1.5rem; text-align: center; color: var(--fg);
  background: radial-gradient(circle at 50% 40%, #1c2f2a, #0b1412);
}
.loading-dot { width: 42px; height: 42px; margin: 0 auto; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brass); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.shutter {
  width: 78px; height: 78px; border-radius: 50%;
  border: 5px solid var(--paper); background: var(--brass);
  box-shadow: 0 0 0 7px rgba(209, 168, 79, .18);
  cursor: pointer; transition: transform .1s ease;
}
.shutter:active { transform: scale(.94); }
.cam-actions { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .75rem; }
.cam-actions > :last-child { justify-self: end; }
.flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 50; }
.flash.on { animation: flash .45s ease-out; }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }

.poster { width: 100%; display: block; border-radius: 6px; background: var(--paper); box-shadow: 0 14px 36px rgba(0, 0, 0, .55); }

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