:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --ink: #20242b;
  --muted: #68707c;
  --panel: #ffffff;
  --road: #303743;
  --slot: #464f5c;
  --slot2: #3d4652;
  --line: #d7dbe2;
  --red: #ef5261;
  --blue: #4d8ce8;
  --green: #42a66d;
  --yellow: #f3b943;
  --purple: #8065d7;
  --orange: #ec7c45;
  --shadow: 0 16px 34px rgba(24, 31, 39, 0.15);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(243, 244, 246, 0.96)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='164' height='164' viewBox='0 0 164 164'%3E%3Cg fill='none' stroke='%23c7ced9' stroke-width='2' opacity='.48'%3E%3Cpath d='M22 38h48v25H22zM31 63v10M61 63v10M96 25h42v23H96zM104 48v9M130 48v9M30 112h58v28H30zM41 140v10M78 140v10M110 102h34v21h-34zM118 123v8M136 123v8'/%3E%3C/g%3E%3C/svg%3E");
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

button {
  border: 0;
  font: inherit;
}

.app {
  width: min(100%, 540px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar,
.hud,
.objective,
.queue-panel,
.controls {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  padding-top: 4px;
}

.eyebrow,
.objective-label {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1;
}

h1 {
  font-size: 33px;
}

h2 {
  font-size: 28px;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--blue);
  box-shadow: var(--shadow);
  font-size: 22px;
  font-weight: 900;
}

.icon-button.muted {
  color: var(--muted);
}

.hud {
  gap: 7px;
}

.meter {
  flex: 1;
  min-width: 0;
  padding: 9px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
}

.meter span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.meter strong {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  font-size: 22px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meter.accent strong {
  color: var(--red);
}

.objective {
  justify-content: space-between;
  gap: 12px;
  min-height: 62px;
  padding: 12px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.objective strong {
  display: block;
  font-size: 15px;
  line-height: 1.25;
}

.mistakes {
  display: flex;
  flex: 0 0 auto;
  gap: 5px;
}

.mistake-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--line);
}

.mistake-dot.used {
  background: var(--red);
}

.queue-panel {
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.queue-panel > div {
  min-width: 0;
}

.queue-panel > div:first-child {
  flex: 1;
}

.chips {
  display: flex;
  gap: 6px;
  min-height: 28px;
  margin-top: 3px;
}

.chip {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  background: var(--chip);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}

.chip.next {
  outline: 3px solid rgba(32, 36, 43, 0.24);
}

.chip.empty {
  border-color: var(--line);
  background: #eef1f5;
  box-shadow: none;
}

.lot-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: 18px;
  border-radius: 8px;
  background: var(--road);
  box-shadow: var(--shadow);
}

.lot {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
}

.cell {
  position: relative;
  z-index: 0;
  min-width: 0;
  min-height: 0;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--slot), var(--slot2));
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.07);
}

.cell::after {
  position: absolute;
  inset: 9px;
  border: 2px dashed rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  content: "";
}

.exit-label {
  position: absolute;
  z-index: 1;
  color: rgba(255, 255, 255, 0.55);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0;
  pointer-events: none;
}

.exit-label.top {
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
}

.exit-label.bottom {
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
}

.exit-label.left {
  top: 50%;
  left: 3px;
  transform: translateY(-50%) rotate(-90deg);
}

.exit-label.right {
  top: 50%;
  right: 3px;
  transform: translateY(-50%) rotate(90deg);
}

.car {
  position: relative;
  z-index: 3;
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: 10px;
  background: var(--car);
  cursor: pointer;
  box-shadow: inset 0 -8px rgba(0, 0, 0, 0.17), 0 5px 0 rgba(0, 0, 0, 0.22);
  transition: transform 260ms ease, opacity 220ms ease, filter 140ms ease;
}

.car::before {
  position: absolute;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.78);
  content: "";
}

.car.horizontal::before {
  top: 22%;
  left: 18%;
  width: 27%;
  height: 48%;
}

.car.vertical::before {
  top: 18%;
  left: 24%;
  width: 52%;
  height: 27%;
}

.car::after {
  position: absolute;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: rgba(0, 0, 0, 0.66);
  font-size: 15px;
  font-weight: 900;
  content: attr(data-arrow);
}

.car.dir-e::after {
  top: 50%;
  right: 7px;
  transform: translateY(-50%);
}

.car.dir-w::after {
  top: 50%;
  left: 7px;
  transform: translateY(-50%);
}

.car.dir-n::after {
  top: 7px;
  left: 50%;
  transform: translateX(-50%);
}

.car.dir-s::after {
  bottom: 7px;
  left: 50%;
  transform: translateX(-50%);
}

.car.hint {
  animation: hint 680ms ease-in-out 2;
  filter: brightness(1.18);
}

.car.blocked {
  animation: blocked 220ms ease;
}

.car.exit-n {
  transform: translateY(-150%);
  opacity: 0;
}

.car.exit-e {
  transform: translateX(150%);
  opacity: 0;
}

.car.exit-s {
  transform: translateY(150%);
  opacity: 0;
}

.car.exit-w {
  transform: translateX(-150%);
  opacity: 0;
}

.floating {
  position: absolute;
  inset: auto 0 45% 0;
  z-index: 6;
  pointer-events: none;
  text-align: center;
  color: #fff;
  font-size: 26px;
  font-weight: 900;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.42);
  opacity: 0;
  transform: translateY(10px);
}

.floating.show {
  animation: floatup 720ms ease forwards;
}

.controls {
  gap: 8px;
}

.primary,
.ghost {
  min-height: 48px;
  border-radius: 8px;
  font-weight: 900;
}

.primary {
  flex: 1.35;
  background: var(--blue);
  color: white;
  box-shadow: 0 8px 0 #2d5f9f;
}

.ghost {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}

.result {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(25, 31, 39, 0.54);
}

.result.hidden {
  display: none;
}

.result-panel {
  width: min(100%, 420px);
  padding: 22px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.result-panel p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.65;
}

@keyframes hint {
  0%,
  100% {
    scale: 1;
  }
  50% {
    scale: 1.06;
  }
}

@keyframes blocked {
  0%,
  100% {
    translate: 0 0;
  }
  25% {
    translate: -5px 0;
  }
  75% {
    translate: 5px 0;
  }
}

@keyframes floatup {
  0% {
    opacity: 0;
    transform: translateY(12px);
  }
  18%,
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-28px);
  }
}

@media (max-width: 410px) {
  .app {
    padding-inline: 10px;
  }

  h1 {
    font-size: 29px;
  }

  .hud {
    gap: 5px;
  }

  .meter {
    padding-inline: 6px;
  }

  .meter strong {
    font-size: 19px;
  }

  .queue-panel {
    align-items: flex-start;
    flex-direction: column;
  }

  .lot {
    gap: 4px;
  }

  .car::after {
    width: 24px;
    height: 24px;
    font-size: 13px;
  }
}
