@font-face {
  font-family: "Snake Regular";
  src: url("assets/font/SnakeRegular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  --bg-1: #1a120c;
  --bg-2: #241813;
  --bg-3: #2d1c16;
  --panel: rgba(32, 20, 14, 0.84);
  --line: rgba(255, 179, 120, 0.34);
  --text: #f1f4ff;
  --muted: #d9bf9f;
  --accent: #ffaf62;
  --accent-2: #ffd27a;
  --danger: #ff7f6d;
  --warn: #ffd067;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Exo 2", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(70vw 70vw at 15% 20%, #4a2f1d 0%, transparent 60%),
    radial-gradient(60vw 60vw at 82% 85%, #5a3324 0%, transparent 58%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3));
  overflow-x: hidden;
}

.bg-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.2;
  background-image:
    linear-gradient(transparent 0, rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, transparent 0, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
  background-size: 3px 3px, 3px 3px;
}

.app {
  max-width: 1720px;
  margin: 0 auto;
  padding: 14px 16px 22px;
}

.app-header {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 6px;
  position: relative;
  z-index: 18;
}

.app-header h1 {
  margin: 0;
  font-family: "Snake Regular", "Russo One", sans-serif;
  letter-spacing: 0.035em;
  font-size: clamp(2.7rem, 7.4vw, 6rem);
  line-height: 1;
  text-transform: uppercase;
}

.app-header h1.title-snake-wave {
  position: relative;
  display: block;
  width: var(--wave-stage-width, min(100%, 800px));
  max-width: min(100%, 800px);
  height: 1.05em;
  line-height: 1;
  letter-spacing: 0;
  overflow: visible;
  transform: none !important;
}

.title-wave-char {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  margin: 0;
  transform: translate(-50%, -50%);
  background: linear-gradient(180deg, #f7ffd8 0%, #bbf778 44%, #72bd3d 100%);
  color: #cbff8a;
  -webkit-text-fill-color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
  text-shadow:
    0 1px 0 #6f9430,
    0 2px 0 #5d7e28,
    0 3px 0 #4b6620,
    0 4px 0 #3b5219,
    0 5px 0 #2d3d12,
    0 8px 14px rgba(0, 0, 0, 0.44),
    0 0 14px rgba(177, 255, 114, 0.24);
  will-change: left, top;
}

.title-wave-char::before {
  content: attr(data-char);
  position: absolute;
  inset: 0;
  transform: translate(2px, 3px);
  color: rgba(45, 66, 23, 0.94);
  -webkit-text-fill-color: rgba(45, 66, 23, 0.94);
  text-shadow: none;
  z-index: -1;
}

.title-wave-space {
  text-shadow: none;
}

.title-wave-space::before {
  content: none;
}

.app-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
}

body.race-screen-active .app-header {
  margin-bottom: clamp(-24px, -2.2vw, -10px);
  z-index: 40;
  pointer-events: none;
}

body.race-screen-active .app-header p {
  opacity: 0;
  max-height: 0;
  overflow: hidden;
}

body.race-screen-active #screen-race {
  margin-top: 0;
}

body.race-screen-active .app-header h1.title-snake-wave {
  max-width: none;
  transform: translateY(-4px) !important;
}

.screen {
  display: none;
  margin-top: 14px;
  animation: fade-in 220ms ease-out;
}

.screen.active {
  display: block;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  backdrop-filter: blur(10px);
}

.menu-panel {
  display: grid;
  gap: 10px;
  max-width: 420px;
}

.menu-field {
  display: grid;
  gap: 6px;
}

.menu-field span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.menu-field input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  outline: none;
}

.menu-field select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  outline: none;
}

.menu-field input:focus {
  border-color: rgba(255, 210, 122, 0.9);
  box-shadow: 0 0 0 2px rgba(255, 210, 122, 0.2);
}

.menu-field select:focus {
  border-color: rgba(255, 210, 122, 0.9);
  box-shadow: 0 0 0 2px rgba(255, 210, 122, 0.2);
}

.menu-field input::placeholder {
  color: rgba(241, 244, 255, 0.46);
}

.online-room-picker {
  margin-top: 6px;
  margin-bottom: 10px;
  display: grid;
  gap: 8px;
}

.online-room-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.online-room-actions input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  outline: none;
}

.online-room-actions input:focus {
  border-color: rgba(255, 210, 122, 0.9);
  box-shadow: 0 0 0 2px rgba(255, 210, 122, 0.2);
}

.online-room-actions input::placeholder {
  color: rgba(241, 244, 255, 0.46);
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.btn.primary {
  color: #051927;
  background: linear-gradient(120deg, var(--accent), #7ef5ff);
  box-shadow: 0 8px 20px rgba(50, 211, 255, 0.28);
}

.btn.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.22);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.card {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 12px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  cursor: pointer;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.card ul {
  margin: 8px 0 0;
  padding-left: 16px;
  color: var(--muted);
  font-size: 0.84rem;
}

.card.selected {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 1px rgba(115, 255, 150, 0.6), 0 14px 20px rgba(115, 255, 150, 0.1);
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.mode-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.btn.mode-active {
  color: #072022;
  background: linear-gradient(120deg, #73ff96, #b5ffd1);
  border-color: rgba(115, 255, 150, 0.84);
  box-shadow: 0 8px 20px rgba(115, 255, 150, 0.2);
}

.mode-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.race-layout {
  position: relative;
  width: fit-content;
  margin: 0 auto;
}

#race-stage {
  width: clamp(700px, 97vw, 1600px) !important;
  height: min(93vh, calc(clamp(700px, 97vw, 1600px) / 1.5806)) !important;
  min-width: 680px;
  min-height: 430px;
  border-radius: 16px;
  border: 1px solid rgba(255, 214, 170, 0.35);
  box-shadow:
    0 20px 34px rgba(20, 12, 8, 0.52),
    inset 0 0 0 1px rgba(255, 235, 210, 0.08);
  background: #1f2f1c;
  overflow: hidden;
}

#race-stage canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.hud-overlay-layer {
  position: absolute;
  inset: 8px;
  pointer-events: none;
  z-index: 8;
}

.hud-cluster {
  position: absolute;
  display: grid;
  gap: 6px;
  width: min(255px, 26vw);
}

.hud-cluster--tl {
  top: 0;
  left: 0;
  width: min(210px, 22vw);
}

.hud-cluster--tr {
  top: 0;
  right: 0;
}

.hud-cluster--bl {
  bottom: 0;
  left: 0;
  width: min(210px, 21vw);
}

.hud-cluster--br {
  right: 0;
  bottom: 0;
  width: min(275px, 28vw);
}

.hud-box {
  background: linear-gradient(135deg, rgba(46, 30, 20, 0.72), rgba(26, 18, 13, 0.76));
  border: 1px solid rgba(255, 188, 132, 0.4);
  border-radius: 10px;
  padding: 8px 9px;
  display: grid;
  gap: 4px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 246, 231, 0.05),
    0 7px 12px rgba(14, 8, 6, 0.33);
}

.hud-box span {
  color: #f7ce9d;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.hud-box strong {
  font-family: "Russo One", sans-serif;
  font-size: 0.9rem;
  color: #fff4e6;
  text-shadow: 0 2px 0 rgba(25, 15, 10, 0.42);
}

.hud-box--time {
  border-color: rgba(255, 204, 112, 0.62);
  background: linear-gradient(135deg, rgba(74, 41, 18, 0.9), rgba(36, 22, 12, 0.93));
}

.hud-box--speed {
  border-color: rgba(220, 181, 110, 0.58);
  background: linear-gradient(135deg, rgba(72, 49, 24, 0.9), rgba(35, 26, 16, 0.92));
}

.hud-box--position {
  border-color: rgba(255, 162, 115, 0.58);
  background: linear-gradient(135deg, rgba(73, 33, 22, 0.9), rgba(36, 20, 15, 0.92));
}

.hud-box--effect {
  border-color: rgba(255, 190, 130, 0.56);
  background: linear-gradient(135deg, rgba(65, 42, 24, 0.89), rgba(34, 24, 15, 0.92));
}

.hud-box--standings {
  border-color: rgba(255, 198, 138, 0.56);
  background: linear-gradient(145deg, rgba(58, 33, 20, 0.9), rgba(30, 20, 15, 0.93));
}

.hud-cluster--tl .hud-box {
  padding: 6px 7px;
  gap: 3px;
  border-radius: 9px;
}

.hud-cluster--tl .hud-box span {
  font-size: 0.56rem;
  letter-spacing: 0.05em;
}

.hud-cluster--tl .hud-box strong {
  font-size: 0.8rem;
  line-height: 1.05;
}

.standings ol {
  margin: 0;
  padding-left: 14px;
  display: grid;
  gap: 3px;
  font-size: 0.78rem;
  line-height: 1.22;
  max-height: min(26vh, 160px);
  overflow-y: auto;
  color: #ffe6c8;
  text-shadow: 0 1px 0 rgba(20, 12, 8, 0.42);
}

.controls {
  border-radius: 12px;
  border: 1px solid rgba(255, 185, 122, 0.42);
  background: linear-gradient(140deg, rgba(42, 27, 19, 0.84), rgba(24, 16, 12, 0.9));
  padding: 10px 12px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 246, 231, 0.04),
    0 8px 14px rgba(16, 10, 7, 0.4);
}

.controls p {
  margin: 0;
  color: #f5cfaa;
  font-size: 0.82rem;
  line-height: 1.3;
}

.race-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(7, 12, 24, 0.28);
  font-family: "Russo One", sans-serif;
  font-size: clamp(2.1rem, 5vw, 4rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--overlay-color, #edf3ff);
  text-shadow:
    0 0 10px rgba(214, 234, 255, 0.75),
    0 6px 14px rgba(3, 8, 18, 0.55);
  opacity: 0;
  transform: scale(1);
  pointer-events: none;
}

.race-overlay.visible {
  display: flex;
  opacity: 1;
}

.race-overlay.countdown {
  font-size: clamp(5rem, 18vw, 18rem);
  font-family: "Snake Regular", "Russo One", sans-serif;
  letter-spacing: 0.02em;
}

.race-overlay.countdown.countdown-burst {
  animation: countdown-burst 820ms cubic-bezier(0.13, 0.16, 0.19, 1) both;
}

.race-overlay.overlay-go {
  font-size: clamp(3.2rem, 10vw, 9rem);
  animation: overlay-pop 640ms ease-out both;
}

.race-overlay.overlay-finish {
  font-size: clamp(2.6rem, 7.2vw, 5.6rem);
  animation: overlay-pop 700ms ease-out both;
}

@keyframes countdown-burst {
  0% {
    opacity: 0;
    transform: scale(0.08);
  }
  10% {
    opacity: 1;
    transform: scale(0.17);
  }
  28% {
    opacity: 1;
    transform: scale(0.5);
  }
  48% {
    opacity: 0.98;
    transform: scale(1.4);
  }
  68% {
    opacity: 0.82;
    transform: scale(3.6);
  }
  84% {
    opacity: 0.45;
    transform: scale(8.8);
  }
  100% {
    opacity: 0;
    transform: scale(15);
  }
}

@keyframes overlay-pop {
  0% {
    opacity: 0;
    transform: scale(0.72);
  }
  22% {
    opacity: 1;
    transform: scale(1.06);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.results-table {
  width: 100%;
  border-collapse: collapse;
}

.results-table th,
.results-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.results-table td:last-child,
.results-table th:last-child {
  text-align: right;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(140%);
  background: rgba(10, 18, 33, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 14px;
  transition: transform 180ms ease;
  z-index: 30;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 990px) {
  #race-stage {
    width: 98vw !important;
    height: calc(98vw / 1.5806) !important;
    max-height: 84vh;
    min-width: 0;
    min-height: 0;
  }

  .hud-overlay-layer {
    inset: 6px;
  }

  .hud-cluster {
    gap: 6px;
    width: min(230px, 40vw);
  }

  .hud-cluster--tl {
    width: min(190px, 34vw);
  }

  .hud-cluster--bl {
    width: min(180px, 34vw);
  }

  .hud-cluster--br {
    width: min(250px, 48vw);
  }

  .hud-box {
    padding: 7px 8px;
  }

  .hud-box span {
    font-size: 0.62rem;
  }

  .hud-box strong {
    font-size: 0.84rem;
  }

  .hud-cluster--tl .hud-box {
    padding: 5px 6px;
  }

  .hud-cluster--tl .hud-box span {
    font-size: 0.53rem;
  }

  .hud-cluster--tl .hud-box strong {
    font-size: 0.72rem;
  }

  .standings ol {
    font-size: 0.73rem;
    max-height: min(24vh, 120px);
  }

  .controls p {
    font-size: 0.76rem;
  }
}

@media (max-width: 680px) {
  .app {
    padding: 16px 10px 20px;
  }

  .actions {
    flex-wrap: wrap;
  }

  .online-room-actions {
    grid-template-columns: 1fr;
  }

  .hud-overlay-layer {
    inset: 5px;
  }

  .hud-cluster {
    width: min(178px, 44vw);
    gap: 4px;
  }

  .hud-cluster--tl {
    width: min(150px, 41vw);
  }

  .hud-cluster--br {
    left: 0;
    right: 0;
    width: auto;
  }

  .standings ol {
    max-height: 88px;
  }

  .controls {
    padding: 8px 9px;
  }

  .controls p {
    font-size: 0.72rem;
  }
}
