:root {
  --ink: #12203a;
  --ink-dark: #0a1420;
  --panel: #16233d;
  --panel-2: #1d2e4f;
  --text: #ffffff;
  --gold: #ffd23c;
  --good: #3ee07a;
  --red: #ff4d62;
  --cyan: #2ee6ff;
  --shadow: 5px 5px 0 rgba(6, 12, 24, 0.55);
  --font: "Consolas", "Cascadia Mono", "Courier New", monospace;
  --cursor-hover: url("../assets/ui/cursor-hover.png") 29 2, auto;
  --cursor-select: url("../assets/ui/cursor-select.png") 29 2, pointer;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--text);
  background: var(--ink-dark);
  cursor: var(--cursor-hover);
  user-select: none;
}

button { cursor: var(--cursor-hover); font-family: var(--font); }
img { image-rendering: pixelated; }
canvas { image-rendering: pixelated; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.visible { display: flex; }

.px-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 22px;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--text);
  background: var(--panel-2);
  border: 3px solid var(--ink-dark);
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.35), inset 3px 3px 0 rgba(255, 255, 255, 0.18), var(--shadow);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.45);
}
.px-btn img { width: 22px; height: 22px; }
.px-btn:hover { transform: translate(-2px, -2px); box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.35), inset 3px 3px 0 rgba(255, 255, 255, 0.18), 7px 7px 0 rgba(6, 12, 24, 0.55); filter: brightness(1.08); }
.px-btn:active { transform: translate(2px, 2px); box-shadow: inset 3px 3px 0 rgba(0, 0, 0, 0.35), var(--shadow); cursor: var(--cursor-select); }

.px-btn.good { background: var(--good); color: #062a14; text-shadow: none; }
.px-btn.gold { background: var(--gold); color: #3a2a04; text-shadow: none; }
.px-btn.danger { background: var(--red); color: #33060c; text-shadow: none; }
.px-btn.small { padding: 8px 14px; font-size: 13px; }
.px-btn.tiny { padding: 5px 9px; font-size: 11px; letter-spacing: 1px; }

/* ---------- HOME ---------- */
#screen-home {
  background: linear-gradient(180deg, #4db2f7 0%, #7cc9ff 55%, #a8ddff 100%);
}

.home-center {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 34px;
}

.home-logo {
  width: min(520px, 80vw);
  filter: drop-shadow(6px 8px 0 rgba(6, 12, 24, 0.45));
  animation: logoBob 3.4s ease-in-out infinite;
}
@keyframes logoBob { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-10px) rotate(1deg); } }

.home-buttons { display: flex; flex-direction: column; gap: 16px; width: min(320px, 84vw); }
.home-buttons .px-btn { width: 100%; justify-content: flex-start; font-size: 20px; padding: 14px 20px; }
.home-buttons .px-btn img { width: 26px; height: 26px; }

.home-stats {
  margin: 0;
  font-weight: 700;
  letter-spacing: 1px;
  color: #0d3557;
  background: rgba(255, 255, 255, 0.75);
  border: 3px solid var(--ink-dark);
  box-shadow: 4px 4px 0 rgba(6, 12, 24, 0.35);
  padding: 7px 16px;
}

/* ---------- TOP BAR / LEVELS ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 4px solid var(--ink-dark);
}
.bar-title { margin: 0; font-size: 22px; letter-spacing: 4px; text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.4); }
.bar-spacer { flex: 1; }

#screen-levels { background: linear-gradient(180deg, #0d1830 0%, #101f3c 100%); }

.level-list {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
  width: min(760px, 100%);
  margin: 0 auto;
}

.level-card {
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
  padding: 16px 18px;
  background: var(--panel-2);
  border: 3px solid var(--ink-dark);
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.09), var(--shadow);
  color: var(--text);
}
.level-card:hover { transform: translate(-2px, -2px); box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.09), 7px 7px 0 rgba(6, 12, 24, 0.55); filter: brightness(1.1); }
.level-card:active { transform: translate(2px, 2px); cursor: var(--cursor-select); }
.level-num {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 900;
  color: #062a14;
  background: var(--good);
  border: 3px solid var(--ink-dark);
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.25);
}
.level-info { flex: 1; min-width: 0; }
.level-name { font-size: 19px; font-weight: 900; letter-spacing: 1px; text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.4); }
.level-meta { font-size: 12px; color: #9db4d8; margin-top: 4px; letter-spacing: 1px; }
.level-done {
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 1px;
  color: #062a14;
  background: var(--good);
  border: 3px solid var(--ink-dark);
  padding: 5px 9px;
  box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.25);
}
.level-best { font-weight: 700; font-size: 13px; color: var(--gold); }

.loading-note { color: #9db4d8; letter-spacing: 1px; padding: 30px; text-align: center; }

/* ---------- GAME ---------- */
#screen-game { background: #05080d; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.hud-chip {
  pointer-events: auto;
  display: flex;
  gap: 12px;
  align-items: center;
  background: rgba(10, 16, 24, 0.85);
  border: 3px solid var(--ink-dark);
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.08), 4px 4px 0 rgba(0, 0, 0, 0.4);
  padding: 8px 12px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 1px;
}

.overlay-card {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(4, 8, 12, 0.6);
}
.overlay-card.visible { display: grid; }
.card {
  min-width: 340px;
  background: var(--panel);
  border: 4px solid var(--ink-dark);
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.1), 8px 8px 0 rgba(0, 0, 0, 0.5);
  padding: 22px 26px;
  text-align: center;
}
.card h2 { margin: 0 0 8px; font-size: 30px; letter-spacing: 3px; color: var(--gold); text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5); }
.card p { margin: 0 0 16px; color: #b9cbe8; letter-spacing: 1px; }
.card-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- MODALS ---------- */
.modal-root {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(4, 8, 14, 0.75);
  z-index: 30;
}
.modal-root.visible { display: grid; }
.modal {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--panel);
  border: 4px solid var(--ink-dark);
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.1), 10px 10px 0 rgba(0, 0, 0, 0.5);
  padding: 18px 20px;
}
.modal h2 { margin: 0 0 14px; font-size: 22px; letter-spacing: 3px; text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.4); }
.row-end { display: flex; justify-content: flex-end; margin-top: 14px; }
.sep { border: 0; border-top: 3px solid var(--ink-dark); margin: 14px 0; }

.skin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; }
.skin-tile {
  position: relative;
  padding: 12px 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 3px solid var(--ink-dark);
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.08), 4px 4px 0 rgba(0, 0, 0, 0.4);
  color: var(--text);
}
.skin-tile img { width: 48px; height: 48px; }
.skin-tile .skin-name { font-size: 11px; font-weight: 900; letter-spacing: 1px; text-align: center; }
.skin-tile.selected { border-color: var(--cyan); box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.08), 0 0 0 2px var(--cyan), 4px 4px 0 rgba(0, 0, 0, 0.4); }
.skin-tile.locked { filter: grayscale(1) brightness(0.55); }
.skin-tile.locked::after {
  content: "\1F512";
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 15px;
}
.skin-hint { font-size: 10px; color: var(--gold); text-align: center; min-height: 24px; letter-spacing: 0.5px; }

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 8px 0;
}
.check-row input { width: 20px; height: 20px; accent-color: var(--good); }
.hint { color: #9db4d8; font-size: 12px; letter-spacing: 0.5px; line-height: 1.5; }

/* ---------- ACHIEVEMENT POPUPS ---------- */
#achievements {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 50;
  pointer-events: none;
}
.achv {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--gold);
  color: #3a2a04;
  border: 4px solid var(--ink-dark);
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.2), inset 3px 3px 0 rgba(255, 255, 255, 0.45), 6px 6px 0 rgba(0, 0, 0, 0.45);
  padding: 12px 18px;
  opacity: 0;
  transform: translateY(-16px);
  transition: opacity 0.28s steps(6), transform 0.28s steps(6);
}
.achv.show { opacity: 1; transform: translateY(0); }
.achv img { width: 44px; height: 44px; image-rendering: pixelated; border: 3px solid var(--ink-dark); background: #fff3c2; }
.achv .achv-title { font-size: 11px; font-weight: 900; letter-spacing: 2px; }
.achv .achv-name { font-size: 17px; font-weight: 900; letter-spacing: 1px; }
