:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #f3f5ee;
  --muted: #b9c2ba;
  --panel: rgba(17, 27, 30, .9);
  --line: rgba(255, 255, 255, .18);
  --green: #9ac85d;
  --yellow: #f2c75b;
  --red: #e45c4f;
  --cyan: #64c6d1;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #172126;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

#gameCanvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 13px;
  background: #172126;
}

.loading-screen strong {
  font-size: clamp(1.4rem, 5vw, 2.3rem);
}

.loading-screen small,
.eyebrow,
.select-footer,
.course-readout span,
.wind-readout small,
.score-readout small,
.result-copy small {
  color: var(--muted);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .12em;
}

.loading-mark {
  width: 38px;
  height: 38px;
  border: 4px solid rgba(255, 255, 255, .16);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.course-select {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 20px;
  padding: max(22px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
  background: rgba(10, 18, 21, .72);
  backdrop-filter: blur(12px);
}

.select-header,
.top-bar,
.settings-dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.select-header {
  width: min(1180px, 100%);
  margin: 0 auto;
}

.select-header h1 {
  margin: 2px 0 0;
  font-size: clamp(2rem, 5vw, 4.6rem);
  line-height: .92;
}

.course-grid {
  align-self: center;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  width: min(1180px, 100%);
  max-height: 66vh;
  margin: 0 auto;
}

.course-card {
  position: relative;
  min-height: 390px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 6px;
  background: #202c2e;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .28);
}

.course-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.course-card::after {
  content: "";
  position: absolute;
  inset: 32% 0 0;
  background: linear-gradient(to bottom, transparent, rgba(8, 14, 16, .94));
  pointer-events: none;
}

.course-card button {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  padding: 24px;
  border: 0;
  background: transparent;
  text-align: left;
}

.course-card button:disabled {
  cursor: not-allowed;
}

.course-card.locked img {
  filter: saturate(.72) brightness(.58);
}

.course-card .course-number {
  position: absolute;
  top: 18px;
  left: 18px;
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  border: 1px solid rgba(255, 255, 255, .65);
  border-radius: 50%;
  background: rgba(12, 19, 21, .55);
  font-size: .72rem;
  font-weight: 900;
}

.course-card .course-number.compact {
  font-size: .52rem;
}

.course-card .course-state {
  color: var(--yellow);
  font-size: .7rem;
  font-weight: 900;
}

.course-card h2 {
  margin: 2px 0;
  font-size: clamp(1.55rem, 3vw, 2.6rem);
  line-height: 1;
}

.course-card p {
  max-width: 28ch;
  margin: 3px 0 12px;
  color: #d5ddd6;
  font-size: .86rem;
  line-height: 1.35;
}

.course-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: .72rem;
  font-weight: 900;
}

.select-footer {
  display: flex;
  justify-content: space-between;
  width: min(1180px, 100%);
  margin: 0 auto;
}

.select-footer strong {
  color: var(--ink);
}

.hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.top-bar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  left: max(12px, env(safe-area-inset-left));
  gap: 12px;
}

.course-readout,
.wind-readout,
.score-readout,
.shot-panel,
.status-pill {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
  backdrop-filter: blur(8px);
}

.course-readout {
  display: flex;
  flex-direction: column;
  min-width: 156px;
  padding: 10px 14px;
}

.course-readout strong {
  margin-top: 2px;
  font-size: 1.05rem;
}

.course-readout small {
  margin-top: 3px;
  color: var(--yellow);
  font-size: .55rem;
  font-weight: 900;
}

.wind-readout {
  position: absolute;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 136px;
  padding: 8px 13px;
  transform: translateX(-50%);
}

.wind-readout div {
  display: flex;
  flex-direction: column;
}

.wind-readout strong {
  font-size: .82rem;
}

.wind-arrow {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  color: var(--cyan);
  font-size: 1.35rem;
  transition: transform .25s ease;
}

.hud-actions {
  display: flex;
  gap: 7px;
  pointer-events: auto;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(16, 26, 29, .9);
}

.icon-button.light {
  background: rgba(240, 244, 237, .12);
}

.icon-button:hover {
  border-color: rgba(255, 255, 255, .48);
  background: rgba(39, 54, 55, .94);
}

.icon-button svg,
.range-setting svg,
.toggle-setting svg {
  width: 19px;
  height: 19px;
  stroke-width: 2;
}

.score-readout {
  position: absolute;
  top: 88px;
  left: max(12px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: auto 1px auto 1px auto;
  gap: 11px;
  align-items: stretch;
  padding: 9px 13px;
}

.score-readout div {
  display: flex;
  flex-direction: column;
  min-width: 40px;
}

.score-readout > span {
  width: 1px;
  background: var(--line);
}

.score-readout strong {
  font-size: 1rem;
}

.status-pill {
  position: absolute;
  top: 91px;
  left: 50%;
  padding: 7px 12px;
  color: var(--green);
  font-size: .68rem;
  font-weight: 900;
  transform: translateX(-50%);
}

.shot-panel {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: auto minmax(220px, 460px);
  justify-content: center;
  gap: 14px;
  align-items: center;
  width: min(760px, calc(100% - 24px));
  margin: 0 auto;
  padding: 10px;
  pointer-events: auto;
}

.shot-modes,
.quality-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.shot-modes button {
  min-width: 72px;
  height: 40px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: .65rem;
  font-weight: 900;
}

.shot-modes button:last-child {
  border-right: 0;
}

.shot-modes button.selected {
  background: var(--green);
  color: #142013;
}

.power-meter {
  display: grid;
  grid-template-columns: 38px minmax(120px, 1fr) 42px;
  gap: 9px;
  align-items: center;
}

.power-meter > span,
.power-meter > strong {
  font-size: .66rem;
  font-weight: 900;
}

.power-meter > strong {
  text-align: right;
}

.power-meter > div {
  position: relative;
  height: 12px;
  overflow: hidden;
  border-radius: 2px;
  background: rgba(255, 255, 255, .13);
}

#powerFill {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(to right, var(--green) 0 58%, var(--yellow) 58% 82%, var(--red) 82%);
  transition: width .04s linear;
}

#powerTarget {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: 78%;
  width: 2px;
  border-radius: 1px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .45);
  pointer-events: none;
}

.result-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr);
  background: #10191c;
}

.result-photo-wrap {
  position: relative;
  min-height: 320px;
  overflow: hidden;
}

.result-photo-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, transparent 65%, #10191c);
  pointer-events: none;
}

.result-photo-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.result-photo-wrap span {
  position: absolute;
  bottom: 24px;
  left: 24px;
  z-index: 1;
  font-size: .75rem;
  font-weight: 900;
}

.result-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: clamp(28px, 6vw, 80px);
}

.result-medal {
  width: 54px;
  height: 54px;
  margin-bottom: 22px;
  border: 6px double rgba(255, 255, 255, .7);
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: inset 0 0 0 4px rgba(0, 0, 0, .2), 0 8px 24px rgba(0, 0, 0, .25);
}

.result-medal.silver { background: #cbd3d4; }
.result-medal.bronze { background: #ba744a; }

.result-copy h2 {
  margin: 8px 0 2px;
  font-size: clamp(2.6rem, 7vw, 6.5rem);
  line-height: .92;
}

.result-copy p {
  margin: 5px 0 30px;
  color: var(--muted);
  font-size: 1.1rem;
}

.result-copy p strong {
  color: var(--ink);
}

.result-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: -18px 0 28px;
  color: var(--yellow);
  font-size: .66rem;
  font-weight: 900;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.primary-button,
.secondary-button,
.fatal-error button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 4px;
  font-size: .72rem;
  font-weight: 900;
}

.primary-button {
  border: 1px solid var(--green);
  background: var(--green);
  color: #122012;
}

.secondary-button,
.fatal-error button {
  border: 1px solid var(--line);
  background: transparent;
}

.settings-dialog {
  width: min(440px, calc(100% - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #172226;
  color: var(--ink);
  box-shadow: 0 24px 90px rgba(0, 0, 0, .6);
}

.settings-dialog::backdrop {
  background: rgba(5, 10, 12, .7);
  backdrop-filter: blur(5px);
}

.settings-dialog form {
  display: grid;
  gap: 22px;
  padding: 22px;
}

.settings-dialog h2 {
  margin: 0;
  font-size: 1.25rem;
}

.range-setting {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 14px;
  align-items: center;
}

.toggle-setting {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  min-height: 36px;
  cursor: pointer;
}

.toggle-setting > span {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: .85rem;
  font-weight: 750;
}

.toggle-setting input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-setting b {
  position: relative;
  width: 42px;
  height: 23px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .12);
}

.toggle-setting b::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .16s ease, background .16s ease;
}

.toggle-setting input:checked + b {
  border-color: var(--green);
  background: rgba(154, 200, 93, .28);
}

.toggle-setting input:checked + b::after {
  background: var(--green);
  transform: translateX(19px);
}

.toggle-setting input:focus-visible + b {
  outline: 3px solid var(--yellow);
  outline-offset: 3px;
}

.range-setting span {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: .85rem;
  font-weight: 750;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

.settings-dialog fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.settings-dialog legend {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
}

.quality-options label {
  position: relative;
}

.quality-options input {
  position: absolute;
  opacity: 0;
}

.quality-options span {
  display: grid;
  place-items: center;
  height: 42px;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 900;
  cursor: pointer;
}

.quality-options input:checked + span {
  background: var(--green);
  color: #142013;
}

.fatal-error {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  justify-items: start;
  gap: 12px;
  padding: 28px;
  background: #172126;
}

.fatal-error p {
  max-width: 42ch;
  margin: 0 0 10px;
  color: var(--muted);
}

@media (max-width: 860px) {
  .course-card { min-height: 330px; }
  .result-screen { grid-template-columns: 1fr 330px; }
}

@media (max-width: 700px) {
  .course-select {
    gap: 12px;
    padding: max(15px, 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));
  }

  .select-header h1 { font-size: 2.1rem; }

  .course-grid {
    grid-template-columns: 1fr;
    align-self: stretch;
    gap: 9px;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .course-card {
    min-height: 148px;
  }

  .course-card::after {
    inset: 0;
    background: linear-gradient(to right, rgba(8, 14, 16, .15), rgba(8, 14, 16, .94) 72%);
  }

  .course-card img {
    width: 58%;
  }

  .course-card button {
    justify-content: center;
    align-items: flex-start;
    padding: 15px 14px 15px 44%;
  }

  .course-card .course-number {
    top: 12px;
    left: 12px;
    width: 30px;
    height: 30px;
  }

  .course-card h2 { font-size: 1.45rem; }
  .course-card p { display: none; }
  .course-card .course-state { font-size: .6rem; }
  .course-meta { font-size: .62rem; }
  .select-footer { font-size: .57rem; }

  .course-readout {
    min-width: 116px;
    padding: 8px 10px;
  }

  .course-readout strong { font-size: .9rem; }
  .course-readout span { font-size: .56rem; }
  .course-readout small { font-size: .49rem; }

  .wind-readout {
    top: 62px;
    right: max(12px, env(safe-area-inset-right));
    left: auto;
    min-width: 126px;
    padding: 6px 10px;
    transform: none;
  }

  .hud-actions { gap: 5px; }

  .icon-button {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }

  #overviewButton { display: none; }

  .score-readout {
    top: 82px;
    gap: 8px;
    padding: 7px 9px;
  }

  .score-readout div { min-width: 32px; }
  .score-readout small { font-size: .52rem; }
  .score-readout strong { font-size: .84rem; }

  .status-pill {
    top: 129px;
    font-size: .58rem;
  }

  .shot-panel {
    grid-template-columns: 1fr;
    gap: 7px;
    width: calc(100% - 20px);
    padding: 8px;
  }

  .shot-modes button {
    height: 34px;
    min-width: 0;
  }

  .power-meter {
    grid-template-columns: 34px minmax(90px, 1fr) 38px;
  }

  .result-screen {
    grid-template-columns: 1fr;
    grid-template-rows: 43vh minmax(0, 1fr);
    overflow-y: auto;
  }

  .result-photo-wrap::after {
    background: linear-gradient(to bottom, transparent 65%, #10191c);
  }

  .result-copy {
    justify-content: flex-start;
    padding: 20px;
  }

  .result-medal {
    width: 42px;
    height: 42px;
    margin-bottom: 12px;
  }

  .result-copy h2 { font-size: 3.1rem; }
  .result-copy p { margin-bottom: 18px; }
  .result-detail { margin: -8px 0 18px; }
  .result-actions { width: 100%; }
  .result-actions button { flex: 1 1 auto; padding: 0 10px; }
}

@media (max-width: 390px) {
  .hud-actions .icon-button { width: 35px; height: 35px; flex-basis: 35px; }
  .course-readout { min-width: 102px; }
  .score-readout > div:last-child,
  .score-readout > span:last-of-type { display: none; }
}

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