:root {
  --sea: #1fb5c4;
  --sea-deep: #0f6f7c;
  --ink: #33302c;
  --ink-soft: #6d665e;
  --paper: #fffdf8;
  --cream: #fbf3e2;
  --line: rgba(51, 48, 44, 0.12);
  --accent: #e8893a;
  --font: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--sea-deep) url("assets/scene-blur.webp") center / cover no-repeat;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.page { min-height: 100%; display: flex; flex-direction: column; align-items: center; padding: 12px 16px 16px; gap: 10px; }

/* Header */
.top { width: 100%; max-width: 1318px; display: flex; align-items: center; gap: 16px; color: #fff; }
.brand { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.brand-zh { font-size: 18px; font-weight: 700; letter-spacing: 0.04em; }
.brand-en { font-size: 13px; opacity: 0.75; letter-spacing: 0.08em; }
.status { flex: 1; font-size: 14px; opacity: 0.92; min-height: 1.4em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .ghost { color: #fff; border-color: rgba(255, 255, 255, 0.55); }
.top-actions { display: flex; gap: 8px; flex-shrink: 0; }
.top #btn-sound[aria-pressed="false"] { opacity: 0.7; }


/* Buttons */
button { cursor: pointer; border-radius: 999px; padding: 8px 16px; font-size: 14px; border: 1px solid transparent; background: none; transition: background 0.15s, opacity 0.15s; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.primary { background: var(--accent); color: #fff; font-weight: 700; }
.primary:hover:not(:disabled) { background: #d97a2c; }
.ghost { border-color: var(--line); background: transparent; }
.ghost:hover:not(:disabled) { background: rgba(0, 0, 0, 0.05); }
:focus-visible { outline: 3px solid #ffd27a; outline-offset: 2px; }

/* Stage: a fixed-aspect viewport onto the 1318x792 scene; on phones it crops to the picnic. */
.stage-wrap { width: 100%; max-width: 1318px; display: flex; justify-content: center; }
.stage { position: relative; width: 100%; overflow: hidden; border-radius: 18px; background: var(--sea); box-shadow: 0 18px 50px rgba(0, 40, 50, 0.35); }
.world { position: absolute; }
.scene { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }

/* Character sprites. Every keyframe scales >= 1 from the feet, so the painted character underneath stays covered. */
.sprite { position: absolute; display: block; transform-origin: 50% 100%; pointer-events: none; user-select: none; -webkit-user-drag: none;
  animation: breathe var(--d, 3.6s) ease-in-out var(--delay, 0s) infinite; }
@keyframes breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.008, 1.026); } }
.sprite.sleepy { animation-name: sleep-breathe; animation-duration: 4.8s; }
@keyframes sleep-breathe { 0%, 100% { transform: scale(1, 1); } 45% { transform: scale(1.022, 1.014); } }
.sprite.thinking { animation: think 1.5s ease-in-out infinite; }
@keyframes think { 0%, 100% { transform: scale(1, 1); } 30% { transform: scale(1.012, 1.04); } 60% { transform: scale(1.004, 1.012); } }
.sprite.talking { animation: talk 0.34s ease-in-out infinite alternate; }
@keyframes talk { from { transform: scale(1, 1); } to { transform: scale(1.016, 1.055); } }
.sprite.listening { animation: perk 0.8s ease-out 1 both; }
@keyframes perk { 0% { transform: scale(1, 1); } 35% { transform: scale(1.02, 1.05); } 100% { transform: scale(1.004, 1.012); } }

/* Lights (config/scene.json): a soft warm glow over the campfire and the lantern. */
.light { position: absolute; aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%; pointer-events: none; mix-blend-mode: screen; }
.light.fire { background: radial-gradient(closest-side, rgba(255, 190, 90, 0.55), rgba(255, 150, 60, 0.18) 55%, rgba(255, 150, 60, 0));
  animation: flicker 2.3s steps(1, end) infinite; }
.light.lantern { background: radial-gradient(closest-side, rgba(255, 236, 160, 0.45), rgba(255, 220, 130, 0.12) 60%, rgba(255, 220, 130, 0));
  animation: glow-soft 4.2s ease-in-out infinite; }
@keyframes flicker { 0% { opacity: 0.55; } 13% { opacity: 0.8; } 27% { opacity: 0.6; } 41% { opacity: 0.9; } 58% { opacity: 0.5; } 72% { opacity: 0.75; } 86% { opacity: 0.62; } }
@keyframes glow-soft { 0%, 100% { opacity: 0.65; } 50% { opacity: 0.95; } }

/* Speaker glow and the "thinking" dots */
.glow, .target-glow { position: absolute; width: 9%; aspect-ratio: 2.2; transform: translate(-50%, -50%); border-radius: 50%; pointer-events: none; opacity: 0; transition: opacity 0.35s, left 0.35s, top 0.35s; }
.glow { background: radial-gradient(closest-side, rgba(255, 249, 214, 0.85), rgba(255, 249, 214, 0)); }
.glow.on { opacity: 1; }
.target-glow { width: 7%; background: radial-gradient(closest-side, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0)); }
.target-glow.on { opacity: 1; }

.dots { position: absolute; transform: translate(-50%, -100%); display: flex; gap: 5px; padding: 8px 12px; background: var(--paper); border-radius: 999px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); opacity: 0; transition: opacity 0.25s; pointer-events: none; }
.dots.on { opacity: 1; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-soft); animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.18s; }
.dots i:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* Bubble: one at a time, white, very round, text typed in. */
.bubble { position: absolute; width: max-content; max-width: min(340px, 30vw); min-width: 150px; background: var(--paper); border-radius: 28px; padding: 12px 20px 14px; box-shadow: 0 6px 22px rgba(0, 0, 0, 0.14); opacity: 0; transform: translate(-50%, calc(-100% + 6px)); transition: opacity 0.25s, transform 0.25s; pointer-events: none; }
.bubble.on { opacity: 1; transform: translate(-50%, -100%); }
.bubble::after { content: ""; position: absolute; left: var(--tail-x, 50%); bottom: -9px; width: 18px; height: 18px; background: var(--paper); transform: translateX(-50%) rotate(45deg); border-radius: 0 0 5px 0; }
.bubble.side-left { transform: translate(calc(-100% + 6px), -50%); }
.bubble.side-left.on { transform: translate(-100%, -50%); }
.bubble.side-left::after { left: auto; right: -8px; bottom: auto; top: 50%; transform: translateY(-50%) rotate(-45deg); border-radius: 0 0 5px 0; }
.bubble.side-right { transform: translate(-6px, -50%); }
.bubble.side-right.on { transform: translate(0, -50%); }
.bubble.side-right::after { left: -8px; bottom: auto; top: 50%; transform: translateY(-50%) rotate(135deg); border-radius: 0 0 5px 0; }
.who { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; white-space: nowrap; }
.who-name { font-weight: 700; color: var(--who-color, var(--ink)); }
.who-name::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--who-color, var(--ink)); margin-right: 5px; vertical-align: 1px; }
.who-to:empty { display: none; }
.line { margin: 0; font-size: 16px; line-height: 1.6; letter-spacing: 0.01em; min-height: 1.6em; }
.line.skipped { color: var(--ink-soft); font-size: 14px; }

.user-bubble { position: absolute; left: 50%; bottom: 14px; transform: translate(-50%, 10px); max-width: min(520px, 86%); background: var(--cream); border: 1px solid rgba(232, 137, 58, 0.35); border-radius: 22px; padding: 9px 18px 11px; opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12); }
.user-bubble.on { opacity: 1; transform: translate(-50%, 0); }
.user-bubble .who-name { --who-color: var(--accent); font-size: 12px; }
.user-bubble p { margin: 2px 0 0; font-size: 15px; line-height: 1.55; }

/* Overlays */
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 80, 90, 0.28); }
.overlay[hidden] { display: none; }
.sheet { background: var(--paper); border-radius: 22px; padding: 22px 24px; width: min(640px, 100%); max-height: 100%; overflow: auto; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2); }
.sheet.small { width: min(440px, 100%); text-align: center; }
.eyebrow { margin: 0 0 4px; font-size: 12px; letter-spacing: 0.12em; color: var(--accent); font-weight: 700; }
.sheet-title { margin: 0 0 6px; font-size: 22px; }
.sheet-sub { margin: 0 0 16px; color: var(--ink-soft); font-size: 14px; line-height: 1.6; }
.topics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.topic { text-align: left; border-radius: 16px; border: 1px solid var(--line); padding: 12px 14px; background: #fff; display: flex; flex-direction: column; gap: 4px; }
.topic:hover { background: var(--cream); }
.topic b { font-size: 15px; }
.topic span { font-size: 13px; color: var(--ink-soft); line-height: 1.5; }
.topic em { font-style: normal; font-size: 11px; color: var(--accent); letter-spacing: 0.06em; }
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.hint { font-size: 13px; color: var(--ink-soft); margin: 12px 0 0; }

/* Controls */
.controls { width: 100%; max-width: 1318px; display: flex; gap: 12px; align-items: center; background: var(--paper); border-radius: 16px; padding: 8px; }
.say { flex: 1; display: flex; gap: 8px; min-width: 0; }
.say input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 999px; padding: 9px 16px; background: #fff; font-size: 15px; }
.say input:disabled { background: #f3f0ea; }
.say input.asked { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(232, 137, 58, 0.2); }
.buttons { display: flex; gap: 6px; }

/* Log drawer */
.logpanel { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100%); background: var(--paper); box-shadow: -10px 0 30px rgba(0, 0, 0, 0.2); display: flex; flex-direction: column; z-index: 10; }
.logpanel[hidden] { display: none; }
.log-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.log-head h2 { margin: 0; font-size: 16px; }
.log-explain { margin: 0 16px 8px; font-size: 12px; color: var(--ink-soft); line-height: 1.6; }
.log-list { list-style: none; margin: 0; padding: 0 16px 24px; overflow: auto; flex: 1; }
.log-list li { border-top: 1px solid var(--line); padding: 10px 0; display: grid; grid-template-columns: 34px 1fr; gap: 10px; font-size: 13px; }
.log-list img { width: 34px; height: 34px; border-radius: 50%; background: var(--cream); }
.log-list .u { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--cream); color: var(--accent); font-weight: 700; font-size: 12px; }
.log-list .l { margin: 2px 0 4px; font-size: 14px; line-height: 1.55; }
.log-list .m { color: var(--ink-soft); font-size: 11.5px; line-height: 1.6; }
.log-list .m code { font-family: ui-monospace, Consolas, monospace; font-size: 11px; background: #f3efe6; border-radius: 4px; padding: 0 4px; }
.log-list .x { color: #a04a3a; }
.log-list .dim { opacity: 0.6; }

@media (max-width: 720px) {
  .page { padding: 10px 12px 12px; }
  .brand-en { display: none; }
  .bubble { max-width: 62vw; min-width: 120px; padding: 10px 14px 12px; border-radius: 22px; }
  .line { font-size: 14.5px; }
  .controls { flex-direction: column; align-items: stretch; }
  .buttons { justify-content: space-between; }
  .buttons button { flex: 1; padding: 8px 6px; }
  .topics { grid-template-columns: 1fr; }
  .overlay { position: fixed; z-index: 5; background: rgba(15, 80, 90, 0.45); }
  .user-bubble { bottom: 10px; padding: 7px 14px 9px; }
  .user-bubble p { font-size: 14px; }
  .sheet { padding: 18px; }
  .sheet-title { font-size: 19px; }
}

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