/* ============================================================
   THE CROOKED ACRE — UI style contract
   Derived from the game's own art direction (grimy illustrated
   folk horror): palette pulled from the scene materials — mud
   umber #2b2015, straw ochre #b8912f, bile green #5c6b3a,
   dried blood #7a2418, bone #d9cdb0. Shape language from the
   maze walls: crooked, hand-cut, nothing is square — every
   panel is clip-path'd into an uneven torn-paper quadrilateral.
   Material: stained parchment (layered radial blooms + a
   water-damage vignette), never a translucent black card.
   Typeface class: heavy old-style serif (broadsheet woodcut),
   letterspaced small-caps for labels. Motion: no easing that
   feels digital — a 90ms hard step, like a page turning.
   ============================================================ */

:root {
  --mud:        #241a11;
  --mud-deep:   #150e08;
  --straw:      #c39a34;
  --straw-pale: #e0c479;
  --bile:       #5c6b3a;
  --blood:      #8a2a18;
  --blood-lit:  #c4482b;
  --bone:       #ddd0b2;
  --parchment:  #c9b58c;
  --ink:        #1a1109;

  --font-display: "Palatino Linotype", "Book Antiqua", Palatino, "Georgia", serif;
  --font-body: "Georgia", "Times New Roman", serif;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0b0805;
  color: var(--bone);
  font-family: var(--font-body);
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; }

/* ---------- stained parchment panel material ---------- */
.panel, .sheet-inner {
  background:
    radial-gradient(ellipse 70% 55% at 22% 18%, rgba(122,84,40,.42), transparent 65%),
    radial-gradient(ellipse 55% 70% at 82% 78%, rgba(60,44,22,.55), transparent 62%),
    radial-gradient(ellipse 120% 90% at 50% 50%, rgba(201,181,140,.10), transparent 72%),
    linear-gradient(168deg, #2e2214 0%, #201709 55%, #17100a 100%);
  border: 2px solid rgba(195,154,52,.34);
  box-shadow:
    inset 0 0 44px rgba(0,0,0,.72),
    inset 0 1px 0 rgba(221,208,178,.10),
    0 6px 22px rgba(0,0,0,.6);
}

/* crooked, hand-cut corners — nothing in this game is square */
.panel-lives  { clip-path: polygon(0 5%, 97% 0, 100% 92%, 3% 100%); }
.panel-region { clip-path: polygon(2% 0, 100% 6%, 97% 100%, 0 93%); }

/* ================= HUD ================= */
.hud {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 10;
  padding:
    calc(var(--safe-t) + 8px)
    calc(var(--safe-r) + 10px)
    calc(var(--safe-b) + 8px)
    calc(var(--safe-l) + 10px);
  display: flex; flex-direction: column;
}

.hud-top {
  display: flex; gap: 10px;
  align-items: flex-start; justify-content: space-between;
}

.panel { padding: 7px 13px 8px; min-width: 0; }

.panel-label {
  font-family: var(--font-display);
  font-size: 12px; letter-spacing: .18em;
  color: var(--straw);
  text-transform: uppercase;
  opacity: .82;
  margin-bottom: 3px;
  text-shadow: 0 1px 0 #000;
}

.panel-region { text-align: right; max-width: 56%; }

.region-name {
  font-family: var(--font-display);
  font-size: clamp(14px, 2.4vw, 21px);
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--bone);
  text-shadow: 0 2px 0 #000, 0 0 14px rgba(138,42,24,.35);
  line-height: 1.05;
}

.objective {
  font-size: clamp(12px, 1.5vw, 14px);
  color: #b3a184;
  font-style: italic;
  margin-top: 2px;
  line-height: 1.2;
}

/* straw effigy life markers — not pips, little scarecrows */
.effigies { display: flex; gap: 6px; align-items: flex-end; height: 22px; }

.effigy {
  width: 13px; height: 20px;
  position: relative;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.9));
}
.effigy::before {            /* crossbar + post */
  content: ""; position: absolute;
  left: 0; right: 0; top: 6px; height: 2.5px;
  background: var(--straw);
}
.effigy::after {             /* head + body */
  content: ""; position: absolute;
  left: 50%; top: 0; width: 3px; height: 100%;
  margin-left: -1.5px;
  background: var(--straw);
  border-radius: 2px 2px 0 0;
  box-shadow: 0 -3px 0 -0.5px var(--straw-pale);
}
.effigy.spent { opacity: .28; }
.effigy.spent::before, .effigy.spent::after { background: #4a3c26; box-shadow: none; }

.banner {
  margin: auto auto 0;
  font-family: var(--font-display);
  font-size: clamp(15px, 3.2vw, 26px);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--blood-lit);
  text-shadow: 0 0 20px rgba(196,72,43,.7), 0 2px 0 #000;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 90ms steps(2), transform 90ms steps(2);
  padding-bottom: 14vh;
  text-align: center;
}
.banner.show { opacity: 1; transform: translateY(0); }

/* ================= full screens ================= */
.screens { position: fixed; inset: 0; z-index: 20; pointer-events: none; }

.sheet {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 16px)
           calc(var(--safe-b) + 12px) calc(var(--safe-l) + 16px);
  background:
    radial-gradient(ellipse at 50% 45%, rgba(20,12,6,.62), rgba(6,4,2,.93) 78%);
  pointer-events: auto;
}
.sheet.hidden { display: none; }

.sheet-inner {
  max-width: min(560px, 88vw);
  max-height: 92vh;
  overflow-y: auto;
  padding: clamp(14px, 3vw, 30px) clamp(18px, 4vw, 38px);
  text-align: center;
  clip-path: polygon(1.5% 0, 100% 3%, 98% 100%, 0 96%);
}
.sheet-caught { clip-path: polygon(0 3%, 98.5% 0, 100% 97%, 2% 100%); }

.sheet h1 {
  font-family: var(--font-display);
  font-size: clamp(26px, 6.5vw, 54px);
  line-height: .96;
  margin: 6px 0 10px;
  letter-spacing: .05em;
  color: var(--bone);
  text-shadow: 0 3px 0 #000, 0 0 30px rgba(138,42,24,.45);
}
.sheet h2 {
  font-family: var(--font-display);
  font-size: clamp(20px, 4.6vw, 36px);
  margin: 4px 0 8px;
  letter-spacing: .07em;
  color: var(--bone);
  text-shadow: 0 2px 0 #000, 0 0 24px rgba(138,42,24,.5);
}

.subtitle {
  font-size: clamp(12px, 1.85vw, 15px);
  line-height: 1.45;
  color: #a9977a;
  font-style: italic;
  margin: 0 auto 12px;
  max-width: 44ch;
}

.stats {
  font-family: var(--font-display);
  font-size: clamp(12px, 1.9vw, 15px);
  color: var(--straw);
  letter-spacing: .08em;
  margin: 0 0 10px;
}

.hint {
  font-family: var(--font-display);
  font-size: clamp(12px, 1.9vw, 15px);
  letter-spacing: .17em;
  text-transform: uppercase;
  color: var(--straw-pale);
  margin: 4px 0 0;
  animation: pulse 1.5s steps(2, end) infinite alternate;
}
@keyframes pulse { from { opacity: .5; } to { opacity: 1; } }

/* warped religious sigil — a crooked cross scratched into the page */
.sigil {
  width: 40px; height: 46px; margin: 0 auto 4px;
  position: relative;
  opacity: .88;
}
.sigil::before {
  content: ""; position: absolute; left: 50%; top: 0;
  width: 4px; height: 100%; margin-left: -2px;
  background: var(--straw);
  transform: rotate(-4deg);
  box-shadow: 0 0 12px rgba(195,154,52,.5);
}
.sigil::after {
  content: ""; position: absolute; left: 4px; right: 4px; top: 14px;
  height: 4px; background: var(--straw);
  transform: rotate(3deg);
  box-shadow: 0 0 12px rgba(195,154,52,.5);
}
.sigil-red::before, .sigil-red::after { background: var(--blood-lit); box-shadow: 0 0 16px rgba(196,72,43,.7); }
.sigil-gold::before, .sigil-gold::after { background: var(--straw-pale); box-shadow: 0 0 22px rgba(224,196,121,.8); }

/* ================= touch controls (game's own language) =================
   Bottom-left: a twine-wrapped stick knot. Bottom-right: a wax seal.
   These two corners are ours; the HUD sits at the top and never enters them. */
.touch { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
.touch.hidden { display: none; }

.stick {
  position: absolute;
  left: calc(var(--safe-l) + 16px);
  bottom: calc(var(--safe-b) + 16px);
  width: 124px; height: 124px;
  pointer-events: auto;
  touch-action: none;
}
.stick-ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 3px solid rgba(195,154,52,.4);
  background:
    radial-gradient(circle at 38% 32%, rgba(122,84,40,.4), transparent 62%),
    radial-gradient(circle at 50% 50%, rgba(20,14,8,.72), rgba(10,7,4,.86));
  box-shadow: inset 0 0 26px rgba(0,0,0,.8), 0 3px 14px rgba(0,0,0,.65);
}
.stick-ring::after {           /* four scratched furrow marks, not arrows */
  content: "";
  position: absolute; inset: 14px;
  border-radius: 50%;
  border: 1px dashed rgba(195,154,52,.24);
}
.stick-knot {
  position: absolute;
  left: 50%; top: 50%;
  width: 52px; height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 36% 30%, var(--straw-pale), var(--straw) 42%, #6d5216 100%);
  border: 2px solid #3a2b10;
  box-shadow: 0 0 18px rgba(195,154,52,.45), inset 0 -4px 8px rgba(0,0,0,.5);
  transition: transform 40ms linear;
}

.action-btn {
  position: absolute;
  right: calc(var(--safe-r) + 18px);
  bottom: calc(var(--safe-b) + 22px);
  width: 92px; height: 92px;
  pointer-events: auto;
  touch-action: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.action-seal {
  position: absolute; inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 30%, #b8452c, #8a2a18 48%, #4a1408 100%);
  border: 3px solid rgba(221,208,178,.28);
  box-shadow: 0 0 22px rgba(138,42,24,.55), inset 0 -6px 12px rgba(0,0,0,.55);
  clip-path: polygon(50% 0%, 82% 9%, 100% 38%, 93% 76%, 64% 98%, 30% 96%, 4% 70%, 2% 32%, 20% 7%);
}
.action-label {
  position: relative;
  font-family: var(--font-display);
  font-size: 13px; letter-spacing: .16em;
  color: #f0e2c0;
  text-shadow: 0 2px 3px rgba(0,0,0,.85);
}
.action-btn:active .action-seal { filter: brightness(1.4); }

/* phone landscape: 390px of height — shrink furniture, keep corners clear */
@media (max-height: 460px) {
  .stick { width: 104px; height: 104px; left: calc(var(--safe-l) + 12px); bottom: calc(var(--safe-b) + 10px); }
  .stick-knot { width: 46px; height: 46px; margin: -23px 0 0 -23px; }
  .action-btn { width: 80px; height: 80px; right: calc(var(--safe-r) + 14px); bottom: calc(var(--safe-b) + 14px); }
  .panel { padding: 5px 10px 6px; }
  .banner { padding-bottom: 6vh; }
  .sheet-inner { padding: 10px 18px; }
  .sheet h1 { font-size: clamp(22px, 5.2vh, 34px); }
  .subtitle { font-size: 12px; margin-bottom: 7px; }
}

/* ============================================================
   THE WALL SCARE — a full-screen video-style presentation cut
   from the game's own painted horror plates. Same visual
   language as everything else: stained, torn, lit from below,
   nothing square. Staged like a damaged reel, not a fade.
   ============================================================ */
.scare {
  position: fixed; inset: 0; z-index: 60;
  pointer-events: none;
  overflow: hidden;
  background: #000;
}
.scare.hidden { display: none; }

.scare-face {
  position: absolute; inset: -6%;
  background-position: center 42%;
  background-size: cover;
  background-repeat: no-repeat;
  transform-origin: 50% 45%;
  will-change: transform, filter;
}

/* horizontal tear bars — the reel jumping its sprockets */
.scare-bars {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0 3px,
    rgba(0,0,0,.30) 3px 4px,
    rgba(0,0,0,0) 4px 9px);
  mix-blend-mode: multiply;
  opacity: .8;
}

/* stain and emulsion damage, built from a few large blooms rather than a
   per-pixel field — big shapes read on a phone, sub-pixel noise strobes */
.scare-grain {
  position: absolute; inset: -20%;
  background:
    radial-gradient(circle 22vmin at 18% 22%, rgba(138,42,24,.34), transparent 70%),
    radial-gradient(circle 30vmin at 84% 74%, rgba(20,12,6,.60), transparent 68%),
    radial-gradient(circle 14vmin at 62% 12%, rgba(195,154,52,.22), transparent 72%),
    radial-gradient(circle 18vmin at 30% 88%, rgba(20,12,6,.55), transparent 70%);
  mix-blend-mode: overlay;
  will-change: transform, opacity;
}

.scare-vignette {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 78% 74% at 50% 46%, transparent 34%, rgba(0,0,0,.90) 100%);
}

.scare-word {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) rotate(-1.6deg);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(20px, 6.4vmin, 54px);
  letter-spacing: .16em;
  color: #e8d7ad;
  text-align: center;
  text-shadow:
    0 0 24px rgba(0,0,0,.95),
    0 3px 0 rgba(0,0,0,.9),
    0 0 60px rgba(138,42,24,.7);
  opacity: 0;
  white-space: nowrap;
  max-width: 92vw;
}
