/* Klotski – App-Shell, randlos, kein Scroll. Brettgröße setzt game.js (bühnenrelativ). */
:root {
  --bg: #0b0c15;
  --fg: #eef1f6;
  --muted: #9aa0b4;
  --accent: #f4b942;          /* Gold = Zielblock/Highlights */
  --accent-2: #f59e0b;
  --board-bg: #141824;
  --cell-bg: #1b2130;
  --piece: #43506b;           /* neutrale Klötze (kühl) – Kontrast zum goldenen Ziel */
  --piece-hi: #56658a;
  --target: #f4b942;
  --exit: #f4b942;
  --cell: 60px;               /* von game.js gesetzt */
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  min-height: 100dvh; height: 100dvh; overflow: hidden;
  background: var(--bg); color: var(--fg);
  display: flex; flex-direction: column; align-items: center;
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
.bg-grid {
  position: fixed; inset: 0; z-index: -1; opacity: 0.5;
  background:
    radial-gradient(circle at 50% 0%, rgba(244,185,66,0.09), transparent 60%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.03) 0 1px, transparent 1px 40px),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.03) 0 1px, transparent 1px 40px);
}

.top { flex: 0 0 auto; width: 100%; max-width: 620px; padding: 0.5rem 1.1rem 0; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.back { color: var(--muted); text-decoration: none; font-weight: 700; font-size: 0.95rem; white-space: nowrap; }
.back:hover { color: var(--accent); }
.game-title { margin: 0; font-size: 1.15rem; font-weight: 800; letter-spacing: 0.02em; color: var(--accent); }
.btn { font: inherit; font-weight: 700; color: var(--fg); background: var(--board-bg); border: 1px solid rgba(255,255,255,0.14); border-radius: 10px; padding: 0.45rem 0.9rem; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-min { font: inherit; font-weight: 800; font-size: 1.1rem; line-height: 1; color: var(--fg); background: var(--board-bg); border: 1px solid rgba(255,255,255,0.14); border-radius: 8px; width: 2rem; height: 2rem; cursor: pointer; }
.btn-min:hover { border-color: var(--accent); }

.wrap { flex: 1 1 auto; min-height: 0; width: 100%; max-width: 620px; padding: 0.4rem 0.9rem 0.5rem; display: flex; flex-direction: column; align-items: stretch; gap: 0.45rem; }
.hud { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; }
.level-pick { display: flex; align-items: center; gap: 0.6rem; }
.level-name { font-size: 0.95rem; font-weight: 700; }
.level-name b { color: var(--accent); }
.stats { display: flex; align-items: center; justify-content: center; gap: 1.4rem; font-size: 0.86rem; color: var(--muted); }
.stat b { color: var(--fg); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; }

.stage { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }

/* Brett: Positionierungs-Container (game.js setzt width/height + --cell). */
.board {
  position: relative; background: var(--board-bg);
  border-radius: 12px; border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 18px 50px -22px rgba(0,0,0,0.85); touch-action: none;
  padding: 0;
}
.cellgrid { position: absolute; inset: 0; border-radius: 12px; overflow: hidden;
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.05) 0 1px, transparent 1px var(--cell)),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.05) 0 1px, transparent 1px var(--cell));
}
/* Ausgangsfeld (unten Mitte, 2×2) */
.exit { position: absolute; border: 2px dashed var(--exit); border-radius: 8px; opacity: 0.55;
  display: flex; align-items: flex-end; justify-content: center; color: var(--exit); pointer-events: none; }
.exit::after { content: "▼ Ausgang"; font-size: 0.62rem; font-weight: 800; letter-spacing: 0.04em; transform: translateY(1.1em); white-space: nowrap; }

.piece {
  position: absolute; border-radius: 9px; cursor: grab;
  background: linear-gradient(160deg, var(--piece-hi), var(--piece));
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.16), inset 0 -3px 8px rgba(0,0,0,0.35), 0 4px 10px -4px rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.5); font-size: 1.1rem; font-weight: 800;
  transition: left 0.13s ease, top 0.13s ease;
  will-change: left, top, transform;
}
.piece:active { cursor: grabbing; }
.piece.dragging { transition: none; z-index: 5; }
.piece .sym { pointer-events: none; }
/* Zielblock: Gold, ★, leuchtender Rand – auch bei Farbenblindheit eindeutig. */
.piece.target {
  background: linear-gradient(160deg, #ffd873, var(--target));
  border-color: #fff0c4; color: #6b4a05;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.6), inset 0 -4px 10px rgba(160,110,0,0.4), 0 0 22px -4px var(--accent);
}
.piece.hint { animation: hintpulse 0.7s ease 3; }
@keyframes hintpulse { 0%,100% { box-shadow: inset 0 1px 0 rgba(255,255,255,0.2), 0 0 0 0 var(--accent); } 50% { box-shadow: 0 0 0 4px var(--accent), 0 0 26px -2px var(--accent); } }
.board.solved .piece { filter: saturate(1.15) brightness(1.05); }

.controls { flex: 0 0 auto; display: flex; gap: 0.6rem; justify-content: center; }
.msg { flex: 0 0 auto; min-height: 1.3rem; margin: 0; text-align: center; font-size: 0.86rem; font-weight: 700; color: var(--accent-2); }

/* Bestenliste (wandert per arcade-scores ins Modal) */
.leaderboard { width: 100%; max-width: 620px; }
.wrap > .leaderboard { display: none; }
.lb-title { margin: 0 0 0.2rem; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); }
.lb-sub { margin: 0 0 0.7rem; font-size: 0.8rem; color: var(--muted); }
.lb-list { list-style: none; margin: 0; padding: 0; }
.lb-empty { color: var(--muted); font-size: 0.9rem; padding: 0.4rem 0; }
.lb-row { display: grid; grid-template-columns: 2.6rem 1fr auto; align-items: center; gap: 0.6rem; padding: 0.5rem 0.7rem; margin-bottom: 0.35rem; border: 1px solid rgba(255,255,255,0.07); border-radius: 10px; background: var(--board-bg); }
.lb-rank { font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-score { font-weight: 800; font-variant-numeric: tabular-nums; }
.lb-row--me { border-color: color-mix(in srgb, var(--accent) 65%, transparent); box-shadow: 0 0 22px -10px var(--accent); }

/* Overlay (Sieg / Eintrag) */
.overlay { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 1rem; background: rgba(4,8,10,0.72); backdrop-filter: blur(3px); }
.overlay[hidden] { display: none; }
.overlay-card { position: relative; width: min(94vw, 380px); background: var(--board-bg); border: 1px solid rgba(255,255,255,0.1); border-radius: 18px; padding: 1.4rem 1.3rem; text-align: center; box-shadow: 0 24px 60px -20px rgba(0,0,0,0.8); }
.overlay-close { position: absolute; top: 0.6rem; right: 0.6rem; width: 1.9rem; height: 1.9rem; border-radius: 8px; background: none; border: 1px solid rgba(255,255,255,0.14); color: var(--muted); font-weight: 800; cursor: pointer; }
.overlay-title { margin: 0.2rem 0 0.3rem; font-size: 1.5rem; color: var(--accent); }
.overlay-sub { margin: 0 0 0.9rem; color: var(--muted); }
.overlay-stars { font-size: 1.6rem; letter-spacing: 0.2rem; margin: 0.2rem 0 0.7rem; }
.overlay-actions { display: flex; gap: 0.7rem; justify-content: center; flex-wrap: wrap; }
.lb-form { margin: 0.6rem 0; }
.lb-form-label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 0.4rem; }
.lb-form-row { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.lb-form-row input { flex: 1; min-width: 7rem; font: inherit; font-weight: 700; color: var(--fg); background: #0c1218; border: 1px solid rgba(255,255,255,0.16); border-radius: 10px; padding: 0.5rem 0.7rem; }
.lb-result { color: var(--accent-2); font-weight: 700; margin: 0.3rem 0; }

/* Querformat: Info/Steuerung links, Brett rechts groß nach Höhe. */
@media (orientation: landscape) and (min-width: 640px) {
  body { padding-bottom: 0 !important; }
  .top { max-width: 1100px; }
  .wrap {
    max-width: 1100px;
    display: grid; column-gap: 1.2rem;
    grid-template-columns: minmax(10rem, 14rem) 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "info board" "ctrl board" "msg board";
  }
  .hud { grid-area: info; align-items: flex-start; align-self: end; gap: 0.6rem; }
  .stats { flex-direction: column; align-items: flex-start; gap: 0.4rem; }
  .controls { grid-area: ctrl; justify-content: flex-start; align-self: start; }
  .stage { grid-area: board; align-self: stretch; }
  .msg { grid-area: msg; text-align: left; align-self: start; }
}
