:root {
  --bg: #141922;
  --surface: #1f2631;
  --surface-2: #2a3240;
  --line: #3a4352;
  --text: #f2f4f7;
  --muted: #a9b2c0; /* --bg üzerinde 8:1 */
  --yellow: #ffc83d;
  --yellow-ink: #3d2a00;
  --red: #ff5a52;
  --focus: #7cc4ff;
  --cell: min(calc((100vw - 56px) / 6), calc((100dvh - 290px) / 6), 76px);
  --pad: calc(var(--cell) * 0.2);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.screen { max-width: 560px; margin: 0 auto; padding: 16px 20px 28px; }

/* Butonlar */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--surface); font-size: 16px; font-weight: 700; cursor: pointer;
  transition: transform 0.12s var(--ease), background 0.15s;
  touch-action: manipulation;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary { background: var(--yellow); color: var(--yellow-ink); border-color: transparent; }
.btn.primary:hover { background: #ffd462; }
.btn.big { min-height: 56px; font-size: 18px; font-weight: 800; width: 100%; }
.icon-btn {
  width: 48px; height: 48px; flex: none; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; cursor: pointer;
}

/* Ana ekran */
.home-head { padding: 12px 0 8px; }
.logo { font-size: 56px; line-height: 1; margin: 8px 0 6px; font-weight: 900; letter-spacing: -1px; }
.logo span { color: var(--red); }
.tagline { color: var(--muted); font-size: 18px; margin: 0 0 20px; }
.tier { margin-top: 28px; }
.tier-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.tier-head h2 { font-size: 22px; margin: 0; font-weight: 800; }
.tier-head span { color: var(--muted); font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.lvl {
  aspect-ratio: 1; min-height: 56px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: 20px; font-weight: 800;
  font-variant-numeric: tabular-nums; transition: transform 0.12s var(--ease);
}
.lvl:active { transform: scale(0.95); }
.lvl small { font-size: 12px; letter-spacing: 1px; color: var(--yellow); line-height: 1; }
.lvl.done { background: #24301f; border-color: #3f5a32; }
.lvl.current { border: 2px solid var(--yellow); }
.lvl:disabled { cursor: default; color: #6b7585; background: transparent; }
.lvl:disabled svg { width: 18px; height: 18px; }
.foot { color: var(--muted); font-size: 13px; margin-top: 28px; line-height: 1.5; }

/* Oyun üst çubuğu */
.bar { display: flex; align-items: center; gap: 12px; }
.bar-title { flex: 1; min-width: 0; }
.bar-title h2 { margin: 0; font-size: 22px; font-weight: 800; }
.bar-title p { margin: 2px 0 0; color: var(--muted); font-size: 14px; font-weight: 600; }
.stats { display: flex; gap: 8px; }
.stats div {
  min-width: 62px; padding: 6px 10px; border-radius: 14px; background: var(--surface);
  border: 1px solid var(--line); text-align: center;
}
.stats span { display: block; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stats small { color: var(--muted); font-size: 12px; font-weight: 600; }

/* Tahta */
.board-wrap { display: flex; justify-content: center; margin: 20px 0 18px; }
.board {
  position: relative; width: calc(var(--cell) * 6 + var(--pad) * 2); height: calc(var(--cell) * 6 + var(--pad) * 2);
  padding: var(--pad); border-radius: calc(var(--pad) * 1.6);
  background: linear-gradient(180deg, #4a5262, #343b48);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.lot {
  position: relative; width: 100%; height: 100%; border-radius: calc(var(--pad) * 0.8);
  background-color: #272e39;
  /* Park çizgileri */
  background-image:
    linear-gradient(90deg, rgba(255, 255, 255, 0.07) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.07) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  background-position: -1px -1px;
}
.exit {
  position: absolute; right: 0; top: calc(var(--pad) + var(--cell) * 2); width: var(--pad); height: var(--cell);
  background: #272e39; display: grid; place-items: center; color: var(--yellow); z-index: 0;
}
.exit svg { width: calc(var(--pad) * 0.9); height: calc(var(--pad) * 0.9); stroke-width: 3.5; animation: nudge 1.4s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateX(3px); } }
.exit::after {
  content: ''; position: absolute; left: calc(var(--pad) * -0.2); top: 6%; bottom: 6%; width: 3px; border-radius: 2px;
  background: repeating-linear-gradient(180deg, var(--yellow) 0 6px, transparent 6px 11px); opacity: 0.8;
}

/* Araçlar */
.car {
  position: absolute; left: 0; top: 0; padding: 0; border: 0; background: none; cursor: grab;
  transition: transform 0.18s var(--ease); touch-action: none; z-index: 1; border-radius: calc(var(--cell) * 0.18);
}
.car.dragging { transition: none; cursor: grabbing; z-index: 3; }
.car.dragging img { filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.5)) brightness(1.06); }
.car img {
  position: absolute; left: 50%; top: 50%; pointer-events: none;
  width: calc(var(--cell) * 0.86);
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.35));
}
.car.len2 img { height: calc(var(--cell) * 1.86); }
.car.len3 img { height: calc(var(--cell) * 2.86); }
.car.target::before {
  content: ''; position: absolute; inset: 6%; border-radius: calc(var(--cell) * 0.22);
  box-shadow: 0 0 0 2px rgba(255, 90, 82, 0.0), 0 0 18px 4px rgba(255, 90, 82, 0.45);
  animation: glow 2s ease-in-out infinite;
}
@keyframes glow { 50% { opacity: 0.35; } }
.car:focus-visible { outline-offset: -2px; }
.car.hint { animation: hint 0.9s ease-in-out 3; }
.car.hint img { filter: drop-shadow(0 0 10px var(--yellow)) drop-shadow(0 0 4px var(--yellow)); }
@keyframes hint { 50% { scale: 1.05; } }
.ghost {
  position: absolute; left: 0; top: 0; border: 3px dashed var(--yellow); border-radius: calc(var(--cell) * 0.2);
  pointer-events: none; z-index: 0; animation: fade 2.6s ease forwards;
}
@keyframes fade { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
.car.leaving { transition: transform 0.7s cubic-bezier(0.5, 0, 0.9, 0.4), opacity 0.7s ease; z-index: 4; }

/* Kontroller */
.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 460px; margin: 0 auto; }
.controls .btn { padding: 0 10px; }
.status { text-align: center; color: var(--muted); font-size: 14px; min-height: 20px; margin: 12px 0 0; }

/* Bölüm sonu */
dialog {
  width: min(92vw, 380px); border: 1px solid var(--line); border-radius: 28px; padding: 28px 22px 22px;
  background: var(--surface); color: var(--text); text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(6, 9, 14, 0.7); }
dialog[open] { animation: pop 0.28s var(--ease); }
@keyframes pop { from { transform: scale(0.92); } }
dialog h2 { font-size: 30px; font-weight: 900; margin: 6px 0 6px; }
dialog p { color: var(--muted); font-size: 17px; margin: 0 0 22px; line-height: 1.45; }
.stars { display: flex; justify-content: center; gap: 6px; }
.stars svg { width: 46px; height: 46px; stroke: none; fill: #49526180; }
.stars svg.on { fill: var(--yellow); animation: star 0.4s var(--ease) both; }
.stars svg.on:nth-child(2) { animation-delay: 0.12s; }
.stars svg.on:nth-child(3) { animation-delay: 0.24s; }
@keyframes star { from { transform: scale(0.3) rotate(-30deg); } }
.win-actions { display: grid; gap: 10px; }
.win-actions .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0.01ms !important; }
}
@media (max-height: 640px) {
  .board-wrap { margin: 12px 0 10px; }
  .bar-title h2 { font-size: 19px; }
}
