:root {
  color-scheme: dark;
  --bg: #101417;
  --panel: #181d21;
  --ink: #f5efe4;
  --muted: #b7ad9f;
  --wall: #244b68;
  --wall-edge: #7cc3df;
  --bean: #d19449;
  --cream: #fff1c7;
  --danger: #e05050;
  --accent: #57b894;
  --page-art: radial-gradient(circle at 25% 12%, rgba(87, 184, 148, 0.18), transparent 28rem),
    linear-gradient(140deg, #0f1518, #1d1915 58%, #111417);
  --page-art-size: auto;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  width: 100%;
}

body {
  margin: 0;
  min-height: 100svh;
  overflow-x: hidden;
  background: var(--page-art);
  background-attachment: fixed;
  background-size: var(--page-art-size);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

button {
  border: 1px solid rgba(245, 239, 228, 0.2);
  border-radius: 8px;
  background: #242a2f;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  min-height: 40px;
  padding: 0 14px;
}

button:hover {
  background: #31383f;
}

.shell {
  --shell-pad-y: clamp(18px, 3svh, 32px);
  max-width: 100vw;
  min-height: 100svh;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: var(--shell-pad-y) clamp(12px, 2.5vw, 24px);
  width: 100%;
}

.game-wrap {
  min-width: 0;
  max-width: min(820px, calc((100svh - 292px) * 0.9048));
  width: 100%;
  display: grid;
  gap: 12px;
  position: relative;
}

.topbar,
.controls {
  background: rgba(24, 29, 33, 0.86);
  border: 1px solid rgba(245, 239, 228, 0.12);
  border-radius: 8px;
  padding: 14px;
}

.topbar {
  align-items: stretch;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 174px;
  overflow: hidden;
}

.topbar > div:first-child {
  min-width: 0;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 3px;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(28px, 4vw, 31px);
  line-height: 1.05;
  margin: 0;
  max-width: 100%;
  min-height: 66px;
  overflow-wrap: break-word;
  text-wrap: wrap;
}

.stats {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(138px, 1.25fr) repeat(2, minmax(96px, 0.85fr)) 52px;
  justify-content: end;
  min-height: 52px;
  width: 100%;
}

.stats > span {
  background: #0e1215;
  border: 1px solid rgba(245, 239, 228, 0.1);
  border-radius: 8px;
  color: var(--muted);
  display: block;
  font-size: clamp(13px, 1.7vw, 16px);
  font-variant-numeric: tabular-nums;
  min-width: 0;
  overflow: hidden;
  padding: 9px 10px;
  text-align: center;
  white-space: nowrap;
  width: 100%;
}

.stats strong {
  color: var(--ink);
  display: inline-block;
  min-width: 2.5ch;
  text-align: right;
}

.stats > span:first-child strong {
  min-width: 4ch;
}

.shop-button {
  align-items: center;
  background: #0e1215;
  border: 1px solid rgba(245, 239, 228, 0.1);
  border-radius: 8px;
  display: grid;
  height: 46px;
  justify-items: center;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: 0;
  position: relative;
  width: 100%;
}

.shop-button[hidden] {
  display: none;
}

.shop-button:hover {
  background: #18211f;
}

.shop-button::before {
  background: transparent;
  border: 2px solid #ffd15c;
  border-bottom: 0;
  border-radius: 9px 9px 0 0;
  content: "";
  height: 11px;
  left: 50%;
  position: absolute;
  top: 9px;
  transform: translateX(-50%);
  width: 18px;
}

.shop-button::after {
  content: none;
}

.shop-button__bag {
  background: #57b894;
  border: 2px solid #ffd15c;
  border-radius: 6px;
  display: block;
  height: 24px;
  left: 50%;
  position: absolute;
  top: 18px;
  transform: translateX(-50%);
  width: 32px;
}

.shop-button__plus {
  color: #f5efe4;
  font-size: 22px;
  font-weight: 1000;
  line-height: 1;
  position: absolute;
  right: auto;
  top: 21px;
  z-index: 2;
}

canvas {
  aspect-ratio: 19 / 21;
  background: #0b0e12;
  border: 1px solid rgba(245, 239, 228, 0.16);
  border-radius: 8px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.4);
  display: block;
  touch-action: none;
  width: 100%;
}

.game-stage {
  position: relative;
}

.touch-controls {
  bottom: max(12px, env(safe-area-inset-bottom));
  display: none;
  gap: 6px;
  grid-template-columns: repeat(3, 42px);
  grid-template-rows: repeat(3, 42px);
  left: max(12px, env(safe-area-inset-left));
  opacity: 0;
  pointer-events: none;
  position: absolute;
  touch-action: none;
  transition: opacity 500ms ease;
  z-index: 3;
}

.touch-btn {
  align-items: center;
  background: rgba(24, 29, 33, 0.78);
  border: 2px solid rgba(245, 239, 228, 0.38);
  border-radius: 999px;
  display: grid;
  min-height: 42px;
  padding: 0;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
}

.touch-btn:active {
  background: rgba(87, 184, 148, 0.55);
  border-color: rgba(255, 241, 199, 0.86);
}

.touch-btn::before {
  content: "";
  display: block;
  height: 0;
  width: 0;
}

.touch-up {
  grid-column: 2;
  grid-row: 1;
}

.touch-up::before {
  border-bottom: 14px solid var(--ink);
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
}

.touch-left {
  grid-column: 1;
  grid-row: 2;
}

.touch-left::before {
  border-bottom: 9px solid transparent;
  border-right: 14px solid var(--ink);
  border-top: 9px solid transparent;
}

.touch-center {
  align-self: center;
  background: rgba(245, 239, 228, 0.16);
  border: 1px solid rgba(245, 239, 228, 0.24);
  border-radius: 999px;
  grid-column: 2;
  grid-row: 2;
  height: 22px;
  justify-self: center;
  pointer-events: none;
  width: 22px;
}

.touch-right {
  grid-column: 3;
  grid-row: 2;
}

.touch-right::before {
  border-bottom: 9px solid transparent;
  border-left: 14px solid var(--ink);
  border-top: 9px solid transparent;
}

.touch-down {
  grid-column: 2;
  grid-row: 3;
}

.touch-down::before {
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 14px solid var(--ink);
}

@media (hover: none), (pointer: coarse) {
  body[data-screen="game"] .touch-controls,
  body[data-screen="challenge"] .touch-controls {
    display: grid;
  }
}

body[data-touch-controls="true"][data-screen="game"] .touch-controls,
body[data-touch-controls="true"][data-screen="challenge"] .touch-controls {
  display: grid;
}

body[data-screen="game"][data-touch-hint="visible"] .touch-controls,
body[data-screen="challenge"][data-touch-hint="visible"] .touch-controls {
  opacity: 0.72;
  pointer-events: none;
}

body[data-screen="intro"] #quit,
body[data-screen="end"] #quit {
  display: none;
}

.controls {
  align-items: center;
  display: flex;
  justify-content: flex-start;
  gap: 12px;
}

#status {
  color: var(--muted);
  font-weight: 700;
  margin-left: auto;
  text-align: right;
}

@media (max-width: 620px) {
  .shell {
    --shell-pad-y: 14px;
    padding-inline: 10px;
  }

  .game-wrap {
    max-width: min(calc(100vw - 20px), calc((100svh - 260px) * 0.9048));
  }

  .topbar {
    align-items: flex-start;
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  h1 {
    font-size: clamp(27px, 8vw, 36px);
    min-height: 0;
  }

  .stats {
    gap: 6px;
    grid-template-columns: minmax(100px, 1.2fr) repeat(2, minmax(76px, 0.8fr)) 40px;
    width: 100%;
  }

  .stats > span {
    font-size: 13px;
    padding-inline: 6px;
  }

  .stats > span {
    width: 100%;
  }

  .controls {
    flex-wrap: wrap;
  }

  #status {
    flex-basis: 100%;
    margin-left: 0;
    text-align: left;
  }
}
