:root {
  --ink: #1a1720;
  --paper: #fff6e6;
  --paper-2: #f2e6d0;
  --accent: #d8543c;
  --accent-2: #4f78c8;
  --muted: rgba(255, 246, 230, 0.7);
  --font: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --serif: "Kanit", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0f1a1c; color: var(--paper); font-family: var(--font); overflow: hidden; }
body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; }

.stage { position: fixed; inset: 0; overflow: hidden; touch-action: none; }
.stage canvas { position: absolute; inset: 0; display: block; }
.ui { position: absolute; inset: 0; pointer-events: none; }
.ui > * { pointer-events: auto; }

button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.btn {
  border: 0; border-radius: 999px; padding: 12px 20px; min-height: 44px;
  background: rgba(255, 246, 230, 0.14); color: var(--paper); font-weight: 600; letter-spacing: 0.01em;
  backdrop-filter: blur(6px);
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.small { padding: 8px 12px; min-height: 36px; min-width: 40px; font-size: 14px; }
.btn.choice { display: block; width: 100%; text-align: left; margin-top: 8px; background: rgba(216, 84, 60, 0.18); border: 1px solid rgba(216, 84, 60, 0.5); }
.btn.tool { background: rgba(79, 120, 200, 0.22); border: 1px solid rgba(79, 120, 200, 0.5); }
.chip { border: 0; border-radius: 10px; padding: 8px 10px; background: rgba(255,246,230,0.12); color: var(--paper); font-size: 13px; text-align: left; }

.hud { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; display: flex; gap: 8px; }
.hud[hidden] { display: none; }
.hud-btn { border: 0; border-radius: 999px; padding: 8px 14px; min-height: 40px; background: rgba(20, 18, 26, 0.55); color: var(--paper); font-weight: 600; backdrop-filter: blur(6px); }

.card {
  position: absolute; top: 18%; left: 50%; transform: translate(-50%, -8px); opacity: 0;
  font-family: var(--serif); font-size: clamp(20px, 5vw, 30px); letter-spacing: 0.02em; text-shadow: 0 2px 12px rgba(0,0,0,0.6);
  transition: opacity 0.6s ease, transform 0.6s ease; pointer-events: none; white-space: nowrap; color: #fff;
}
.card.on { opacity: 1; transform: translate(-50%, 0); }

.toast {
  position: absolute; top: max(60px, calc(env(safe-area-inset-top) + 48px)); left: 50%; transform: translate(-50%, -6px); opacity: 0;
  background: rgba(20, 18, 26, 0.72); padding: 8px 14px 8px 10px; border-radius: 999px; font-size: 14px; display: flex; align-items: center; gap: 8px;
  transition: opacity 0.4s ease, transform 0.4s ease; pointer-events: none; max-width: 92vw;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast .box { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; background: var(--accent); color: #fff; font-size: 13px; }

.title {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding: 24px 24px max(32px, env(safe-area-inset-bottom)); text-align: center;
  background: radial-gradient(ellipse 80% 60% at 50% 30%, #2a4a5a 0%, #0f1a1c 70%);
}
.title[hidden] { display: none; }
.title-art { position: absolute; top: 14%; left: 50%; transform: translateX(-50%); width: 160px; height: 160px; }
.title-cat { position: absolute; inset: 0; border-radius: 50%; background: radial-gradient(circle at 50% 55%, #1a1720 0 44%, transparent 45%); }
.title-cat::before, .title-cat::after { content: ""; position: absolute; top: 22px; width: 0; height: 0; border-left: 16px solid transparent; border-right: 16px solid transparent; border-bottom: 30px solid #1a1720; }
.title-cat::before { left: 34px; transform: rotate(-20deg); }
.title-cat::after { right: 34px; transform: rotate(20deg); }
.title h1 { font-family: var(--serif); font-size: clamp(56px, 18vw, 96px); margin: 0; line-height: 0.9; letter-spacing: -0.02em; }
.title-sub { margin: 10px 0 22px; color: var(--muted); max-width: 30ch; }
.title-actions { display: flex; flex-direction: column; gap: 10px; width: min(100%, 300px); }
.title-note { margin: 18px 0 0; font-size: 12px; color: rgba(255,246,230,0.45); max-width: 36ch; }
.chapters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 12px; width: min(100%, 340px); }
.chapters[hidden] { display: none; }

.dialogue {
  position: absolute; left: 12px; right: 12px; bottom: max(14px, env(safe-area-inset-bottom));
  background: rgba(20, 18, 26, 0.88); border: 1px solid rgba(255,246,230,0.12); border-radius: 18px; padding: 14px 16px 16px;
  min-height: 118px; max-height: 46%; overflow: auto; box-shadow: 0 10px 30px rgba(0,0,0,0.35); backdrop-filter: blur(8px);
}
.dialogue[hidden] { display: none; }
.dialogue .who { font-family: var(--serif); font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
.dialogue .who[hidden] { display: none; }
.dialogue .text { font-size: clamp(16px, 4.2vw, 19px); line-height: 1.42; min-height: 2.8em; padding-right: 36px; }
.dialogue .tap { position: absolute; inset: 0; background: transparent; border: 0; border-radius: 18px; }
.dialogue .tap::after { content: "▾"; position: absolute; right: 16px; bottom: 10px; color: var(--muted); animation: nod 1.2s ease-in-out infinite; }
.dialogue .tap[hidden] { display: none; }
.dialogue .choices { position: relative; z-index: 1; }
@keyframes nod { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(4px); } }

.panel {
  position: absolute; left: 12px; right: 12px; bottom: max(14px, env(safe-area-inset-bottom)); top: auto; max-height: 82%; overflow: auto;
  background: rgba(20, 18, 26, 0.92); border: 1px solid rgba(255,246,230,0.12); border-radius: 18px; padding: 18px 16px; backdrop-filter: blur(8px);
}
.panel[hidden] { display: none; }
.panel-title { font-family: var(--serif); margin: 0 0 12px; font-size: 20px; }
.panel .eyebrow { margin: 0; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }
.panel h2 { font-family: var(--serif); margin: 6px 0 4px; font-size: 40px; }
.panel .help { margin: 0 0 12px; color: var(--muted); }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.panel-actions .btn { flex: 1 1 auto; }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid rgba(255,246,230,0.08); font-size: 15px; }
.checklist li:last-child { border-bottom: 0; }
.checklist .box { flex: 0 0 22px; height: 22px; border-radius: 6px; border: 2px solid rgba(255,246,230,0.4); display: grid; place-items: center; font-size: 13px; }
.checklist li.done { color: var(--muted); text-decoration: line-through; }
.checklist li.done .box { background: var(--accent); border-color: var(--accent); color: #fff; }
.checklist li.locked { opacity: 0.45; }
.checklist li.empty { color: var(--muted); }

.dial { padding: 8px 0; border-bottom: 1px solid rgba(255,246,230,0.08); }
.dial-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.dial-row { display: flex; align-items: center; gap: 6px; }
.dial-value { flex: 1; text-align: center; font-family: var(--serif); font-size: 22px; font-variant-numeric: tabular-nums; }
.btn.dir { min-width: 58px; }
.puzzle-message { min-height: 1.4em; color: var(--muted); margin: 8px 0 0; }
.ask { font-size: 17px; margin: 0 0 10px; }
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

@media (min-width: 700px) {
  .dialogue, .panel { left: 50%; right: auto; width: min(560px, 92vw); transform: translateX(-50%); }
}
