/*
 * public/css/core.css — Last Stream
 * TH: สไตล์ของ core + เมนู + ซับไตเติล — มืด เรียบ ตัวใหญ่ อ่านบนมือถือของคนดูสตรีมได้ ไม่มีอีโมจิ
 * EN: Core layer styles: canvas, fade, crosshair, subtitles/dialog/choices, prompt, morning card,
 *     menus (warning, main, settings, pause, log). Dark, minimal, large type (viewers watch on phones).
 * Owner: core.
 */
:root {
  --lsc-bg: #07070a;
  --lsc-panel: rgba(10, 10, 14, 0.86);
  --lsc-ink: #ece8e1;
  --lsc-dim: #9c968d;
  --lsc-faint: #5b5752;
  --lsc-line: rgba(236, 232, 225, 0.16);
  --lsc-accent: #c8333a;
  --lsc-accent-ink: #fff3f0;
  --lsc-focus: #e9d9a8;
  --lsc-font: "Sarabun", "Leelawadee UI", "Noto Sans Thai", "Tahoma", system-ui, sans-serif;
  --lsc-sub: clamp(22px, 2.6vw, 34px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--lsc-bg); color: var(--lsc-ink); font-family: var(--lsc-font); }
body { -webkit-font-smoothing: antialiased; }

#ls-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; outline: none; touch-action: none; }
#ls-fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 40; }
#ls-ui { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
#ls-ui > * { pointer-events: auto; }
#ls-ui[data-error]::after {
  content: attr(data-error); position: absolute; left: 16px; bottom: 16px; padding: 8px 12px;
  background: #300; color: #fdd; font-size: 14px; pointer-events: none;
}

/* crosshair: only in game, walk mode */
#ls-crosshair { position: fixed; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px; border-radius: 50%;
  background: rgba(236, 232, 225, 0.55); z-index: 45; display: none; pointer-events: none; }
body.in-game.is-locked #ls-crosshair { display: block; }

/* -------------------------------------------------------------- dialog */
.lsc-dialog { position: absolute; inset: 0; pointer-events: none !important; }
.lsc-dialog > * { pointer-events: auto; }
.lsc-sub {
  position: absolute; left: 50%; bottom: 7vh; transform: translateX(-50%);
  width: min(92vw, 1100px); padding: 0.55em 0.9em 0.65em; background: rgba(0, 0, 0, 0.62);
  border-left: 3px solid var(--lsc-line); font-size: var(--lsc-sub); line-height: 1.45; cursor: pointer;
  text-shadow: 0 1px 2px #000;
}
.lsc-dialog[data-size="m"] { --lsc-sub: clamp(18px, 2vw, 26px); }
.lsc-dialog[data-size="l"] { --lsc-sub: clamp(22px, 2.6vw, 34px); }
.lsc-dialog[data-size="xl"] { --lsc-sub: clamp(28px, 3.4vw, 44px); }
.lsc-sub[data-who="system"] { font-style: italic; color: var(--lsc-dim); }
.lsc-sub[data-who="obs"] { border-left-color: var(--lsc-accent); }
.lsc-sub-who { font-size: 0.62em; letter-spacing: 0.08em; color: var(--lsc-dim); margin-bottom: 0.15em; /* never uppercase: names are player-typed / Thai */ }
.lsc-prompt {
  position: absolute; left: 50%; top: calc(50% + 34px); transform: translateX(-50%);
  padding: 0.25em 0.7em; font-size: clamp(18px, 1.8vw, 24px); background: rgba(0, 0, 0, 0.5); color: var(--lsc-ink);
  pointer-events: none !important; white-space: nowrap;
}
.lsc-choice {
  position: absolute; left: 50%; bottom: calc(7vh + 5.5em); transform: translateX(-50%);
  width: min(92vw, 720px); display: grid; gap: 10px; font-size: clamp(20px, 2.2vw, 28px);
}
.lsc-choice-title { color: var(--lsc-dim); font-size: 0.8em; }
.lsc-choice-list { display: grid; gap: 8px; }
.lsc-choice-btn {
  display: flex; gap: 0.8em; align-items: baseline; width: 100%; text-align: left; font: inherit; color: var(--lsc-ink);
  background: var(--lsc-panel); border: 1px solid var(--lsc-line); padding: 0.5em 0.8em; cursor: pointer;
}
.lsc-choice-btn:hover, .lsc-choice-btn:focus-visible { border-color: var(--lsc-focus); outline: none; background: rgba(30, 28, 26, 0.92); }
.lsc-choice-key { color: var(--lsc-dim); font-variant-numeric: tabular-nums; min-width: 1em; }

.lsc-card {
  position: absolute; inset: 0; display: grid; place-items: center; z-index: 60; pointer-events: none !important;
  font-size: clamp(30px, 4vw, 56px); letter-spacing: 0.04em; color: var(--lsc-ink); text-shadow: 0 2px 12px #000;
}
.lsc-card[hidden], .lsc-sub[hidden], .lsc-choice[hidden], .lsc-prompt[hidden] { display: none; }

/* --------------------------------------------------------------- menus */
.lsc-menu {
  position: absolute; inset: 0; overflow-y: auto; display: flex; flex-direction: column; align-items: center; padding: 24px 16px;
  background: radial-gradient(ellipse at 30% 20%, rgba(40, 18, 20, 0.55), transparent 60%), rgba(4, 4, 6, 0.94);
}
.lsc-menu[data-ingame="true"] { background: rgba(4, 4, 6, 0.8); }
.lsc-menu[hidden] { display: none; }
.lsc-page { width: min(100%, 760px); display: grid; gap: 18px; margin: auto 0; /* centred, never clipped when taller than the screen */ }
.lsc-title { margin: 0; font-size: clamp(48px, 8vw, 104px); font-weight: 300; letter-spacing: 0.02em; line-height: 1; }
.lsc-tagline { margin: 0 0 12px; color: var(--lsc-dim); font-size: clamp(18px, 2vw, 24px); }
.lsc-h1 { margin: 0; font-size: clamp(30px, 4vw, 48px); font-weight: 400; }
.lsc-h2 { margin: 12px 0 0; font-size: 22px; font-weight: 400; color: var(--lsc-dim); }
.lsc-lead { font-size: clamp(20px, 2.2vw, 26px); line-height: 1.5; margin: 0; }
.lsc-note { margin: -8px 0 4px; color: var(--lsc-faint); font-size: 16px; }
.lsc-help { color: var(--lsc-dim); font-size: 20px; }
.lsc-nav { display: grid; gap: 10px; justify-items: stretch; max-width: 460px; }
.lsc-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.lsc-row > .lsc-btn { flex: 0 1 auto; white-space: nowrap; }

.lsc-btn {
  font: inherit; font-size: clamp(20px, 2.1vw, 26px); color: var(--lsc-ink); background: transparent; text-align: left;
  border: 1px solid var(--lsc-line); padding: 0.55em 0.9em; cursor: pointer; min-height: 52px;
  transition: border-color 0.15s, background 0.15s;
}
.lsc-btn:hover:not(:disabled), .lsc-btn:focus-visible { border-color: var(--lsc-focus); background: rgba(255, 255, 255, 0.04); outline: none; }
.lsc-btn:disabled { color: var(--lsc-faint); cursor: not-allowed; border-style: dashed; }
.lsc-btn.lsc-primary { border-color: var(--lsc-accent); background: rgba(200, 51, 58, 0.16); }
.lsc-btn.lsc-primary:hover:not(:disabled) { background: rgba(200, 51, 58, 0.3); }
.lsc-btn.lsc-primary:disabled { border-color: var(--lsc-faint); background: transparent; }

.lsc-lang { display: flex; gap: 8px; margin-top: 6px; }
.lsc-chip {
  font: inherit; font-size: 18px; color: var(--lsc-dim); background: transparent; border: 1px solid var(--lsc-line);
  padding: 0.35em 0.8em; cursor: pointer; min-height: 44px;
}
.lsc-chip.is-on { color: var(--lsc-ink); border-color: var(--lsc-ink); }
.lsc-chip:focus-visible { outline: 2px solid var(--lsc-focus); outline-offset: 2px; }

.lsc-warning-list { margin: 0; padding-left: 1.1em; display: grid; gap: 12px; font-size: clamp(19px, 2vw, 24px); line-height: 1.5; }
.lsc-warning-list li::marker { color: var(--lsc-accent); }

/* settings */
.lsc-tabs { display: flex; flex-wrap: wrap; gap: 6px; border-bottom: 1px solid var(--lsc-line); }
.lsc-tab {
  font: inherit; font-size: 19px; color: var(--lsc-dim); background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 0.5em 0.8em; cursor: pointer; min-height: 48px;
}
.lsc-tab.is-on { color: var(--lsc-ink); border-bottom-color: var(--lsc-accent); }
.lsc-set-body { display: grid; gap: 14px; }
.lsc-set-row { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(200px, 1.4fr); gap: 6px 16px; align-items: center; }
.lsc-set-label { font-size: 20px; }
.lsc-set-range { display: flex; gap: 12px; align-items: center; }
.lsc-set-range input { flex: 1; accent-color: var(--lsc-accent); height: 32px; min-width: 0; }
.lsc-set-value { min-width: 4.5em; text-align: right; color: var(--lsc-dim); font-variant-numeric: tabular-nums; font-size: 18px; }
.lsc-set-hint { grid-column: 1 / -1; color: var(--lsc-faint); font-size: 16px; }
.lsc-toggle {
  justify-self: start; font: inherit; font-size: 18px; min-width: 96px; min-height: 44px; cursor: pointer;
  color: var(--lsc-dim); background: transparent; border: 1px solid var(--lsc-line);
}
.lsc-toggle.is-on { color: var(--lsc-accent-ink); background: rgba(200, 51, 58, 0.35); border-color: var(--lsc-accent); }
.lsc-seg { display: flex; gap: 6px; flex-wrap: wrap; }
.lsc-calib { grid-column: 1 / -1; display: flex; gap: 12px; align-items: center; color: var(--lsc-faint); }
.lsc-calib-dim { width: 44px; height: 44px; background: #000; position: relative; flex: none; }
.lsc-calib-dim::after { content: ""; position: absolute; inset: 12px; background: #0b0b0b; }
.lsc-keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; margin: 0; font-size: 19px; }
.lsc-keys dt { color: var(--lsc-dim); }
.lsc-keys dd { margin: 0; display: flex; gap: 6px; flex-wrap: wrap; }
kbd { font-family: inherit; font-size: 16px; border: 1px solid var(--lsc-line); padding: 2px 8px; min-width: 2em; text-align: center; }

.lsc-log-list { margin: 0; padding-left: 1.2em; max-height: 60vh; overflow-y: auto; display: grid; gap: 10px; font-size: 20px; line-height: 1.45; }
.lsc-log-list b { color: var(--lsc-dim); font-weight: 400; }
.lsc-log-list li[data-who="system"] { color: var(--lsc-dim); font-style: italic; }

@media (max-width: 640px) {
  .lsc-set-row { grid-template-columns: 1fr; }
  .lsc-nav { max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  .lsc-btn { transition: none; }
}

/* settings: fixed-size dialog (TK playtest, glue wave 2) — header + tabs pinned, the tab body scrolls, so switching
   tabs never moves the header up/down */
.lsc-page.lsc-settings {
  height: min(86vh, 760px); margin: auto 0; align-content: stretch;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}
.lsc-settings .lsc-set-body { overflow-y: auto; align-content: start; padding-right: 6px; min-height: 0; overscroll-behavior: contain; }
@media (max-width: 640px) {
  .lsc-page.lsc-settings { height: calc(100dvh - 48px); }
}

/* manual dialog (DESIGN addendum "Dialog แบบ manual"): ▼ = waiting for Space / E / click / Enter */
.lsc-sub-next { display: inline-block; margin-left: 0.4em; font-size: 0.6em; color: var(--lsc-dim); vertical-align: middle; animation: lsc-next 1.6s ease-in-out infinite; }
.lsc-sub-next[hidden] { display: none; }
@keyframes lsc-next { 0%, 100% { opacity: 0.35; transform: translateY(0); } 50% { opacity: 0.9; transform: translateY(2px); } }
@media (prefers-reduced-motion: reduce) { .lsc-sub-next { animation: none; opacity: 0.7; } }

/* chapter card (DESIGN addendum "สคริปต์เปิดเรื่อง", glue wave 2): fade to black 1 s → title / subtitle → extra → fade out */
.lsc-chapter {
  position: absolute; inset: 0; z-index: 70; display: grid; place-content: center; justify-items: center; gap: 0.35em;
  background: #000; color: var(--lsc-ink); text-align: center; padding: 16px; pointer-events: none !important;
  opacity: 0; transition: opacity 1000ms ease;
}
.lsc-chapter.is-on { opacity: 1; }
.lsc-chapter.is-on.is-out { opacity: 0; transition-duration: 800ms; }
.lsc-chapter[hidden] { display: none; }
.lsc-chapter-title { font-size: clamp(16px, 1.8vw, 22px); font-variant: small-caps; letter-spacing: 0.18em; color: var(--lsc-dim); }
.lsc-chapter-sub { font-size: clamp(34px, 5.5vw, 72px); font-weight: 300; letter-spacing: 0.02em; line-height: 1.15; }
.lsc-chapter-extra { font-size: clamp(18px, 2vw, 26px); color: var(--lsc-dim); opacity: 0; transition: opacity 900ms ease; min-height: 1.4em; }
.lsc-chapter-extra.is-on { opacity: 1; }

/* quest tracker: one line top-left, under the stream HUD while it is up */
.lsc-quest {
  position: absolute; left: 16px; top: 14px; max-width: min(70vw, 520px); z-index: 30; pointer-events: none !important;
  display: flex; gap: 0.45em; align-items: baseline; padding: 0.3em 0.7em; background: rgba(0, 0, 0, 0.45);
  font-size: clamp(15px, 1.5vw, 20px); color: var(--lsc-ink); text-shadow: 0 1px 2px #000; transition: opacity 250ms ease;
}
.lsc-quest[hidden] { display: none; }
.lsc-quest.is-fade { opacity: 0; }
.lsc-quest-mark { color: var(--lsc-accent); font-size: 0.85em; }
body:has(.ls-stream:not(.ls-hidden)) .lsc-quest { top: calc(clamp(15px, calc(1.1vw + 6px), 26px) * 2.4 + 8px); }
@media (prefers-reduced-motion: reduce) { .lsc-chapter, .lsc-chapter-extra, .lsc-quest { transition: none; } }

/* choices (TK screenshot, glue wave 2): lower third, left-aligned with the subtitle band, never over a face in the middle */
.lsc-choice { left: calc(50% - min(46vw, 550px)); transform: none; width: min(92vw, 640px); bottom: calc(7vh + 4.8em); }
.lsc-choice[data-position="center"] { left: 50%; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: min(92vw, 720px); }

/* splash "Zilo game" (Arrow Tag's studio wipe, DOM port — src/menu/splash.js) */
.lsc-splash { position: fixed; inset: 0; z-index: 90; background: #000; cursor: pointer; }
.lsc-splash-clip { position: absolute; inset: 0; display: grid; place-items: center; }
.lsc-splash-img { width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.lsc-splash-edge { position: absolute; top: 0; bottom: 0; width: 24px; background: linear-gradient(90deg, rgba(0, 0, 0, 0), #000); pointer-events: none; }
.lsc-splash-edge[hidden] { display: none; }

/* mic screen (after the warning) */
.lsc-mic-status { margin: 0; font-size: clamp(18px, 2vw, 22px); }
.lsc-mic-status.is-granted { color: #9fd99f; }
.lsc-mic-status.is-denied { color: var(--lsc-dim); }
