:root {
  color-scheme: dark;
  --bg: #071015;
  --panel: #111925;
  --panel-strong: #172536;
  --ink: #f4fbff;
  --muted: #9db4be;
  --line: rgba(195, 227, 234, 0.18);
  --electric: #1faeff;
  --cyan: #42e8d4;
  --lime: #8dff62;
  --sun: #f5c84b;
  --coral: #ff6d65;
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(66, 232, 212, 0.045) 1px, transparent 1px),
    linear-gradient(0deg, rgba(245, 200, 75, 0.035) 1px, transparent 1px),
    linear-gradient(135deg, rgba(31, 174, 255, 0.16), transparent 42%),
    linear-gradient(315deg, rgba(245, 200, 75, 0.09), transparent 36%),
    var(--bg);
  background-size: 48px 48px, 48px 48px, auto, auto, auto;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(31, 174, 255, 0.14), transparent 42%),
    rgba(7, 16, 21, 0.92);
  backdrop-filter: blur(16px);
}

.brand-stack {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.lab-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0.6rem 0.35rem 0.35rem;
  border: 1px solid rgba(66, 232, 212, 0.22);
  white-space: nowrap;
  border-radius: 8px;
  background: rgba(17, 25, 37, 0.62);
}

.lab-brand img {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 0 18px rgba(31, 174, 255, 0.36);
}

.lab-brand span {
  display: grid;
  gap: 0.08rem;
}

.lab-brand strong {
  font-size: 1rem;
  line-height: 1;
}

.lab-brand small {
  color: var(--electric);
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
  text-shadow: 0 0 12px rgba(31, 174, 255, 0.44);
}

.game-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  font-size: 1.15rem;
  font-weight: 900;
}

.game-brand img {
  width: 2.55rem;
  height: 2.55rem;
  flex: 0 0 auto;
  border: 1px solid rgba(66, 232, 212, 0.45);
  border-radius: 8px;
  object-fit: cover;
  box-shadow:
    0 0 16px rgba(31, 174, 255, 0.38),
    0 0 28px rgba(66, 232, 212, 0.18);
}

.game-brand span {
  overflow: hidden;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topnav {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.topnav a {
  min-height: 2.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.75rem;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
}

.topnav a:hover {
  color: var(--ink);
  border-color: rgba(66, 232, 212, 0.28);
  background: rgba(17, 25, 37, 0.72);
}

.game-layout {
  width: min(1500px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  gap: 1.25rem;
  padding: clamp(1rem, 3vw, 2rem);
}

.game-stage,
.control-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(31, 174, 255, 0.09), rgba(17, 25, 37, 0.86)),
    rgba(17, 25, 37, 0.86);
  box-shadow: 0 24px 60px var(--shadow);
}

.game-stage {
  min-height: calc(100vh - 116px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: clamp(1rem, 3vw, 1.5rem);
}

.stage-heading {
  display: grid;
  justify-items: start;
  gap: 0.55rem;
  margin-bottom: 1.2rem;
}

.eyebrow,
.section-label {
  margin: 0 0 0.55rem;
  color: var(--cyan);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.stage-heading h1 {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 5.4rem);
  line-height: 0.92;
  text-shadow: 0 0 28px rgba(31, 174, 255, 0.24);
}

.stage-heading .eyebrow {
  margin: 0;
}

.puzzle-workbench {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(190px, 0.34fr) minmax(360px, 1fr);
  gap: 1rem;
  align-items: stretch;
}

.piece-tray-panel,
.table-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.75rem;
  padding: 0.85rem;
  border: 1px solid rgba(195, 227, 234, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(66, 232, 212, 0.06), rgba(7, 16, 21, 0.48)),
    rgba(7, 16, 21, 0.62);
}

.area-heading,
.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.area-heading .section-label,
.section-row .section-label {
  margin-bottom: 0;
}

.area-heading span {
  min-width: 2.6rem;
  min-height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.55rem;
  border: 1px solid rgba(66, 232, 212, 0.24);
  border-radius: 8px;
  color: var(--ink);
  font-weight: 900;
  background: rgba(7, 16, 21, 0.72);
}

.piece-tray {
  min-height: 24rem;
  max-height: calc(100vh - 250px);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 0.45rem;
  align-content: start;
  padding: 0.85rem;
  border: 1px dashed rgba(66, 232, 212, 0.28);
  border-radius: 8px;
  overflow-y: auto;
  background:
    linear-gradient(135deg, rgba(245, 200, 75, 0.08), transparent 48%),
    rgba(3, 8, 12, 0.68);
}

.piece-tray.has-selection {
  border-color: rgba(245, 200, 75, 0.52);
}

.piece-tray.is-empty {
  border-style: solid;
  background:
    linear-gradient(135deg, rgba(141, 255, 98, 0.09), transparent 52%),
    rgba(3, 8, 12, 0.68);
}

.puzzle-table-wrap {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
}

.puzzle-table {
  --preview-image: none;
  position: relative;
  width: min(76vh, 100%);
  max-width: 820px;
  aspect-ratio: 1;
  display: grid;
  gap: 0;
  padding: clamp(8px, 0.9vw, 12px);
  border: 1px solid rgba(66, 232, 212, 0.32);
  border-radius: 8px;
  overflow: visible;
  background:
    linear-gradient(135deg, rgba(66, 232, 212, 0.09), rgba(31, 174, 255, 0.05)),
    rgba(5, 10, 15, 0.82);
  box-shadow:
    inset 0 0 42px rgba(66, 232, 212, 0.08),
    0 24px 70px rgba(0, 0, 0, 0.36);
}

.puzzle-table::before {
  content: "";
  position: absolute;
  inset: clamp(8px, 1vw, 14px);
  border-radius: 6px;
  pointer-events: none;
  background-image: var(--preview-image);
  background-position: center;
  background-size: cover;
  opacity: 0;
  transition: opacity 160ms ease;
}

.puzzle-table.is-preview::before {
  opacity: 0.2;
}

.slot {
  position: relative;
  z-index: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 0;
  outline: none;
  overflow: visible;
  background: transparent;
  transition: border-color 130ms ease, background 130ms ease, box-shadow 130ms ease;
}

.slot.has-piece {
  border-color: transparent;
  background: transparent;
}

.slot.is-target:hover,
.slot:focus-visible {
  border-color: rgba(245, 200, 75, 0.76);
  box-shadow: inset 0 0 0 1px rgba(245, 200, 75, 0.32);
}

.slot.is-correct {
  border-color: transparent;
}

.slot .jigsaw-piece {
  width: 136%;
  max-width: none;
  transform: translateY(-1.6%);
}

.jigsaw-piece {
  position: relative;
  z-index: 2;
  width: 100%;
  aspect-ratio: 1;
  display: block;
  padding: 0;
  border: 0;
  outline: none;
  overflow: visible;
  cursor: grab;
  background: transparent;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.32));
  transition: filter 130ms ease, transform 130ms ease;
}

.jigsaw-piece:hover,
.jigsaw-piece:focus-visible {
  z-index: 6;
  transform: translateY(-2px) scale(1.02);
  filter:
    drop-shadow(0 12px 16px rgba(0, 0, 0, 0.36))
    drop-shadow(0 0 12px rgba(66, 232, 212, 0.38));
}

.jigsaw-piece.is-selected {
  z-index: 7;
  transform: scale(1.04);
  filter:
    drop-shadow(0 12px 18px rgba(0, 0, 0, 0.4))
    drop-shadow(0 0 16px rgba(245, 200, 75, 0.64));
}

.jigsaw-piece.is-correct {
  filter:
    drop-shadow(0 10px 14px rgba(0, 0, 0, 0.32))
    drop-shadow(0 0 10px rgba(141, 255, 98, 0.3));
}

.slot .jigsaw-piece:hover,
.slot .jigsaw-piece:focus-visible {
  transform: translateY(calc(-1.6% - 2px)) scale(1.02);
}

.slot .jigsaw-piece.is-selected {
  transform: translateY(-1.6%) scale(1.04);
}

.jigsaw-piece[draggable="false"] {
  cursor: default;
}

.piece-tray .jigsaw-piece {
  width: min(100%, 5.8rem);
  justify-self: center;
}

.piece-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.piece-backer {
  fill: rgba(7, 16, 21, 0.72);
}

.piece-outline {
  fill: none;
  stroke: rgba(244, 251, 255, 0.74);
  stroke-width: 2.4;
  vector-effect: non-scaling-stroke;
}

.complete-banner {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: clamp(1rem, 3vw, 2rem);
  min-width: min(90%, 28rem);
  display: grid;
  justify-items: center;
  gap: 0.25rem;
  padding: 1rem;
  border: 1px solid rgba(141, 255, 98, 0.36);
  border-radius: 8px;
  color: #071015;
  text-align: center;
  transform: translateX(-50%);
  background: linear-gradient(135deg, var(--lime), var(--cyan));
  box-shadow: 0 18px 50px rgba(66, 232, 212, 0.24);
}

.complete-banner[hidden],
.panel-body[hidden],
.stat-grid[hidden] {
  display: none;
}

.complete-banner strong {
  font-size: 1.35rem;
}

.control-panel {
  align-self: start;
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.panel-section {
  display: grid;
  gap: 0.75rem;
}

.panel-body {
  display: grid;
  gap: 0.75rem;
}

.upload-drop {
  min-height: 3rem;
  display: grid;
  place-items: center;
  padding: 0.85rem;
  border: 1px dashed rgba(66, 232, 212, 0.38);
  border-radius: 8px;
  color: var(--cyan);
  cursor: pointer;
  background: rgba(7, 16, 21, 0.58);
}

.upload-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.upload-drop span {
  font-weight: 800;
}

.sample-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}

.sample-button {
  min-height: 5.4rem;
  padding: 0;
  border: 1px solid rgba(195, 227, 234, 0.18);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: rgba(7, 16, 21, 0.68);
}

.sample-button img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.sample-button.is-active {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(66, 232, 212, 0.22);
}

.difficulty-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.difficulty-button {
  min-height: 4.3rem;
  padding: 0.65rem;
  border: 1px solid rgba(195, 227, 234, 0.16);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  background: rgba(7, 16, 21, 0.72);
}

.difficulty-button strong,
.difficulty-button span {
  display: block;
}

.difficulty-button strong {
  color: var(--ink);
}

.difficulty-button span {
  margin-top: 0.15rem;
  font-size: 0.76rem;
}

.difficulty-button.is-active {
  color: #071015;
  border-color: transparent;
  background: linear-gradient(135deg, var(--cyan), var(--sun));
}

.difficulty-button.is-active strong {
  color: #071015;
}

.mini-toggle {
  min-height: 2.1rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid rgba(66, 232, 212, 0.28);
  border-radius: 8px;
  color: var(--cyan);
  cursor: pointer;
  background: rgba(7, 16, 21, 0.68);
}

.mini-toggle:hover {
  border-color: rgba(66, 232, 212, 0.58);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.stat-grid div {
  min-height: 4.2rem;
  display: grid;
  align-content: center;
  gap: 0.2rem;
  padding: 0.7rem;
  border: 1px solid rgba(195, 227, 234, 0.16);
  border-radius: 8px;
  background: rgba(7, 16, 21, 0.72);
}

.stat-grid span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stat-grid strong {
  font-size: 1.35rem;
}

.preview-image {
  width: 100%;
  aspect-ratio: 1;
  display: block;
  border: 1px solid rgba(195, 227, 234, 0.16);
  border-radius: 8px;
  object-fit: cover;
  background: #071015;
}

.panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.primary-button,
.secondary-button {
  min-height: 3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, border-color 140ms ease;
}

.primary-button {
  border: 0;
  color: #071015;
  font-weight: 900;
  background: linear-gradient(135deg, var(--cyan), var(--sun));
  box-shadow: 0 0 28px rgba(66, 232, 212, 0.22);
}

.secondary-button {
  color: var(--ink);
  border: 1px solid rgba(245, 200, 75, 0.34);
  background: rgba(7, 16, 21, 0.72);
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

@media (max-width: 1180px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .game-stage {
    min-height: auto;
  }

  .puzzle-table {
    width: min(92vw, 760px);
  }

  .piece-tray {
    max-height: none;
  }
}

@media (max-width: 820px) {
  .puzzle-workbench {
    grid-template-columns: 1fr;
  }

  .piece-tray {
    min-height: 10rem;
    grid-template-columns: repeat(auto-fit, minmax(56px, 1fr));
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand-stack {
    align-items: flex-start;
    flex-direction: column;
  }

  .topnav {
    width: 100%;
  }

  .topnav a {
    flex: 1;
  }

  .game-layout {
    padding: 0.75rem;
  }

  .stage-heading {
    align-items: start;
    flex-direction: column;
  }

  .difficulty-buttons,
  .panel-actions {
    grid-template-columns: 1fr;
  }

  .sample-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
