@import url("https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@400;600;700&family=Space+Grotesk:wght@400;600&family=Oxanium:wght@400;600;700&display=swap");

:root {
  color-scheme: dark;
  --bg: #060708;
  --bg-soft: #0c0e12;
  --bg-card: rgba(10, 12, 16, 0.7);
  --accent: #8ab6a6;
  --accent-soft: rgba(138, 182, 166, 0.16);
  --text: #e2e6ea;
  --text-muted: #9aa3ad;
  --stroke: rgba(226, 230, 234, 0.12);
  --glow: rgba(138, 182, 166, 0.18);
  --shadow: rgba(0, 0, 0, 0.25);
  --radius: 18px;
  --radius-sm: 12px;
  --shell-padding-x: clamp(18px, 6vw, 72px);
  --shell-padding-top: clamp(20px, 4vw, 32px);
  --shell-padding-bottom: clamp(32px, 7vw, 56px);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Chakra Petch", "Space Grotesk", "Trebuchet MS", sans-serif;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0.02em;
  overflow-x: hidden;
}

body.home-active {
  overflow: hidden;
}

body.game-active {
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.03) 1px, transparent 0),
    linear-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.012) 1px, transparent 1px);
  background-size: 28px 28px, 48px 48px, 48px 48px;
  pointer-events: none;
  opacity: 0.18;
  z-index: -2;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.03), #050607 70%),
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: auto, 100% 6px;
  pointer-events: none;
  z-index: -1;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    calc(var(--shell-padding-top) + env(safe-area-inset-top))
    var(--shell-padding-x)
    calc(var(--shell-padding-bottom) + env(safe-area-inset-bottom));
  gap: 32px;
}

body.home-active .app-shell {
  padding-top: 0;
}

body.home-active .site-header {
  position: absolute;
  top: calc(var(--shell-padding-top) + env(safe-area-inset-top));
  left: var(--shell-padding-x);
  right: var(--shell-padding-x);
  z-index: 2;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  font-family: "Oxanium", "Chakra Petch", sans-serif;
  font-weight: 700;
  font-size: 20px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  text-shadow: 0 0 12px rgba(138, 182, 166, 0.15);
}

.status-pill {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
  border: 1px solid var(--stroke);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(12, 14, 21, 0.6);
}

.view-stack {
  flex: 1;
  display: grid;
  min-height: 0;
}

.home-screen,
.select-screen,
.game-screen {
  grid-area: 1 / 1;
  min-height: 70vh;
}

.home-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    calc(24px + env(safe-area-inset-top))
    0
    calc(24px + env(safe-area-inset-bottom));
}

.home-card {
  background: var(--bg-card);
  border: 1px solid rgba(226, 230, 234, 0.1);
  border-radius: var(--radius);
  padding: clamp(28px, 5vw, 56px);
  text-align: center;
  width: min(520px, 92vw);
  box-shadow: 0 14px 40px var(--shadow);
}

.home-title {
  font-family: "Oxanium", "Chakra Petch", sans-serif;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.home-card h1 {
  margin: 0 0 12px;
  font-size: clamp(32px, 6vw, 42px);
  font-family: "Oxanium", "Chakra Petch", sans-serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-shadow: 0 0 16px rgba(138, 182, 166, 0.22);
}

.home-card p {
  margin: 0 0 28px;
  color: var(--text-muted);
  line-height: 1.6;
}

.start-button {
  font-size: 18px;
  font-weight: 600;
  padding: 16px 44px;
  border-radius: 999px;
  border: 1px solid rgba(138, 182, 166, 0.6);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  box-shadow: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.start-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 24px rgba(138, 182, 166, 0.18);
}

.select-screen {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 32px;
  align-items: start;
  min-height: 0;
}

.game-screen {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  border-radius: 0;
  border: none;
  overflow: hidden;
  background: rgba(6, 7, 8, 0.92);
  z-index: 10;
}

.game-over {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 7, 8, 0.82);
  z-index: 5;
}

.racing-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 7, 8, 0.78);
  z-index: 4;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.racing-card {
  background: rgba(10, 12, 16, 0.85);
  border: 1px solid rgba(226, 230, 234, 0.12);
  padding: 32px 36px;
  border-radius: var(--radius);
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  display: grid;
  gap: 16px;
  min-width: min(320px, 85vw);
}

.racing-title {
  font-family: "Oxanium", "Chakra Petch", sans-serif;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 22px;
}

.racing-score {
  font-size: 16px;
  color: var(--text-muted);
  letter-spacing: 0.12em;
}

.game-over-card {
  background: rgba(10, 12, 16, 0.85);
  border: 1px solid rgba(226, 230, 234, 0.12);
  padding: 32px 36px;
  border-radius: var(--radius);
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  display: grid;
  gap: 16px;
  min-width: min(320px, 85vw);
}

.game-over-title {
  font-family: "Oxanium", "Chakra Petch", sans-serif;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 22px;
}

.game-over-score {
  font-size: 18px;
  color: var(--text-muted);
  letter-spacing: 0.12em;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.game-module-mount {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.game-hud {
  position: relative;
  z-index: 2;
  padding: calc(16px + env(safe-area-inset-top)) clamp(16px, 3vw, 24px) 0;
  pointer-events: none;
}

.hud-bar {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 16px;
  pointer-events: auto;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(10, 12, 16, 0.45);
  backdrop-filter: blur(10px);
}


.score-readout {
  font-size: 18px;
  letter-spacing: 0.2em;
  font-weight: 600;
  font-family: "Oxanium", "Chakra Petch", sans-serif;
}

.missed-readout {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.hearts-readout {
  font-size: 16px;
  letter-spacing: 0.2em;
  color: var(--accent);
}

.exit-button {
  pointer-events: auto;
  border: 1px solid rgba(226, 230, 234, 0.2);
  background: transparent;
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
}

.tag-sidebar {
  position: sticky;
  top: 24px;
  align-self: start;
  border: 1px solid rgba(226, 230, 234, 0.1);
  border-radius: var(--radius-sm);
  background: rgba(8, 10, 14, 0.8);
  padding: 20px;
}

.sidebar-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.tag-links {
  display: grid;
  gap: 10px;
}

.tag-links a {
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: border 0.2s ease, background 0.2s ease;
}

.tag-links a:hover {
  border-color: rgba(138, 182, 166, 0.6);
  background: rgba(138, 182, 166, 0.06);
}

.game-list {
  display: grid;
  gap: 40px;
  min-width: 0;
}

.tag-section {
  display: grid;
  gap: 18px;
}

.tag-heading {
  font-size: 18px;
  font-weight: 600;
  font-family: "Oxanium", "Chakra Petch", sans-serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: 18px;
}

.game-card {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 22px 24px;
  min-height: clamp(150px, 24vw, 220px);
  border-radius: var(--radius);
  border: 1px solid rgba(226, 230, 234, 0.18);
  background: var(--bg-card);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.2s ease, border 0.2s ease;
}

.game-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.6;
  pointer-events: none;
  z-index: 0;
}

.game-card > *:not(.game-preview) {
  position: relative;
  z-index: 2;
}


.game-card:hover {
  transform: translateY(-4px);
  border-color: rgba(138, 182, 166, 0.4);
}

.game-card h3 {
  margin: 0;
  font-size: clamp(18px, 2.2vw, 20px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.game-card p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.5;
}

.tag-chip {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
}

.game-icon {
  position: absolute;
  inset: auto 10% 10% auto;
  width: 110px;
  height: 110px;
  opacity: 0.2;
}

.game-icon path,
.game-icon circle,
.game-icon line,
.game-icon rect {
  stroke: currentColor;
}

.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}

.is-collapsed {
  display: none;
}

.info-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
}

.info-scrim {
  position: absolute;
  inset: 0;
  background: rgba(6, 7, 8, 0.7);
}

.info-card {
  position: relative;
  z-index: 2;
  background: rgba(10, 12, 16, 0.95);
  border: 1px solid rgba(226, 230, 234, 0.12);
  border-radius: var(--radius);
  padding: clamp(18px, 4vw, 24px);
  width: min(620px, 90vw);
  max-height: min(88vh, 88dvh);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  display: grid;
  gap: 16px;
  overflow: auto;
}

.info-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: 1px solid rgba(226, 230, 234, 0.15);
  background: transparent;
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 999px;
  cursor: pointer;
}

.info-title {
  font-family: "Oxanium", "Chakra Petch", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.info-body {
  display: grid;
  gap: 12px;
}

#infoCanvas {
  width: 100%;
  height: auto;
  border-radius: 14px;
  border: 1px solid rgba(226, 230, 234, 0.12);
  background: #060708;
}

.info-text {
  color: var(--text-muted);
  line-height: 1.5;
}

#racingIframeOverlay {
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

.home-screen,
.select-screen,
.game-screen {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

@media (max-width: 960px) {
  .app-shell {
    gap: 24px;
  }

  .select-screen {
    grid-template-columns: 1fr;
  }

  .tag-sidebar {
    position: static;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 16px;
  }

  .tag-links {
    grid-template-columns: repeat(auto-fit, minmax(110px, max-content));
    overflow-x: auto;
  }

  .hud-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .exit-button {
    justify-self: end;
  }
}

@media (max-width: 600px) {
  .brand {
    font-size: 16px;
    letter-spacing: 0.14em;
  }

  .status-pill {
    width: 100%;
    text-align: center;
  }

  .home-card {
    width: 100%;
  }

  .start-button {
    width: 100%;
    padding-inline: 24px;
  }

  .game-card {
    padding: 18px;
  }

  .hud-bar {
    grid-template-columns: 1fr;
  }

  .score-readout {
    font-size: 16px;
  }

  .missed-readout,
  .hearts-readout,
  .exit-button {
    justify-self: start;
  }

  .info-card {
    width: min(94vw, 620px);
  }
}
