:root {
  color-scheme: dark;
  --ink: #fff8ee;
  --muted: #b8c7db;
  --line: rgba(255, 255, 255, 0.18);
  --panel: rgba(10, 18, 38, 0.94);
  --blue: #54c7ff;
  --store-blue: #1266ff;
  --yellow: #ffd166;
  --pink: #ff5ca8;
  --green: #42d97b;
  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 16% 14%, rgba(255, 92, 168, 0.24), transparent 28%),
    radial-gradient(circle at 86% 10%, rgba(84, 199, 255, 0.26), transparent 30%),
    linear-gradient(155deg, #07142e 0%, #14377d 52%, #080e20 100%);
  color: var(--ink);
  touch-action: none;
  user-select: none;
}

button,
input {
  font: inherit;
}

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

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

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.bottombar {
  display: grid;
  grid-template-columns: minmax(92px, 1fr) auto auto auto auto;
  align-items: center;
  gap: 8px;
}

.metric {
  min-width: 82px;
  padding: 8px 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.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

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

#modeText {
  font-size: clamp(0.95rem, 3dvh, 1.28rem);
}

.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.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    rgba(4, 10, 28, 0.8);
  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: 48%;
  transform: translate(-50%, -50%) scale(0.96);
  color: var(--yellow);
  font-size: 1.35rem;
  font-weight: 950;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  text-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
}

.bleeping-word {
  display: inline-block;
  font-size: 1.85em;
  line-height: 0.78;
  text-transform: uppercase;
}

.toast.pop {
  animation: toastPop 1400ms ease-out;
}

.small-button,
.primary-button,
.secondary-button,
.arcade-button,
.store-button,
.mode-option {
  border-radius: 8px;
  cursor: pointer;
  font-weight: 950;
}

.small-button,
.primary-button {
  border: 0;
  background: var(--yellow);
  color: #101827;
}

.small-button {
  min-height: 46px;
  padding: 0 14px;
}

.icon-button {
  width: 46px;
  min-width: 46px;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
}

.rules-mini {
  min-width: 54px;
  padding: 0 10px;
  font-size: 0.86rem;
}

.star-button {
  width: 50px;
  min-width: 50px;
  padding: 0;
  background: rgba(255, 255, 255, 0.1);
}

.star-shape,
.hero-star-fly {
  display: grid;
  width: 34px;
  height: 34px;
  margin: auto;
  place-items: center;
  clip-path: polygon(50% 0%, 61% 34%, 98% 35%, 68% 56%, 79% 91%, 50% 70%, 21% 91%, 32% 56%, 2% 35%, 39% 34%);
  background: linear-gradient(160deg, #ffe88b, #ffd166 48%, #f5a900);
  color: #111827;
  font-size: 0.78rem;
  font-weight: 1000;
  line-height: 1;
  text-align: center;
  text-shadow: none;
  box-shadow: 0 0 14px rgba(255, 209, 102, 0.45);
}

.star-button.empty .star-shape {
  background: linear-gradient(160deg, #a6adb8, #6d7580 52%, #434a55);
  color: #e6ebf2;
  box-shadow: none;
}

.star-button.armed {
  outline: 2px solid rgba(255, 209, 102, 0.92);
  outline-offset: 2px;
}

.hero-star-fly {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: heroStarFly 1450ms cubic-bezier(0.2, 0.72, 0.22, 1) forwards;
}

.primary-button,
.secondary-button,
.arcade-button,
.store-button {
  width: 100%;
  min-height: 46px;
  margin-top: 12px;
  padding: 0 18px;
}

.primary-button {
  background: var(--blue);
  color: #101827;
  box-shadow: 0 10px 22px rgba(84, 199, 255, 0.22);
}

.secondary-button,
.arcade-button,
.store-button {
  border: 1px solid var(--line);
  color: #fff8ee;
}

.secondary-button {
  background: #2b9ee8;
}

.arcade-button {
  background: #1f75c5;
}

.store-button {
  background: #16539d;
}

.thing-button {
  border-color: rgba(84, 199, 255, 0.86);
  background: rgba(84, 199, 255, 0.08);
  color: #dff4ff;
  box-shadow: inset 0 0 0 1px rgba(84, 199, 255, 0.2), 0 10px 22px rgba(18, 102, 255, 0.12);
}

.secondary-button:hover,
.secondary-button:focus-visible,
.arcade-button:hover,
.arcade-button:focus-visible,
.store-button:hover,
.store-button:focus-visible,
.thing-button:hover,
.thing-button:focus-visible {
  border-color: rgba(84, 199, 255, 0.92);
  filter: brightness(1.1);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow: hidden;
  background: rgba(4, 7, 14, 0.68);
  backdrop-filter: blur(10px);
}

.overlay.show {
  display: flex;
}

.panel {
  width: min(100%, 390px);
  max-height: calc(100dvh - 36px);
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(18, 102, 255, 0.22), rgba(255, 92, 168, 0.08)),
    var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.4);
}

.kicker,
.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;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 8dvw, 3.25rem);
  line-height: 0.94;
}

.panel p:not(.kicker) {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.42;
}

.mode-picker,
.difficulty-picker {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.difficulty-picker {
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.difficulty-bubble {
  display: grid;
  aspect-ratio: 1;
  min-width: 0;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  place-items: center;
  color: #101827;
  cursor: pointer;
  font-size: clamp(0.9rem, 4.4vw, 1.18rem);
  font-weight: 1000;
  text-align: center;
  box-shadow: inset -10px -14px 18px rgba(0, 0, 0, 0.22), inset 8px 10px 16px rgba(255, 255, 255, 0.34), 0 14px 24px rgba(0, 0, 0, 0.28);
}

.difficulty-bubble.easy {
  background: radial-gradient(circle at 32% 25%, #ddffe8 0 12%, #42d97b 38%, #149447 100%);
}

.difficulty-bubble.medium {
  background: radial-gradient(circle at 32% 25%, #fff8cb 0 12%, #ffd166 40%, #d69000 100%);
}

.difficulty-bubble.danger {
  background: radial-gradient(circle at 32% 25%, #ffe1e1 0 12%, #ff5c6d 39%, #c51625 100%);
  color: #fff8ee;
}

.mode-option {
  display: grid;
  gap: 2px;
  min-height: 58px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  text-align: left;
}

.mode-option.active {
  border-color: rgba(84, 199, 255, 0.72);
  background: rgba(84, 199, 255, 0.2);
  box-shadow: inset 0 0 0 1px rgba(84, 199, 255, 0.22);
}

.mode-option span {
  font-size: 1rem;
  font-weight: 950;
}

.mode-option small {
  color: var(--muted);
  font-weight: 800;
  line-height: 1.2;
}

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

.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: 900;
  padding: 0 12px;
}

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

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

.home-scores {
  margin-top: 16px;
  max-height: 190px;
  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-badge {
  display: inline-grid;
  width: 1.35em;
  height: 1.35em;
  margin-right: 0.2em;
  border-radius: 50%;
  place-items: center;
  color: #101827;
  font-size: 0.72em;
  font-weight: 1000;
  vertical-align: 0.08em;
  box-shadow: inset -3px -4px 6px rgba(0, 0, 0, 0.22), inset 2px 3px 5px rgba(255, 255, 255, 0.36);
}

.score-badge.easy {
  background: #42d97b;
}

.score-badge.medium {
  background: #ffd166;
}

.score-badge.danger {
  background: #ff4c5b;
  color: #fff8ee;
}

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

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

.rules-list {
  margin: 14px 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
  line-height: 1.35;
}

.rules-list li {
  margin: 8px 0;
}

@keyframes toastPop {
  0% {
    opacity: 0;
    transform: translate(-50%, -24%) scale(0.9);
  }
  18% {
    opacity: 1;
  }
  74% {
    opacity: 1;
    transform: translate(-50%, -54%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -82%) scale(1.1);
  }
}

@keyframes heroStarFly {
  0% {
    left: var(--star-start-x);
    top: var(--star-start-y);
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.25) rotate(-18deg);
  }
  14% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(2.65) rotate(8deg);
  }
  52% {
    left: var(--star-start-x);
    top: var(--star-start-y);
    opacity: 1;
    transform: translate(-50%, -50%) scale(2.35) rotate(20deg);
  }
  72% {
    left: var(--star-mid-x);
    top: var(--star-mid-y);
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.25) rotate(120deg);
  }
  100% {
    left: var(--star-end-x);
    top: var(--star-end-y);
    opacity: 0.9;
    transform: translate(-50%, -50%) scale(0.45) rotate(220deg);
  }
}

@media (max-height: 650px) {
  .game {
    min-height: 0;
    gap: 7px;
  }

  .metric {
    padding: 6px 8px;
  }

  .panel {
    padding: 14px;
  }

.mode-picker,
.difficulty-picker {
    gap: 6px;
    margin-top: 10px;
  }

  .mode-option {
    min-height: 48px;
  }
}
