@font-face {
  font-family: "Barlow";
  src: url("./fonts/barlow-semibold.ttf") format("truetype");
  font-display: swap;
  font-style: normal;
  font-weight: 600 800;
}

@font-face {
  font-family: "Barlow Condensed";
  src: url("./fonts/barlow-condensed-bold.ttf") format("truetype");
  font-display: swap;
  font-style: normal;
  font-weight: 700 800;
}

:root {
  color-scheme: dark;
  --pitch: #4f6d35;
  --ink: #151d21;
  --ink-soft: #293137;
  --chalk: #f7f4e9;
  --chalk-muted: #c7cbc5;
  --amber: #f2a51a;
  --amber-deep: #c77b08;
  --flight: #fff8da;
  --clay: #c9523f;
  --line: rgba(247, 244, 233, 0.48);
  --safe-top: max(0px, env(safe-area-inset-top));
  --safe-right: max(12px, env(safe-area-inset-right));
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
  --safe-left: max(12px, env(safe-area-inset-left));
  --display: "Barlow Condensed", "Arial Narrow", Haettenschweiler, Impact, sans-serif;
  --body: Barlow, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --focus: 0 0 0 2px var(--ink), 0 0 0 5px var(--flight);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--ink);
  color: var(--chalk);
  font-family: var(--body);
  -webkit-tap-highlight-color: transparent;
}

button,
input { font: inherit; }

button,
a { touch-action: manipulation; }

button { color: inherit; }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  z-index: 200;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  background: var(--chalk);
  color: var(--ink);
  font-weight: 800;
  transform: translateY(-150%);
}

.skip-link:focus { transform: translateY(0); }

#game-app,
#scene-host {
  position: fixed;
  inset: 0;
}

#scene-host {
  z-index: 0;
  background: #8f9a91;
}

#scene-host canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.top-rail {
  position: fixed;
  z-index: 70;
  top: 0;
  left: 0;
  right: 0;
  min-height: calc(56px + var(--safe-top));
  padding: var(--safe-top) var(--safe-right) 0 var(--safe-left);
  display: grid;
  grid-template-columns: minmax(94px, 1fr) auto minmax(94px, 1fr);
  align-items: center;
  background: linear-gradient(180deg, rgba(21, 29, 33, 0.98), rgba(21, 29, 33, 0.9));
  box-shadow: 0 1px 0 rgba(247, 244, 233, 0.2);
}

.back-link,
.icon-button {
  min-width: 44px;
  min-height: 44px;
}

.back-link {
  width: max-content;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--chalk);
  text-decoration: none;
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.09em;
}

.back-link svg,
.icon-button svg,
.spot-button svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.back-link svg { width: 26px; height: 26px; }

.spot-status {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1rem, 2.3vw, 1.32rem);
  font-weight: 700;
  letter-spacing: 0.055em;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

.icon-button {
  justify-self: end;
  padding: 8px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.icon-button svg { width: 27px; height: 27px; }
.icon-button .sound-off { display: none; }
.icon-button[aria-pressed="true"] .sound-on { display: none; }
.icon-button[aria-pressed="true"] .sound-off { display: block; }

.system-panel {
  position: fixed;
  z-index: 100;
  top: 50%;
  left: 50%;
  width: min(390px, calc(100vw - 32px));
  padding: 26px;
  border: 1px solid rgba(247, 244, 233, 0.3);
  border-radius: 6px;
  background: rgba(21, 29, 33, 0.96);
  transform: translate(-50%, -50%);
  text-align: center;
}

.system-panel h1,
.spot-rail h2,
.kicker-rail h2 {
  margin: 2px 0 9px;
  font-family: var(--display);
  font-size: 2.15rem;
  letter-spacing: 0.03em;
  line-height: 0.95;
  text-transform: uppercase;
}

.system-panel p { margin: 0; color: var(--chalk-muted); }

.eyebrow {
  margin: 0;
  color: var(--amber) !important;
  font-family: var(--display);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.loading-line {
  height: 4px;
  margin-top: 20px;
  overflow: hidden;
  background: var(--ink-soft);
}

.loading-line span {
  display: block;
  width: 38%;
  height: 100%;
  background: var(--amber);
  animation: loading 1.1s ease-in-out infinite alternate;
}

@keyframes loading {
  from { transform: translateX(-10%); }
  to { transform: translateX(190%); }
}

.system-actions {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
}

.system-actions a {
  color: var(--chalk);
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.trajectory-input {
  position: fixed;
  z-index: 12;
  inset: calc(56px + var(--safe-top)) 0 0;
  cursor: crosshair;
  touch-action: none;
  outline: 0;
}

.trajectory-input:focus-visible::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 2px solid var(--flight);
  pointer-events: none;
}

.aim-marker {
  position: fixed;
  z-index: 24;
  left: 0;
  top: 0;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 248, 218, 0.9);
  border-radius: 50%;
  box-shadow: 0 0 0 6px rgba(242, 165, 26, 0.12), 0 0 18px rgba(255, 248, 218, 0.3);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.aim-marker::before {
  content: "";
  position: absolute;
  inset: 18px;
  border-radius: 50%;
  background: var(--flight);
}

.coach-copy {
  position: fixed;
  z-index: 34;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 164px);
  margin: 0;
  color: var(--flight);
  font-family: var(--display);
  font-size: clamp(1rem, 2.7vw, 1.28rem);
  letter-spacing: 0.035em;
  text-shadow: 0 2px 7px #000;
  transform: translateX(-50%);
  pointer-events: none;
  white-space: nowrap;
}

.coach-copy[data-tone="error"] { color: #ffd2c8; }

.control-rail,
.result-panel,
.spot-rail,
.kicker-rail {
  position: fixed;
  z-index: 50;
  left: 0;
  right: 0;
  bottom: 0;
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  background: linear-gradient(180deg, rgba(21, 29, 33, 0), rgba(21, 29, 33, 0.84) 24%, rgba(21, 29, 33, 0.98));
}

.control-rail {
  min-height: 150px;
  padding-top: 26px;
  display: grid;
  grid-template-columns: minmax(168px, 204px) minmax(180px, 440px) 108px;
  justify-content: space-between;
  align-items: end;
  gap: clamp(10px, 3vw, 32px);
  pointer-events: none;
}

.control-rail > * { pointer-events: auto; }

.primary-button,
.secondary-button,
.curve-presets button,
.spot-options button,
.kicker-options button,
.rail-close {
  min-height: 44px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.055em;
}

.primary-button {
  border: 1px solid #ffbc3e;
  background: var(--amber);
  color: var(--ink);
}

.secondary-button {
  border: 1px solid rgba(247, 244, 233, 0.9);
  background: rgba(21, 29, 33, 0.82);
  color: var(--chalk);
}

.control-selectors {
  display: grid;
  grid-template-columns: repeat(2, minmax(78px, 1fr));
  gap: 8px;
}

.selector-button {
  min-height: 64px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  font-size: 0.98rem;
}

.spot-button svg { width: 28px; height: 28px; }

.kicker-button {
  grid-template-rows: auto auto;
  padding: 8px 6px;
}

.kicker-button .selector-label {
  color: var(--chalk-muted);
  font-size: 0.68rem;
  letter-spacing: 0.09em;
}

.kicker-button strong {
  color: var(--amber);
  font-family: var(--display);
  font-size: 1.08rem;
  letter-spacing: 0.08em;
}

.shot-inputs { align-self: end; min-width: 0; }

.draw-prompt {
  margin: 0 0 4px;
  color: var(--flight);
  font-family: var(--display);
  text-align: center;
  text-shadow: 0 1px 5px #000;
}

.power-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.power-heading label,
.power-heading output {
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.power-heading output { font-size: 1.12rem; }

input[type="range"] {
  width: 100%;
  min-height: 44px;
  height: 44px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
  --band-start: 36%;
  --band-end: 58%;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 11px;
  border: 1px solid rgba(247, 244, 233, 0.58);
  border-radius: 0;
  background: linear-gradient(
    to right,
    rgba(21, 29, 33, 0.82) 0 var(--band-start),
    var(--amber-deep) var(--band-start) var(--band-end),
    rgba(21, 29, 33, 0.82) var(--band-end) 100%
  );
}

input[type="range"]::-moz-range-track {
  height: 11px;
  border: 1px solid rgba(247, 244, 233, 0.58);
  border-radius: 0;
  background: linear-gradient(
    to right,
    rgba(21, 29, 33, 0.82) 0 var(--band-start),
    var(--amber-deep) var(--band-start) var(--band-end),
    rgba(21, 29, 33, 0.82) var(--band-end) 100%
  );
}

input[type="range"]::-webkit-slider-thumb {
  width: 4px;
  height: 27px;
  margin-top: -9px;
  appearance: none;
  border: 0;
  border-radius: 0;
  background: var(--chalk);
  box-shadow: 0 0 0 1px rgba(21, 29, 33, 0.45);
}

input[type="range"]::-moz-range-thumb {
  width: 4px;
  height: 27px;
  border: 0;
  border-radius: 0;
  background: var(--chalk);
}

.power-state {
  min-height: 1em;
  margin: -2px 0 0;
  color: var(--chalk-muted);
  font-size: 0.69rem;
  font-weight: 700;
  text-align: center;
}

.curve-presets {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.curve-presets button {
  min-width: 44px;
  padding: 0 8px;
  border: 1px solid rgba(247, 244, 233, 0.35);
  background: rgba(21, 29, 33, 0.75);
  color: var(--chalk);
  font-size: 1rem;
}

.curve-presets button[aria-pressed="true"] {
  border-color: var(--amber);
  color: var(--amber);
}

#clear-path {
  width: auto;
  color: var(--chalk-muted);
  font-size: 0.76rem;
}

.kick-button {
  min-width: 108px;
  min-height: 64px;
  font-size: 1.55rem;
}

button:disabled { cursor: not-allowed; opacity: 0.43; }

button:not(:disabled):active { transform: translateY(1px); }

button:focus-visible,
a:focus-visible,
input:focus-visible { outline: 0; box-shadow: var(--focus); }

.spot-rail {
  z-index: 80;
  min-height: 166px;
  padding-top: 18px;
  background: rgba(21, 29, 33, 0.97);
  border-top: 1px solid rgba(247, 244, 233, 0.32);
}

.kicker-rail {
  z-index: 80;
  min-height: 178px;
  padding-top: 18px;
  background: rgba(21, 29, 33, 0.97);
  border-top: 1px solid rgba(247, 244, 233, 0.32);
}

.spot-rail-heading,
.kicker-rail-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.spot-rail h2,
.kicker-rail h2 { margin: 1px 0 9px; font-size: 1.55rem; }

.rail-close {
  min-width: 58px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--chalk-muted);
}

.spot-options {
  display: grid;
  grid-template-columns: repeat(5, minmax(96px, 1fr));
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.kicker-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.spot-options button {
  min-height: 64px;
  padding: 8px 10px;
  border: 1px solid rgba(247, 244, 233, 0.3);
  background: var(--ink-soft);
  color: var(--chalk);
  text-align: left;
}

.kicker-options button {
  min-height: 78px;
  padding: 8px 10px;
  border: 1px solid rgba(247, 244, 233, 0.3);
  background: var(--ink-soft);
  color: var(--chalk);
  text-align: left;
}

.spot-options button[aria-checked="true"] {
  border-color: var(--amber);
  box-shadow: inset 4px 0 0 var(--amber);
}

.kicker-options button[aria-checked="true"] {
  border-color: var(--amber);
  box-shadow: inset 4px 0 0 var(--amber);
}

.spot-options strong,
.spot-options span,
.kicker-options strong,
.kicker-options span,
.kicker-options small { display: block; }
.spot-options strong { font-size: 0.94rem; }
.spot-options span { margin-top: 2px; color: var(--chalk-muted); font-size: 0.76rem; }
.kicker-options strong { font-size: 1.08rem; letter-spacing: 0.08em; }
.kicker-options span { color: var(--amber); font-size: 0.7rem; letter-spacing: 0.09em; }
.kicker-options small { margin-top: 3px; color: var(--chalk-muted); font-size: 0.72rem; }

.result-panel {
  min-height: 218px;
  padding-top: 28px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 18px;
}

.result-word {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(4.4rem, 13vw, 8rem);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 0.74;
  text-shadow: 0 3px 16px rgba(0, 0, 0, 0.48);
}

.result-detail {
  margin: 17px 0 0;
  font-family: var(--display);
  font-size: clamp(1.05rem, 3vw, 1.5rem);
  letter-spacing: 0.025em;
  text-shadow: 0 2px 8px #000;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(124px, 190px));
  gap: 10px;
}

.result-actions button { min-height: 58px; padding: 0 18px; font-size: 1.06rem; }

.noscript-panel {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--ink);
  text-align: center;
}

.noscript-panel a { color: var(--amber); }

@media (max-width: 620px) and (orientation: portrait) {
  .top-rail { grid-template-columns: minmax(84px, 1fr) auto minmax(44px, 1fr); }
  .back-link span { font-size: 0.9rem; }
  .spot-status { font-size: 1rem; }
  .control-rail {
    min-height: 190px;
    padding-top: 28px;
    grid-template-columns: 64px minmax(0, 1fr) 72px;
    gap: 8px;
  }
  .control-selectors { grid-template-columns: 1fr; gap: 6px; }
  .selector-button,
  .kick-button { min-width: 0; min-height: 64px; padding: 0 5px; }
  .selector-button { min-height: 44px; }
  .spot-button svg { width: 21px; height: 21px; }
  .kick-button { font-size: 1.35rem; }
  .curve-presets { gap: 8px; }
  .curve-presets button { min-width: 44px; width: 44px; padding: 0; }
  #clear-path { width: auto; min-width: 44px; padding: 0 4px; font-size: 0.65rem; }
  .coach-copy { bottom: calc(var(--safe-bottom) + 195px); }
  .spot-rail { min-height: 174px; }
  .kicker-rail { min-height: 190px; }
  .spot-options { grid-template-columns: repeat(5, 104px); }
  .result-panel {
    min-height: 230px;
    grid-template-columns: 1fr;
    gap: 18px;
  }
  .result-word { font-size: clamp(4.4rem, 22vw, 6.2rem); }
  .result-actions { grid-template-columns: 1fr 1fr; }
  #shoot-again { grid-column: 1 / -1; }
  .result-actions button { min-width: 0; padding: 0 8px; font-size: 0.98rem; }
}

@media (max-height: 470px) and (orientation: landscape) {
  .top-rail { min-height: calc(52px + var(--safe-top)); }
  .trajectory-input { inset: calc(52px + var(--safe-top)) 0 0; }
  .control-rail {
    min-height: 130px;
    padding-top: 8px;
    grid-template-columns: 76px minmax(240px, 440px) 96px;
    gap: 12px;
  }
  .selector-button,
  .kick-button { min-width: 0; min-height: 56px; }
  .control-selectors { grid-template-columns: repeat(2, minmax(58px, 1fr)); }
  .draw-prompt,
  .power-state { display: none; }
  .curve-presets {
    position: static;
    gap: 8px;
    margin-top: 5px;
    transform: none;
  }
  .curve-presets button { min-height: 44px; min-width: 44px; }
  .coach-copy { bottom: calc(var(--safe-bottom) + 139px); }
  .spot-rail { min-height: 126px; padding-top: 9px; }
  .kicker-rail { min-height: 136px; padding-top: 9px; }
  .spot-rail-heading h2 { display: inline; margin-left: 8px; }
  .kicker-rail-heading h2 { display: inline; margin-left: 8px; }
  .spot-options button { min-height: 54px; }
  .kicker-options button { min-height: 60px; }
  .result-panel {
    min-height: 130px;
    padding-top: 20px;
    grid-template-columns: 1fr auto;
  }
  .result-word { font-size: 4.2rem; }
  .result-detail { margin-top: 8px; font-size: 1rem; }
  .result-actions button { min-height: 52px; }
}

@media (max-width: 320px) {
  .top-rail { grid-template-columns: 44px minmax(0, 1fr) 44px; }
  .back-link { width: 44px; }
  .back-link span { display: none; }
  .spot-status {
    overflow: hidden;
    font-size: 0.78rem;
    text-overflow: ellipsis;
  }
  .control-rail {
    min-height: 260px;
    padding-top: 16px;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .shot-inputs {
    grid-row: 1;
    grid-column: 1 / -1;
  }
  .control-selectors,
  .kick-button {
    grid-row: 2;
  }
  .control-selectors { grid-template-columns: 1fr 1fr; }
  .selector-button,
  .kick-button { min-height: 52px; }
  .curve-presets {
    display: grid;
    grid-template-columns: repeat(2, minmax(44px, 1fr));
    gap: 8px;
  }
  .curve-presets button,
  #clear-path { width: 100%; }
  .coach-copy { bottom: calc(var(--safe-bottom) + 265px); }
  .result-panel { min-height: 260px; }
  .result-word { font-size: 3.4rem; }
  .result-actions { grid-template-columns: 1fr; }
  #shoot-again { grid-column: auto; }
}

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