:root {
  --bg:        #080d1a;
  --surface:   #0f1729;
  --surface-2: #131e30;
  --border:    #1e2d45;
  --border-2:  #263548;
  --text:      #e2e8f0;
  --muted:     #4a6080;

  /* Tile colours */
  --floor:     #09111f;
  --wall:      #1e3050;
  --target:    #6366f1;
  --box:       #f59e0b;
  --box-done:  #10b981;
  --player:    #f43f5e;
}

* { box-sizing: border-box; }

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: 16px;
}

button, select {
  touch-action: manipulation;
}

/* ── App shell ─────────────────────────────────────────────────── */
.app {
  width: min(820px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 24px 56px rgba(0, 0, 0, 0.55);
}

/* ── Top bar ────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text);
}

.status {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--muted);
}

select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.8rem;
  font-family: inherit;
  padding: 4px 8px;
  cursor: pointer;
}

select:focus {
  outline: 2px solid var(--target);
  outline-offset: 2px;
}

/* ── Board ──────────────────────────────────────────────────────── */
.board-wrap {
  position: relative;
  background: var(--floor);
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.board {
  position: relative;
}

/* ── Base tile ──────────────────────────────────────────────────── */
.tile {
  position: absolute;
  width: var(--tile-size, 40px);
  height: var(--tile-size, 40px);
  will-change: transform;
}

.tile.animated {
  transition: transform 120ms cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* ── Floor ──────────────────────────────────────────────────────── */
.floor {
  background: var(--floor);
}

/* ── Wall ───────────────────────────────────────────────────────── */
.wall {
  background: var(--wall);
  border-radius: 2px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 -1px 0 rgba(0, 0, 0, 0.35);
}

/* ── Target ─────────────────────────────────────────────────────── */
.target::after {
  content: "";
  position: absolute;
  inset: 38%;
  background: var(--target);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.7);
}

/* ── Box ────────────────────────────────────────────────────────── */
.box { z-index: 2; }

.box::after {
  content: "";
  position: absolute;
  inset: 10%;
  background: var(--box);
  border-radius: 5px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    inset 0 -2px 0 rgba(0, 0, 0, 0.22),
    0 3px 8px rgba(0, 0, 0, 0.4);
}

.box.on-target::after {
  background: var(--box-done);
  box-shadow:
    0 0 14px rgba(16, 185, 129, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    inset 0 -2px 0 rgba(0, 0, 0, 0.15);
  transition: background 200ms ease, box-shadow 200ms ease;
}

/* ── Player  (diamond) ──────────────────────────────────────────── */
.player { z-index: 10; }

.player::after {
  content: "";
  position: absolute;
  inset: 26%;
  background: var(--player);
  border-radius: 4px;
  transform: rotate(45deg);
  box-shadow:
    0 0 16px rgba(244, 63, 94, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* ── Win overlay ────────────────────────────────────────────────── */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 6px;
  text-align: center;
  background: rgba(8, 13, 26, 0.82);
  backdrop-filter: blur(6px);
  border-radius: 10px;
}

.overlay p { margin: 0; }
.overlay p:first-child {
  font-size: 1rem;
  font-weight: 600;
}
.overlay p:last-child {
  font-size: 0.78rem;
  color: var(--muted);
}

.hidden { display: none; }

/* ── Controls ───────────────────────────────────────────────────── */
.controls {
  margin-top: 16px;
  display: grid;
  gap: 6px;
}

.row {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
  font-family: inherit;
  font-weight: 500;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

/* Direction buttons — square, larger arrow glyph */
button[data-action="up"],
button[data-action="down"],
button[data-action="left"],
button[data-action="right"] {
  width: 48px;
  font-size: 1.1rem;
}

/* Action buttons — wider */
button[data-action="undo"],
button[data-action="restart"],
button[data-action="next"] {
  min-width: 88px;
  padding: 0 12px;
}

button:hover {
  background: var(--border-2);
  color: var(--text);
  border-color: var(--border-2);
}

button:active { transform: translateY(1px); }

button:focus-visible {
  outline: 2px solid var(--target);
  outline-offset: 2px;
}

/* ── Help ───────────────────────────────────────────────────────── */
.help {
  margin-top: 12px;
  color: var(--muted);
  text-align: center;
  font-size: 0.72rem;
  opacity: 0.55;
}

/* ── Board: prevent page scroll when swiping ────────────────────── */
.board-wrap {
  touch-action: none;
  user-select: none;
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .status {
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
  }
  .topbar { align-items: flex-start; }
}

@media (max-width: 480px) {
  body { padding: 8px; }

  .app {
    padding: 12px;
    border-radius: 12px;
  }

  .topbar {
    padding-bottom: 10px;
    margin-bottom: 10px;
  }

  /* Larger touch targets for d-pad */
  button[data-action="up"],
  button[data-action="down"],
  button[data-action="left"],
  button[data-action="right"] {
    width: 60px;
    min-height: 54px;
    font-size: 1.35rem;
    border-radius: 10px;
  }

  /* Action buttons — comfortable tap area */
  button[data-action="undo"],
  button[data-action="restart"],
  button[data-action="next"] {
    min-width: 76px;
    min-height: 48px;
    font-size: 0.8rem;
  }

  .controls { margin-top: 10px; gap: 8px; }

  /* Keyboard shortcuts are irrelevant on mobile */
  .help { display: none; }
}

@media (max-width: 360px) {
  button[data-action="up"],
  button[data-action="down"],
  button[data-action="left"],
  button[data-action="right"] {
    width: 52px;
    min-height: 48px;
    font-size: 1.2rem;
  }

  button[data-action="undo"],
  button[data-action="restart"],
  button[data-action="next"] {
    min-width: 64px;
    font-size: 0.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile.animated { transition: none; }
}
