:root {
  color-scheme: dark;
  --ink: #202338;
  --cream: #fff3d7;
  --muted: #c8c7d4;
  --gold: #f4bd68;
  --teal: #2e7775;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: "Trebuchet MS", "Avenir Next", Avenir, system-ui, sans-serif;
  color: var(--cream);
  background:
    radial-gradient(ellipse at 52% 32%, #44476a 0%, #2b304e 42%, #191d32 100%);
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene:active { cursor: grabbing; }
#scene.is-over-grill { cursor: pointer; }

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(9, 12, 27, .25), transparent 24%, transparent 70%, rgba(9, 12, 27, .48));
  box-shadow: inset 0 0 140px rgba(5, 8, 22, .25);
}

.masthead {
  position: fixed;
  z-index: 3;
  top: clamp(22px, 4vw, 48px);
  left: clamp(22px, 4.5vw, 70px);
  display: flex;
  gap: 15px;
  align-items: flex-start;
  pointer-events: none;
  filter: drop-shadow(0 2px 12px rgba(9, 12, 27, .28));
}

.brand-mark {
  width: 31px;
  margin-top: 3px;
  color: #e89a50;
}
.brand-mark svg { width: 100%; display: block; }

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .22em;
  line-height: 1.4;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(32px, 3.4vw, 51px);
  font-weight: 500;
  letter-spacing: -.045em;
  line-height: .98;
}
h1 span { color: #f0c78e; font-style: italic; }
.tagline { margin: 11px 0 0; color: #d5d2dc; font-size: 12px; letter-spacing: .035em; }

.top-actions {
  position: fixed;
  z-index: 5;
  top: clamp(22px, 4vw, 44px);
  right: clamp(20px, 3.5vw, 54px);
  display: flex;
  align-items: center;
  gap: 18px;
}
.open-sign {
  display: flex;
  gap: 8px;
  align-items: center;
  color: #d9d6df;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .18em;
}
.open-sign i {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #e9b568;
  box-shadow: 0 0 12px #f1b75d;
  animation: live-pulse 3s ease-in-out infinite;
}
.glass-button {
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(24, 28, 47, .35);
  backdrop-filter: blur(10px);
  color: #e7e1dc;
  border-radius: 30px;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 9px 14px;
  font-size: 11px;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.glass-button:hover { background: rgba(55, 59, 84, .65); border-color: rgba(255,255,255,.3); }
.glass-button svg { width: 15px; height: 15px; }

.speech-bubble {
  position: fixed;
  z-index: 4;
  left: 50%;
  top: 35%;
  width: max-content;
  max-width: min(280px, calc(100vw - 40px));
  padding: 13px 17px 14px;
  border-radius: 15px 15px 15px 4px;
  background: #fff5df;
  color: #343141;
  box-shadow: 0 8px 30px rgba(11, 13, 27, .25);
  pointer-events: none;
  transform: translate(-50%, -100%);
  transform-origin: 20% 100%;
  transition: opacity .2s;
}
.speech-bubble::after {
  content: "";
  position: absolute;
  left: 23px;
  bottom: -9px;
  width: 17px;
  height: 17px;
  background: #fff5df;
  clip-path: polygon(0 0, 100% 0, 0 100%);
}
.speech-bubble span {
  display: block;
  margin-bottom: 5px;
  color: #9c6643;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .17em;
}
.speech-bubble p { margin: 0; font-family: Georgia, serif; font-size: 15px; line-height: 1.35; }
.speech-bubble.pop { animation: bubble-pop .35s cubic-bezier(.2,.9,.25,1.25); }

.story-card {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: clamp(25px, 4vh, 43px);
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 48px));
  min-height: 116px;
  display: grid;
  grid-template-columns: 54px 1fr auto;
  align-items: center;
  gap: 21px;
  padding: 20px 21px;
  border: 1px solid rgba(255, 243, 215, .19);
  border-radius: 17px;
  background: linear-gradient(115deg, rgba(30, 32, 49, .93), rgba(35, 38, 57, .89));
  box-shadow: 0 18px 50px rgba(7, 9, 22, .28), inset 0 1px rgba(255,255,255,.035);
  backdrop-filter: blur(16px);
}
.chapter-number {
  align-self: stretch;
  display: grid;
  place-items: center;
  border-right: 1px solid rgba(255,255,255,.11);
  color: #e2b77b;
  font-family: Georgia, serif;
  font-size: 28px;
  font-style: italic;
}
.story-copy .eyebrow { margin-bottom: 5px; font-size: 8px; }
#story-text { margin: 0; max-width: 430px; color: #eee7dc; font-family: Georgia, serif; font-size: 14px; line-height: 1.48; }
.story-dots { display: flex; gap: 6px; margin-top: 12px; }
.story-dot {
  width: 14px;
  height: 3px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: rgba(255,255,255,.17);
  cursor: pointer;
  transition: width .25s, background .25s;
}
.story-dot.active { width: 25px; background: var(--gold); }
.story-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 156px;
  padding: 13px 16px;
  border: 0;
  border-radius: 10px;
  background: #e7ad61;
  color: #272738;
  box-shadow: 0 4px 18px rgba(231, 173, 97, .13);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .2s, background .2s;
}
.story-button:hover { transform: translateY(-2px); background: #f5c47e; }
.story-button:active { transform: translateY(0); }
.story-button svg { width: 17px; height: 17px; }
.story-card.turn .story-copy { animation: text-turn .4s ease; }

.scene-hint {
  position: fixed;
  z-index: 3;
  left: clamp(20px, 3.5vw, 52px);
  bottom: 35px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: rgba(235, 231, 234, .6);
  font-size: 9px;
  letter-spacing: .03em;
  pointer-events: none;
}
.scene-hint svg { width: 16px; height: 16px; }
.scene-hint b { margin: 0 5px; color: rgba(255,255,255,.25); }
.keyboard-hint {
  position: fixed;
  z-index: 3;
  right: clamp(20px, 3.5vw, 52px);
  bottom: 36px;
  color: rgba(235, 231, 234, .5);
  font-size: 9px;
  pointer-events: none;
}
kbd { padding: 3px 5px; border: 1px solid rgba(255,255,255,.18); border-radius: 4px; font-family: inherit; font-size: 8px; }

.loading-screen, .error-screen {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  background: #222840;
  color: #f6d8a9;
  transition: opacity .65s ease, visibility .65s;
}
.loading-screen.done { opacity: 0; visibility: hidden; }
.loading-screen p { color: #c7c4d1; font-family: Georgia, serif; font-size: 14px; }
.loading-flame { font-size: 35px; animation: live-pulse 1.2s ease-in-out infinite; }
.error-screen { padding: 30px; text-align: center; }
.error-screen[hidden] { display: none; }
.error-screen h2 { font-family: Georgia, serif; font-weight: 400; }
.error-screen p { max-width: 420px; color: #c7c4d1; line-height: 1.6; }

@keyframes live-pulse { 50% { opacity: .45; transform: scale(.92); } }
@keyframes bubble-pop { from { opacity: 0; transform: translate(-50%, -90%) scale(.85); } to { opacity: 1; transform: translate(-50%, -100%) scale(1); } }
@keyframes text-turn { from { opacity: .2; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1100px) {
  .scene-hint, .keyboard-hint { display: none; }
  .story-card { bottom: 22px; }
}

@media (max-width: 650px) {
  .masthead { top: 20px; left: 18px; gap: 10px; }
  .brand-mark { width: 23px; }
  .masthead .eyebrow { font-size: 8px; margin-bottom: 6px; }
  h1 { font-size: 31px; }
  .tagline { font-size: 10px; margin-top: 7px; }
  .top-actions { top: 20px; right: 16px; }
  .open-sign, .glass-button span { display: none; }
  .glass-button { padding: 9px; }
  .story-card {
    width: calc(100vw - 24px);
    min-height: 0;
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 15px;
    bottom: 12px;
    border-radius: 14px;
  }
  .chapter-number { display: none; }
  #story-text { font-size: 12px; line-height: 1.4; }
  .story-copy .eyebrow { font-size: 7px; }
  .story-button { min-width: 43px; width: 43px; height: 43px; padding: 0; border-radius: 50%; align-self: center; }
  .story-button span { display: none; }
  .story-dots { margin-top: 9px; }
  .speech-bubble { padding: 10px 13px; max-width: 220px; }
  .speech-bubble p { font-size: 13px; }
}

@media (max-height: 600px) and (min-width: 651px) {
  .masthead { top: 20px; }
  .tagline { display: none; }
  .story-card { bottom: 15px; min-height: 96px; padding-top: 14px; padding-bottom: 14px; }
  .scene-hint, .keyboard-hint { bottom: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
