:root {
  --ink: #f4ecdc;
  --ink-dim: #c9bfae;
  --ink-faint: #8e8676;
  --panel: rgba(18, 18, 32, 0.78);
  --panel-solid: #16172a;
  --line: rgba(255, 240, 210, 0.14);
  --gold: #f2c46d;
  --gold-deep: #c8913a;
  --red: #e0623a;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #121427; color: var(--ink); font-family: var(--sans); }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#vignette { position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(5, 4, 12, 0.55) 100%); }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { font-family: var(--sans); font-size: 0.8em; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: rgba(255,255,255,0.06); }
.hidden { display: none !important; }
.small { font-size: 0.85rem; color: var(--ink-dim); }

.ghost { background: rgba(255,255,255,0.06); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-size: 0.9rem; backdrop-filter: blur(8px); }
.ghost:hover { background: rgba(255,255,255,0.12); }
.ghost.small { padding: 5px 11px; font-size: 0.82rem; }
.cta { background: linear-gradient(180deg, var(--gold), var(--gold-deep)); color: #2a1a06; border: 0; border-radius: 999px; padding: 9px 18px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(242, 196, 109, 0.35); }
.cta.big { font-size: 1.15rem; padding: 13px 34px; }
.cta.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(242,196,109,0.15), 0 6px 30px rgba(242,196,109,0.55); } }
.badge { display: inline-block; min-width: 1.4em; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: var(--gold); color: #2a1a06; font-size: 0.75rem; font-weight: 700; text-align: center; }
.badge.bump { animation: bump 0.6s ease; }
@keyframes bump { 30% { transform: scale(1.5); } }

/* top bar */
#top { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px; background: linear-gradient(180deg, rgba(8,8,18,0.7), transparent); z-index: 20; }
.brand { font-family: var(--serif); font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .mark { color: var(--gold); }
.brand .ep { color: var(--ink-dim); font-size: 0.88rem; margin-left: 8px; font-style: italic; }
.tools { display: flex; gap: 8px; flex-shrink: 0; }
.drop { position: fixed; top: 58px; right: 16px; width: min(420px, calc(100vw - 32px)); max-height: calc(100vh - 80px); overflow: auto;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; z-index: 30; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.drop h3 { font-family: var(--serif); margin: 0 0 8px; font-weight: 600; }
.drop ol { padding-left: 20px; margin: 0 0 10px; line-height: 1.5; }
.drop li { margin-bottom: 6px; }
#settings label { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 6px 0 10px; font-size: 0.92rem; }
#settings select { background: #0e0f1e; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 5px; }
#clues { list-style: none; margin: 0; padding: 0; }
#clues li { padding: 9px 0; border-top: 1px solid var(--line); }
#clues li:first-child { border-top: 0; }
#clues li b { font-family: var(--serif); font-weight: 600; color: var(--gold); display: block; }
#clues li span { font-size: 0.9rem; color: var(--ink-dim); line-height: 1.4; }
#clues li.empty { color: var(--ink-faint); font-style: italic; }
#clues li.fresh { animation: fresh 2s ease; }
@keyframes fresh { from { background: rgba(242,196,109,0.18); } }

/* objective */
#objective { position: fixed; top: 64px; left: 16px; width: min(330px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; z-index: 10; backdrop-filter: blur(10px); }
.obj-time { font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold); margin-bottom: 4px; }
.obj-text { font-family: var(--serif); font-size: 1rem; line-height: 1.35; }
.obj-pips { display: flex; gap: 6px; margin: 8px 0 2px; }
.obj-pips i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--gold); }
.obj-pips i.on { background: var(--gold); box-shadow: 0 0 10px var(--gold); }
.obj-hint { font-size: 0.88rem; color: var(--ink-dim); margin-top: 8px; line-height: 1.4; font-style: italic; }
.obj-row { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }

/* name tags */
#tags { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.tag { position: absolute; transform: translate(-50%, -100%); pointer-events: auto; cursor: pointer; white-space: nowrap;
  background: rgba(18,18,32,0.82); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px 5px 10px; font-size: 0.86rem;
  display: flex; align-items: center; gap: 7px; transition: transform 0.2s, background 0.2s; backdrop-filter: blur(6px); }
.tag:hover, .tag.hot { background: rgba(40,34,52,0.95); transform: translate(-50%, -100%) scale(1.07); }
.tag .dot { width: 9px; height: 9px; border-radius: 50%; }
.tag .ask { color: var(--gold); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.tag.talked .ask { color: var(--ink-faint); }

/* narration */
#narr { position: fixed; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(820px, calc(100vw - 32px));
  background: linear-gradient(180deg, rgba(20,18,34,0.86), rgba(12,12,24,0.92)); border: 1px solid var(--line); border-radius: 18px;
  padding: 16px 56px 18px 22px; z-index: 12; box-shadow: 0 18px 60px rgba(0,0,0,0.45); cursor: pointer; backdrop-filter: blur(10px); }
#narr .who { font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold); margin-bottom: 6px; }
#narr .line { font-family: var(--serif); font-size: clamp(1.02rem, 2.2vw, 1.28rem); line-height: 1.5; min-height: 3em; }
#narr .line .rest { opacity: 0; }
#narr.char .line { font-style: italic; }
#narr .next { position: absolute; right: 12px; bottom: 12px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,0.07); }

/* talk panel */
#talk { position: fixed; right: 16px; top: 64px; bottom: 22px; width: min(400px, calc(100vw - 32px)); display: flex; flex-direction: column;
  background: linear-gradient(180deg, rgba(22,20,38,0.92), rgba(14,14,26,0.95)); border: 1px solid var(--line); border-radius: 18px; z-index: 15;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5); backdrop-filter: blur(12px); overflow: hidden; }
.talk-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.talk-name { font-family: var(--serif); font-size: 1.45rem; font-weight: 600; }
.talk-role { font-size: 0.85rem; color: var(--ink-dim); font-style: italic; }
.talk-log { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 9px 13px; border-radius: 14px; line-height: 1.45; font-size: 0.95rem; }
.msg.them { align-self: flex-start; background: rgba(255,255,255,0.07); border: 1px solid var(--line); font-family: var(--serif); font-size: 1.02rem; }
.msg.me { align-self: flex-end; background: rgba(242,196,109,0.16); border: 1px solid rgba(242,196,109,0.3); }
.msg.sys { align-self: center; font-size: 0.82rem; color: var(--ink-faint); font-style: italic; background: none; padding: 2px; }
.msg.clue { align-self: center; font-size: 0.82rem; color: var(--gold); border: 1px dashed rgba(242,196,109,0.5); }
.msg .play { margin-left: 6px; border: 0; background: none; color: var(--ink-faint); font-size: 0.85rem; padding: 0; }
.msg.thinking { color: var(--ink-faint); }
.msg.thinking::after { content: "…"; animation: dots 1.2s steps(3) infinite; display: inline-block; width: 1em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1em; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 4px; }
.chip { background: rgba(255,255,255,0.05); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 0.86rem; text-align: left; }
.chip:hover { border-color: var(--gold); color: var(--gold); }
.talk-input { display: flex; gap: 8px; padding: 10px 14px 6px; align-items: center; }
.talk-input input { flex: 1; min-width: 0; background: rgba(0,0,0,0.3); border: 1px solid var(--line); border-radius: 999px; padding: 10px 14px; color: var(--ink); font: inherit; font-size: 0.95rem; }
.talk-input input:focus { outline: none; border-color: var(--gold); }
.send { background: rgba(242,196,109,0.2); border: 1px solid rgba(242,196,109,0.4); border-radius: 999px; padding: 9px 14px; font-weight: 600; color: var(--gold); }
.mic { width: 46px; height: 46px; flex-shrink: 0; border-radius: 50%; border: 0; background: linear-gradient(180deg, #e9784e, #b8431f); color: #fff; display: grid; place-items: center;
  box-shadow: 0 4px 16px rgba(224,98,58,0.4); touch-action: none; user-select: none; -webkit-user-select: none; }
.mic.rec { background: linear-gradient(180deg, #ff5a4a, #c0201a); animation: rec 1s ease-in-out infinite; }
@keyframes rec { 50% { box-shadow: 0 0 0 10px rgba(255,90,74,0.18); } }
.mic.busy { opacity: 0.6; }
.talk-status { font-size: 0.78rem; color: var(--ink-faint); padding: 0 16px 10px; min-height: 1.3em; }

/* toast, scene card */
#toast { position: fixed; left: 50%; top: 70px; transform: translate(-50%, -20px); opacity: 0; pointer-events: none; z-index: 40;
  background: var(--panel-solid); border: 1px solid rgba(242,196,109,0.5); color: var(--ink); border-radius: 999px; padding: 9px 18px; transition: all 0.4s; font-size: 0.92rem; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast b { color: var(--gold); font-family: var(--serif); }
#card { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; z-index: 25; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(10,8,20,0.65), rgba(10,8,20,0.2) 70%); animation: cardin 3.2s ease forwards; }
#card h2 { font-family: var(--serif); font-size: clamp(2.2rem, 6vw, 4rem); font-weight: 600; margin: 6px 0; text-shadow: 0 4px 30px rgba(0,0,0,0.6); }
.card-ep, .card-time { color: var(--gold); letter-spacing: 0.14em; text-transform: uppercase; font-size: 0.85rem; }
@keyframes cardin { 0% { opacity: 0; } 15% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }

/* title + end */
#title, #end { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; overflow: auto; padding: 24px 16px;
  background: radial-gradient(ellipse at 50% 30%, rgba(40,34,80,0.55), rgba(8,8,18,0.92) 75%); }
.title-inner { max-width: 640px; text-align: center; }
.kicker { color: var(--gold); letter-spacing: 0.2em; text-transform: uppercase; font-size: 0.78rem; }
#title h1, #end h1 { font-family: var(--serif); font-weight: 800; font-size: clamp(2.6rem, 9vw, 5rem); margin: 6px 0 4px; line-height: 1; }
#title h1 .mark { color: var(--gold); font-weight: 400; }
#title h2, #end h2 { font-family: var(--serif); font-weight: 400; color: var(--ink-dim); margin: 0 0 14px; font-size: clamp(1.1rem, 3vw, 1.4rem); }
.lede { font-family: var(--serif); font-size: 1.12rem; line-height: 1.5; color: var(--ink); }
.howto { text-align: left; background: rgba(255,255,255,0.05); border: 1px solid var(--line); border-radius: 16px; padding: 12px 18px; margin: 18px 0; }
.howto h3 { margin: 4px 0 6px; font-family: var(--serif); font-weight: 600; font-size: 1.05rem; color: var(--gold); }
.howto ul { margin: 0; padding-left: 18px; line-height: 1.5; font-size: 0.94rem; }
.howto li { margin-bottom: 5px; }
.title-btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.credit { margin-top: 18px; font-size: 0.78rem; color: var(--ink-faint); }
.credit a { color: inherit; }
.concept { font-size: 0.95rem; line-height: 1.5; color: var(--ink-dim); margin: 0 auto 14px; max-width: 34em; }
body:not(.web) .only-web, body.web .only-lan { display: none; }
body:has(#title:not(.hidden)) #top { visibility: hidden; }

@media (max-width: 760px) {
  .brand .ep { display: none; }
  .tools .ghost { padding: 6px 10px; font-size: 0.82rem; }
  #btnHow { display: none; }
  #objective { top: 56px; padding: 9px 12px; }
  .obj-text { font-size: 0.92rem; }
  #talk { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; height: 56vh; }
  body.talking #objective { display: none; }
  #narr { padding: 12px 50px 14px 16px; }
}
