:root {
  --bg: #171726;
  --panel: rgba(21, 23, 43, 0.82);
  --ink: #f4f5ff;
  --muted: #bcc0df;
  --accent: #ff64b7;
  --accent-2: #5cc8ff;
  --ok: #59d37b;
  --warn: #ff8b8b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

body {
  overflow: hidden;
}

.screen {
  width: 100vw;
  height: 100vh;
}

.hidden {
  display: none !important;
}

#loading-screen {
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #683a9d 0%, #381f69 100%);
}

.loading-wrap {
  width: min(90vw, 460px);
  text-align: center;
}

#loader-art {
  width: min(86vw, 340px);
  image-rendering: auto;
}

#spinner-art {
  width: 42px;
  height: 42px;
  margin-top: 18px;
  animation: spin 1.1s linear infinite;
}

.loading-bar-shell {
  width: 100%;
  height: 20px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.2);
  margin-top: 10px;
  overflow: hidden;
}

.loading-bar-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #ffe77c, #ff8ad9);
  transition: width 0.2s ease;
}

.loading-text {
  margin-top: 8px;
  font-weight: 700;
}

#game-screen {
  background-image: linear-gradient(rgba(17, 18, 35, 0.68), rgba(17, 18, 35, 0.9)), url("../images/bg3.jpg");
  background-size: cover;
  background-position: center;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(20px, 3vw, 30px);
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
}

.level-map {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.level-flag {
  border: 0;
  background: transparent;
  color: inherit;
  width: 38px;
  height: 40px;
  position: relative;
  cursor: pointer;
  opacity: 0.95;
}

.level-flag:before {
  content: "";
  position: absolute;
  left: 10px;
  top: 0;
  width: 4px;
  height: 28px;
  background: #d8ddff;
}

.level-flag:after {
  content: attr(data-label);
  position: absolute;
  left: 14px;
  top: 2px;
  font-size: 11px;
  font-weight: 700;
  color: #1f2040;
  width: 18px;
  height: 13px;
  line-height: 13px;
  text-align: center;
  background: #ffe17b;
  clip-path: polygon(0 0, 100% 0, 84% 50%, 100% 100%, 0 100%);
}

.level-flag.done:after {
  background: var(--ok);
  color: #102a19;
}

.level-flag.current:after {
  background: var(--accent);
  color: #fff;
}

.level-flag.locked {
  opacity: 0.34;
  cursor: not-allowed;
}

.play-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  gap: 12px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  padding: 12px;
  overflow: auto;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

.target-sequence {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.sequence-cell,
.packed-cell {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  justify-items: center;
  gap: 6px;
  min-height: 86px;
}

.sequence-cell.done {
  border-color: rgba(89, 211, 123, 0.9);
  background: rgba(89, 211, 123, 0.15);
}

.sequence-index {
  font-size: 12px;
  color: var(--muted);
}

.status {
  min-height: 30px;
  margin: 12px 0 0;
  color: #f6f0ff;
}

.item-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  align-content: start;
}

.item-card {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  padding: 8px;
  display: grid;
  justify-items: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.item-card:hover {
  transform: translateY(-2px);
  border-color: rgba(92, 200, 255, 0.9);
}

.item-card.correct {
  border-color: rgba(89, 211, 123, 0.92);
}

.item-card.wrong {
  border-color: rgba(255, 139, 139, 0.95);
  animation: shake 0.32s linear;
}

.item-card:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}

.item-label {
  font-size: 12px;
  text-align: center;
}

.backpack {
  border-radius: 20px;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  background: radial-gradient(circle at 30% 20%, #43518f, #252b58);
  min-height: 170px;
  display: grid;
  place-items: center;
  font-size: 64px;
}

.backpack:before {
  content: "??";
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
}

.packed-list {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.next-level {
  margin-top: 12px;
  width: 100%;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--accent), #ff9e78);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  padding: 12px;
  cursor: pointer;
}

.next-level:hover {
  filter: brightness(1.06);
}

.flying {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  transition: transform 0.44s ease, opacity 0.44s ease;
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-4px); }
  100% { transform: translateX(0); }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@media (max-width: 1100px) {
  .play-layout {
    grid-template-columns: 1fr;
    grid-auto-rows: auto;
  }

  .panel {
    max-height: none;
  }

  .backpack {
    min-height: 120px;
  }
}