:root {
  --bg: #07070a; --panel: rgba(20, 20, 26, .78); --panel-solid: #15151b; --fg: #f1ecdf; --muted: #a39d8c;
  --accent: #d41f3a; --accent-2: #ff3b57; --gold: #e8c46a; --line: rgba(255, 255, 255, .08);
  --serif: "Playfair Display", "Georgia", "Times New Roman", serif;
  --sans: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--fg); font: 17px/1.55 var(--serif); -webkit-font-smoothing: antialiased; }
body { position: relative; overflow-x: hidden; }
button { font: inherit; }

/* blurred scene frame behind everything: no empty black space, no seams */
#backdrop { position: fixed; inset: -40px; z-index: 0; background: var(--bg) center/cover no-repeat; filter: blur(28px) brightness(.35) saturate(.6); transform: scale(1.08); transition: background-image .8s ease; }
#backdrop::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 20%, rgba(212, 31, 58, .12), transparent 55%), linear-gradient(180deg, rgba(7, 7, 10, .2), rgba(7, 7, 10, .85) 80%); }
header, main, .overlay, .popover, #toast { position: relative; z-index: 1; }

header { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: calc(10px + var(--sat)) 14px 10px; background: linear-gradient(180deg, rgba(7, 7, 10, .92), rgba(7, 7, 10, .55)); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand > div { min-width: 0; }
.brand img { width: 34px; height: 34px; border-radius: 8px; box-shadow: 0 0 0 1px var(--line); }
.brand-name { font-weight: 700; letter-spacing: .12em; text-transform: uppercase; font-size: 13px; line-height: 1.1; }
#chapter-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.chip { background: rgba(255, 255, 255, .06); color: var(--fg); border: 1px solid var(--line); border-radius: 999px; padding: 6px 11px; cursor: pointer; font-family: var(--sans); font-size: 14px; line-height: 1; transition: background .15s, border-color .15s; }
.chip:hover { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .2); }
#credits { color: var(--gold); font-weight: 700; border-color: rgba(232, 196, 106, .35); }

main { max-width: 1180px; margin: 0 auto; padding: 0 0 calc(24px + var(--sab)); display: grid; grid-template-columns: 1fr; gap: 0; }

/* screen */
#screen { position: relative; background: #000; aspect-ratio: 4/3; max-height: 62vh; overflow: hidden; box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .9); }
#screen::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, .55)); }
#screen::before { content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none; opacity: .18; mix-blend-mode: overlay; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }
#video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000 url(/static/poster.svg) center/cover; }
#shoot-layer { position: absolute; inset: 0; cursor: crosshair; z-index: 2; }
.target { position: absolute; border: 2px solid rgba(255, 59, 87, .9); border-radius: 6px; box-shadow: 0 0 22px rgba(212, 31, 58, .6), inset 0 0 12px rgba(212, 31, 58, .25); animation: pulse .45s infinite alternate; }
@keyframes pulse { from { opacity: .55; transform: scale(.97); } to { opacity: 1; transform: scale(1); } }
.video-cta { position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 8px; padding: 0 16px 18px; background: linear-gradient(180deg, transparent 35%, rgba(0, 0, 0, .75)); }
.video-cta .btn.primary { min-width: 240px; box-shadow: 0 8px 30px rgba(212, 31, 58, .45); }
.video-cta .btn.primary:disabled { background: rgba(20, 20, 26, .85); color: var(--muted); box-shadow: none; border: 1px solid var(--line); cursor: default; }
.video-cta .btn.primary:disabled::after { content: ""; display: inline-block; width: 12px; height: 12px; margin-left: 10px; border: 2px solid var(--accent-2); border-right-color: transparent; border-radius: 50%; vertical-align: -2px; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.timer { position: absolute; top: 12px; right: 14px; z-index: 3; font-family: var(--sans); font-size: 30px; font-weight: 800; color: var(--accent-2); text-shadow: 0 0 12px #000, 0 0 30px rgba(212, 31, 58, .7); }

/* story panel */
#panel { padding: 0; }
#story { padding: 20px 18px 6px; }
.eyebrow { font-family: var(--sans); font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--accent-2); margin-bottom: 8px; }
#story h1 { font-size: clamp(24px, 5.5vw, 34px); line-height: 1.15; margin: 0 0 12px; font-weight: 700; letter-spacing: -.01em; text-shadow: 0 2px 20px rgba(0, 0, 0, .6); }
#story h1:empty, .eyebrow:empty { display: none; }
#story p { margin: 0 0 12px; white-space: pre-line; font-size: 18px; line-height: 1.6; color: var(--fg); text-shadow: 0 1px 2px rgba(0, 0, 0, .8); }
#story p::first-letter { font-size: 1.6em; line-height: 1; color: var(--accent-2); font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; font-family: var(--sans); }
.gen { position: relative; padding: 10px 14px 10px 16px; margin: 10px 0; color: #ddd7c8; background: var(--panel); border-radius: 10px; font-style: italic; border-left: 3px solid var(--accent); }
.gen b { font-style: normal; color: var(--gold); font-family: var(--sans); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; margin-right: 4px; }
.event { font-family: var(--sans); font-size: 14px; color: var(--gold); margin: 4px 0; padding-left: 14px; position: relative; }
.event::before { content: "◆"; position: absolute; left: 0; font-size: 9px; top: 5px; }
.event.death { color: var(--accent-2); font-weight: 700; font-size: 16px; }
.event.ending { color: var(--fg); font-family: var(--serif); font-size: 22px; font-weight: 700; margin-top: 12px; padding-left: 0; }
.event.ending::before { display: none; }
#items-here { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
#items-here:empty, #events:empty, #talk-log:empty, #generated:empty { display: none; }
#talk-log { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.line { padding: 8px 12px; border-radius: 12px; max-width: 92%; font-size: 16px; line-height: 1.45; }
.line.you { align-self: flex-end; background: rgba(255, 255, 255, .07); color: #d8d3c6; border-bottom-right-radius: 4px; }
.line.npc { align-self: flex-start; background: rgba(212, 31, 58, .12); border-bottom-left-radius: 4px; }
.line .who { color: var(--accent-2); font-weight: 700; font-family: var(--sans); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; display: block; margin-bottom: 2px; }

/* actions */
#actions { padding: 8px 18px 4px; display: flex; flex-direction: column; gap: 10px; }
#choices { display: flex; flex-direction: column; gap: 10px; }
#choices:empty { display: none; }
.btn { position: relative; background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px 14px 40px; text-align: left; cursor: pointer; font-size: 16.5px; line-height: 1.35; transition: transform .12s, border-color .15s, background .15s; -webkit-tap-highlight-color: transparent; }
#choices .btn::before { content: "›"; position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--accent-2); font-size: 24px; font-weight: 700; line-height: 1; }
.btn:hover { border-color: rgba(255, 255, 255, .25); background: rgba(35, 35, 44, .9); }
.btn:active { transform: scale(.985); }
.btn.primary { background: linear-gradient(180deg, var(--accent-2), var(--accent)); border-color: transparent; color: #fff; text-align: center; padding-left: 16px; font-weight: 700; font-family: var(--sans); letter-spacing: .02em; }
.btn.primary::before, .btn.danger::before, .btn.small::before, .btn.pack::before { display: none; }
.btn.danger { background: linear-gradient(180deg, #4a0d18, #2a0810); border-color: var(--accent); color: #fff; text-align: center; padding-left: 16px; font-family: var(--sans); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.btn.locked { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 999px; font-family: var(--sans); }
.btn.ghost { background: rgba(0, 0, 0, .35); border-color: rgba(255, 255, 255, .25); color: #fff; }
.btn.big { padding: 16px 28px; font-size: 18px; }
#talk, #riddle { display: flex; gap: 8px; flex-wrap: wrap; }
#talk input, #riddle input { flex: 1; min-width: 200px; background: rgba(0, 0, 0, .45); border: 1px solid rgba(255, 255, 255, .15); color: var(--fg); padding: 13px 14px; border-radius: 12px; font: inherit; font-size: 16px; outline: none; }
#talk input:focus, #riddle input:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(212, 31, 58, .2); }
#talk .btn, #riddle .btn { padding: 12px 18px; }
#talk .muted { width: 100%; }

/* overlays */
.overlay { position: fixed; inset: 0; background: rgba(4, 4, 7, .86); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.card { background: var(--panel-solid); border: 1px solid var(--line); border-radius: 16px; padding: 22px; max-width: 440px; width: 100%; box-shadow: 0 30px 80px rgba(0, 0, 0, .8); }
.card h2 { margin: 0 0 10px; font-size: 26px; }
.card .btn { width: 100%; margin-top: 6px; }
.inv-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.inv-item .name { font-weight: 700; }
.popover { position: fixed; right: 12px; top: calc(60px + var(--sat)); background: var(--panel-solid); border: 1px solid var(--line); border-radius: 12px; padding: 14px; z-index: 25; display: flex; flex-direction: column; gap: 10px; min-width: 230px; box-shadow: 0 20px 50px rgba(0, 0, 0, .7); }
.popover label { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 14px; font-family: var(--sans); }
.popover input[type=range] { width: 130px; accent-color: var(--accent); }
#toast { position: fixed; left: 50%; bottom: calc(24px + var(--sab)); transform: translateX(-50%); background: rgba(20, 20, 26, .96); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 30; max-width: 90vw; font-family: var(--sans); font-size: 15px; border: 1px solid var(--line); box-shadow: 0 10px 40px rgba(0, 0, 0, .6); }
.hidden { display: none !important; }
#shop-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.btn.pack { width: 100%; padding-left: 16px; }
.btn.pack .name { font-weight: 700; }

/* intro trailer */
.overlay.intro { background: #000; padding: 0; z-index: 40; }
#intro-video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.intro-ui { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.intro-ui .btn { pointer-events: auto; }
#intro-skip { position: absolute; top: calc(14px + var(--sat)); right: 14px; }

/* desktop: screen left, story right — no dead space */
@media (min-width: 900px) {
  body { font-size: 18px; }
  main { max-width: 1600px; grid-template-columns: minmax(0, 8fr) minmax(380px, 5fr); gap: 0 32px; padding: 18px 24px calc(18px + var(--sab)); align-items: stretch; }
  #screen { border-radius: 16px; aspect-ratio: auto; max-height: none; height: calc(100vh - 100px); min-height: 480px; position: sticky; top: 74px; }
  #panel { display: flex; flex-direction: column; justify-content: center; min-height: calc(100vh - 100px); padding: 12px 0; }
  #story { padding: 4px 0 8px; }
  #story h1 { font-size: 36px; }
  #actions { padding: 8px 0 0; }
}
@media (min-width: 1240px) { #story h1 { font-size: 40px; } #story p { font-size: 19px; } }

/* location transition clip */
#screen.transition::after { background: linear-gradient(180deg, rgba(0, 0, 0, .35), transparent 30%, transparent 70%, rgba(0, 0, 0, .6)); }
#screen.transition #video { cursor: pointer; animation: fadein .6s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
