:root {
  color-scheme: dark;
  --bg: #07111f;
  --ink: #f8fbff;
  --muted: #bed0e5;
  --steel: #d8e7f4;
  --green: #5eead4;
  --amber: #ffd166;
  --red: #ff5f7e;
  --cyan: #55d6ff;
  --pink: #ff6f91;
  --cream: #fff1c7;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  touch-action: none;
}

body { min-height: 100svh; }

button {
  font: inherit;
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
}

#gameRoot {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 22%, rgba(85, 214, 255, 0.18), transparent 34%),
    radial-gradient(circle at 82% 24%, rgba(255, 209, 102, 0.16), transparent 32%),
    linear-gradient(180deg, #102034 0%, #0a1728 54%, #07111f 100%);
}

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

#hud {
  position: absolute;
  z-index: 4;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(480px, 42vw);
  min-height: 66px;
  padding: 10px 14px;
  border: 1px solid rgba(85, 214, 255, 0.36);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(8, 16, 28, 0.9), rgba(16, 32, 52, 0.78));
  box-shadow: 0 16px 54px rgba(0, 0, 0, 0.34), 0 0 34px rgba(94, 234, 212, 0.12);
  backdrop-filter: blur(12px);
}

.mark,
.rail-emblem {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 41%, var(--steel) 42% 56%, transparent 57%),
    linear-gradient(45deg, transparent 42%, var(--green) 43% 55%, transparent 56%),
    radial-gradient(circle at 72% 30%, var(--red) 0 13%, transparent 14%),
    var(--bg);
  box-shadow: 0 0 28px rgba(94, 234, 212, 0.38);
}

.brand-lockup h1 {
  margin: 0;
  color: #ffffff;
  font-size: 26px;
  line-height: 1;
}

.brand-lockup p {
  margin: 5px 0 0;
  color: #e2eefb;
  font-size: 13px;
  line-height: 1.25;
}

.meter-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(96px, 1fr));
  gap: 8px;
  width: min(510px, 52vw);
}

.meter {
  position: relative;
  min-height: 56px;
  overflow: hidden;
  padding: 8px 11px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(7, 13, 28, 0.76);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.22);
}

.meter span {
  display: block;
  color: #cfe1f7;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.meter b {
  display: block;
  margin-top: 5px;
  color: #ffffff;
  font-size: 21px;
  line-height: 1;
}

.meter i {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 50%;
  height: 4px;
  background: var(--green);
  box-shadow: 0 0 18px currentColor;
}

.score i { background: var(--pink); }
.arrivals i { background: var(--green); }
.combo i { background: var(--amber); }
.timer i { background: var(--cyan); }

#touchControls {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 128px 128px 118px 106px;
  gap: 10px;
  transform: translateX(-50%);
}

.switch-button,
.signal-button,
.brake-button {
  min-width: 88px;
  min-height: 64px;
  border: 0;
  border-radius: 999px;
  color: #07111f;
  cursor: pointer;
  font-weight: 950;
  text-transform: uppercase;
  box-shadow:
    inset 0 -7px 18px rgba(3, 7, 18, 0.2),
    0 16px 34px rgba(0, 0, 0, 0.3);
}

.switch-button { background: linear-gradient(135deg, #55d6ff, #5eead4); }
.signal-button { background: linear-gradient(135deg, #5eead4, #ffd166); }
.brake-button { background: linear-gradient(135deg, #ff5f7e, #ffd166); }

.switch-button:active,
.signal-button:active,
.brake-button:active {
  transform: translateY(2px) scale(0.98);
}

#modal {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 50% 50%, rgba(85, 214, 255, 0.12), transparent 42%),
    rgba(6, 10, 22, 0.2);
  transition: opacity 180ms ease, visibility 180ms ease;
}

#modal.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.modal-frame {
  width: min(560px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid rgba(85, 214, 255, 0.42);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(8, 16, 30, 0.95), rgba(16, 42, 62, 0.92));
  box-shadow:
    0 30px 100px rgba(0, 0, 0, 0.48),
    0 0 80px rgba(94, 234, 212, 0.18);
  text-align: center;
}

.titleplate {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.titleplate p {
  margin: 0;
  color: var(--amber);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.titleplate h2 {
  margin: 0;
  color: #ffffff;
  font-size: 54px;
  line-height: 0.96;
}

.brief {
  margin: 16px auto 0;
  max-width: 460px;
  color: #e3f0ff;
  font-size: 16px;
  line-height: 1.45;
}

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

.brief-grid span {
  display: grid;
  align-items: center;
  min-height: 58px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #eef6ff;
  font-size: 12px;
  font-weight: 850;
}

#modalPrimary {
  width: min(270px, 100%);
  min-height: 58px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--amber), var(--green));
  color: #07111f;
  cursor: pointer;
  font-size: 15px;
  font-weight: 950;
  text-transform: uppercase;
  box-shadow: 0 18px 48px rgba(255, 209, 102, 0.28);
}

@media (max-width: 820px) {
  #hud {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .brand-lockup {
    width: min(100%, 360px);
    min-height: 58px;
  }

  .brand-lockup h1 { font-size: 19px; }

  .brand-lockup p {
    max-width: 278px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .meter-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: min(100%, 370px);
  }

  .meter {
    min-height: 48px;
    padding: 7px 8px;
  }

  .meter b { font-size: 17px; }

  #touchControls {
    width: calc(100vw - 18px);
    grid-template-columns: 1fr 1fr 0.92fr 0.82fr;
    gap: 7px;
  }

  .switch-button,
  .signal-button,
  .brake-button {
    min-width: 0;
    min-height: 62px;
    padding: 0 5px;
    font-size: 12px;
  }

  .modal-frame { padding: 18px; }
  .titleplate h2 { font-size: 40px; }
  .brief-grid { grid-template-columns: 1fr; }
}
