/* ═══════════════════════════════════════════════════════════════════════════
   Sokoban — black and green, in the Game Room's house style.

   The WAREHOUSE is the interface, so the chrome stays quiet: one accent green,
   crates in warm amber so "pushable" reads instantly against the green goals,
   and a weight badge on any crate that costs more than one move to shift.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --font-display: 'Bebas Neue', 'DM Sans', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'DM Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --bg: #000000;
  --surface: #0b0b0b;
  --surface2: #131313;
  --surface3: #1c1c1c;
  --border: #232323;
  --border2: #2f2f2f;

  --text: #f5f5f5;
  --muted: #8a8a8a;

  --green: #1db954;
  --green-bright: #1ed760;
  --green-dim: #0f5c2a;
  --red: #e91429;

  --wall: #1e2a22;
  --wall-top: #2c3f33;
  --floor: #070907;
  --goal: #1db954;
  --crate: #b8860b;
  --crate-light: #e0a92a;
  --crate-on-goal: #2aa85a;
}

html[data-theme='light'] {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface2: #f0f3f0;
  --surface3: #e6eae6;
  --border: #d8ded8;
  --border2: #c6cec6;
  --text: #101410;
  --muted: #5c665c;
  --wall: #c3cec6;
  --wall-top: #aab8ae;
  --floor: #eef3ef;
  --crate: #b8860b;
  --crate-light: #d19b18;
  --crate-on-goal: #12833c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.shell { max-width: 1080px; margin: 0 auto; padding: 14px 16px 44px; }

/* ── Header ────────────────────────────────────────────────────────────── */

.header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.home-btn {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: 12px; letter-spacing: .08em;
  color: var(--muted); text-decoration: none; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  transition: color .15s, border-color .15s;
}
.home-btn svg { width: 14px; height: 14px; }
.home-btn:hover { color: var(--green); border-color: var(--green-dim); }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { font-size: 20px; color: var(--green); line-height: 1; }
.brand-text { font-family: var(--font-display); font-size: 22px; letter-spacing: .12em; }
.header-right { display: flex; align-items: center; gap: 8px; }
.user-badge { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
  transition: color .15s, border-color .15s;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { color: var(--green); border-color: var(--green-dim); }

/* ── Screens ───────────────────────────────────────────────────────────── */

.screen { display: none; padding-top: 18px; }
.screen.active { display: block; }

.screen-title {
  font-family: var(--font-display); font-size: 40px; letter-spacing: .04em;
  margin: 0 0 6px; color: var(--text);
}
.screen-sub { color: var(--muted); font-size: 14px; line-height: 1.55; margin: 0 0 18px; max-width: 70ch; }

/* ── Buttons ───────────────────────────────────────────────────────────── */

.btn {
  font-family: var(--font-display); font-size: 16px; letter-spacing: .08em;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border2); border-radius: 10px;
  padding: 9px 16px; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.btn:hover { border-color: var(--green); color: var(--green); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--green); border-color: var(--green); color: #04140a; font-weight: 700; }
.btn-primary:hover { background: var(--green-bright); color: #04140a; }
.btn-sm { font-size: 13px; padding: 6px 11px; border-radius: 8px; }
.btn-danger:hover { border-color: var(--red); color: var(--red); }

/* ── Menu ──────────────────────────────────────────────────────────────── */

.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.mode-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; display: flex; flex-direction: column; gap: 8px;
  transition: border-color .18s, background .18s;
}
.mode-card:hover { border-color: var(--green-dim); background: var(--surface2); }
.mode-icon { font-size: 26px; line-height: 1; }
.mode-name { font-family: var(--font-display); font-size: 22px; letter-spacing: .04em; }
.mode-desc { color: var(--muted); font-size: 13px; line-height: 1.5; flex: 1; }

.record {
  margin-top: 18px; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); color: var(--muted); font-size: 13px;
}

/* ── Tiers and level list ──────────────────────────────────────────────── */

.tier { margin-bottom: 22px; }
.tier-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.tier-title { font-family: var(--font-display); font-size: 24px; letter-spacing: .06em; color: var(--green); margin: 0; }
.tier-blurb { color: var(--muted); font-size: 12.5px; }

.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.level-card {
  text-align: left; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; cursor: pointer; color: inherit;
  display: flex; flex-direction: column; gap: 6px;
  transition: border-color .15s, background .15s, transform .12s;
}
.level-card:hover { border-color: var(--green); background: var(--surface2); transform: translateY(-2px); }
.level-card .lc-name { font-family: var(--font-display); font-size: 18px; letter-spacing: .04em; }
.level-card .lc-meta { font-family: var(--font-mono); font-size: 11px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.level-card .lc-best { color: var(--green); }
.level-card.solved { border-color: var(--green-dim); }

/* ── Game ──────────────────────────────────────────────────────────────── */

.game-layout { display: grid; grid-template-columns: 1fr; gap: 14px; justify-items: center; }

.hud {
  width: 100%; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); justify-content: space-between;
}
.hud-stats { display: flex; gap: 16px; flex-wrap: wrap; }
.hud-stat { display: flex; flex-direction: column; gap: 1px; }
.hud-label { font-family: var(--font-mono); font-size: 10px; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; }
.hud-value { font-family: var(--font-display); font-size: 22px; letter-spacing: .04em; }
.hud-value.over { color: var(--muted); }
.hud-optimal { color: var(--green); }
.hud-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* The board: a grid of square cells. `aspect-ratio` is derived from the level
   size in JS, so the tiles are always square no matter the viewport. */
.board-wrap { display: flex; justify-content: center; width: 100%; }
.board {
  display: grid;
  gap: 1px;
  width: 100%;
  background: var(--border);
  border: 1px solid var(--border2);
  border-radius: 8px;
  overflow: hidden;
  touch-action: manipulation;
}
.cell { position: relative; background: var(--floor); display: flex; align-items: center; justify-content: center; }
.cell.wall {
  background: linear-gradient(180deg, var(--wall-top), var(--wall));
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.35);
}
.cell.goal::after {
  content: ''; width: 34%; height: 34%; border-radius: 50%;
  border: 2px solid var(--goal); opacity: .85;
}
.cell.crate {
  background: var(--floor);
}
.cell.crate::after {
  content: ''; position: absolute; inset: 12%;
  background: linear-gradient(160deg, var(--crate-light), var(--crate));
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.35), 0 1px 0 rgba(0,0,0,.4);
}
.cell.crate-on-goal::after { background: linear-gradient(160deg, #34c46c, var(--crate-on-goal)); }
.cell .weight {
  position: relative; z-index: 2;
  font-family: var(--font-mono); font-size: clamp(7px, 1.5vh, 12px); font-weight: 700;
  color: #1a1204; text-shadow: 0 1px 0 rgba(255,255,255,.25);
  pointer-events: none;
}
.cell.player::before {
  content: ''; position: absolute; inset: 18%; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--green-bright), var(--green));
  box-shadow: 0 0 10px rgba(29,185,84,.5);
  z-index: 3;
}
.cell.just-moved::before,
.cell.just-moved::after { animation: pop .18s ease-out; }
@keyframes pop { from { transform: scale(.82); } to { transform: scale(1); } }
.board.no-anim .cell::before,
.board.no-anim .cell::after { animation: none !important; }

/* ── D-pad (touch) ─────────────────────────────────────────────────────── */

.dpad { display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); gap: 6px; justify-content: center; }
.dpad-btn {
  background: var(--surface2); border: 1px solid var(--border2); border-radius: 10px;
  color: var(--text); font-size: 22px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none;
}
.dpad-btn:active { background: var(--green-dim); border-color: var(--green); }
.dpad-up { grid-area: 1 / 2; } .dpad-left { grid-area: 2 / 1; }
.dpad-right { grid-area: 2 / 3; } .dpad-down { grid-area: 3 / 2; }

/* ── Win overlay ───────────────────────────────────────────────────────── */

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.82);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.overlay.open { display: flex; }
.overlay-card {
  background: var(--surface2); border: 1px solid var(--border2); border-radius: 14px;
  padding: 24px; max-width: 420px; width: 100%; text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
}
.overlay-title { font-family: var(--font-display); font-size: 32px; letter-spacing: .05em; color: var(--green); margin: 0 0 6px; }
.overlay-body { color: var(--muted); font-size: 14px; line-height: 1.6; margin-bottom: 14px; }
.overlay-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.stars { font-size: 30px; letter-spacing: 6px; color: var(--green); margin-bottom: 8px; }
.stars .dim { color: var(--border2); }

/* ── Builder ───────────────────────────────────────────────────────────── */

.builder-layout { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: start; }
@media (max-width: 780px) { .builder-layout { grid-template-columns: 1fr; } }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.panel-title { font-family: var(--font-display); font-size: 18px; letter-spacing: .06em; color: var(--green); margin: 0 0 10px; }

.palette { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.palette-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 9px 6px; border: 1px solid var(--border2); border-radius: 9px;
  background: var(--surface2); color: var(--text); cursor: pointer; font-size: 11.5px;
}
.palette-btn .swatch { width: 22px; height: 22px; border-radius: 4px; background: var(--swatch, var(--border2)); }
.palette-btn.active { border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); color: var(--green); }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; }
.field input[type="text"], .field input[type="number"], .field select {
  background: var(--surface2); border: 1px solid var(--border2); border-radius: 8px;
  color: var(--text); padding: 8px 10px; font-family: var(--font-body); font-size: 14px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--green); }
.checkbox-row { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; margin-bottom: 10px; }

.builder-status {
  font-family: var(--font-mono); font-size: 12px; line-height: 1.6;
  padding: 10px; border-radius: 8px; background: var(--surface2);
  border: 1px solid var(--border); white-space: pre-wrap; word-break: break-word;
}
.builder-status.ok { border-color: var(--green-dim); color: var(--green); }
.builder-status.bad { border-color: var(--red); color: var(--red); }
.builder-status.warn { border-color: #b8860b; color: #e0a92a; }

.edit-board .cell { cursor: pointer; }
.edit-board .cell:hover { outline: 1px solid var(--green); outline-offset: -1px; }

/* ── Library ───────────────────────────────────────────────────────────── */

.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.lib-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; display: flex; flex-direction: column; gap: 8px;
}
.lib-name { font-family: var(--font-display); font-size: 20px; letter-spacing: .04em; }
.lib-author { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.lib-meta { font-family: var(--font-mono); font-size: 11px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.lib-meta .opt { color: var(--green); }
.lib-meta .unverified { color: #e0a92a; }
.lib-actions { display: flex; gap: 8px; margin-top: auto; }

/* ── Settings ──────────────────────────────────────────────────────────── */

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }

/* ── Utility ───────────────────────────────────────────────────────────── */

.banner {
  margin: 10px 0; padding: 10px 12px; border-radius: 9px; font-size: 13px;
  border: 1px solid var(--border2); background: var(--surface2); color: var(--muted);
}
.banner.ok { border-color: var(--green-dim); color: var(--green); }
.banner.bad { border-color: var(--red); color: var(--red); }
.spinner {
  display: inline-block; width: 13px; height: 13px; margin-right: 7px;
  border: 2px solid var(--border2); border-top-color: var(--green);
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
