:root {
  --ink: #14171b;
  --asphalt: #22272d;
  --steel: #333a42;
  --paint: #e9e3d1;
  --yellow: #e6b422;
  --orange: #e2582a;
  --red: #b8332a;
  --paper: #f4efe2;
  --roofH: clamp(92px, 13.5vh, 138px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #0e1013;
  color: var(--paper);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "Archivo Narrow", "Arial Narrow", sans-serif;
  background:
    radial-gradient(ellipse at 50% 28%, #232a31 0%, #121519 62%, #0a0c0f 100%);
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  touch-action: none;
}

.app {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ---------------- mall roof ---------------- */

.roof {
  position: relative;
  flex: 0 0 auto;
  height: var(--roofH);
  overflow: hidden;
  border-radius: 3px;
  box-shadow: 0 2px 0 #0a0c0e, 0 8px 18px #0006;
  isolation: isolate;
}

.roof-art {
  position: absolute;
  inset: 0;
  background: url("elements/mall_roof_band.webp") center / 100% 100% no-repeat;
  filter: brightness(1) saturate(1);
  transition: filter 700ms ease;
  z-index: 0;
}

.roof::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(230,180,34,.10), transparent 24%, transparent 74%, rgba(20,23,27,.28)),
    linear-gradient(180deg, rgba(20,23,27,.30), transparent 26%, transparent 68%, rgba(20,23,27,.55));
  pointer-events: none;
  z-index: 1;
}

.marquee {
  position: absolute;
  left: 50%;
  bottom: 1px;
  width: calc(var(--roofH) * 1.12);
  transform: translateX(-50%);
  z-index: 3;
  filter: drop-shadow(0 4px 3px rgba(0,0,0,.55));
}

.marquee-img {
  display: block;
  width: 100%;
  height: auto;
}

.marquee-title {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 3.5%;
  height: 39%;
  background: #b8332a;
  border-top: 1px solid #d9503e;
  box-shadow: inset 0 0 0 1px #8f2119, inset 0 10px 10px rgba(255,255,255,.03);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #fff7e8;
  font-family: "Alfa Slab One", Georgia, serif;
  font-size: calc(var(--roofH) * 0.092);
  line-height: .96;
  letter-spacing: .01em;
  text-shadow: 1px 1px 0 #6e140f;
}

.marquee-title span { display: block; }

.marquee-level {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 47%;
  height: 23%;
  background: #f4efe2;
  box-shadow: inset 0 0 0 1px #b7ae9a;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #272b31;
  font-family: "Silkscreen", "Courier New", monospace;
}

.marquee-level .lv-cap {
  font-size: calc(var(--roofH) * 0.055);
  letter-spacing: .08em;
  color: #6b6a62;
}

.marquee-level .lv-num {
  font-size: calc(var(--roofH) * 0.105);
  font-weight: 700;
  line-height: 1;
}

.flip {
  animation: flipcard 460ms steps(4, end);
}

@keyframes flipcard {
  0% { transform: rotateX(0deg); opacity: 1; }
  45% { transform: rotateX(88deg); opacity: .4; }
  55% { transform: rotateX(-88deg); opacity: .4; }
  100% { transform: rotateX(0deg); opacity: 1; }
}

/* ---------------- lot ---------------- */

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 3px;
  overflow: hidden;
  background: #1c2127 url("elements/asphalt_tile.webp") center / 166px repeat;
  box-shadow: inset 0 0 0 2px #0c0e10, 0 2px 0 #0a0c0e;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(230,180,34,.13), rgba(230,180,34,.04) 32%, transparent 62%);
  mix-blend-mode: screen;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 48%, transparent 55%, rgba(6,8,10,.24) 100%),
    linear-gradient(90deg, rgba(230,180,34,.05), transparent 18%);
}

.lot {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.lot canvas {
  display: block;
}

.toast {
  position: absolute;
  z-index: 30;
  left: 50%;
  top: 10px;
  transform: translate(-50%, -8px);
  max-width: 88%;
  padding: 7px 12px 8px;
  border: 2px solid #0c0e10;
  border-radius: 3px;
  background: rgba(20,23,27,.92);
  box-shadow: inset 0 0 0 1px rgba(244,239,226,.14), 0 4px 0 rgba(0,0,0,.35);
  color: var(--paper);
  font-family: "Silkscreen", "Courier New", monospace;
  font-size: clamp(8px, 2.3vw, 11px);
  line-height: 1.45;
  letter-spacing: .04em;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
}

.toast.on {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.bad {
  border-color: #5d1712;
  background: rgba(93,23,18,.95);
  box-shadow: inset 0 0 0 1px rgba(244,239,226,.18), 0 4px 0 rgba(0,0,0,.35);
  color: #ffdfd4;
}

.toast.good {
  border-color: #6d5210;
  background: rgba(64,50,14,.95);
  color: #ffe9a8;
}

/* ---------------- overlays ---------------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(8,10,12,.64);
  backdrop-filter: blur(1.5px);
}

.overlay.on { display: flex; }

.card {
  width: min(96%, 400px);
  max-height: 100%;
  overflow-y: auto;
  padding: 15px 16px 16px;
  border: 2px solid #0b0d0f;
  border-radius: 4px;
  background:
    linear-gradient(180deg, #2b3138, #20252b 55%, #191d22);
  box-shadow:
    inset 0 0 0 1px rgba(244,239,226,.12),
    inset 0 2px 0 rgba(244,239,226,.08),
    0 8px 0 rgba(0,0,0,.35),
    0 14px 26px rgba(0,0,0,.55);
  color: var(--paper);
}

.card h2 {
  margin: 0 0 4px;
  font-family: "Alfa Slab One", Georgia, serif;
  font-weight: 400;
  font-size: clamp(19px, 5.8vw, 28px);
  line-height: 1.02;
  letter-spacing: .01em;
  color: #fff8e9;
  text-shadow: 2px 2px 0 #7d1c14;
}

.card .kicker {
  margin: 0 0 8px;
  padding-bottom: 7px;
  border-bottom: 3px solid var(--yellow);
  color: var(--yellow);
  font-family: "Silkscreen", "Courier New", monospace;
  font-size: clamp(8px, 2.3vw, 11px);
  letter-spacing: .1em;
}

.card p {
  margin: 0 0 8px;
  font-size: clamp(12px, 3.5vw, 15px);
  line-height: 1.38;
  color: #e3ddce;
}

.card p b { color: #fff4d4; font-weight: 700; }

.card .rules {
  margin: 9px 0 11px;
  padding: 8px 9px;
  border-left: 3px solid var(--orange);
  background: rgba(0,0,0,.22);
  font-size: clamp(11px, 3.2vw, 14px);
  line-height: 1.4;
  color: #cfc9bb;
}

.card .rules ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.card .rules li {
  position: relative;
  padding-left: 12px;
  margin-bottom: 4px;
}

.card .rules li:last-child { margin-bottom: 0; }

.card .rules li::before {
  content: "";
  position: absolute;
  left: 0;
  top: .45em;
  width: 5px;
  height: 5px;
  background: var(--yellow);
  box-shadow: 0 0 0 1px #6d5210;
}

.card .score-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 9px 0 12px;
  padding: 8px 10px;
  background: rgba(0,0,0,.3);
  border: 1px solid rgba(244,239,226,.12);
  font-family: "Silkscreen", "Courier New", monospace;
  font-size: clamp(10px, 3vw, 13px);
  color: var(--yellow);
  letter-spacing: .05em;
}

.card .score-box span:last-child { color: #d7d1c2; }

.card-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 4px;
}

.big-key {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: clamp(52px, 14vw, 66px);
  background: url("elements/keycap_buttons_05_keycap_start.webp") center / 100% 100% no-repeat;
  filter: drop-shadow(0 4px 0 rgba(0,0,0,.4));
  display: flex;
  align-items: center;
  justify-content: center;
}

.big-key.retry {
  background-image: url("elements/keycap_buttons_06_keycap_retry.webp");
}

.big-key span {
  font-family: "Silkscreen", "Courier New", monospace;
  font-size: clamp(12px, 3.4vw, 16px);
  font-weight: 700;
  letter-spacing: .08em;
  color: #fff4df;
  text-shadow: 0 2px 0 #6f1a14, 0 0 6px rgba(0,0,0,.35);
}

.big-key.retry span {
  color: #1c2025;
  text-shadow: 0 1px 0 #fff0b8;
}

.big-key:active { transform: translateY(2px); filter: drop-shadow(0 2px 0 rgba(0,0,0,.4)); }

.ghost-key {
  flex: 0 0 auto;
  height: clamp(46px, 12vw, 58px);
  padding: 0 13px;
  border: 2px solid #0b0d0f;
  border-radius: 4px;
  background: #333a42;
  box-shadow: inset 0 0 0 1px rgba(244,239,226,.16), 0 3px 0 #0b0d0f;
  font-family: "Silkscreen", "Courier New", monospace;
  font-size: clamp(9px, 2.6vw, 12px);
  letter-spacing: .06em;
  color: #e9e3d1;
}

.ghost-key:active { transform: translateY(2px); box-shadow: inset 0 0 0 1px rgba(244,239,226,.16), 0 1px 0 #0b0d0f; }

.badge-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 2px;
}

.badge-line img { height: clamp(22px, 6vw, 30px); width: auto; }

.badge-line .plus {
  font-family: "Silkscreen", monospace;
  color: #8e978f;
  font-size: 10px;
}

.badge-line .to {
  font-family: "Silkscreen", monospace;
  color: var(--yellow);
  font-size: 10px;
  letter-spacing: .08em;
}

/* ---------------- console ---------------- */

.console {
  --cap: clamp(44px, 13vw, 62px);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.plate {
  position: relative;
  width: 100%;
  height: clamp(100px, 13.6vh, 142px);
  background: url("elements/hud_plate.webp") center / 100% 100% no-repeat;
  filter: drop-shadow(0 3px 0 rgba(0,0,0,.35));
}

.plate .win {
  position: absolute;
  top: 15%;
  height: 30%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  border-radius: 2px;
  background: rgba(9,11,13,.22);
  box-shadow: inset 0 0 10px rgba(0,0,0,.35);
  overflow: hidden;
}

.win-left { left: 15.5%; width: 28%; }
.win-right { left: 60.5%; width: 27%; }

.plate .cap {
  font-family: "Archivo Narrow", sans-serif;
  font-weight: 700;
  font-size: clamp(6.5px, 1.85vw, 9px);
  line-height: 1;
  letter-spacing: .14em;
  color: #b9c1bd;
  text-shadow: 0 1px 0 #000;
}

.plate .num {
  font-family: "Silkscreen", "Courier New", monospace;
  font-weight: 700;
  font-size: clamp(17px, 4.6vw, 25px);
  line-height: 1.05;
  color: #fff6de;
  text-shadow: 0 2px 0 #000;
}

.carry {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  line-height: 1;
}

.carry-badge {
  height: clamp(15px, 4.2vw, 23px);
  width: auto;
  filter: drop-shadow(0 1px 0 #000);
}

.carry-badge.hide { visibility: hidden; }

.scoreline {
  position: absolute;
  left: 12%;
  right: 9%;
  top: 47.5%;
  height: 18%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 6px;
  font-family: "Silkscreen", "Courier New", monospace;
  font-size: clamp(8px, 2.25vw, 11px);
  letter-spacing: .03em;
  color: #e9e3d1;
  text-shadow: 0 1px 0 #000, 0 0 5px rgba(0,0,0,.55);
  background: linear-gradient(90deg, transparent, rgba(8,10,12,.34) 8%, rgba(8,10,12,.34) 92%, transparent);
}

.scoreline #hudBest { color: #d9b64d; }

.slots {
  position: absolute;
  left: 19%;
  right: 10%;
  top: 71%;
  height: 8.5%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0 4px;
}

.pip {
  flex: 0 0 auto;
  width: clamp(5px, 1.65vw, 8px);
  height: clamp(5px, 1.65vw, 8px);
  border-radius: 50%;
  border: 1.5px solid #cfc8b6;
  opacity: .42;
  background: rgba(12,14,16,.45);
  transition: transform 140ms ease, opacity 140ms ease;
}

.pip.full {
  border-color: #2a2413;
  opacity: 1;
  background: url("elements/cart_badges_04_filled_pip.webp") center / 100% 100% no-repeat;
  transform: scale(1.12);
}

.pip.new { animation: pippop 260ms ease; }

@keyframes pippop {
  0% { transform: scale(.4); }
  60% { transform: scale(1.55); }
  100% { transform: scale(1.12); }
}

.slots .need {
  margin-left: 5px;
  font-family: "Silkscreen", "Courier New", monospace;
  font-size: clamp(7px, 2vw, 10px);
  color: #f4efe2;
  text-shadow: 0 1px 0 #000;
  white-space: nowrap;
}

.mission {
  min-height: 31px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 3px 8px;
  border: 2px solid #0b0d0f;
  border-radius: 3px;
  background: linear-gradient(180deg, #2d333a, #1a1f24);
  box-shadow: inset 0 0 0 1px rgba(244,239,226,.13), inset 0 2px 0 rgba(255,255,255,.04), 0 2px 0 rgba(0,0,0,.35);
  color: #f4efe2;
  font-family: "Silkscreen", "Courier New", monospace;
  font-size: clamp(8px, 2.35vw, 10.5px);
  line-height: 1.1;
  letter-spacing: .03em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

.mission img {
  height: clamp(16px, 4.4vw, 21px);
  width: auto;
  flex: 0 0 auto;
  filter: drop-shadow(0 1px 0 #000);
}

.mission b { color: #ffe9a8; font-weight: 700; }
.mission .where { color: #e6b422; }
.mission .or { color: #8e978f; font-size: .85em; }

.controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
}

.utils {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  flex: 0 1 auto;
}

.cap-btn {
  position: relative;
  width: calc(var(--cap) * 1.44);
  height: calc(var(--cap) * 1.04);
  background: url("elements/keycap_buttons_05_keycap_start.webp") center / 100% 100% no-repeat;
  filter: drop-shadow(0 3px 0 rgba(0,0,0,.4));
  display: flex;
  align-items: center;
  justify-content: center;
}

.cap-btn.retry {
  background-image: url("elements/keycap_buttons_06_keycap_retry.webp");
}

.cap-btn span {
  font-family: "Silkscreen", "Courier New", monospace;
  font-weight: 700;
  font-size: calc(var(--cap) * 0.22);
  letter-spacing: .06em;
  color: #fff4df;
  text-shadow: 0 2px 0 #6f1a14;
}

.cap-btn.retry span {
  color: #20242a;
  text-shadow: 0 1px 0 #ffe9a1;
}

.cap-btn:active:not(:disabled) { transform: translateY(2px); filter: drop-shadow(0 1px 0 rgba(0,0,0,.4)); }

.cap-btn:disabled {
  filter: grayscale(.75) brightness(.55) drop-shadow(0 2px 0 rgba(0,0,0,.4));
  opacity: .6;
  cursor: default;
}

.help-btn {
  width: calc(var(--cap) * 0.56);
  height: calc(var(--cap) * 0.56);
  margin-bottom: calc(var(--cap) * 0.06);
  border: 2px solid #0b0d0f;
  border-radius: 3px;
  background: linear-gradient(180deg, #4a525b, #2b3138);
  box-shadow: inset 0 0 0 1px rgba(244,239,226,.2), inset 0 2px 0 rgba(255,255,255,.1), 0 3px 0 #0b0d0f;
  font-family: "Alfa Slab One", Georgia, serif;
  font-size: calc(var(--cap) * 0.34);
  line-height: 1;
  color: #f4efe2;
  text-shadow: 0 1px 0 #000;
}

.help-btn:active { transform: translateY(2px); box-shadow: inset 0 0 0 1px rgba(244,239,226,.2), 0 1px 0 #0b0d0f; }

.dpad {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, var(--cap));
  grid-template-rows: repeat(2, var(--cap));
  gap: 4px;
}

.arrow {
  position: relative;
  width: var(--cap);
  height: var(--cap);
  filter: drop-shadow(0 3px 0 rgba(0,0,0,.42));
  transition: filter 70ms linear;
}

.arrow::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(#ff8438, #ff8438), url("elements/keycap_buttons_04_keycap_down.webp");
  background-size: 100% 100%, 100% 100%;
  background-repeat: no-repeat;
  background-blend-mode: multiply;
}

.arrow::after {
  content: "";
  position: absolute;
  left: 30%;
  top: 29%;
  width: 40%;
  height: 42%;
  background: #fff2d2;
  clip-path: polygon(50% 2%, 98% 48%, 68% 48%, 68% 96%, 32% 96%, 32% 48%, 2% 48%);
  filter: drop-shadow(0 2px 0 rgba(96,34,8,.85));
}

.arrow.up { grid-column: 2; grid-row: 1; }
.arrow.left { grid-column: 1; grid-row: 2; transform: rotate(-90deg); }
.arrow.down { grid-column: 2; grid-row: 2; transform: rotate(180deg); }
.arrow.right { grid-column: 3; grid-row: 2; transform: rotate(90deg); }

.arrow:active { filter: brightness(1.32) drop-shadow(0 0 7px rgba(255,196,96,.95)) drop-shadow(0 1px 0 rgba(0,0,0,.42)); }
.arrow.left:active { transform: rotate(-90deg) translateY(2px); }
.arrow.down:active { transform: rotate(180deg) translateY(2px); }
.arrow.right:active { transform: rotate(90deg) translateY(2px); }
.arrow.up:active { transform: translateY(2px); }

.fineprint {
  margin: 0;
  min-height: 10px;
  text-align: center;
  font-size: clamp(8px, 2.2vw, 10px);
  letter-spacing: .04em;
  color: #79838a;
}

/* ---------------- landscape ---------------- */

@media (orientation: landscape) {
  .app {
    max-width: 1220px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(232px, 27vw, 330px);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 6px 10px;
    padding: 6px 8px 6px;
  }

  .roof {
    grid-column: 1 / -1;
    grid-row: 1;
    height: clamp(66px, 16vh, 118px);
    --roofH: clamp(66px, 16vh, 118px);
  }

  .stage {
    grid-column: 1;
    grid-row: 2;
  }

  .console {
    grid-column: 2;
    grid-row: 2;
    justify-content: space-between;
    min-height: 0;
  }

  .plate { height: clamp(100px, 22vh, 142px); }

  .console { --cap: clamp(42px, 8.2vh, 58px); }

  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .utils { justify-content: center; }

  .dpad { align-self: center; }

  .mission {
    font-size: 9px;
    gap: 4px;
  }

  .mission img { height: 15px; }

  .fineprint { display: none; }
}

@media (max-height: 730px) {
  .card { padding: 10px 11px 11px; }
  .card h2 { font-size: clamp(16px, 5vw, 21px); }
  .card .kicker { margin-bottom: 4px; padding-bottom: 4px; }
  .card .intro { display: none; }
  .card .rules { margin: 5px 0 7px; padding: 5px 7px; font-size: clamp(10px, 2.9vw, 12px); line-height: 1.3; }
  .card .rules li { margin-bottom: 2px; }
  .card-actions { margin-top: 2px; }
  .big-key { height: 50px; }
  .card p { margin-bottom: 5px; }
  .card .score-box { margin: 5px 0 6px; padding: 5px 8px; }
}

@media (max-width: 370px) {
  .app { gap: 4px; padding-left: 4px; padding-right: 4px; }
  .console { --cap: clamp(42px, 12.4vw, 52px); }
  .hint { font-size: 9px; }
  .plate { height: 100px; }
  .scoreline { font-size: 7.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .flip { animation: none; }
  .pip.new { animation: none; }
}
