:root {
  color-scheme: dark;
  --panel: rgba(10, 11, 8, 0.78);
  --line: rgba(224, 214, 137, 0.28);
  --text: #eee8ba;
  --accent: #d9c765;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  height: 100dvh;
  overflow: hidden;
  background: #080906;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

button {
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(217, 231, 176, 0.22);
}

.shell {
  position: fixed;
  inset: 0;
  height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
  background: #080906;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at center, transparent 0 42%, rgba(0, 0, 0, 0.24) 72%, rgba(0, 0, 0, 0.72) 100%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 4px);
  mix-blend-mode: multiply;
}

.fade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: #050604;
  opacity: 0;
  transition: opacity 220ms ease;
}

.fade.active {
  opacity: 0.72;
}

.hud {
  position: absolute;
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  top: max(12px, env(safe-area-inset-top));
  display: grid;
  gap: 8px;
  max-width: 460px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(10px);
}

.readout {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: #f3efbd;
  font-size: 0.92rem;
  font-weight: 800;
}

.meter {
  height: 9px;
  border: 1px solid rgba(222, 210, 126, 0.34);
  background: rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #72633b, #d9e7b0);
  transition: width 240ms ease;
}

.status {
  min-height: 40px;
  margin: 0;
  color: #e5ddb2;
  font-size: 0.94rem;
  line-height: 1.38;
}

.actions {
  position: absolute;
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: grid;
  gap: 10px;
}

.start,
.directions button {
  min-height: 44px;
  border: 1px solid rgba(225, 214, 125, 0.5);
  background: rgba(219, 200, 99, 0.92);
  color: #15130c;
  font-weight: 900;
  cursor: pointer;
}

.start:disabled {
  opacity: 0.72;
}

.directions {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 7px;
}

.directions button {
  min-height: 40px;
  background: rgba(13, 14, 10, 0.76);
  color: #f0e8ad;
  border-color: rgba(225, 214, 125, 0.34);
  backdrop-filter: blur(8px);
}

.directions button:hover,
.directions button:focus-visible,
.start:hover,
.start:focus-visible {
  outline: 2px solid rgba(217, 231, 176, 0.58);
}

.hidden {
  display: none;
}

.ending {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 14px;
  padding: max(28px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 52% 38%, rgba(235, 226, 142, 0.11), transparent 28%),
    rgba(4, 5, 3, 0.78);
  color: #f4efbd;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 700ms ease, transform 700ms ease;
}

.ending.show {
  opacity: 1;
  transform: translateY(0);
}

.ending.hidden {
  display: none;
}

.ending-line {
  width: min(340px, 82vw);
  height: 3px;
  background: linear-gradient(90deg, #f2edb7, transparent);
  box-shadow: 0 0 22px rgba(242, 237, 183, 0.45);
  animation: endingPulse 1.4s ease-in-out infinite alternate;
}

.ending-kicker,
.ending p,
.ending h1 {
  max-width: 560px;
  margin: 0;
}

.ending-kicker {
  color: #cfc46f;
  font-size: 0.82rem;
  font-weight: 900;
}

.ending h1 {
  font-size: clamp(2rem, 7vw, 4rem);
  line-height: 1.02;
}

.ending p {
  color: #e2dba5;
  font-size: 1rem;
  line-height: 1.55;
}

.ending button {
  min-height: 44px;
  min-width: 124px;
  border: 1px solid rgba(225, 214, 125, 0.6);
  background: rgba(219, 200, 99, 0.92);
  color: #15130c;
  font-weight: 900;
}

@keyframes endingPulse {
  from {
    opacity: 0.38;
    transform: scaleX(0.78);
    transform-origin: left center;
  }
  to {
    opacity: 1;
    transform: scaleX(1);
    transform-origin: left center;
  }
}

@media (min-width: 780px) {
  .hud {
    left: 18px;
    top: 18px;
  }

  .actions {
    left: 18px;
    right: auto;
    bottom: 18px;
    width: min(520px, calc(100vw - 36px));
  }
}

@media (max-width: 380px), (max-height: 700px) {
  .hud {
    padding: 9px;
    gap: 6px;
  }

  .status {
    min-height: 34px;
    font-size: 0.86rem;
  }

  .start,
  .directions button {
    min-height: 38px;
    font-size: 0.9rem;
  }

  .directions {
    gap: 5px;
  }
}
