/* ============================================================
   Jabberwock — a game in verse
   Palette: illuminated-bestiary. Ink, parchment, ember gold,
   verdigris, vermilion, lapis. One language for world, UI,
   creatures and light.
   ============================================================ */

@font-face {
  font-family: 'Uncial';
  src: url('../fonts/uncial-antiqua-latin.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Garamond';
  src: url('../fonts/eb-garamond-latin.woff2') format('woff2');
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Garamond';
  src: url('../fonts/eb-garamond-italic-latin.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

:root {
  /* world palette — identical in both colour schemes, because the
     world is a place and not a skin */
  --ink:        #0d0b10;
  --ink-soft:   #171426;
  --lapis:      #1d2550;
  --parch:      #e8dfc6;
  --parch-dim:  #b9ae93;
  --ember:      #e8a33d;
  --ember-hi:   #ffd694;
  --verdigris:  #3f8f76;
  --vermilion:  #cf4b2c;

  /* HUD sits over a dark world in both schemes, so it stays light */
  --hud-fg:      #ece3cb;
  --hud-dim:     #a99f88;
  --hud-line:    rgba(236,227,203,.20);
  --hud-bg:      rgba(13,11,16,.55);

  /* reading panels follow the operating system */
  --panel-bg:    rgba(13,11,16,.90);
  --panel-fg:    #ece3cb;
  --panel-dim:   #a99f88;
  --panel-line:  rgba(236,227,203,.22);
  --panel-btn:   #e8a33d;
  --panel-btn-fg:#1a1408;
  --scrim:       rgba(6,5,9,.72);

  --ui: 'Garamond', 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --display: 'Uncial', 'Garamond', Georgia, serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --panel-bg:    rgba(240,233,214,.94);
    --panel-fg:    #211c15;
    --panel-dim:   #5d5344;
    --panel-line:  rgba(33,28,21,.22);
    --panel-btn:   #8a4a12;
    --panel-btn-fg:#f6efdd;
    --scrim:       rgba(232,223,198,.55);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #07060a;
  color: var(--hud-fg);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { touch-action: none; }

#app { position: fixed; inset: 0; }

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}
#scene:focus-visible { outline: 2px solid var(--ember); outline-offset: -3px; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* ===================== HUD ===================== */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-size: 15px;
  line-height: 1.35;
  user-select: none;
}

.hud-corner { position: absolute; display: flex; flex-direction: column; gap: .35em; }
.hud-top-left    { top: max(16px, env(safe-area-inset-top)); left: max(18px, env(safe-area-inset-left)); }
.hud-top-right   { top: max(16px, env(safe-area-inset-top)); right: max(18px, env(safe-area-inset-right)); align-items: flex-end; }
.hud-bottom-right{ bottom: max(16px, env(safe-area-inset-bottom)); right: max(18px, env(safe-area-inset-right)); align-items: flex-end; flex-direction: row-reverse; flex-wrap: wrap; }

.zone-name {
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: .10em;
  text-transform: lowercase;
  color: var(--ember-hi);
  text-shadow: 0 1px 0 rgba(0,0,0,.9), 0 0 18px rgba(0,0,0,.85);
  transition: opacity .5s ease;
}
.zone-name::before {
  content: '';
  display: inline-block;
  width: 22px; height: 1px;
  margin: 0 .5em .28em 0;
  background: var(--ember);
  vertical-align: middle;
  opacity: .8;
}

.hearts { display: flex; gap: 5px; }
.heart {
  width: 13px; height: 13px;
  background: var(--ember);
  box-shadow: 0 0 0 1px rgba(0,0,0,.75), 0 0 12px rgba(232,163,61,.6);
  clip-path: polygon(50% 100%, 0 45%, 12% 12%, 50% 26%, 88% 12%, 100% 45%);
  transition: background .25s ease, box-shadow .25s ease, transform .25s ease;
}
.heart.spent {
  background: rgba(236,227,203,.16);
  box-shadow: 0 0 0 1px rgba(0,0,0,.6);
  transform: scale(.82);
}

.quest {
  font-style: italic;
  font-size: 14px;
  color: var(--hud-dim);
  text-shadow: 0 1px 0 rgba(0,0,0,.9);
  max-width: 30ch;
}

.fps {
  font-family: var(--display);
  font-size: 17px;
  letter-spacing: .08em;
  color: var(--hud-fg);
  text-shadow: 0 1px 0 rgba(0,0,0,.9);
  font-variant-numeric: tabular-nums;
}
.fps.warn { color: var(--ember-hi); }
.fps.bad  { color: var(--vermilion); }
.fpsbar {
  width: 74px; height: 2px;
  background: rgba(236,227,203,.18);
  overflow: hidden;
}
.fpsbar > i { display: block; height: 100%; width: 100%; background: var(--ember); transition: width .4s linear; }

.boss {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  opacity: 0;
  transition: opacity .6s ease;
}
.boss.show { opacity: 1; }
.boss-name {
  font-family: var(--display);
  font-size: 20px;
  letter-spacing: .22em;
  color: var(--vermilion);
  text-shadow: 0 0 22px rgba(207,75,44,.7), 0 1px 0 rgba(0,0,0,.9);
}
.boss-pips { display: flex; gap: 8px; justify-content: center; margin: 4px 0 2px; }
.pip {
  width: 26px; height: 5px;
  background: var(--vermilion);
  box-shadow: 0 0 12px rgba(207,75,44,.85);
  transition: opacity .3s ease, transform .3s ease;
}
.pip.spent { background: rgba(236,227,203,.16); box-shadow: none; transform: scaleY(.6); }
.boss-hint {
  font-size: 12.5px;
  font-style: italic;
  letter-spacing: .06em;
  color: var(--hud-dim);
  text-shadow: 0 1px 0 rgba(0,0,0,.9);
}

.toast {
  position: absolute;
  top: 27%;
  left: 50%;
  transform: translate(-50%, 0);
  font-family: var(--display);
  font-size: clamp(20px, 3.4vw, 34px);
  letter-spacing: .14em;
  text-align: center;
  color: var(--ember-hi);
  text-shadow: 0 0 28px rgba(0,0,0,.95), 0 2px 0 rgba(0,0,0,.85);
  opacity: 0;
  transition: opacity .35s ease, transform .5s cubic-bezier(.2,.9,.25,1);
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, -10px); }
.toast.small { font-family: var(--ui); font-style: italic; font-size: clamp(15px, 1.8vw, 19px); letter-spacing: .02em; color: var(--hud-fg); }

.prompt {
  position: absolute;
  bottom: 12%;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(14px, 1.6vw, 17px);
  font-style: italic;
  letter-spacing: .03em;
  color: var(--hud-fg);
  background: var(--hud-bg);
  border: 1px solid var(--hud-line);
  padding: .45em .95em;
  text-align: center;
  max-width: 76vw;
  opacity: 0;
  transition: opacity .25s ease;
}
.prompt.show { opacity: 1; }
.prompt kbd {
  font-family: var(--ui);
  font-style: normal;
  font-size: .86em;
  letter-spacing: .06em;
  border: 1px solid var(--hud-line);
  border-bottom-width: 2px;
  padding: 0 .38em;
  color: var(--ember-hi);
  background: rgba(0,0,0,.35);
}

.chip {
  pointer-events: auto;
  font-family: var(--ui);
  font-size: 12.5px;
  letter-spacing: .04em;
  color: var(--hud-dim);
  background: var(--hud-bg);
  border: 1px solid var(--hud-line);
  padding: .34em .7em;
  cursor: pointer;
  transition: color .2s, border-color .2s, background .2s;
}
.chip:hover, .chip:focus-visible { color: var(--ember-hi); border-color: var(--ember); outline: none; }
.chip[aria-pressed="true"] { color: var(--ink); background: var(--ember); border-color: var(--ember); }
.chip.on { color: var(--ember-hi); border-color: var(--ember); }

.crosshair {
  position: absolute;
  top: 50%; left: 50%;
  width: 6px; height: 6px;
  margin: -3px 0 0 -3px;
  border: 1px solid rgba(236,227,203,.5);
  border-radius: 50%;
  opacity: 0;
  transition: opacity .3s ease;
}
.crosshair.show { opacity: .75; }

/* screen effects */
.flash {
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 45%, rgba(255,236,190,.92), rgba(255,190,90,.28) 42%, rgba(255,160,60,0) 72%);
  opacity: 0;
  mix-blend-mode: screen;
}
.vignette {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0) 42%, rgba(6,4,10,.55) 82%, rgba(4,3,7,.86) 100%);
  opacity: .85;
  transition: opacity 1.2s ease, background 1.2s ease;
}
.slash {
  position: absolute;
  top: 50%; left: 50%;
  width: 78vmax; height: 3px;
  margin: -1.5px 0 0 -39vmax;
  background: linear-gradient(90deg, rgba(255,255,255,0), rgba(255,244,214,.95) 18%, #fff 50%, rgba(255,244,214,.95) 82%, rgba(255,255,255,0));
  filter: blur(.4px) drop-shadow(0 0 14px rgba(255,214,148,.95));
  opacity: 0;
  transform-origin: 50% 50%;
}
.snack {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5em;
  font-family: var(--display);
  font-size: clamp(30px, 8vw, 96px);
  letter-spacing: .1em;
  color: #fff6e2;
  text-shadow: 0 0 34px rgba(255,190,90,.95), 0 3px 0 rgba(80,20,10,.65);
  opacity: 0;
}
.snack b { color: var(--ember); font-weight: 400; }

/* ===================== Overlay panels ===================== */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 4vh 4vw;
  z-index: 20;
}
.overlay[hidden] { display: none; }
.overlay-scrim { position: absolute; inset: 0; background: var(--scrim); backdrop-filter: blur(3px); }

.panel {
  position: relative;
  width: min(760px, 94vw);
  max-height: 90vh;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--panel-bg);
  color: var(--panel-fg);
  border: 1px solid var(--panel-line);
  box-shadow: 0 30px 80px rgba(0,0,0,.6), inset 0 0 90px rgba(232,163,61,.05);
  padding: clamp(22px, 3.4vw, 44px) clamp(20px, 3.6vw, 52px);
  text-align: center;
}
.panel:focus { outline: none; }
.panel:focus-visible { outline: 2px solid var(--ember); outline-offset: 3px; }

.panel-rule {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--panel-line) 18%, var(--ember) 50%, var(--panel-line) 82%, transparent);
  opacity: .7;
}

.eyebrow {
  margin: .9em 0 .2em;
  font-size: 13px;
  letter-spacing: .34em;
  text-transform: uppercase;
  color: var(--panel-dim);
}

.panel-title {
  margin: .05em 0 .3em;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(28px, 5vw, 52px);
  line-height: 1.06;
  letter-spacing: .03em;
  color: var(--panel-fg);
}

.poem {
  margin: 0 auto;
  max-width: 52ch;
  font-size: clamp(15px, 1.75vw, 19.5px);
  line-height: 1.62;
  color: var(--panel-fg);
  text-align: left;
  white-space: pre-wrap;
}
.poem p { margin: 0 0 .85em; }
.poem p:last-child { margin-bottom: 0; }
.poem .indent { padding-left: 2.4em; }
.poem em { font-style: italic; color: var(--ember); }

.note {
  margin: 1.1em auto .2em;
  max-width: 56ch;
  font-size: clamp(13.5px, 1.4vw, 16px);
  font-style: italic;
  line-height: 1.55;
  color: var(--panel-dim);
}

.panel-actions {
  margin-top: 1.25em;
  display: flex;
  flex-wrap: wrap;
  gap: .6em;
  justify-content: center;
  align-items: center;
}
.panel-actions button {
  font-family: var(--ui);
  font-size: clamp(14px, 1.5vw, 16.5px);
  letter-spacing: .05em;
  color: var(--panel-btn-fg);
  background: var(--panel-btn);
  border: 1px solid var(--panel-btn);
  padding: .55em 1.3em;
  cursor: pointer;
  transition: transform .12s ease, filter .2s ease;
}
.panel-actions button:hover { filter: brightness(1.12); }
.panel-actions button:active { transform: translateY(1px); }
.panel-actions button:focus-visible { outline: 2px solid var(--panel-fg); outline-offset: 3px; }
.panel-actions button.ghost {
  background: transparent;
  color: var(--panel-fg);
  border-color: var(--panel-line);
}
.panel-actions button.ghost:hover { border-color: var(--panel-btn); color: var(--panel-btn); }

.keylist { text-align: left; max-width: 44ch; margin: 0 auto; font-size: clamp(14px,1.5vw,16.5px); line-height: 1.9; }
.keylist div { display: flex; gap: .8em; border-bottom: 1px dotted var(--panel-line); padding: .1em 0; }
.keylist span:first-child { flex: 0 0 12ch; color: var(--panel-dim); }
.keylist b { font-weight: 400; color: var(--panel-fg); }

.panel h2.group {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(17px, 2vw, 22px);
  letter-spacing: .1em;
  color: var(--panel-fg);
  margin: 1.4em 0 .5em;
}

/* ===================== small screens ===================== */

@media (max-width: 620px) {
  .hud-top-left { max-width: 54vw; }
  .zone-name { font-size: 18px; }
  .quest { font-size: 12.5px; }
  .hud-bottom-right { gap: .3em; }
  .chip { font-size: 11px; padding: .3em .5em; }
  .poem { font-size: 15.5px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .001ms !important; animation-duration: .001ms !important; }
  .toast { transform: translate(-50%, 0); }
  .toast.show { transform: translate(-50%, 0); }
}
