:root {
  color-scheme: dark;
  --bg: #07111f;
  --bg-2: #0b1b2d;
  --surface: rgba(10, 25, 43, 0.82);
  --text: #f7fbff;
  --muted: #a9b8c9;
  --accent: #c8ff5a;
  --accent-2: #ff8b78;
  --radius: 22px;
  --font: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
  --display: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
  --glass: rgba(7, 20, 36, 0.76);
  --glass-strong: rgba(7, 18, 33, 0.94);
  --line: rgba(255, 255, 255, 0.13);
  --shadow: 0 22px 70px rgba(0, 5, 15, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

button,
[role="button"] {
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 12%, rgba(151, 211, 240, 0.34), transparent 48%),
    linear-gradient(180deg, #8bc5df 0%, #b9ddec 48%, #142b3b 100%);
}

#game canvas,
canvas {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  touch-action: none;
}

#game canvas {
  user-select: none;
  -webkit-user-select: none;
}

/* Broadcast HUD */
#hud {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 100%;
  padding:
    calc(env(safe-area-inset-top, 0px) + 14px)
    calc(env(safe-area-inset-right, 0px) + 14px)
    calc(env(safe-area-inset-bottom, 0px) + 16px)
    calc(env(safe-area-inset-left, 0px) + 14px);
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

#hud > * {
  min-width: 0;
}

/* Keep the starter HUD's pill styling off our structural rows. */
#hud {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  align-items: end;
  gap: 12px;
}

#hud > .hud-stats,
#hud > .power-meter,
#hud > .hud-actions {
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

#hud > .hud-stats {
  grid-row: 1;
  align-self: start;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 440px);
}

.hud-stats .stat {
  display: grid;
  grid-template-rows: auto auto;
  place-items: initial;
  gap: 5px;
  width: auto;
  height: auto;
  min-width: 0;
  padding: 9px 6px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(7, 20, 38, 0.88);
  box-shadow: 0 8px 24px rgba(0, 8, 20, 0.2);
  text-align: center;
}

.hud-stats .stat > span {
  display: block;
  color: #eef6ff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hud-stats .stat > b {
  display: flex;
  min-height: 0;
  padding: 5px 4px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  font-size: 13px;
  text-shadow: none;
}

#hud > .power-meter {
  grid-row: 3;
  display: grid;
  justify-items: center;
  gap: 7px;
  width: min(100%, 360px);
  justify-self: center;
  padding: 10px 14px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(7, 20, 38, 0.88);
}

.power-label {
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.7);
}

#hud > .hud-actions {
  grid-row: 4;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: min(100%, 440px);
  justify-self: center;
}

.hud-actions button {
  width: 100%;
  min-width: 0;
}

#hud > .row,
#hud > .hud,
#hud > div {
  pointer-events: none;
}

#hud .row {
  align-items: center;
  gap: 8px;
}

#hud button,
#hud .btn,
#camera-btn,
#sound-btn,
#pause-btn {
  pointer-events: auto;
}

#hole-label,
#par-label,
#stroke-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(7, 20, 38, 0.88);
  box-shadow: 0 8px 24px rgba(0, 8, 20, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(16px) saturate(135%);
  -webkit-backdrop-filter: blur(16px) saturate(135%);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.075em;
  text-transform: uppercase;
  white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

#hole-label {
  border-color: rgba(200, 255, 90, 0.36);
  color: var(--accent);
}

#stroke-label {
  min-width: 82px;
}

#camera-btn,
#sound-btn,
#pause-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  height: 48px;
  min-height: 48px;
  margin: 0;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.17);
  border-radius: 15px;
  background: rgba(7, 20, 38, 0.88);
  box-shadow: 0 8px 24px rgba(0, 8, 20, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px) saturate(135%);
  -webkit-backdrop-filter: blur(16px) saturate(135%);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background-color 140ms ease;
}

.hud-actions svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#camera-btn:hover,
#sound-btn:hover,
#pause-btn:hover {
  border-color: rgba(200, 255, 90, 0.55);
  background: rgba(15, 36, 57, 0.94);
  transform: translateY(-2px);
}

#camera-btn:active,
#sound-btn:active,
#pause-btn:active {
  transform: translateY(0) scale(0.95);
}

#camera-btn:focus-visible,
#sound-btn:focus-visible,
#pause-btn:focus-visible,
#start-btn:focus-visible,
#next-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* Power meter: its track is whichever element directly contains the fill. */
#hud *:has(> #power-fill) {
  position: relative;
  width: 100%;
  max-width: 320px;
  height: 12px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 999px;
  background: rgba(4, 14, 27, 0.96);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.35);
}

#power-fill {
  display: block;
  width: 0%;
  max-width: 100%;
  height: 100%;
  min-height: 10px;
  border-radius: inherit;
  background: linear-gradient(90deg, #a8ef48 0%, var(--accent) 68%, #dcff91 100%);
  box-shadow: 0 0 16px rgba(200, 255, 90, 0.55);
  transform-origin: left center;
  transition: width 60ms linear, filter 140ms ease;
  will-change: width;
}

#hud.aiming *:has(> #power-fill),
#hud.is-aiming *:has(> #power-fill),
#hud[data-aiming="true"] *:has(> #power-fill),
body.aiming #hud *:has(> #power-fill) {
  min-height: 12px;
  border-color: rgba(200, 255, 90, 0.75);
  box-shadow: 0 0 0 4px rgba(200, 255, 90, 0.12), 0 8px 28px rgba(0, 5, 14, 0.34);
  animation: power-pulse 1.1s ease-in-out infinite alternate;
}

#hud.aiming #power-fill,
#hud.is-aiming #power-fill,
#hud[data-aiming="true"] #power-fill,
body.aiming #power-fill {
  filter: brightness(1.12) saturate(1.12);
}

@keyframes power-pulse {
  from { box-shadow: 0 0 0 3px rgba(200, 255, 90, 0.09), 0 8px 26px rgba(0, 5, 14, 0.3); }
  to { box-shadow: 0 0 0 6px rgba(200, 255, 90, 0.17), 0 8px 30px rgba(0, 5, 14, 0.38); }
}

#hint {
  position: fixed;
  z-index: 12;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 140px);
  width: max-content;
  max-width: calc(100vw - 36px);
  margin: 0;
  padding: 9px 15px;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  background: rgba(7, 20, 38, 0.88);
  box-shadow: 0 8px 24px rgba(0, 6, 16, 0.22);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: #f7fbff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0.025em;
  text-align: center;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

/* Title, pause and results */
.overlay {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 100%;
  padding:
    calc(env(safe-area-inset-top, 0px) + 24px)
    calc(env(safe-area-inset-right, 0px) + 18px)
    calc(env(safe-area-inset-bottom, 0px) + 24px)
    calc(env(safe-area-inset-left, 0px) + 18px);
  overflow: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at 50% 18%, rgba(99, 159, 190, 0.2), transparent 46%),
    rgba(3, 12, 23, 0.66);
  backdrop-filter: blur(12px) saturate(110%);
  -webkit-backdrop-filter: blur(12px) saturate(110%);
  animation: overlay-in 240ms ease-out both;
}

.panel {
  position: relative;
  width: 100%;
  max-width: 380px;
  max-height: calc(100dvh - 48px);
  padding: 30px 26px 26px;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.065), transparent 45%),
    var(--glass-strong);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  color: var(--text);
  text-align: center;
  animation: panel-in 360ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 26px;
  right: 26px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.85;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(16px) scale(0.975); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.brand {
  margin: 4px 0 12px;
  color: #fff;
  font-family: var(--display);
  font-size: clamp(38px, 12vw, 56px);
  font-weight: 700;
  line-height: 0.98;
  letter-spacing: -0.065em;
  text-wrap: balance;
}

.brand::first-letter {
  color: var(--accent);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.help {
  margin: 18px auto 22px;
  color: #c2cfdd;
  font-size: 14px;
  line-height: 1.65;
  text-wrap: balance;
}

.help > p {
  display: grid;
  gap: 4px;
  margin: 0 0 14px;
}

.help > p:last-child {
  margin-bottom: 0;
}

.help > p > span {
  display: block;
}

.help .shortcuts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 14px;
  margin-top: 16px;
  font-size: 12px;
}

.help .shortcuts > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.help kbd {
  min-width: 24px;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  font: 700 12px/1.2 var(--font);
}

.help strong {
  color: #fff;
  font-weight: 650;
}

#start-btn,
#next-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 54px;
  margin: 4px 0 0;
  padding: 14px 22px;
  border: 0;
  border-radius: 15px;
  background: var(--accent);
  box-shadow: 0 10px 28px rgba(164, 224, 65, 0.2), inset 0 -2px 0 rgba(50, 76, 11, 0.15);
  color: #102005;
  font-size: 15px;
  font-weight: 750;
  line-height: 1.2;
  letter-spacing: 0.025em;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, filter 150ms ease;
}

#start-btn:hover,
#next-btn:hover {
  filter: brightness(1.06);
  box-shadow: 0 13px 34px rgba(164, 224, 65, 0.29), inset 0 -2px 0 rgba(50, 76, 11, 0.13);
  transform: translateY(-2px);
}

#start-btn:active,
#next-btn:active {
  box-shadow: 0 5px 16px rgba(164, 224, 65, 0.18);
  transform: translateY(1px) scale(0.99);
}

#result-title {
  margin: 2px 0 10px;
  color: #fff;
  font-family: var(--display);
  font-size: clamp(28px, 8vw, 38px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.04em;
  text-wrap: balance;
}

#result-copy {
  margin: 0 0 20px;
  color: #bfcedd;
  font-size: 15px;
  line-height: 1.6;
}

#result-copy strong,
#result-copy b {
  color: var(--accent);
  font-weight: 700;
}

.title-panel .sources {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px 12px;
  margin: 0 0 18px;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.sources strong {
  flex-basis: 100%;
  color: #dce7f2;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sources a {
  color: var(--muted);
  text-decoration: none;
}

.sources a:hover,
.sources a:focus-visible {
  color: var(--accent);
  text-decoration: underline;
}

#start-btn,
#next-btn {
  position: relative;
  z-index: 1;
  margin-top: 0;
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  margin: 8px 0;
  padding: 11px 14px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.045);
  color: #dce7f1;
  font-size: 14px;
  text-align: left;
}

.score-row > :last-child,
.score-row strong,
.score-row b {
  color: #fff;
  font-weight: 700;
  text-align: right;
}

.score-row:last-of-type {
  border-color: rgba(200, 255, 90, 0.26);
  background: rgba(200, 255, 90, 0.075);
}

#toast {
  position: fixed;
  z-index: 45;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 136px);
  width: max-content;
  max-width: calc(100vw - 36px);
  margin: 0;
  padding: 12px 18px;
  transform: translateX(-50%);
  border: 1px solid rgba(200, 255, 90, 0.3);
  border-radius: 14px;
  background: rgba(7, 22, 38, 0.94);
  box-shadow: 0 12px 34px rgba(0, 5, 15, 0.35);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: #fff;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
  animation: toast-in 220ms ease-out both;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (pointer: coarse), (max-width: 600px) {
  #hud {
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: 8px;
    padding:
      calc(env(safe-area-inset-top, 0px) + 10px)
      calc(env(safe-area-inset-right, 0px) + 10px)
      calc(env(safe-area-inset-bottom, 0px) + 10px)
      calc(env(safe-area-inset-left, 0px) + 10px);
  }

  .hud-stats .stat {
    gap: 4px;
    padding: 7px 4px 8px;
    border-radius: 12px;
  }

  .hud-stats .stat > span {
    font-size: 12px;
  }

  #hole-label,
  #par-label,
  #stroke-label {
    min-height: 0;
    padding: 4px 2px;
    font-size: 12px;
  }

  #stroke-label {
    min-width: 0;
  }

  #hud > .power-meter {
    gap: 6px;
    padding: 8px 12px 10px;
  }

  #hud > .hud-actions {
    gap: 8px;
  }

  #camera-btn,
  #sound-btn,
  #pause-btn {
    min-width: 44px;
    gap: 5px;
    height: 44px;
    min-height: 44px;
    padding: 0 7px;
    border-radius: 12px;
    font-size: 12px;
  }

  .hud-actions svg {
    width: 16px;
    height: 16px;
  }

  #hint,
  #toast {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 132px);
    max-width: calc(100vw - 24px);
    padding: 8px 12px;
    font-size: 13px;
  }

  .panel {
    padding: 24px 20px 22px;
  }

  .help {
    margin: 14px auto 16px;
  }

  .title-panel .sources {
    margin-bottom: 16px;
  }
}

@media (min-width: 700px) {
  #hud {
    padding:
      calc(env(safe-area-inset-top, 0px) + 22px)
      calc(env(safe-area-inset-right, 0px) + 26px)
      calc(env(safe-area-inset-bottom, 0px) + 24px)
      calc(env(safe-area-inset-left, 0px) + 26px);
  }

  #hole-label,
  #par-label,
  #stroke-label {
    min-height: 46px;
    padding-inline: 18px;
    font-size: 13px;
  }

  #camera-btn,
  #sound-btn,
  #pause-btn {
    width: 50px;
    min-width: 50px;
    height: 50px;
    min-height: 50px;
  }

  #hint {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 140px);
    font-size: 13px;
  }

  .panel {
    padding: 34px 30px 28px;
  }
}

@media (max-height: 620px) and (orientation: landscape) {
  #hud {
    padding-top: calc(env(safe-area-inset-top, 0px) + 9px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 9px);
  }

  #hole-label,
  #par-label,
  #stroke-label {
    min-height: 38px;
    padding: 7px 11px;
  }

  #camera-btn,
  #sound-btn,
  #pause-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }

  #hint {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 112px);
  }

  .overlay {
    padding-top: 12px;
    padding-bottom: 12px;
  }

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

  .brand {
    font-size: 38px;
  }

  .help {
    margin: 10px auto 14px;
    line-height: 1.45;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
