/* Cratepusher — warm amber warehouse theme, built on the plan33.io harness. */

:root {
  --bg: #0b0e14;
  --fg: #f1e9dd;
  --muted: #a89a86;
  --accent: #e2a03f;
  --accent-2: #c97b2e;
  --scrim: rgba(10, 8, 6, 0.80);
  --panel: rgba(28, 22, 17, 0.94);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  background: var(--bg);
}

/* ---------- corner chrome ---------- */
.chrome {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  z-index: 20;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg);
  font: 600 16px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.icon-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

/* Undo/restart chrome buttons only make sense while a level is loaded. */
#btn-undo { display: none; }
body.state-playing #btn-undo,
body.state-paused #btn-undo { display: inline-block; }

/* ---------- touch controls (coarse pointers, while playing) ---------- */
.touchpad { display: none; }

@media (pointer: coarse) {
  body.state-playing .touchpad,
  body.state-paused .touchpad {
    display: grid;
    position: fixed;
    left: calc(12px + env(safe-area-inset-left));
    bottom: calc(12px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(2, 56px);
    gap: 6px;
    z-index: 15;
  }
  .pad-btn {
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.08);
    color: var(--fg);
    font-size: 18px;
    touch-action: none;
  }
  .pad-btn:active { background: var(--accent); color: #2a1a04; }
  .pad-btn[data-dir="left"]  { grid-area: 2 / 1; }
  .pad-btn[data-dir="up"]    { grid-area: 1 / 2; }
  .pad-btn[data-dir="down"]  { grid-area: 2 / 2; }
  .pad-btn[data-dir="right"] { grid-area: 2 / 3; }
}

/* ---------- overlays: visibility driven purely by body state class ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  z-index: 30;
  overflow-y: auto;
}

body.state-menu        .overlay-menu,
body.state-levelselect .overlay-levelselect,
body.state-paused      .overlay-paused,
body.state-gameover    .overlay-gameover { display: grid; }

.panel {
  width: min(420px, 100%);
  max-height: calc(100% - 48px);
  overflow-y: auto;
  padding: 28px 24px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: var(--panel);
  text-align: center;
  animation: pop 180ms ease-out;
}

@keyframes pop { from { transform: scale(0.96); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .panel { animation: none; } }

.panel h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: 0.5px; color: var(--accent); }
.panel h2 { margin: 0 0 14px; font-size: 24px; }
.tagline  { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.score    { margin: 0 0 4px; font-size: 18px; font-weight: 600; }
.hi       { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.hint     { margin: 14px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }

.btn {
  display: block;
  width: 100%;
  margin: 8px 0 0;
  padding: 14px 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #2a1a04;
  font: 700 16px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

/* ---------- level select grid ---------- */
.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 4px 0 6px;
}

.level-btn {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg);
  font: 700 18px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
}
.level-btn.done { background: var(--accent); color: #2a1a04; border-color: var(--accent); }
.level-btn.locked { background: rgba(255, 255, 255, 0.03); color: var(--muted); cursor: not-allowed; }
