:root {
  --sand: #d9b382;
  --clay: #b5653f;
  --sky: #6fa6d6;
  --ink: #1a1d21;
  --amber: #ffb02a;
  --bone: #f4ead8;
  --red: #ff3f31;
  --display: "Saira Stencil One", "Barlow Condensed", Impact, sans-serif;
  --text: "Barlow Condensed", "Arial Narrow", system-ui, sans-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);
}

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

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 30; }
.overlay[hidden], [hidden] { display: none !important; }

#menu { background: var(--ink); transition: opacity .35s ease; }
#menu.leaving { opacity: 0; pointer-events: none; }
#menu .scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.brief {
  position: absolute;
  left: calc(var(--safe-l) + clamp(20px, 6vw, 96px));
  right: calc(var(--safe-r) + 20px);
  bottom: calc(var(--safe-b) + clamp(44px, 10vh, 104px));
  max-width: 34rem;
}

.logo {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(3.5rem, 12.5vw, 8.5rem);
  line-height: .9;
  letter-spacing: .01em;
  text-transform: uppercase;
  color: var(--bone);
  text-shadow: 0 3px 0 rgba(26, 29, 33, .55);
}

.tagline {
  margin: .5rem 0 1.5rem;
  font-size: clamp(1.25rem, 3.4vw, 1.75rem);
  font-weight: 500;
  line-height: 1.15;
  color: var(--bone);
}

button.primary {
  appearance: none;
  border: 0;
  border-radius: 3px;
  min-width: 11rem;
  min-height: 3.25rem;
  padding: .55rem 2.4rem .65rem;
  background: var(--amber);
  color: var(--ink);
  font-family: var(--text);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 100ms ease-out, background-color 120ms ease-out;
}
button.primary:hover { background: #ffc35a; }
button.primary:active { transform: scale(.97); }
button.primary:focus-visible { outline: 3px solid var(--bone); outline-offset: 3px; }

#loader { min-height: 3.25rem; display: flex; flex-direction: column; justify-content: center; gap: .55rem; }
#loader .track { width: min(17rem, 70vw); height: 4px; background: rgba(244, 234, 216, .28); overflow: hidden; }
#loaderFill { width: 0; height: 100%; background: var(--amber); transition: width .25s ease-out; }
#loaderSub { margin: 0; font-size: 1.1rem; font-weight: 500; color: var(--bone); }

.best { margin: 1rem 0 0; font-size: 1.15rem; font-weight: 600; color: var(--amber); font-variant-numeric: tabular-nums; }
.hint { margin: .7rem 0 0; max-width: 30rem; font-size: 1.05rem; font-weight: 500; line-height: 1.3; color: rgba(244, 234, 216, .82); }
.credit {
  position: absolute;
  left: calc(var(--safe-l) + clamp(20px, 6vw, 96px));
  bottom: calc(var(--safe-b) + 12px);
  margin: 0;
  font-size: .85rem;
  font-weight: 500;
  color: rgba(244, 234, 216, .55);
}

/* ---------- sheets: down, end, lost ---------- */
.sheet {
  display: grid;
  place-items: center;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 20px) calc(var(--safe-b) + 16px) calc(var(--safe-l) + 20px);
  background: rgba(20, 22, 26, .8);
  animation: sheet-in .28s ease-out both;
}
#down { background: radial-gradient(ellipse at center, rgba(74, 14, 10, .62), rgba(20, 9, 9, .9)); }
.card { width: min(30rem, 100%); text-align: center; }
.card h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.2rem, 8vw, 3.6rem);
  line-height: 1;
  text-transform: uppercase;
  color: var(--bone);
}
.card p { margin: .6rem 0 1.4rem; font-size: 1.3rem; font-weight: 500; line-height: 1.25; color: rgba(244, 234, 216, .88); }
.card .best { margin: 0 0 1.3rem; color: var(--amber); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin: 1.2rem 0 1.1rem; }
.stats div { padding: .6rem .3rem .7rem; background: rgba(244, 234, 216, .08); border-top: 2px solid var(--clay); }
.stats dt { font-size: .95rem; font-weight: 500; color: rgba(244, 234, 216, .72); }
.stats dd { margin: .1rem 0 0; font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--bone); }

@keyframes sheet-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- in-game extras ---------- */
#lives {
  position: fixed;
  z-index: 11;
  top: calc(var(--safe-t) + var(--lives-top, 86px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 5px;
  pointer-events: none;
}
#lives i { width: 20px; height: 6px; background: var(--amber); transform: skewX(-22deg); box-shadow: 0 1px 2px rgba(0, 0, 0, .5); }
#lives i.spent { background: rgba(244, 234, 216, .26); }

#rotate {
  position: fixed;
  z-index: 13;
  left: 50%;
  top: calc(var(--safe-t) + 132px);
  transform: translateX(-50%);
  padding: .4rem .9rem;
  background: rgba(26, 29, 33, .72);
  border-left: 3px solid var(--amber);
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- touch controls ---------- */
#touch { position: fixed; inset: 0; z-index: 12; touch-action: none; }
.tbtn {
  position: absolute;
  display: grid;
  place-items: center;
  width: var(--s);
  height: var(--s);
  right: calc(var(--safe-r) + var(--r));
  bottom: calc(var(--safe-b) + var(--b));
  border-radius: 50%;
  border: 1.5px solid rgba(244, 234, 216, .6);
  background: rgba(26, 29, 33, .4);
  color: var(--bone);
  touch-action: none;
}
.tbtn svg { width: 46%; height: 46%; pointer-events: none; }
.tbtn.on { background: rgba(255, 176, 42, .55); border-color: var(--amber); transform: scale(.95); }
.b-fire { --s: 84px; --r: 22px; --b: 96px; border-color: rgba(255, 63, 49, .85); background: rgba(255, 63, 49, .24); }
.b-fire.on { background: rgba(255, 63, 49, .6); border-color: var(--red); }
.b-aim { --s: 60px; --r: 118px; --b: 84px; }
.b-jump { --s: 56px; --r: 100px; --b: 164px; }
.b-reload { --s: 52px; --r: 28px; --b: 198px; }
.b-crouch { --s: 46px; --r: 172px; --b: 150px; }
.b-swap { --s: 46px; --r: 31px; --b: 266px; }
.b-pause {
  --s: 42px;
  right: calc(var(--safe-r) + 12px);
  bottom: auto;
  top: calc(var(--safe-t) + 12px);
}
.stick-base {
  position: absolute;
  width: 116px;
  height: 116px;
  margin: -58px 0 0 -58px;
  border-radius: 50%;
  border: 1.5px solid rgba(244, 234, 216, .45);
  background: rgba(26, 29, 33, .26);
  pointer-events: none;
}
.stick-base.rest { left: calc(var(--safe-l) + 86px); top: auto; bottom: calc(var(--safe-b) + 66px); margin: 0 0 0 -58px; opacity: .55; }
.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  margin: -25px 0 0 -25px;
  border-radius: 50%;
  background: rgba(244, 234, 216, .7);
}

/* phones held sideways: tuck the cluster lower */
@media (max-height: 500px) {
  .brief { bottom: calc(var(--safe-b) + 34px); }
  .logo { font-size: clamp(3rem, 15vh, 5rem); }
  .tagline { margin-bottom: .9rem; }
  .hint { display: none; }
  .credit { left: auto; right: calc(var(--safe-r) + 20px); }
  .b-fire { --s: 78px; --r: 26px; --b: 62px; }
  .b-aim { --s: 54px; --r: 120px; --b: 40px; }
  .b-jump { --s: 52px; --r: 112px; --b: 108px; }
  .b-reload { --s: 48px; --r: 34px; --b: 152px; }
  .b-crouch { --s: 44px; --r: 186px; --b: 56px; }
  .b-swap { --s: 44px; --r: 104px; --b: 172px; }
  .stick-base.rest { bottom: calc(var(--safe-b) + 44px); }
  .stats { margin: .7rem 0; }
  .card p { margin: .4rem 0 .8rem; }
}

@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  #menu, button.primary, #loaderFill { transition: none; }
  .sheet { animation: none; }
}
