:root {
  --bg: #111;
  --panel: #1d1f25;
  --accent: #4ac37d;
  --accent-alt: #ffcc4d;
  --text: #eee;
  --danger: #ff5c64;
  --font-stack: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-stack);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  background: var(--panel);
  padding: .75rem 1rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
  border-bottom: 2px solid #222;
}

h1 {
  margin: 0 1rem 0 0;
  font-size: 1.4rem;
  letter-spacing: .5px;
}

.controls {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: center;
}

.controls label {
  display: flex;
  flex-direction: column;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  gap: 2px;
  color: #bbb;
}

.controls input {
  width: 4.5rem;
  padding: .25rem .4rem;
  border: 1px solid #333;
  border-radius: 4px;
  background: #0d0f13;
  color: var(--text);
}

button {
  cursor: pointer;
  border: 1px solid #2d323b;
  background: linear-gradient(#2a3038,#21252b);
  color: var(--text);
  padding: .45rem .75rem;
  border-radius: 5px;
  font-weight: 500;
  transition: background .15s, transform .1s;
  font-size: .8rem;
}

button:hover {
  background: linear-gradient(#353c47,#262b31);
}

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

#solveBtn.active {
  border-color: var(--accent-alt);
  box-shadow: 0 0 0 1px var(--accent-alt);
  color: var(--accent-alt);
}

.stats {
  margin-left: auto;
  display: flex;
  gap: 1.25rem;
  font-size: .85rem;
  font-weight: 600;
}

main {
  flex: 1;
  display: flex;
  gap: 1rem;
  padding: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
}

#canvasWrapper {
  position: relative;
  background: #000;
  border: 2px solid #222;
  border-radius: 8px;
  padding: .5rem;
  max-width: 100%;
  box-shadow: 0 0 0 4px #141414;
}

#mazeCanvas {
  display: block;
  max-width: 100%;
  height: auto;
  background: #05070a;
  border-radius: 4px;
}

.help {
  max-width: 340px;
  line-height: 1.4;
  font-size: .85rem;
}

details {
  background: #191c22;
  border: 1px solid #232831;
  padding: .75rem .9rem;
  border-radius: 6px;
}

summary {
  cursor: pointer;
  font-weight: 600;
  font-size: .9rem;
  margin: -.75rem -.9rem .5rem;
  padding: .75rem .9rem;
  background: #20252d;
  border-bottom: 1px solid #232831;
  border-radius: 6px 6px 0 0;
}

footer {
  text-align: center;
  padding: .75rem;
  font-size: .7rem;
  color: #888;
  background: #0e1013;
  border-top: 1px solid #1a1d22;
}

/* Touch / on-screen directional pad */
#touchOverlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.dpad {
  position: absolute;
  width: 50px;
  height: 50px;
  background: #1f2329d0;
  color: #ddd;
  font-size: 1.2rem;
  border: 1px solid #2f343c;
  border-radius: 8px;
  pointer-events: auto;
}

.dpad:active {
  background: #30363dd0;
}

.dpad.up { bottom: 120px; left: 60px; }
.dpad.down { bottom: 20px; left: 60px; }
.dpad.left { bottom: 70px; left: 10px; }
.dpad.right { bottom: 70px; left: 110px; }

@media (max-width: 780px) {
  header { flex-direction: column; align-items: stretch; }
  .stats { margin-left: 0; }
  #touchOverlay .dpad { width: 56px; height: 56px; }
  .dpad.up { bottom: 150px; left: 50px; }
  .dpad.left { bottom: 95px; left: 0; }
  .dpad.right { bottom: 95px; left: 100px; }
  .dpad.down { bottom: 40px; left: 50px; }
}