:root {
  --bg: #0b1020;
  --bg-2: #121a33;
  --panel: rgba(18, 26, 51, 0.86);
  --ink: #e8ecff;
  --muted: #8b96c4;
  --accent: #38f2c4;
  --accent-2: #6ea8ff;
  --danger: #ff5d8f;
  --wall: #ffd24a;
  --filled: #2a3566;
  --grid-line: rgba(110, 168, 255, 0.06);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(1200px 800px at 20% -10%, #1a2550 0%, transparent 55%),
    radial-gradient(1000px 700px at 110% 120%, #23184a 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 12px max(8px, env(safe-area-inset-bottom));
  gap: 10px;
}

/* ---------- HUD ---------- */
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.hud-group { display: flex; align-items: center; gap: 18px; }
.stat { display: flex; flex-direction: column; line-height: 1.1; }
.stat .label { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.stat .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
#stat-lives { color: var(--danger); letter-spacing: 2px; }

.progress-wrap { flex: 1; min-width: 180px; max-width: 420px; margin-left: auto; }
.progress-track {
  position: relative;
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05);
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.25s ease;
}
.progress-target {
  position: absolute; top: -3px; bottom: -3px;
  width: 2px; left: 75%;
  background: var(--ink);
  opacity: 0.55;
}
.progress-readout { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Stage ---------- */
#stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
#board-wrap { position: relative; line-height: 0; }
#game {
  display: block;
  border-radius: 14px;
  background: linear-gradient(160deg, #0e1530, #0a0f24);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(110,168,255,0.12);
  touch-action: none;
  cursor: crosshair;
}
#chrome { position: absolute; bottom: 100%; left: 0; right: 0; line-height: normal; }

/* ---------- Level skins: window chrome homages ---------- */
/* Windows XP (Luna) */
#board-wrap[data-skin="xp"] #game {
  border-radius: 0 0 8px 8px;
  box-shadow: 0 0 0 3px #0855dd, var(--shadow);
}
.xp-titlebar {
  height: 30px;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(#66a1f4, #2b74e8 12%, #0855dd 45%, #0349c8 88%, #0343b5);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 5px 0 10px;
  color: #fff; font-weight: 700; font-size: 13px;
  font-family: Tahoma, 'Segoe UI', sans-serif;
  text-shadow: 1px 1px 1px rgba(0,0,0,0.55);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), 0 0 0 3px #0855dd;
}
.xp-btns { display: flex; gap: 3px; }
.xp-btn {
  width: 21px; height: 21px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 10px; font-weight: 700;
  border: 1px solid rgba(255,255,255,0.65);
  background: linear-gradient(#5b9bf5, #2a70e0 50%, #1e5ecc);
  text-shadow: none;
}
.xp-btn.close { background: linear-gradient(#ffa78f, #e2442c 45%, #c33b23); }

/* Windows 95 (Minesweeper) */
#board-wrap[data-skin="win95"] #game {
  border-radius: 0;
  box-shadow: 0 0 0 3px #c0c0c0, 0 0 0 4px #000;
}
.w95-titlebar {
  height: 24px;
  background: linear-gradient(90deg, #000080, #1084d0);
  color: #fff;
  font: bold 12px Tahoma, 'MS Sans Serif', sans-serif;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 3px 0 6px;
  box-shadow: 0 0 0 3px #c0c0c0, 0 0 0 4px #000;
}
.w95-btns { display: flex; gap: 2px; }
.w95-btn {
  width: 18px; height: 16px;
  background: #c0c0c0; color: #000;
  font: bold 10px Tahoma, sans-serif;
  display: flex; align-items: center; justify-content: center;
  border-top: 1px solid #fff; border-left: 1px solid #fff;
  border-right: 1px solid #404040; border-bottom: 1px solid #404040;
}
.w95-face {
  position: absolute; top: 26px; left: 50%;
  transform: translateX(-50%);
  font-size: 15px; line-height: 1;
  background: #c0c0c0;
  padding: 2px 3px;
  border-top: 2px solid #fff; border-left: 2px solid #fff;
  border-right: 2px solid #404040; border-bottom: 2px solid #404040;
  z-index: 2;
}

/* Windows 3.1 */
#board-wrap[data-skin="win31"] #game {
  border-radius: 0;
  box-shadow: 0 0 0 2px #c0c0c0, 0 0 0 3px #000;
}
.w3-titlebar {
  height: 22px;
  background: #000082;
  color: #fff;
  font: bold 13px Tahoma, 'MS Sans Serif', sans-serif;
  display: flex; align-items: stretch;
  box-shadow: 0 0 0 2px #c0c0c0, 0 0 0 3px #000;
}
.w3-title { flex: 1; text-align: center; align-self: center; }
.w3-box {
  width: 24px; background: #c0c0c0; color: #000;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  border-left: 1px solid #000; border-right: 1px solid #000;
}
.w3-menubar {
  background: #fff;
  color: #000;
  font: 13px Tahoma, 'MS Sans Serif', sans-serif;
  padding: 3px 10px;
  display: flex; gap: 18px;
  border-bottom: 1px solid #000;
}

/* ---------- Overlay ---------- */
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 9, 20, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 14px;
  padding: 16px;
  transition: opacity 0.2s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.panel {
  width: min(440px, 92%);
  background: var(--panel);
  border: 1px solid rgba(110,168,255,0.16);
  border-radius: 18px;
  padding: 26px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.logo { margin: 0 0 6px; font-size: 40px; font-weight: 800; letter-spacing: 2px; }
.logo span { color: var(--accent); }
.tagline { margin: 0 0 16px; color: var(--muted); font-size: 15px; line-height: 1.5; }
.tagline b { color: var(--ink); }
.how { display: grid; gap: 8px; margin: 0 0 20px; text-align: left; font-size: 13px; color: var(--muted); }
.how .key {
  display: inline-block; min-width: 118px;
  color: var(--accent-2); font-weight: 600;
}
.panel h2 { margin: 0 0 8px; font-size: 26px; }
.panel .sub { color: var(--muted); margin: 0 0 18px; }

/* ---------- Fake crashes ---------- */
.bsod {
  width: min(620px, 96%);
  background: #0000aa;
  color: #fff;
  font-family: 'Lucida Console', 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.55;
  padding: 34px 38px;
  text-align: left;
  cursor: pointer;
}
.bsod p { margin: 0 0 14px; }
.bsod-code { text-align: center; letter-spacing: 0.05em; }
.bsod-blink { animation: bsod-blink 1s steps(2, start) infinite; }
@keyframes bsod-blink { 50% { opacity: 0; } }

#board-wrap.hung #game {
  filter: saturate(0.25) brightness(1.45) contrast(0.75);
}
#board-wrap.hung .w3-titlebar { opacity: 0.85; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid rgba(110,168,255,0.22);
  background: rgba(255,255,255,0.04);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 600;
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { background: rgba(255,255,255,0.08); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn.primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #06210f;
  border: none;
  font-size: 17px;
  padding: 13px 34px;
  width: 100%;
  box-shadow: 0 8px 24px rgba(56,242,196,0.25);
}

/* ---------- Menu extras ---------- */
.menu-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.menu-row .btn { flex: 1; min-width: 110px; padding: 10px 12px; font-size: 14px; }

/* ---------- Level select ---------- */
.levels-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 0 0 16px;
  max-height: 46dvh;
  overflow-y: auto;
  padding: 2px;
}
.lvl {
  font: inherit;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px;
  border-radius: 10px;
  border: 1px solid rgba(110,168,255,0.22);
  background: rgba(255,255,255,0.04);
  color: var(--ink);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.lvl:hover:not(.locked) { background: rgba(255,255,255,0.09); border-color: var(--accent); }
.lvl.locked { opacity: 0.4; cursor: not-allowed; }
.lvl-num { font-size: 18px; font-weight: 800; }
.lvl-name { font-size: 9.5px; color: var(--muted); line-height: 1.15; text-align: center; }

/* ---------- Leaderboard ---------- */
.board { margin: 0 0 14px; }
.board table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.board th {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted); text-align: left; padding: 4px 8px;
}
.board td { padding: 5px 8px; text-align: left; border-top: 1px solid rgba(255,255,255,0.05); }
.board .nm { font-weight: 700; letter-spacing: 0.15em; color: var(--accent); }
.board .sc { font-weight: 700; }
.board tr.me td { background: rgba(56,242,196,0.10); }
.board tr.me .nm { color: var(--wall); }
.sub.offline { font-size: 12px; opacity: 0.7; margin-top: 10px; }

/* ---------- Initials entry (arcade style) ---------- */
.entry-slots {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin: 0 0 16px;
}
.entry-slots .slot {
  width: 52px;
  font-size: 38px; font-weight: 800; line-height: 1.2;
  text-align: center;
  color: var(--ink);
  padding: 2px 0 6px;
  border-bottom: 3px solid rgba(110,168,255,0.25);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.entry-slots .slot.active {
  color: var(--accent);
  border-color: var(--accent);
  animation: cursor-blink 1s steps(2, start) infinite;
}
@keyframes cursor-blink { 50% { border-color: transparent; } }

.kb {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin: 0 0 14px;
}
.kb .kbk {
  font: inherit; font-weight: 700; font-size: 15px;
  color: var(--ink);
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(110,168,255,0.14);
  border-radius: 8px;
  padding: 8px 0;
  cursor: pointer;
  transition: background 0.1s ease, border-color 0.1s ease;
}
.kb .kbk:hover { background: rgba(255,255,255,0.09); }
.kb .kbk.op { color: var(--wall); }
.kb .kbk.sel {
  background: rgba(56,242,196,0.16);
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(56,242,196,0.3);
  color: var(--accent);
}
.kb .kbk.op.sel { color: var(--wall); border-color: var(--wall); box-shadow: 0 0 10px rgba(255,210,74,0.35); background: rgba(255,210,74,0.14); }
.entry-title { margin-top: 4px; }
.entry-hint { font-size: 12px; opacity: 0.8; }

@media (max-width: 380px) {
  .kb .kbk { font-size: 13px; padding: 6px 0; }
  .entry-slots .slot { width: 42px; font-size: 32px; }
}

/* ---------- Controls ---------- */
#controls {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.btn.ctrl {
  flex: 1;
  max-width: 200px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
#btn-sound { flex: 0 0 auto; min-width: 58px; font-size: 18px; }
.orient-icon {
  width: 14px; height: 14px; position: relative; display: inline-block;
}
.orient-icon::before {
  content: ""; position: absolute; background: var(--wall); border-radius: 2px;
}
.orient-icon.vertical::before { width: 4px; height: 14px; left: 5px; top: 0; }
.orient-icon.horizontal::before { width: 14px; height: 4px; left: 0; top: 5px; }

@media (max-width: 520px) {
  .logo { font-size: 34px; }
  .stat .value { font-size: 18px; }
  .btn.ctrl { padding: 14px 10px; }
}
@media (min-width: 700px) {
  .btn.ctrl { max-width: 220px; }
}
