:root {
  color-scheme: dark;
  --bg: #07111b;
  --panel: rgba(9, 18, 30, 0.56);
  --panel-strong: rgba(7, 14, 26, 0.72);
  --panel-soft: rgba(255, 255, 255, 0.05);
  --line: rgba(184, 226, 255, 0.18);
  --line-strong: rgba(133, 207, 255, 0.36);
  --text: #f6fbff;
  --muted: #95a9be;
  --accent: #5ee7ff;
  --accent-strong: #8bffbe;
  --warning: #ffb168;
  --danger: #ff6b74;
  --gold: #ffd56a;
  --shadow-xl: 0 28px 80px rgba(0, 0, 0, 0.42);
  --shadow-lg: 0 18px 42px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 12px 26px rgba(0, 0, 0, 0.24);
  --speed-color: #f7fbff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(89, 186, 255, 0.18), transparent 34%),
    linear-gradient(180deg, #08111d 0%, #05070d 100%);
  color: var(--text);
  font-family: "Bahnschrift", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body {
  position: relative;
}

#game-root {
  position: absolute;
  inset: 0;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.screen-vignette,
.screen-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.screen-vignette {
  background:
    radial-gradient(circle at center, transparent 52%, rgba(3, 7, 14, 0.14) 74%, rgba(2, 4, 9, 0.54) 100%),
    linear-gradient(180deg, rgba(2, 4, 9, 0.06), rgba(2, 4, 9, 0.18));
}

.screen-glow {
  background:
    radial-gradient(circle at 18% 14%, rgba(95, 231, 255, 0.1), transparent 24%),
    radial-gradient(circle at 82% 76%, rgba(255, 161, 98, 0.08), transparent 24%);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(94, 231, 255, 0.08), transparent 32%),
    rgba(3, 8, 14, 0.58);
  backdrop-filter: blur(14px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease;
}

#start-screen {
  min-height: 100vh;
  align-items: stretch;
  justify-items: center;
  padding: clamp(14px, 2vh, 24px) clamp(16px, 2vw, 28px);
  overflow: auto;
}

#result-screen {
  min-height: 100vh;
  align-items: stretch;
  justify-items: center;
  padding: clamp(12px, 2vh, 24px) clamp(16px, 2vw, 28px);
  overflow: auto;
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.hidden {
  display: none !important;
}

.panel {
  position: relative;
  width: min(940px, 100%);
  padding: 32px;
  border-radius: 28px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(17, 31, 48, 0.82), rgba(6, 10, 18, 0.74)),
    var(--panel-strong);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: inherit;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.12), transparent 28%),
    radial-gradient(circle at top right, rgba(94, 231, 255, 0.18), transparent 30%);
  pointer-events: none;
}

.panel-large {
  width: min(1040px, 100%);
}

.start-panel {
  width: min(1200px, 100%);
  min-height: calc(100vh - clamp(28px, 4vh, 56px));
  max-height: calc(100vh - clamp(28px, 4vh, 56px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(12px, 1.8vh, 20px);
  padding: clamp(18px, 2vw, 28px);
  overflow: auto;
  scrollbar-width: thin;
}

.panel-results {
  width: min(1120px, 100%);
  max-height: calc(100vh - clamp(24px, 4vh, 48px));
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
  gap: clamp(10px, 1.4vh, 16px);
  padding: clamp(18px, 2vw, 28px);
  overflow: hidden;
}

.panel-results > * {
  min-width: 0;
}

.panel-results .summary-line,
.panel-results .record-board,
.panel-results .results-scroll-area,
.panel-results .primary-button {
  margin-top: 0;
}

.eyebrow {
  position: relative;
  z-index: 1;
  margin: 0 0 10px;
  color: #9eeaff;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  font-size: 0.76rem;
}

h1,
h2,
h3,
p,
ol,
ul {
  position: relative;
  z-index: 1;
  margin: 0;
}

h1 {
  font-size: clamp(2.7rem, 7vw, 5.8rem);
  line-height: 0.9;
}

h2 {
  font-size: clamp(1.7rem, 3vw, 2.25rem);
}

h3 {
  font-size: 0.98rem;
  color: #cbe9ff;
  letter-spacing: 0.06em;
}

.hero-title {
  display: grid;
  gap: 2px;
  margin-top: 2px;
  font-size: clamp(3rem, 5.2vw, 5.4rem);
  line-height: 0.84;
  max-width: 8ch;
}

.hero-title span {
  display: block;
  width: fit-content;
  background: linear-gradient(120deg, #f7fbff 4%, #9deeff 45%, #ffb67d 96%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 10px 36px rgba(94, 231, 255, 0.1);
}

.hero-title span:last-child {
  letter-spacing: 0.08em;
}

.intro,
.summary-line {
  max-width: 58ch;
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.58;
}

.start-header {
  display: grid;
  gap: clamp(6px, 1vh, 10px);
  align-content: start;
}

.start-content {
  display: grid;
  grid-template-columns: minmax(320px, 0.86fr) minmax(420px, 1.14fr);
  gap: clamp(14px, 1.8vw, 22px);
  min-height: 0;
  align-items: start;
}

.start-column {
  display: grid;
  gap: clamp(10px, 1.4vh, 16px);
  min-height: 0;
  align-content: start;
}

.start-selection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: clamp(10px, 1.4vw, 16px);
}

.online-section {
  align-content: start;
}

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

.online-controls {
  display: grid;
  gap: 12px;
}

.online-field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.input-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.text-input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid rgba(184, 226, 255, 0.12);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
    rgba(6, 12, 22, 0.56);
  color: var(--text);
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.text-input:focus {
  border-color: rgba(94, 231, 255, 0.34);
  box-shadow: 0 0 0 4px rgba(94, 231, 255, 0.08);
}

.text-input::placeholder {
  color: rgba(149, 169, 190, 0.75);
}

.online-room-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 10px;
}

.room-code-input {
  text-transform: uppercase;
}

.secondary-button {
  position: relative;
  overflow: hidden;
  min-height: 42px;
  padding: 10px 16px;
  border-radius: 14px;
  border: 1px solid rgba(184, 226, 255, 0.14);
  background:
    linear-gradient(135deg, rgba(94, 231, 255, 0.14), rgba(255, 177, 104, 0.08)),
    rgba(8, 14, 24, 0.72);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.secondary-button:hover {
  transform: translateY(-2px);
  border-color: rgba(94, 231, 255, 0.28);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.22), 0 0 22px rgba(94, 231, 255, 0.1);
}

.secondary-button:active {
  transform: translateY(0);
}

.difficulty-option:disabled,
.secondary-button:disabled,
.primary-button:disabled,
.text-input:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  filter: saturate(0.72);
  box-shadow: none;
}

.difficulty-option:disabled:hover,
.secondary-button:disabled:hover,
.primary-button:disabled:hover {
  transform: none;
  box-shadow: none;
}

.secondary-button-soft {
  background:
    linear-gradient(135deg, rgba(255, 177, 104, 0.12), rgba(255, 107, 116, 0.08)),
    rgba(8, 14, 24, 0.72);
}

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

.online-status {
  color: var(--muted);
  line-height: 1.5;
  min-height: 1.5em;
}

.compact-leaderboard {
  gap: 8px;
}

.start-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  min-height: 0;
}

.start-actions .primary-button {
  margin-top: 0;
  min-width: min(300px, 100%);
}

.instruction-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  margin-top: 26px;
}

.results-scroll-area {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  align-content: start;
}

.results-stack,
.results-column,
.history-board {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
}

.results-section-card {
  position: relative;
  padding: 16px 18px 18px;
  border-radius: 20px;
  border: 1px solid rgba(184, 226, 255, 0.12);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.025)),
    rgba(9, 18, 30, 0.48);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.results-section-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 32%);
  pointer-events: none;
}

.start-instruction-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: clamp(10px, 1.3vw, 14px);
  margin-top: 0;
}

.instruction-card,
.difficulty-section,
.record-board,
.debug-panel {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(184, 226, 255, 0.12);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.025)),
    rgba(9, 18, 30, 0.48);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-md);
}

.instruction-card::before,
.difficulty-section::before,
.record-board::before,
.debug-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 32%);
  pointer-events: none;
}

.instruction-card {
  padding: 18px 20px;
  border-radius: 20px;
}

.start-panel .instruction-card {
  padding: clamp(14px, 1.5vw, 18px);
}

.instruction-card h2 {
  font-size: 1.15rem;
}

.start-panel .instruction-card h2,
.start-panel .difficulty-header h2 {
  font-size: clamp(1rem, 1.5vw, 1.15rem);
}

.instruction-card p {
  margin-top: 10px;
  color: var(--muted);
}

.start-panel .instruction-card p {
  margin-top: 8px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.difficulty-section {
  margin-top: 24px;
  padding: 20px;
  border-radius: 22px;
}

.start-record-board {
  margin-top: 24px;
  padding: 20px 20px 18px;
  border-radius: 22px;
}

.start-section,
.start-record-board {
  margin-top: 0;
  padding: clamp(14px, 1.5vw, 18px);
}

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

.start-panel .difficulty-header {
  align-items: start;
  gap: 10px;
}

.difficulty-description {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.difficulty-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.start-panel .difficulty-options {
  grid-template-columns: repeat(auto-fit, minmax(138px, 1fr));
  gap: 10px;
  margin-top: 0;
}

.start-panel .mode-options {
  margin-top: 0;
}

.difficulty-option {
  position: relative;
  display: grid;
  gap: 8px;
  padding: 18px 18px 16px;
  border-radius: 18px;
  border: 1px solid rgba(184, 226, 255, 0.14);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
    rgba(7, 13, 22, 0.6);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease;
}

.start-panel .difficulty-option {
  min-height: 0;
  padding: 12px 14px 11px;
  gap: 6px;
}

.start-panel .online-controls {
  margin-top: 10px;
}

.start-panel .online-status {
  font-size: 0.84rem;
}

.difficulty-option::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(94, 231, 255, 0.16), transparent 42%);
  opacity: 0;
  transition: opacity 180ms ease;
}

.difficulty-option strong,
.difficulty-option span {
  position: relative;
  z-index: 1;
}

.difficulty-option strong {
  font-size: 1rem;
}

.difficulty-option span {
  color: var(--muted);
  line-height: 1.55;
}

.start-panel .difficulty-option strong {
  font-size: 0.94rem;
}

.start-panel .difficulty-option span {
  font-size: 0.82rem;
  line-height: 1.35;
}

.difficulty-option:hover {
  transform: translateY(-4px) scale(1.015);
  border-color: rgba(116, 224, 255, 0.38);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.26), 0 0 28px rgba(94, 231, 255, 0.1);
}

.difficulty-option:hover::before,
.difficulty-option.active::before {
  opacity: 1;
}

.difficulty-option.active {
  border-color: rgba(94, 231, 255, 0.44);
  background:
    linear-gradient(180deg, rgba(94, 231, 255, 0.12), rgba(255, 177, 104, 0.06)),
    rgba(8, 16, 28, 0.7);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    0 18px 36px rgba(0, 0, 0, 0.24),
    0 0 30px rgba(94, 231, 255, 0.12);
}

.primary-button,
.debug-toggle {
  position: relative;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.04em;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    filter 160ms ease;
}

.primary-button::before,
.debug-toggle::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.34), transparent 40%, transparent 60%, rgba(255, 255, 255, 0.14));
  transform: translateX(-120%);
  transition: transform 280ms ease;
}

.primary-button:hover::before,
.debug-toggle:hover::before {
  transform: translateX(0);
}

.primary-button {
  margin-top: 30px;
  padding: 15px 28px;
  background: linear-gradient(135deg, #5ee7ff 0%, #8bffbe 36%, #ffb168 100%);
  color: #06131b;
  font-size: 1rem;
  box-shadow: 0 16px 36px rgba(94, 231, 255, 0.24), 0 10px 22px rgba(255, 177, 104, 0.18);
}

.primary-button:hover {
  transform: translateY(-3px) scale(1.02);
  filter: brightness(1.04);
  box-shadow: 0 20px 42px rgba(94, 231, 255, 0.26), 0 12px 28px rgba(255, 177, 104, 0.2);
}

.primary-button:active,
.debug-toggle:active {
  transform: translateY(0) scale(0.985);
}

.center-banner {
  position: absolute;
  z-index: 35;
  left: 50%;
  top: 14%;
  transform: translateX(-50%);
  min-width: 172px;
  padding: 16px 26px;
  border-radius: 999px;
  border: 1px solid rgba(184, 226, 255, 0.22);
  background:
    linear-gradient(180deg, rgba(19, 34, 52, 0.78), rgba(8, 13, 22, 0.78)),
    rgba(8, 14, 24, 0.76);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-xl);
  text-align: center;
  font-size: clamp(2.1rem, 7vw, 5rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.hud {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.hud-card {
  position: absolute;
  overflow: hidden;
  border-radius: 24px;
  border: 1px solid rgba(184, 226, 255, 0.18);
  background:
    linear-gradient(180deg, rgba(20, 35, 54, 0.52), rgba(8, 14, 24, 0.6)),
    var(--panel);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease,
    transform 180ms ease;
}

.hud-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.14), transparent 34%),
    radial-gradient(circle at top right, rgba(94, 231, 255, 0.12), transparent 28%);
  pointer-events: none;
}

.hud-card::after {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.38), transparent);
  opacity: 0.78;
}

#hud-race-card {
  top: 24px;
  left: 24px;
  width: min(430px, calc(100vw - 48px));
  padding: 20px 20px 18px;
}

#hud-time-card {
  top: 24px;
  right: 24px;
  min-width: 290px;
  padding: 18px 20px 16px;
}

#hud-speed-card {
  right: 24px;
  bottom: 24px;
  width: min(390px, calc(100vw - 48px));
  padding: 20px;
}

#minimap-panel {
  left: 24px;
  bottom: 24px;
  width: min(270px, calc(100vw - 48px));
  padding: 16px;
}

.hud-card-head,
.hud-chip-row,
.hud-metric-grid,
.hud-detail-grid,
.hud-speed-readout {
  position: relative;
  z-index: 1;
}

.hud-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hud-section-label {
  color: #cfe9ff;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.hud-card-ping {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5ee7ff, #8bffbe);
  box-shadow: 0 0 0 4px rgba(94, 231, 255, 0.12), 0 0 16px rgba(94, 231, 255, 0.45);
  animation: hudPing 1.8s ease-in-out infinite;
}

.hud-metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.hud-metric-block,
.hud-detail-block {
  padding: 14px 14px 12px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.035);
}

.hud-metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

.hud-metric-value,
.hud-detail-value,
.hud-time-value,
.hud-speed-value {
  display: block;
  margin-top: 7px;
  color: var(--text);
  font-weight: 800;
}

.hud-metric-value-lg {
  font-size: clamp(1.25rem, 2.4vw, 1.8rem);
  letter-spacing: 0.02em;
}

.hud-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.hud-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.82rem;
}

.hud-chip strong {
  color: var(--text);
}

.hud-chip-inline {
  padding-right: 14px;
}

.hud-time-value {
  margin-top: 12px;
  font-size: clamp(2rem, 4vw, 3rem);
  letter-spacing: 0.06em;
  text-shadow: 0 10px 28px rgba(94, 231, 255, 0.16);
}

.hud-support-text {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.6;
}

.minimap-canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  margin-top: 14px;
  border-radius: 18px;
  border: 1px solid rgba(184, 226, 255, 0.12);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
    rgba(6, 12, 22, 0.68);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.hud-speed-readout {
  margin-top: 14px;
}

.hud-speed-value {
  margin-top: 8px;
  font-size: clamp(2.25rem, 4.5vw, 3.5rem);
  letter-spacing: 0.04em;
  color: var(--speed-color);
  text-shadow: 0 0 26px rgba(121, 216, 255, 0.2);
  transition: color 180ms ease, text-shadow 180ms ease;
}

.hud-speed-bar {
  position: relative;
  z-index: 1;
  height: 12px;
  margin-top: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.hud-speed-bar-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffffff 0%, #79d8ff 48%, #ff6b74 100%);
  box-shadow: 0 0 20px rgba(121, 216, 255, 0.28);
  transition: width 180ms ease, box-shadow 180ms ease, filter 180ms ease;
}

.hud-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 15px;
}

.hud-detail-value {
  font-size: 1.05rem;
}

.hud-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(94, 231, 255, 0.2);
  background: rgba(94, 231, 255, 0.1);
  color: #e8fbff;
  font-size: 0.88rem;
  font-weight: 700;
  transition:
    color 180ms ease,
    background 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.hud-status-pill[data-tone="neutral"] {
  border-color: rgba(94, 231, 255, 0.22);
  background: rgba(94, 231, 255, 0.1);
}

.hud-status-pill[data-tone="notice"] {
  border-color: rgba(139, 255, 190, 0.28);
  background: rgba(139, 255, 190, 0.12);
}

.hud-status-pill[data-tone="drift"] {
  border-color: rgba(255, 177, 104, 0.32);
  background: rgba(255, 177, 104, 0.14);
  color: #fff2df;
}

.hud-status-pill[data-tone="boost"] {
  border-color: rgba(94, 231, 255, 0.42);
  background: rgba(94, 231, 255, 0.18);
  box-shadow: 0 0 24px rgba(94, 231, 255, 0.16);
}

.hud-status-pill[data-tone="warning"] {
  border-color: rgba(255, 107, 116, 0.34);
  background: rgba(255, 107, 116, 0.14);
  color: #fff0f1;
}

.hud.is-drifting #hud-speed-card {
  border-color: rgba(255, 177, 104, 0.34);
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.34), 0 0 34px rgba(255, 177, 104, 0.16);
}

.hud.is-drifting #hud-speed-card::before {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.14), transparent 34%),
    radial-gradient(circle at top right, rgba(255, 177, 104, 0.18), transparent 28%);
}

.hud.is-boosting #hud-speed-card {
  border-color: rgba(94, 231, 255, 0.42);
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.34), 0 0 36px rgba(94, 231, 255, 0.22);
}

.hud.is-boosting .hud-speed-bar-fill {
  filter: brightness(1.18);
  box-shadow: 0 0 28px rgba(94, 231, 255, 0.4);
}

#hud-speed-card.boost-burst {
  animation: boostBurst 620ms ease-out;
}

.ui-value-pop {
  animation: valuePop 260ms ease;
}

.ui-rank-pop {
  animation: rankShift 500ms cubic-bezier(0.2, 0.82, 0.2, 1);
}

.ui-status-pop {
  animation: statusPop 320ms ease;
}

.result-list,
.lap-time-list,
.mini-leaderboard-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 0;
  list-style: none;
}

.panel-results .result-list,
.panel-results .lap-time-list,
.panel-results .mini-leaderboard-list {
  margin-top: 0;
  max-height: none;
  overflow: visible;
  padding-right: 0;
  align-content: start;
}

.result-item,
.lap-time-item {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  border-radius: 20px;
  border: 1px solid rgba(184, 226, 255, 0.12);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.025)),
    rgba(8, 14, 24, 0.56);
  overflow: hidden;
}

.mini-leaderboard-item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(184, 226, 255, 0.1);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.02)),
    rgba(8, 14, 24, 0.5);
  overflow: hidden;
}

.result-item::before,
.lap-time-item::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 34%);
  pointer-events: none;
}

.mini-leaderboard-item::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.07), transparent 34%);
  pointer-events: none;
}

.mini-leaderboard-main,
.mini-leaderboard-tag {
  position: relative;
  z-index: 1;
}

.mini-leaderboard-main {
  display: grid;
  gap: 4px;
}

.mini-leaderboard-main strong {
  font-size: 1rem;
  color: var(--text);
}

.mini-leaderboard-main span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.mini-leaderboard-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(94, 231, 255, 0.12);
  background: rgba(94, 231, 255, 0.08);
  color: #dff8ff;
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
}

.result-item {
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.result-item.is-first {
  border-color: rgba(255, 213, 106, 0.32);
  box-shadow: 0 0 30px rgba(255, 213, 106, 0.12);
}

.result-item.is-player {
  border-color: rgba(94, 231, 255, 0.32);
  background:
    linear-gradient(180deg, rgba(94, 231, 255, 0.08), rgba(255, 255, 255, 0.03)),
    rgba(8, 14, 24, 0.62);
}

.result-rank-badge,
.lap-time-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.05);
  font-weight: 800;
  color: var(--text);
}

.result-item.is-first .result-rank-badge {
  color: #251400;
  border-color: rgba(255, 213, 106, 0.38);
  background: linear-gradient(135deg, #ffd56a, #ffb168);
}

.result-item-main,
.lap-time-main {
  display: grid;
  gap: 4px;
}

.result-item-name,
.lap-time-title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
}

.result-item-meta,
.lap-time-meta {
  color: var(--muted);
  line-height: 1.5;
}

.result-item-tag {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(94, 231, 255, 0.22);
  background: rgba(94, 231, 255, 0.1);
  color: #e8fbff;
  font-size: 0.8rem;
  font-weight: 700;
}

.result-item.is-first .result-item-tag {
  border-color: rgba(255, 213, 106, 0.26);
  background: rgba(255, 213, 106, 0.12);
  color: #ffe9b4;
}

.record-board {
  margin-top: 18px;
  padding: 16px 18px;
  border-radius: 20px;
}

.history-board {
  margin-top: 20px;
}

.panel-results .history-board {
  margin-top: 0;
}

.mini-leaderboard-section {
  margin-top: 14px;
}

.start-panel .mini-leaderboard-section {
  margin-top: 10px;
}

.record-line {
  margin-top: 8px;
  color: var(--muted);
}

.record-line:first-child {
  margin-top: 0;
}

.record-line-highlight {
  color: #fff0da;
  font-weight: 800;
  min-height: 1.4em;
}

.start-panel .record-line {
  margin-top: 6px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.start-panel .mini-leaderboard-list {
  margin-top: 10px;
  gap: 8px;
}

.start-panel .mini-leaderboard-item {
  padding: 10px 12px;
}

.start-panel .mini-leaderboard-item:nth-child(n + 3) {
  display: none;
}

.debug-toggle {
  position: absolute;
  left: 24px;
  bottom: 24px;
  z-index: 40;
  padding: 12px 18px;
  border: 1px solid rgba(184, 226, 255, 0.16);
  background:
    linear-gradient(135deg, rgba(94, 231, 255, 0.18), rgba(255, 177, 104, 0.16)),
    rgba(8, 14, 24, 0.76);
  color: var(--text);
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(14px);
}

#start-screen.visible ~ .debug-toggle {
  top: clamp(14px, 2vh, 24px);
  right: clamp(16px, 2vw, 24px);
  bottom: auto;
  left: auto;
  padding: 10px 16px;
  font-size: 0.9rem;
}

.debug-toggle:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.28), 0 0 26px rgba(94, 231, 255, 0.12);
}

.debug-panel {
  position: absolute;
  left: 24px;
  bottom: 78px;
  z-index: 40;
  width: min(320px, calc(100vw - 48px));
  padding: 18px;
  border-radius: 22px;
}

#start-screen.visible ~ .debug-panel {
  top: clamp(64px, 9vh, 86px);
  right: clamp(16px, 2vw, 24px);
  bottom: auto;
  left: auto;
  max-height: calc(100vh - clamp(88px, 12vh, 120px));
  overflow: auto;
}

.debug-panel-header p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.55;
}

.debug-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  margin-top: 15px;
  color: var(--muted);
}

.debug-control strong {
  color: var(--text);
}

.debug-control input {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: #79d8ff;
}

@keyframes hudPing {
  0%,
  100% {
    opacity: 0.8;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.12);
  }
}

@keyframes valuePop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes rankShift {
  0% {
    transform: scale(1) translateY(0);
  }
  30% {
    transform: scale(1.12) translateY(-2px);
  }
  100% {
    transform: scale(1) translateY(0);
  }
}

@keyframes statusPop {
  0% {
    transform: scale(1);
    filter: brightness(1);
  }
  40% {
    transform: scale(1.06);
    filter: brightness(1.12);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

@keyframes boostBurst {
  0% {
    transform: scale(1);
    box-shadow: 0 22px 50px rgba(0, 0, 0, 0.34), 0 0 0 rgba(94, 231, 255, 0);
  }
  30% {
    transform: scale(1.025);
    box-shadow: 0 24px 56px rgba(0, 0, 0, 0.36), 0 0 40px rgba(94, 231, 255, 0.34);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 22px 50px rgba(0, 0, 0, 0.34), 0 0 0 rgba(94, 231, 255, 0);
  }
}

@media (max-width: 1180px) {
  .start-content {
    grid-template-columns: minmax(280px, 0.82fr) minmax(0, 1.18fr);
  }

  .start-selection-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

@media (max-width: 980px) {
  #start-screen {
    padding-inline: 16px;
  }

  .start-panel {
    min-height: auto;
    max-height: none;
  }

  .start-content {
    grid-template-columns: 1fr;
  }

  .start-selection-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }

  .online-room-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .start-panel .mini-leaderboard-item:nth-child(n + 4) {
    display: none;
  }
}

@media (max-height: 900px) {
  .panel-results {
    max-height: calc(100vh - 20px);
    gap: 10px;
    padding: 20px 22px;
  }

  .panel-results .summary-line,
  .panel-results .record-line,
  .panel-results .result-item-meta,
  .panel-results .lap-time-meta,
  .panel-results .mini-leaderboard-main span {
    font-size: 0.86rem;
    line-height: 1.42;
  }

  .panel-results .record-board {
    padding: 14px 16px;
  }

  .panel-results .result-item,
  .panel-results .lap-time-item,
  .panel-results .mini-leaderboard-item {
    padding: 12px 14px;
    border-radius: 16px;
  }

  .panel-results .result-list,
  .panel-results .lap-time-list,
  .panel-results .mini-leaderboard-list {
    gap: 8px;
    max-height: none;
  }

  .panel-results .primary-button {
    padding: 13px 24px;
    margin-top: 0;
  }

  #start-screen {
    padding-block: 12px;
  }

  .start-panel {
    gap: 12px;
    padding: 18px 20px;
  }

  .hero-title {
    font-size: clamp(2.8rem, 4.5vw, 4.6rem);
    line-height: 0.82;
  }

  .intro {
    margin-top: 10px;
    font-size: 0.95rem;
    line-height: 1.48;
  }

  .start-panel .instruction-card,
  .start-section,
  .start-record-board {
    padding: 14px;
  }

  .start-panel .difficulty-description {
    font-size: 0.84rem;
  }
}

@media (max-height: 820px) {
  .panel-results {
    gap: 8px;
    padding: 18px 20px;
  }

  .panel-results h2 {
    font-size: clamp(1.45rem, 2.4vw, 1.9rem);
  }

  .panel-results h3 {
    font-size: 0.9rem;
  }

  .panel-results .record-board {
    padding: 12px 14px;
  }

  .panel-results .result-rank-badge,
  .panel-results .lap-time-badge {
    min-width: 62px;
    min-height: 36px;
    padding: 0 12px;
  }

  .panel-results .result-item-name,
  .panel-results .lap-time-title,
  .panel-results .mini-leaderboard-main strong {
    font-size: 0.92rem;
  }

  .panel-results .result-list,
  .panel-results .lap-time-list,
  .panel-results .mini-leaderboard-list {
    max-height: none;
  }

  .start-panel {
    gap: 10px;
    padding: 16px 18px;
  }

  .hero-title {
    font-size: clamp(2.45rem, 4vw, 4rem);
  }

  .start-panel .instruction-card p,
  .start-panel .difficulty-option span,
  .start-panel .record-line {
    font-size: 0.8rem;
  }

  .start-panel .difficulty-options {
    gap: 8px;
  }

  .start-panel .difficulty-option {
    padding: 10px 12px;
  }

  .start-panel .difficulty-description {
    display: none;
  }

  .start-panel .mini-leaderboard-item:nth-child(n + 2) {
    display: none;
  }

  .start-panel .online-room-members {
    display: none;
  }
}

@media (max-height: 780px) {
  .panel-results {
    padding: 16px 18px;
  }

  .panel-results .record-board {
    padding: 10px 12px;
  }

  .panel-results .result-item,
  .panel-results .lap-time-item,
  .panel-results .mini-leaderboard-item {
    padding: 10px 12px;
  }

  .panel-results .results-scroll-area,
  .panel-results .results-stack {
    gap: 10px;
  }

  .panel-results .result-list,
  .panel-results .lap-time-list,
  .panel-results .mini-leaderboard-list {
    max-height: none;
  }

  .start-record-board {
    display: none;
  }

  .start-actions .primary-button {
    padding: 13px 24px;
  }
}

@media (max-width: 920px) {
  .panel,
  .panel-large,
  .panel-results {
    padding: 24px;
  }

  #hud-race-card,
  #hud-time-card,
  #hud-speed-card,
  #minimap-panel {
    position: static;
    width: 100%;
    min-width: 0;
  }

  .hud {
    display: grid;
    align-content: start;
    gap: 12px;
    padding: 16px;
  }

  .hud-metric-grid,
  .hud-detail-grid,
  .results-scroll-area {
    grid-template-columns: 1fr;
  }

  .result-item {
    grid-template-columns: 1fr;
  }

  .mini-leaderboard-item {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .debug-panel {
    left: 16px;
    bottom: 74px;
    width: calc(100vw - 32px);
  }

  .debug-toggle {
    left: 16px;
    bottom: 16px;
  }

  #start-screen.visible ~ .debug-toggle {
    left: auto;
    right: 16px;
    top: 16px;
    bottom: auto;
  }

  #start-screen.visible ~ .debug-panel {
    right: 16px;
    left: auto;
    top: 64px;
    bottom: auto;
    width: min(320px, calc(100vw - 32px));
  }
}

@media (max-width: 640px) {
  .overlay {
    padding: 16px;
  }

  .instruction-grid,
  .difficulty-options,
  .mode-options,
  .online-field-grid,
  .online-meta-grid {
    grid-template-columns: 1fr;
  }

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

  .hero-title {
    gap: 4px;
  }

  .hud-time-value,
  .hud-speed-value {
    letter-spacing: 0.02em;
  }

  .start-actions .primary-button {
    width: 100%;
    min-width: 0;
  }
}
