* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --page-bg: #050b2b;
  --surface: rgba(7, 24, 65, 0.78);
  --surface-strong: rgba(5, 14, 46, 0.9);
  --line: rgba(136, 241, 255, 0.22);
  --line-hot: rgba(255, 211, 69, 0.46);
  --text: #f7fbff;
  --muted: rgba(247, 251, 255, 0.68);
  --cyan: #2ce5ec;
  --pink: #ff4fa3;
  --gold: #ffd84b;
  --violet: #8b5cff;
  --radius: 8px;
  --focus: 0 0 0 3px rgba(44, 229, 236, 0.38);
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 79, 163, 0.28), transparent 28%),
    radial-gradient(circle at 90% 88%, rgba(44, 229, 236, 0.24), transparent 26%),
    linear-gradient(145deg, #060b2b 0%, #071b49 48%, #25165a 100%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  user-select: none;
  touch-action: none;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.game-root {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 0;
}

.hud {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.hud-card {
  min-height: 55px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(15, 51, 105, 0.9), rgba(6, 16, 48, 0.82)),
    var(--surface);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  display: grid;
  place-items: center;
  gap: 2px;
}

.hud-card span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0;
}

.hud-card strong {
  color: var(--text);
  font-size: clamp(18px, 3vw, 25px);
  line-height: 1;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

#shotsText,
#goldText {
  color: var(--gold);
}

.board-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100vh;
}

#gameCanvas {
  display: block;
  width: min(100vw, 177.7778vh);
  max-height: 100vh;
  aspect-ratio: 16 / 9;
  border-radius: 0;
  background: #06133b;
  box-shadow: none;
  cursor: crosshair;
  touch-action: none;
}

.status-row {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

#goalText {
  color: #ffffff;
  font-weight: 900;
  white-space: nowrap;
}

#statusText {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 8, 30, 0.76);
  backdrop-filter: blur(8px);
}

.overlay.hidden {
  display: none;
}

.overlay-panel {
  width: min(430px, 100%);
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 79, 163, 0.22), transparent 42%),
    linear-gradient(180deg, rgba(11, 37, 86, 0.96), rgba(5, 14, 45, 0.96));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  text-align: center;
}

.overlay-panel.compact {
  width: min(370px, 100%);
}

.mini-peg {
  display: inline-block;
  width: 46px;
  height: 46px;
  border: 5px solid rgba(255, 216, 75, 0.96);
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 24%, rgba(255, 255, 255, 0.86) 0 13%, transparent 14%),
    radial-gradient(circle at 50% 46%, rgba(255, 255, 255, 0.24), transparent 43%),
    linear-gradient(145deg, #ff4fa3, #8b5cff);
  box-shadow:
    0 0 24px rgba(255, 79, 163, 0.34),
    inset 0 -10px 16px rgba(0, 0, 0, 0.18);
}

.mini-peg.paused {
  background:
    radial-gradient(circle at 34% 24%, rgba(255, 255, 255, 0.86) 0 13%, transparent 14%),
    linear-gradient(145deg, #2ce5ec, #2874ff);
}

.overlay h1,
.overlay h2 {
  margin-top: 14px;
  color: #ffffff;
  font-size: clamp(30px, 8vw, 52px);
  line-height: 1.02;
  font-weight: 950;
}

.overlay h2 {
  font-size: clamp(26px, 7vw, 40px);
}

.overlay p {
  margin: 12px auto 0;
  max-width: 34ch;
  color: rgba(247, 251, 255, 0.74);
  font-size: 15px;
  line-height: 1.5;
}

.overlay button {
  min-height: 46px;
  margin-top: 21px;
  padding: 0 25px;
  border: 1px solid rgba(255, 216, 75, 0.68);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #ffd84b, #ff9b31);
  color: #141333;
  font-size: 15px;
  font-weight: 950;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.overlay button:hover {
  transform: translateY(-1px);
  box-shadow: 0 13px 26px rgba(255, 155, 49, 0.3);
}

.overlay button.secondary {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(247, 251, 255, 0.86);
}

.result-score {
  margin-top: 14px;
  color: var(--gold);
  font-size: clamp(42px, 12vw, 64px);
  line-height: 0.96;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.action-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 720px) {
  .game-root {
    padding: 0;
  }

  .hud {
    gap: 5px;
  }

  .hud-card {
    min-height: 48px;
    padding: 7px 4px;
  }

  .hud-card span {
    font-size: 10px;
  }

  .status-row {
    min-height: 34px;
    padding: 7px 9px;
    font-size: 12px;
  }

  #gameCanvas {
    width: min(100vw, 177.7778vh);
    max-height: 100vh;
    border-radius: 0;
  }

  .overlay-panel {
    padding: 24px 18px;
  }
}

@media (max-width: 720px) and (orientation: portrait) {
  .game-root {
    align-content: start;
  }

  .board-wrap {
    align-items: start;
  }

  #gameCanvas {
    width: 100%;
    max-height: none;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .hud-card {
    min-height: 42px;
  }

  .hud-card strong {
    font-size: 18px;
  }

  .status-row {
    display: none;
  }

  #gameCanvas {
    max-height: calc(100vh - 62px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .overlay button {
    transition: none;
  }
}
