:root {
  --bg-1: #152033;
  --bg-2: #243a54;
  --card: rgba(18, 30, 48, 0.78);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f7fbff;
  --muted: #b8c5d3;
  --accent: #ff9f43;
  --accent-2: #ffd166;
  --danger: #ff4d4f;
  --ok: #31d0aa;
  --board-size: min(92vw, 440px);
  --radius: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: radial-gradient(circle at 20% 10%, #355d8a 0%, var(--bg-2) 35%, var(--bg-1) 100%);
  color: var(--text);
  min-height: 100%;
}

body {
  padding: env(safe-area-inset-top) 10px env(safe-area-inset-bottom);
}

.bg-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image: radial-gradient(rgba(255, 255, 255, 0.3) 0.6px, transparent 0.8px);
  background-size: 3px 3px;
}

.app {
  position: relative;
  max-width: 560px;
  margin: 0 auto;
  padding: 10px;
  display: grid;
  gap: 10px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

h1 {
  margin: 0;
  font-size: clamp(1.5rem, 3.8vw, 1.95rem);
  letter-spacing: 1px;
}

.eyebrow {
  margin: 0;
  font-size: 0.82rem;
  color: var(--accent-2);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.18);
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 9px;
}

.stat {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 11px;
  padding: 8px;
  text-align: center;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.stat strong {
  font-size: 1rem;
}

.rage {
  padding: 10px;
}

.rage-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.rage-title span {
  color: var(--muted);
  font-size: 0.86rem;
}

#rageLabel {
  color: var(--accent-2);
}

.meter {
  height: 13px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
}

#rageFill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #33d1ff 0%, #ffb347 55%, #ff5f59 100%);
  transition: width 140ms linear;
}

.rage.danger {
  animation: pulse 0.4s linear 2;
}

#rageHint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.83rem;
}

.board-wrap {
  position: relative;
  padding: 10px;
}

.round-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 159, 67, 0.2);
  border: 1px solid rgba(255, 215, 150, 0.45);
  font-size: 0.78rem;
}

.exit-sign {
  position: absolute;
  right: 12px;
  top: 10px;
  color: #ffe29d;
  font-weight: 700;
}

.exit-sign.open {
  color: #5affb8;
  text-shadow: 0 0 10px rgba(89, 255, 188, 0.7);
}

.board {
  position: relative;
  width: var(--board-size);
  aspect-ratio: 1;
  margin: 10px auto;
  border-radius: 15px;
  border: 2px solid rgba(255, 255, 255, 0.26);
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.09) 1px, transparent 1px) 0 0 / 20% 20%,
    linear-gradient(rgba(255, 255, 255, 0.09) 1px, transparent 1px) 0 0 / 20% 20%,
    linear-gradient(145deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.16));
}

.board.flash {
  animation: boardFlash 0.35s ease;
}

.vehicle {
  position: absolute;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.45), 0 6px 12px rgba(0, 0, 0, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  touch-action: none;
  transition: left 120ms ease, top 120ms ease, transform 120ms ease;
}

.vehicle::after {
  content: attr(data-emoji);
  font-size: clamp(1rem, 4.2vw, 1.5rem);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.32));
}

.vehicle.red {
  border-color: rgba(255, 65, 58, 0.8);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.5), 0 0 16px rgba(255, 96, 80, 0.45);
}

.vehicle.selected {
  outline: 3px solid rgba(255, 245, 202, 0.75);
  transform: scale(1.03);
}

.vehicle.blocked {
  animation: shake 0.24s linear;
}

.hint {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.83rem;
}

.controls {
  padding: 10px;
}

.dpad {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.btn,
.dir {
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.96rem;
  font-weight: 700;
}

.btn:active,
.dir:active {
  transform: scale(0.97);
}

.btn.primary {
  background: linear-gradient(135deg, #ffbf5e, #ff8f4a);
  color: #2d1f0f;
  border-color: rgba(255, 255, 255, 0.4);
}

.btn.skill {
  width: 100%;
  background: linear-gradient(135deg, rgba(66, 229, 212, 0.25), rgba(39, 160, 255, 0.26));
}

.btn.ghost {
  font-size: 0.84rem;
  padding: 8px 10px;
}

.dir[disabled],
.btn[disabled] {
  opacity: 0.45;
  pointer-events: none;
}

.start-layer,
.result-layer {
  position: fixed;
  inset: 0;
  background: rgba(8, 13, 24, 0.78);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 5;
}

.hidden {
  display: none;
}

.panel {
  width: min(92vw, 430px);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: linear-gradient(140deg, rgba(26, 42, 65, 0.96), rgba(14, 24, 39, 0.96));
  padding: 16px;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.35);
}

.panel h2 {
  margin: 0 0 10px;
}

.panel p,
.panel li {
  color: #d9e4f1;
}

.panel ul {
  margin: 0 0 14px;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.result-score {
  font-size: 1.2rem;
  margin: 8px 0;
}

.share {
  display: block;
  color: var(--muted);
  margin: 10px 0 6px;
}

textarea {
  width: 100%;
  height: 86px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  padding: 10px;
  resize: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.result-actions {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(15px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(140%);
  background: rgba(20, 29, 44, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  color: #fff;
  padding: 8px 14px;
  font-size: 0.86rem;
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
  z-index: 9;
}

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

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 rgba(255, 77, 79, 0);
  }
  60% {
    box-shadow: 0 0 20px rgba(255, 77, 79, 0.45);
  }
  100% {
    box-shadow: 0 0 0 rgba(255, 77, 79, 0);
  }
}

@keyframes boardFlash {
  0% {
    box-shadow: inset 0 0 0 rgba(255, 255, 255, 0);
  }
  30% {
    box-shadow: inset 0 0 0 500px rgba(127, 255, 187, 0.2);
  }
  100% {
    box-shadow: inset 0 0 0 rgba(255, 255, 255, 0);
  }
}

@media (min-width: 760px) {
  .app {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "top top"
      "hud rage"
      "board board"
      "controls controls";
    max-width: 940px;
  }

  .topbar {
    grid-area: top;
  }

  .hud {
    grid-area: hud;
  }

  .rage {
    grid-area: rage;
  }

  .board-wrap {
    grid-area: board;
  }

  .controls {
    grid-area: controls;
  }

  :root {
    --board-size: min(60vh, 500px);
  }
}
