:root {
  --gold: #e8c27a;
  --gold-deep: #b8863b;
  --ink: #0b0a10;
  --teal: #4fe3d0;
  --rose: #ff5fa8;
  --paper: #f3e6cc;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: #05060a; color: var(--paper); font-family: 'Cormorant Garamond', Georgia, serif; }
/* The game fills the viewport above a reserved footer row. Short screens scroll
   the document instead of squeezing the stage below a playable height. */
body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
#stage { position: relative; flex: 1 0 auto; min-height: 360px; overflow: hidden; isolation: isolate; }
canvas#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
canvas#c:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.hidden { display: none !important; }

.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 10; }

/* Loader */
#loader { background: radial-gradient(ellipse at center, #1a1424 0%, #07060b 70%); transition: opacity 1.2s ease; }
#loader.fadeout { opacity: 0; pointer-events: none; }
.loader-inner { text-align: center; }
.crest { font-size: 38px; color: var(--gold); text-shadow: 0 0 24px #ffb35a; animation: pulse 2.4s ease-in-out infinite; }
.loader-title { font-family: 'Cinzel', serif; letter-spacing: 0.5em; font-size: 22px; margin: 14px 0 24px; color: var(--gold); padding-left: 0.5em; }
.bar { width: min(340px, 70vw); height: 2px; background: #2a2433; margin: 0 auto; overflow: hidden; border-radius: 2px; }
#bar-fill { width: 0%; height: 100%; background: linear-gradient(90deg, var(--gold-deep), #ffd89a); box-shadow: 0 0 12px #ffc46b; transition: width 0.3s ease; }
#loader-text { margin-top: 14px; font-style: italic; opacity: 0.7; font-size: 16px; }
@keyframes pulse { 0%,100% { opacity: .6; transform: scale(1);} 50% { opacity: 1; transform: scale(1.12);} }

/* Title */
#title { overflow-y: auto; background: linear-gradient(180deg, rgba(5,5,12,0.15) 0%, rgba(5,5,12,0.0) 35%, rgba(5,5,12,0.55) 75%, rgba(5,5,12,0.9) 100%); align-items: flex-end; padding-bottom: 7vh; transition: opacity 1s ease; }
#title.fadeout { opacity: 0; pointer-events: none; }
.title-inner { text-align: center; max-width: 1100px; width: 100%; padding: 0 16px; }
.ornament { font-size: 30px; color: var(--gold); text-shadow: 0 0 18px #ffae4a; }
/* inline-block keeps the gradient-clipped box as wide as the lettering */
h1 { display: inline-block; font-family: 'Cinzel', serif; font-weight: 600; font-size: clamp(28px, 7vw, 104px); letter-spacing: 0.16em; margin: 6px 0 0; padding-left: 0.16em; white-space: nowrap;
  background: linear-gradient(180deg, #fff3d6 0%, #f0c67c 45%, #a8702c 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 22px rgba(255, 170, 80, 0.35)) drop-shadow(0 4px 2px rgba(0,0,0,0.6)); }
.subtitle { font-family: 'Cinzel', serif; letter-spacing: 0.45em; font-size: clamp(11px, 1.4vw, 15px); color: var(--teal); text-shadow: 0 0 12px rgba(79,227,208,0.7); margin-top: 4px; padding-left: 0.45em; }
.story { font-size: clamp(16px, 1.8vw, 21px); line-height: 1.5; opacity: 0.9; margin: 22px auto 26px; font-style: italic; text-shadow: 0 2px 8px #000; }
button { font-family: 'Cinzel', serif; cursor: pointer; }
#start-btn, #continue-btn { font-size: 18px; letter-spacing: 0.35em; padding: 14px 44px 14px 50px; color: #1a0f05; background: linear-gradient(180deg, #ffe2a6, #d49a4a); border: 1px solid #ffe7b8; border-radius: 2px;
  box-shadow: 0 0 30px rgba(255, 170, 70, 0.45), inset 0 1px 0 #fff6e0; transition: transform .2s ease, box-shadow .2s ease; }
#start-btn:hover, #continue-btn:hover { transform: translateY(-2px); box-shadow: 0 0 46px rgba(255, 180, 80, 0.7), inset 0 1px 0 #fff6e0; }
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 22px; margin-top: 26px; font-size: 15px; opacity: 0.75; }
.controls b { font-family: 'Cinzel', serif; color: var(--gold); font-weight: 400; letter-spacing: 0.08em; }
.quality { margin-top: 16px; font-size: 14px; opacity: 0.7; }
.quality .q { background: transparent; color: var(--paper); border: 1px solid rgba(232,194,122,0.4); padding: 3px 12px; margin: 0 3px; font-size: 12px; letter-spacing: 0.1em; }
.quality .q.active { background: rgba(232,194,122,0.25); border-color: var(--gold); color: #fff; }

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
#embers { position: absolute; top: 26px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; align-items: center; }
.ember-slot { width: 22px; height: 30px; clip-path: polygon(50% 0, 100% 38%, 78% 100%, 22% 100%, 0 38%); background: rgba(40,30,20,0.6); border: none; position: relative;
  box-shadow: inset 0 0 0 1px rgba(232,194,122,0.5); transition: all .6s ease; }
.ember-slot::after { content: ''; position: absolute; inset: 2px; clip-path: inherit; background: rgba(20,14,10,0.8); }
.ember-slot.found::after { background: radial-gradient(circle at 50% 60%, #fff4c2 0%, #ffb23f 40%, #d4540f 100%); }
.ember-slot.found { filter: drop-shadow(0 0 8px #ff9a2f); }
.ember-slot.placed::after { background: radial-gradient(circle at 50% 60%, #ffffff 0%, #ffe07a 50%, #ffa21f 100%); }
.ember-slot.placed { filter: drop-shadow(0 0 14px #ffd25f); }
#ember-label { position: absolute; top: 38px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-family: 'Cinzel', serif; font-size: 11px; letter-spacing: 0.4em; color: var(--gold); opacity: 0.8; }
#objective { position: absolute; top: 86px; left: 50%; transform: translateX(-50%); font-style: italic; font-size: 19px; text-shadow: 0 2px 10px #000, 0 0 2px #000; opacity: 0.92; white-space: nowrap; }
#prompt { position: absolute; bottom: 18%; left: 50%; transform: translateX(-50%); font-size: 18px; padding: 8px 20px; background: rgba(8,8,14,0.55); border: 1px solid rgba(232,194,122,0.35); border-radius: 2px; backdrop-filter: blur(4px); }
#prompt b { font-family: 'Cinzel', serif; color: var(--gold); padding: 0 6px; border: 1px solid rgba(232,194,122,0.6); margin-right: 8px; }
#toast { position: absolute; top: 32%; left: 50%; transform: translateX(-50%); font-family: 'Cinzel', serif; letter-spacing: 0.3em; font-size: clamp(18px, 2.5vw, 30px); color: #ffe9b8; text-shadow: 0 0 20px #ff9a2f, 0 2px 6px #000; transition: opacity .8s ease; white-space: nowrap; }
#fps { position: absolute; bottom: 8px; right: 10px; font: 11px monospace; opacity: 0.35; }

/* Finale */
#finale { background: radial-gradient(ellipse at center, rgba(255,210,140,0.12) 0%, rgba(0,0,0,0) 60%); transition: opacity 1.5s ease; }
.finale-inner { text-align: center; padding: 0 16px; }
h2 { font-family: 'Cinzel', serif; font-weight: 400; font-size: clamp(28px, 5vw, 60px); letter-spacing: 0.12em; color: #fff4dc; text-shadow: 0 0 30px rgba(255,190,90,0.8), 0 3px 8px rgba(60,30,0,0.8); margin: 8px 0; }
.finale-inner p { font-size: clamp(16px, 2vw, 23px); font-style: italic; text-shadow: 0 2px 8px rgba(40,20,0,0.9); margin-bottom: 28px; }

#fade { position: absolute; inset: 0; background: #fff6e2; opacity: 0; pointer-events: none; z-index: 20; transition: opacity 2s ease; }

/* Touch controls */
#touch-ui { display: none; position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom)); gap: 14px; pointer-events: auto; }
body.touch #touch-ui { display: flex; }
#touch-ui button { width: 64px; height: 64px; border-radius: 50%; border: 1px solid rgba(232,194,122,0.55); background: rgba(12,10,18,0.45); color: var(--gold); font-size: 26px; backdrop-filter: blur(4px); }
#touch-ui button:active { background: rgba(232,194,122,0.3); }
body.touch .controls { display: none; }
@media (max-width: 640px) { .story { font-size: 15px; margin: 14px auto 18px; } #objective { font-size: 15px; top: 76px; } #title { padding-bottom: 4vh; } }

/* Site shell: gallery navigation, signup and the shared footer */
.site-header { position: absolute; top: 0; left: 0; right: 0; z-index: 30; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left)); pointer-events: none; }
.site-header a { pointer-events: auto; font-family: 'Cinzel', serif; font-size: 12px; letter-spacing: 0.14em; color: var(--paper); text-decoration: none; padding: 7px 12px; min-height: 32px; display: inline-flex; align-items: center; gap: 6px; background: rgba(8, 8, 14, 0.55); border: 1px solid rgba(232, 194, 122, 0.35); border-radius: 2px; backdrop-filter: blur(4px); white-space: nowrap; }
.site-header a:hover, .site-header a:focus-visible { border-color: var(--gold); color: #fff; }
.site-header a:focus-visible, .exploration-bar a:focus-visible, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.site-header .create-yours { color: #1a0f05; background: linear-gradient(180deg, #ffe2a6, #d49a4a); border-color: #ffe7b8; }
.site-header .create-yours:hover, .site-header .create-yours:focus-visible { color: #1a0f05; }

.exploration-bar { --exploration-footer-bg: #0b0a10; --exploration-footer-ink: #d8cbb0; --exploration-footer-border: rgba(232, 194, 122, 0.22); flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 22px; padding: 6px max(24px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left)); background: #0b0a10; color: #d8cbb0; border-top: 1px solid rgba(232, 194, 122, 0.22); font: 12px/1.4 'Cormorant Garamond', Georgia, serif; }
.exploration-credit { display: flex; align-items: baseline; gap: 12px; }
.exploration-credit strong { font-family: 'Cinzel', serif; font-weight: 600; font-size: 15px; letter-spacing: 0.2em; color: var(--gold); }
.exploration-credit span { font-size: 14px; font-style: italic; }
.exploration-bar a { color: #f3e6cc; }
.exploration-bar .making-of { font-family: 'Cinzel', serif; font-size: 12px; letter-spacing: 0.12em; text-decoration: none; border-bottom: 1px solid rgba(232, 194, 122, 0.5); padding: 8px 0 2px; }
.exploration-bar .making-of:hover { color: #fff; border-color: var(--gold); }
[data-exploration-controls].exploration-bar #scenario-exploration-analytics .scenario-exploration-controls { background: transparent; color: #d8cbb0; border: 0; padding: 0; gap: 18px; }

/* Latched renderer failure / unsupported browser */
#halt { z-index: 25; background: radial-gradient(ellipse at center, #1a1424 0%, #07060b 75%); }
.halt-inner { text-align: center; max-width: 520px; padding: 0 20px; }
.halt-inner p { font-size: 19px; font-style: italic; margin: 0 0 24px; }
#halt-btn { font-size: 15px; letter-spacing: 0.3em; padding: 12px 34px 12px 40px; color: #1a0f05; background: linear-gradient(180deg, #ffe2a6, #d49a4a); border: 1px solid #ffe7b8; border-radius: 2px; }
.noscript { position: absolute; inset: auto 0 40% 0; text-align: center; font-size: 20px; font-style: italic; padding: 0 20px; }

@media (max-width: 640px) {
  .site-header a { font-size: 11px; letter-spacing: 0.08em; padding: 6px 10px; }
  #embers { top: 60px; }
  #objective { top: 120px; white-space: normal; width: calc(100% - 32px); text-align: center; }
  #toast { white-space: normal; width: calc(100% - 32px); text-align: center; }
  .exploration-bar { padding-left: 16px; padding-right: 16px; gap: 2px 16px; }
  .exploration-credit strong { font-size: 13px; }
  .exploration-bar #scenario-exploration-analytics { width: 100%; }
}
@media (max-height: 520px) {
  #toast { top: 52%; }
  #title { align-items: flex-start; padding: 56px 0 16px; }
  .story { margin: 10px auto 14px; }
  .controls { margin-top: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .crest { animation: none; }
  #start-btn, #continue-btn { transition: none; }
}
