@import url("https://fonts.googleapis.com/css2?family=Pirata+One&display=swap");

:root {
  color-scheme: dark;
  --ink: #f6f0dc;
  --muted: #b8c7ca;
  --panel: rgba(8, 26, 34, 0.86);
  --panel-strong: rgba(5, 16, 23, 0.95);
  --gold: #f2bf55;
  --red: #d75d4d;
  --teal: #35b8b0;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 12%, rgba(226, 116, 79, 0.28), transparent 28rem),
    linear-gradient(180deg, #102c3b 0%, #07141d 58%, #041015 100%);
  overflow: hidden;
}

.game-shell {
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 0;
  overflow: hidden;
}

.race-stage {
  position: relative;
  min-height: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: #0b2b3a;
}

canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
}

.topbar {
  position: absolute;
  inset: 16px 16px auto;
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 14px;
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: "Pirata One", Georgia, "Times New Roman", serif;
  font-size: clamp(2.6rem, 6vw, 5.4rem);
  font-weight: 400;
  line-height: 0.98;
  letter-spacing: 0;
  text-shadow: 0 3px 16px rgba(0, 0, 0, 0.48);
}

.version-tag {
  display: block;
  margin-top: 2px;
  color: rgba(246, 240, 220, 0.46);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(62px, 1fr));
  gap: 8px;
  width: min(430px, 54vw);
}

.stats div {
  padding: 9px 10px;
  border: 1px solid rgba(246, 240, 220, 0.16);
  border-radius: 8px;
  background: var(--panel);
  text-align: center;
}

.stats span {
  display: block;
  font-size: clamp(1rem, 2.2vw, 1.35rem);
  font-weight: 900;
}

.stats small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.gold-stat span {
  color: var(--gold);
}

.countdown {
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  min-width: 118px;
  min-height: 118px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(242, 191, 85, 0.68);
  border-radius: 50%;
  background: rgba(5, 16, 23, 0.82);
  color: var(--gold);
  font-size: 3.8rem;
  font-weight: 950;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}

.countdown.hidden {
  display: none;
}

.debug-panel {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 3;
  width: min(360px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow: auto;
  border: 1px solid rgba(246, 240, 220, 0.18);
  border-radius: 8px;
  background: rgba(4, 13, 18, 0.88);
  color: var(--ink);
  font-size: 0.78rem;
}

.debug-panel summary {
  cursor: pointer;
  padding: 8px 10px;
  color: var(--gold);
  font-weight: 900;
  text-transform: uppercase;
}

.debug-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  padding: 0 10px 10px;
}

.debug-grid label {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-weight: 800;
}

.debug-grid input,
.debug-grid select {
  width: 100%;
  margin: 0;
  padding: 4px;
  border-radius: 6px;
  font-size: 0.78rem;
}

.debug-grid input[type="range"] {
  padding: 0;
  accent-color: var(--gold);
  background: transparent;
}

.debug-grid output {
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.debug-cheat-button {
  width: calc(100% - 20px);
  margin: 0 10px 10px;
  min-height: 32px;
  border: 1px solid rgba(242, 191, 85, 0.55);
  border-radius: 6px;
  background: rgba(242, 191, 85, 0.12);
  color: var(--gold);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

#debugReadout {
  margin: 0;
  padding: 8px 10px 10px;
  border-top: 1px solid rgba(246, 240, 220, 0.12);
  color: rgba(246, 240, 220, 0.78);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.72rem;
  line-height: 1.35;
  white-space: pre-wrap;
}

.prompt-wrap {
  min-width: 0;
}

.prompt {
  max-width: 100%;
  min-height: 0;
  max-height: 9.5rem;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 13px 14px;
  border: 1px solid rgba(246, 240, 220, 0.1);
  border-radius: 8px;
  background: rgba(246, 240, 220, 0.08);
  color: rgba(246, 240, 220, 0.72);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(1rem, 2.2vw, 1.35rem);
  line-height: 1.55;
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
}

.prompt-overlay {
  position: absolute;
  left: 50%;
  top: clamp(90px, 19vh, 160px);
  z-index: 2;
  width: min(920px, calc(100vw - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}

.prompt-overlay .prompt {
  border-color: transparent;
  background:
    linear-gradient(180deg, rgba(246, 240, 220, 0.1), rgba(246, 240, 220, 0.02) 56%, transparent),
    linear-gradient(90deg, transparent, rgba(246, 240, 220, 0.1) 24%, rgba(246, 240, 220, 0.08) 72%, transparent);
  box-shadow: none;
  color: rgba(238, 249, 250, 0.76);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.16rem, 2.35vw, 1.6rem);
  font-weight: 700;
  letter-spacing: 0;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.2),
    0 0 14px rgba(210, 238, 246, 0.46),
    0 3px 18px rgba(5, 16, 23, 0.5);
}

.prompt span {
  border-radius: 4px;
}

.prompt .done {
  color: rgba(140, 228, 188, 0.88);
  text-shadow:
    0 0 12px rgba(140, 228, 188, 0.5),
    0 3px 16px rgba(5, 16, 23, 0.48);
}

.prompt .current {
  color: rgba(255, 246, 205, 0.98);
  background: rgba(242, 191, 85, 0.2);
  box-shadow:
    0 0 0 1px rgba(242, 191, 85, 0.28),
    0 0 18px rgba(242, 191, 85, 0.34);
}

.prompt .wrong {
  color: #fff1ec;
  background: rgba(215, 93, 77, 0.52);
  text-shadow: 0 2px 10px rgba(5, 16, 23, 0.52);
}

.wind-panel {
  display: grid;
  grid-template-columns: auto minmax(90px, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.wind-meter {
  height: 10px;
  overflow: hidden;
  border: 1px solid rgba(246, 240, 220, 0.18);
  border-radius: 999px;
  background: rgba(4, 12, 17, 0.72);
}

.wind-meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  transition: width 140ms ease;
}

#windLabel.boosting,
#comboLabel.boosting {
  color: var(--gold);
}

.game-gui {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 3;
  display: grid;
  gap: 12px;
  width: min(310px, calc(100vw - 32px));
  padding: 12px;
  border: 1px solid rgba(246, 240, 220, 0.14);
  border-radius: 8px;
  background: rgba(5, 16, 23, 0.76);
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 180ms ease;
}

.game-gui:not(.is-racing) .wind-panel {
  display: none;
}

.game-gui.is-racing {
  width: min(330px, calc(100vw - 32px));
  pointer-events: none;
}

.game-gui.is-racing .button-row,
.game-gui.is-racing .music-widget,
.game-gui.is-racing #statusText {
  display: none;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--gold);
  color: #17100a;
  cursor: pointer;
  font-weight: 900;
  text-transform: uppercase;
}

button:hover {
  filter: brightness(1.06);
}

button.secondary {
  border: 1px solid rgba(246, 240, 220, 0.22);
  background: rgba(246, 240, 220, 0.08);
  color: var(--ink);
}

.music-widget {
  display: grid;
  gap: 7px;
  padding: 9px;
  border: 1px solid rgba(246, 240, 220, 0.12);
  border-radius: 8px;
  background: rgba(246, 240, 220, 0.05);
}

.track-title {
  overflow: hidden;
  color: rgba(246, 240, 220, 0.68);
  font-size: 0.74rem;
  font-weight: 800;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.track-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

button.icon-button {
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid rgba(246, 240, 220, 0.16);
  background: rgba(4, 12, 17, 0.44);
  color: var(--muted);
  font-size: 0.68rem;
}

#statusText {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.results-dialog,
.harbor-dialog,
.shop-dialog {
  width: min(430px, calc(100vw - 28px));
  border: 1px solid rgba(246, 240, 220, 0.22);
  border-radius: 8px;
  padding: 18px;
  background: rgba(5, 16, 23, 0.96);
  color: var(--ink);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.55);
}

.harbor-dialog {
  width: min(480px, calc(100vw - 28px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}

.boat-preview-wrap {
  position: relative;
  margin: 0 0 14px;
  border: 1px solid rgba(246, 240, 220, 0.14);
  border-radius: 10px;
  overflow: hidden;
  background:
    radial-gradient(circle at 30% 0%, rgba(242, 191, 85, 0.18), transparent 55%),
    linear-gradient(180deg, #243d68 0%, #d1775e 52%, #194454 100%);
  aspect-ratio: 4 / 3;
}

.boat-preview {
  display: block;
  width: 100%;
  height: 100%;
}

.boat-preview-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: rgba(246, 240, 220, 0.62);
  font-weight: 800;
  text-transform: uppercase;
}

.harbor-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0 0 12px;
}

.harbor-tab {
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid rgba(246, 240, 220, 0.18);
  background: rgba(246, 240, 220, 0.06);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.harbor-tab[aria-selected="true"] {
  border-color: rgba(242, 191, 85, 0.7);
  background: rgba(242, 191, 85, 0.12);
  color: var(--gold);
}

.harbor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 12px;
}

.harbor-empty {
  margin: 4px 0 14px;
  padding: 12px;
  border: 1px dashed rgba(246, 240, 220, 0.2);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  text-align: center;
}

.flag-preview {
  width: 100%;
  height: 56px;
  border-radius: 6px;
  object-fit: contain;
  background: #101010;
  image-rendering: pixelated;
}

.results-dialog::backdrop,
.harbor-dialog::backdrop,
.shop-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.results-header p {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.results-header h2 {
  margin: 0 0 16px;
  font-family: "Pirata One", Georgia, "Times New Roman", serif;
  font-size: 2.8rem;
  font-weight: 400;
  line-height: 1;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.results-grid div,
.gold-award {
  padding: 12px;
  border: 1px solid rgba(246, 240, 220, 0.14);
  border-radius: 8px;
  background: rgba(246, 240, 220, 0.08);
  text-align: center;
}

.results-grid span,
.gold-award span {
  display: block;
  font-size: 1.45rem;
  font-weight: 950;
}

.results-grid small,
.gold-award small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.gold-award {
  margin: 10px 0 14px;
  border-color: rgba(242, 191, 85, 0.42);
}

.gold-award span {
  color: var(--gold);
  font-size: 2rem;
}

.result-bonus {
  min-height: 1.2em;
  margin: -4px 0 12px;
  color: var(--gold);
  font-size: 0.86rem;
  font-weight: 900;
  text-align: center;
}

.results-dialog button,
.harbor-dialog button,
.shop-dialog button {
  width: 100%;
}

.shop-balance {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid rgba(242, 191, 85, 0.34);
  border-radius: 8px;
  background: rgba(242, 191, 85, 0.08);
  text-align: center;
}

.shop-balance span {
  display: block;
  color: var(--gold);
  font-size: 2rem;
  font-weight: 950;
}

.shop-balance small,
.wager-card small,
.shop-skin-card small,
.skin-card small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.shop-section-title {
  margin: 12px 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

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

.shop-skin-card {
  display: grid;
  gap: 6px;
  min-height: 106px;
  padding: 9px 7px;
  border: 1px solid rgba(246, 240, 220, 0.14);
  background: rgba(246, 240, 220, 0.08);
  color: var(--ink);
  font-size: 0.78rem;
  text-transform: none;
}

.rarity-badge {
  justify-self: start;
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(246, 240, 220, 0.08);
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

.rarity-common {
  border-color: rgba(246, 240, 220, 0.16);
}

.rarity-rare {
  border-color: rgba(53, 184, 176, 0.46);
}

.rarity-rare .rarity-badge {
  color: #8ce4bc;
}

.rarity-epic {
  border-color: rgba(157, 124, 255, 0.56);
}

.rarity-epic .rarity-badge {
  color: #c8b8ff;
}

.rarity-mythic {
  border-color: rgba(255, 111, 203, 0.62);
}

.rarity-mythic .rarity-badge {
  color: #ff9edc;
}

.rarity-legendary {
  border-color: rgba(242, 191, 85, 0.7);
  box-shadow: inset 0 0 18px rgba(242, 191, 85, 0.08);
}

.rarity-legendary .rarity-badge {
  color: var(--gold);
}

.rarity-ultra {
  border-color: rgba(125, 255, 220, 0.78);
  box-shadow:
    inset 0 0 18px rgba(125, 255, 220, 0.09),
    0 0 18px rgba(157, 124, 255, 0.1);
}

.rarity-ultra .rarity-badge {
  color: #7dffdc;
}

.shop-skin-card:disabled,
.skin-card:disabled {
  cursor: default;
  opacity: 0.52;
}

.trail-preview {
  width: 100%;
  height: 22px;
  border-radius: 999px;
  background:
    radial-gradient(circle at 72% 50%, var(--trail-secondary), transparent 32%),
    linear-gradient(90deg, transparent, var(--trail-color));
  box-shadow: 0 0 12px color-mix(in srgb, var(--trail-color), transparent 35%);
}

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

.wager-card {
  display: grid;
  gap: 4px;
  min-height: 82px;
  padding: 10px 8px;
  border: 1px solid rgba(246, 240, 220, 0.14);
  background: rgba(246, 240, 220, 0.08);
  color: var(--ink);
  text-transform: none;
}

.wager-card span {
  color: var(--gold);
  font-size: 1.3rem;
  font-weight: 950;
}

.shop-result {
  min-height: 2.6em;
  margin: 12px 0;
  color: var(--gold);
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
}

.skin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 14px;
}

.skin-card {
  display: grid;
  gap: 8px;
  min-height: 96px;
  padding: 10px;
  border: 1px solid rgba(246, 240, 220, 0.16);
  border-radius: 8px;
  background: rgba(246, 240, 220, 0.08);
  color: var(--ink);
  text-align: left;
  text-transform: none;
}

.skin-card[aria-pressed="true"] {
  border-color: rgba(242, 191, 85, 0.78);
  box-shadow: 0 0 0 2px rgba(242, 191, 85, 0.16);
}

.skin-preview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.skin-swatch {
  height: 22px;
  border: 1px solid rgba(246, 240, 220, 0.18);
  border-radius: 6px;
}

.skin-name {
  font-weight: 900;
}

@media (max-width: 760px) {
  .topbar {
    inset: 10px 10px auto;
    flex-direction: column;
  }

  .stats {
    width: 100%;
    max-width: 330px;
  }

  .prompt-overlay {
    top: 150px;
    width: calc(100vw - 20px);
  }

  .prompt-overlay .prompt {
    max-height: 7.2rem;
  }

  .game-gui {
    right: 10px;
    bottom: 10px;
    max-height: 42dvh;
    overflow: auto;
  }

  .debug-panel {
    left: 10px;
    right: auto;
    bottom: calc(42dvh + 20px);
    width: min(320px, calc(100vw - 20px));
    max-height: 34dvh;
  }
}
