:root {
  color-scheme: dark;
  --ink: #fff8ee;
  --muted: #b9c4d8;
  --line: rgba(255, 255, 255, 0.18);
  --panel: rgba(12, 21, 42, 0.94);
  --blue: #54c7ff;
  --store-blue: #1266ff;
  --yellow: #ffd166;
  --green: #42d97b;
  --pink: #ff5ca8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 92, 168, 0.2), transparent 28%),
    radial-gradient(circle at 84% 12%, rgba(84, 199, 255, 0.24), transparent 30%),
    linear-gradient(155deg, #08122d 0%, #102b68 52%, #090f1f 100%);
  color: var(--ink);
  touch-action: none;
  user-select: none;
}

button,
input {
  font: inherit;
}

.shell {
  display: grid;
  width: 100vw;
  height: 100svh;
  min-height: 100svh;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  place-items: center;
}

@supports (height: 100dvh) {
  .shell {
    height: 100dvh;
    min-height: 100dvh;
  }
}

.game {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: clamp(7px, 1.2dvh, 11px);
  width: min(100%, 520px);
  height: min(100%, 920px);
  min-height: 0;
}

.brand-header {
  display: grid;
  min-height: clamp(40px, 7dvh, 62px);
  place-items: center;
  text-align: center;
}

.dash-logo {
  color: transparent;
  font-size: clamp(1.65rem, min(7.4dvw, 5.8dvh), 3.1rem);
  font-weight: 1000;
  line-height: 0.9;
  background: linear-gradient(90deg, #ffd166 0%, #ff5ca8 36%, #54c7ff 72%, #fff8ee 100%);
  background-clip: text;
  -webkit-background-clip: text;
  filter: drop-shadow(0 5px 0 rgba(5, 10, 24, 0.5)) drop-shadow(0 0 16px rgba(84, 199, 255, 0.34));
  letter-spacing: 0;
  text-transform: uppercase;
}

.site-tag {
  margin-top: 3px;
  color: rgba(255, 248, 238, 0.78);
  font-size: clamp(0.62rem, min(2.2dvw, 1.9dvh), 0.88rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.topbar,
.bottombar {
  display: grid;
  align-items: center;
  gap: clamp(6px, 1.3dvw, 10px);
}

.topbar {
  grid-template-columns: repeat(3, 1fr);
}

.bottombar {
  grid-template-columns: 0.78fr 1fr 1fr 0.78fr 1.2fr;
}

.metric {
  min-width: 0;
  padding: clamp(6px, 1dvh, 9px) 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.09);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.2);
}

.metric.center {
  text-align: center;
}

.metric.right {
  text-align: right;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 850;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 1px;
  overflow: hidden;
  font-size: clamp(1.02rem, 3.1dvh, 1.42rem);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    rgba(4, 10, 28, 0.86);
  background-size: 34px 34px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 18px 45px rgba(0, 0, 0, 0.3);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.toast {
  position: absolute;
  left: 50%;
  top: 44%;
  max-width: min(86%, 340px);
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(8, 14, 30, 0.9);
  color: var(--yellow);
  font-weight: 950;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, -50%) scale(0.95);
}

.toast.show {
  animation: toastPop 1300ms ease-out;
}

.toast.show.encounter-message {
  max-width: min(92%, 520px);
  animation-duration: 3000ms;
  font-size: clamp(0.98rem, 3.8vw, 1.25rem);
}

.small-button,
.secondary-button,
.primary-button,
.arcade-button,
.store-button {
  min-height: clamp(38px, 6.2dvh, 48px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.small-button {
  padding: 0 8px;
  font-size: clamp(0.72rem, min(3dvw, 1.75dvh), 0.92rem);
}

.icon-button {
  display: grid;
  place-items: center;
  font-size: 1.2rem;
}

.primary-button {
  width: 100%;
  margin-top: 10px;
  border: 0;
  background: var(--blue);
  color: #081122;
  box-shadow: 0 10px 28px rgba(84, 199, 255, 0.24);
}

.secondary-button,
.arcade-button,
.store-button {
  width: 100%;
  margin-top: 10px;
}

.arcade-button {
  border-color: rgba(84, 199, 255, 0.48);
  background: rgba(84, 199, 255, 0.34);
}

.store-button {
  border-color: rgba(84, 199, 255, 0.42);
  background: rgba(84, 199, 255, 0.14);
}

.buy-button,
.thing-button {
  border-color: rgba(84, 199, 255, 0.62);
  background: rgba(84, 199, 255, 0.24);
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  padding: 18px;
  place-items: center;
  background: rgba(5, 8, 18, 0.68);
  backdrop-filter: blur(10px);
}

.overlay.show {
  display: grid;
}

.panel {
  width: min(100%, 390px);
  max-height: calc(100svh - 32px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  text-align: center;
}

@supports (height: 100dvh) {
  .panel {
    max-height: calc(100dvh - 32px);
  }
}

.kicker {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 950;
  text-transform: uppercase;
}

.panel h1 {
  margin: 0;
  font-size: clamp(2rem, 9dvw, 3.3rem);
  line-height: 0.95;
}

.panel p {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.score-form {
  margin-top: 16px;
}

.tutorial-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.tutorial-panel div {
  display: grid;
  min-width: 0;
  gap: 6px;
  padding: 10px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
}

.tutorial-panel strong {
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 950;
  text-transform: uppercase;
}

.tutorial-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.15;
}

.tutorial-icon {
  position: relative;
  display: block;
  width: 46px;
  height: 34px;
  border: 3px solid #071225;
}

.box-icon {
  border-radius: 8px;
  background: #ff8a5b;
}

.tag-icon {
  border-radius: 8px;
  background: #ff5ca8;
}

.tag-icon::after {
  content: "SALE";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff8ee;
  font-size: 0.62rem;
  font-weight: 1000;
}

.cart-icon {
  height: 30px;
  border-radius: 8px;
  background: #54c7ff;
}

.cart-icon::before,
.cart-icon::after {
  content: "";
  position: absolute;
  bottom: -8px;
  width: 9px;
  height: 9px;
  border: 2px solid #071225;
  border-radius: 50%;
  background: #fff8ee;
}

.cart-icon::before {
  left: 7px;
}

.cart-icon::after {
  right: 7px;
}

.score-form label,
.home-scores h2 {
  display: block;
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 950;
  text-transform: uppercase;
}

.initials-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 7px 0 12px;
}

.initials-row input,
.city-input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 0 12px;
}

.initials-row input {
  text-align: center;
  text-transform: uppercase;
}

.city-input {
  margin-top: 7px;
}

.home-scores {
  margin-top: 16px;
  max-height: min(230px, 32dvh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.06);
}

.home-scores ol {
  margin: 0;
  padding-left: 0;
  list-style-position: inside;
  font-variant-numeric: tabular-nums;
}

.home-scores li {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-form[hidden],
.tutorial-panel[hidden],
.home-scores[hidden],
.secondary-button[hidden],
.arcade-button[hidden],
.store-button[hidden] {
  display: none;
}

.high-score {
  min-height: 1.35em;
  font-weight: 800;
}

@keyframes toastPop {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.92); }
  16% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  76% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.96); }
}

@media (max-height: 640px) {
  .shell {
    padding: max(5px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
      max(5px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

  .game {
    gap: 5px;
  }

  .brand-header {
    min-height: 34px;
  }

  .site-tag {
    display: none;
  }

  .metric {
    padding: 5px 7px;
  }

  .metric-label {
    font-size: 0.62rem;
  }

  .small-button {
    padding: 0 5px;
    font-size: 0.68rem;
    min-height: 36px;
  }

  .panel {
    max-height: calc(100svh - 16px);
    padding: 14px;
  }
}

.pause-action-row {
  display: contents;
}

.pause-action-row:has(> button:not([hidden]) + button:not([hidden])) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.pause-action-row:has(> button:not([hidden]) + button:not([hidden])) > button {
  width: 100% !important;
  min-width: 0;
  margin-top: 0 !important;
  margin-right: 0 !important;
}
.arcade-store-arcade-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.22em;
  width: 100%;
  margin: 0 0 14px;
  border: 2px solid #1266ff;
  background: #ffffff;
  color: #071225;
  box-shadow: 0 0 0 2px rgba(18, 102, 255, 0.16), 0 8px 20px rgba(18, 102, 255, 0.2);
  text-transform: none;
}

.arcade-store-arcade-button span:nth-child(2) {
  color: #1266ff;
  text-transform: uppercase;
}

.arcade-store-arcade-button:hover,
.arcade-store-arcade-button:focus-visible {
  background: #ffffff;
  color: #071225;
  outline: 3px solid rgba(84, 199, 255, 0.55);
  outline-offset: 3px;
}
/* Shared 3D arcade button polish. */
.arcade-store-arcade-button {
  gap: 0;
  border: 2px solid #1266ff;
  background: linear-gradient(180deg, #ffffff 0%, #f2f8ff 44%, #d4e8ff 100%);
  color: #071225;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.95), inset 0 -4px 0 rgba(18,102,255,.2), 0 8px 20px rgba(18,102,255,.22);
  text-shadow: 0 1px 0 rgba(255,255,255,.8);
}

.arcade-store-arcade-button .bleep-blue,
.arcade-store-arcade-button span:nth-child(2) {
  color: #1266ff;
  text-transform: uppercase;
}

.arcade-store-arcade-button:hover,
.arcade-store-arcade-button:focus-visible {
  background: linear-gradient(180deg, #ffffff 0%, #eaf4ff 42%, #bfdcff 100%);
  color: #071225;
  outline: 3px solid rgba(84,199,255,.58);
  outline-offset: 3px;
}

.primary-button {
  background: linear-gradient(180deg, color-mix(in srgb, var(--blue, #54c7ff) 34%, #fff) 0%, var(--blue, #54c7ff) 52%, color-mix(in srgb, var(--blue, #54c7ff) 72%, #071225) 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.42), inset 0 -4px 0 rgba(5,10,24,.22), 0 8px 18px rgba(0,0,0,.26);
}

.secondary-button,
.small-button {
  background: linear-gradient(180deg, color-mix(in srgb, var(--yellow, #ffd166) 34%, #fff) 0%, var(--yellow, #ffd166) 54%, color-mix(in srgb, var(--yellow, #ffd166) 72%, #8a5a00) 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.48), inset 0 -4px 0 rgba(89,51,0,.22), 0 7px 16px rgba(0,0,0,.24);
}

.store-button,
.buy-button {
  background: linear-gradient(180deg, rgba(255,255,255,.2) 0%, rgba(255,255,255,.1) 50%, rgba(5,10,24,.22) 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.2), inset 0 -4px 0 rgba(5,10,24,.22), 0 7px 16px rgba(0,0,0,.22);
}
/* Compact high-score entry row: Initials, City, Save. */
.score-form {
  display: grid;
  grid-template-columns: minmax(4.2rem, 4.9rem) minmax(0, 1fr) auto;
  gap: 6px 8px;
  align-items: end;
}

.score-form label[for="initialsInput"] {
  grid-column: 1;
  grid-row: 1;
}

.score-form label[for="cityInput"] {
  grid-column: 2;
  grid-row: 1;
}

.initials-row {
  display: contents;
}

.initials-row input,
#initialsInput {
  grid-column: 1;
  grid-row: 2;
  width: 4.8rem;
  min-width: 0;
  text-align: center;
}

.city-input,
#cityInput {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
}

.initials-row button,
.score-form button[type="submit"] {
  grid-column: 3;
  grid-row: 2;
  min-width: 4.1rem;
  padding-inline: 10px;
}

.score-form datalist {
  display: none;
}

.score-form .high-score,
#highScoreText {
  grid-column: 1 / -1;
}
/* Keep the Arcade return button visible on initials/end-game overlays. */
.overlay {
  align-items: flex-start !important;
  overflow: auto !important;
  padding-top: max(10px, env(safe-area-inset-top)) !important;
  padding-bottom: max(10px, env(safe-area-inset-bottom)) !important;
}

.panel {
  max-height: calc(100dvh - 20px) !important;
}

.arcade-store-arcade-button {
  position: sticky;
  top: 0;
  z-index: 5;
}
