:root {
  color-scheme: dark;
  --ink: #fff8df;
  --muted: #b8c5d9;
  --panel: rgba(19, 28, 48, 0.82);
  --panel-deep: rgba(9, 15, 30, 0.9);
  --line: rgba(236, 243, 255, 0.16);
  --green: #62d58b;
  --amber: #f1c45b;
  --red: #ff6b67;
  --blue: #4da7ff;
  --purple: #b58cff;
  --teal: #71efe3;
}

* {
  box-sizing: border-box;
}

html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(160deg, rgba(17, 28, 57, 0.98), rgba(10, 18, 34, 0.98)),
    url("sucai/SmartGames_SG-433_Ghost-Hunters_product-shot_30c352.jpg") center / cover fixed;
  overflow-x: hidden;
}

button {
  border: 0;
  cursor: pointer;
  color: #101627;
  background: var(--amber);
  font: inherit;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

button:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
}

.game-shell {
  min-height: 100vh;
  padding: clamp(10px, 3vw, 28px);
  display: grid;
  place-items: center;
}

.stage {
  width: min(1420px, 100%);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: end;
  margin-bottom: 18px;
}

.level-picker {
  min-width: min(360px, 34vw);
  padding: 10px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 18px 40px rgba(0, 0, 0, 0.18);
}

.level-picker span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.level-select {
  width: 100%;
  min-height: 44px;
  padding: 0 38px 0 12px;
  border-radius: 7px;
  border: 1px solid rgba(236, 243, 255, 0.22);
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(241, 196, 91, 0.18), rgba(77, 167, 255, 0.12)),
    rgba(5, 12, 28, 0.88);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 900;
}

.level-select option {
  color: #101627;
  background: #f8fbff;
}

.how-to-play {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(260px, 420px);
  gap: 14px;
  margin-bottom: 14px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(12, 20, 40, 0.76);
  backdrop-filter: blur(18px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 18px 40px rgba(0, 0, 0, 0.18);
}

.how-to-play h2 {
  margin-bottom: 6px;
  font-size: 1.1rem;
}

.how-to-play p {
  margin-bottom: 6px;
  color: var(--muted);
  line-height: 1.45;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-content: center;
}

.quick-actions span {
  min-height: 34px;
  padding: 8px 10px;
  border-radius: 7px;
  background: rgba(236, 243, 255, 0.08);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.help-button {
  min-height: 34px;
  border-radius: 7px;
  color: #101627;
  background: linear-gradient(135deg, var(--teal), var(--amber));
  font-size: 0.82rem;
}

.success-banner {
  margin-bottom: 14px;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid rgba(98, 213, 139, 0.55);
  background: linear-gradient(90deg, rgba(98, 213, 139, 0.22), rgba(113, 239, 227, 0.12));
  box-shadow: 0 0 30px rgba(98, 213, 139, 0.24);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.success-banner[hidden] {
  display: none;
}

.level-clear-pop {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: grid;
  place-items: center;
  padding: 18px;
  pointer-events: none;
}

.level-clear-pop[hidden] {
  display: none;
}

.level-clear-card {
  position: relative;
  width: min(330px, calc(100vw - 38px));
  min-height: 176px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 26px 22px;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgba(186, 255, 203, 0.68);
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 255, 235, 0.42), transparent 38%),
    linear-gradient(180deg, rgba(25, 85, 70, 0.96), rgba(8, 24, 38, 0.96));
  box-shadow:
    0 0 0 999px rgba(2, 7, 16, 0.42),
    0 0 44px rgba(98, 213, 139, 0.5),
    0 28px 80px rgba(0, 0, 0, 0.5);
  animation: clearCardPop 780ms cubic-bezier(.18, 1.24, .28, 1) both;
}

.level-clear-card::before {
  content: "";
  position: absolute;
  width: 150px;
  height: 150px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(186, 255, 203, 0.44), rgba(98, 213, 139, 0.08) 52%, transparent 70%);
  animation: clearGlowPulse 1300ms ease-out both;
}

.level-clear-card strong,
.level-clear-card p {
  position: relative;
  z-index: 1;
  margin: 0;
  text-align: center;
}

.level-clear-card strong {
  color: #f8ffe9;
  font-size: 1.8rem;
  letter-spacing: 0;
  text-shadow: 0 0 20px rgba(186, 255, 203, 0.68);
}

.level-clear-card p {
  color: #dfffe9;
  font-weight: 800;
  font-size: 0.95rem;
}

.level-clear-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.level-clear-burst span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #ffe98b;
  box-shadow: 0 0 14px currentColor;
  animation: clearSpark 980ms ease-out both;
}

.level-clear-burst span:nth-child(1) { color: #ffe98b; transform: rotate(12deg) translateX(0); }
.level-clear-burst span:nth-child(2) { color: #62d58b; animation-delay: 40ms; }
.level-clear-burst span:nth-child(3) { color: #bde8ff; animation-delay: 80ms; }
.level-clear-burst span:nth-child(4) { color: #ffffff; animation-delay: 120ms; }
.level-clear-burst span:nth-child(5) { color: #a9ffbd; animation-delay: 160ms; }
.level-clear-burst span:nth-child(6) { color: #ffd36d; animation-delay: 200ms; }

@keyframes clearCardPop {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.82);
  }
  58% {
    opacity: 1;
    transform: translateY(-4px) scale(1.04);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes clearGlowPulse {
  0% {
    opacity: 0.95;
    transform: scale(0.25);
  }
  100% {
    opacity: 0;
    transform: scale(2.25);
  }
}

@keyframes clearSpark {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(calc(var(--spin, 0) * 1deg)) translateX(0) scale(0.5);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(calc((var(--spin, 0) + 60) * 1deg)) translateX(var(--travel, 126px)) scale(0.9);
  }
}

.level-clear-burst span:nth-child(1) { --spin: 0; --travel: 118px; }
.level-clear-burst span:nth-child(2) { --spin: 62; --travel: 130px; }
.level-clear-burst span:nth-child(3) { --spin: 126; --travel: 114px; }
.level-clear-burst span:nth-child(4) { --spin: 188; --travel: 132px; }
.level-clear-burst span:nth-child(5) { --spin: 246; --travel: 120px; }
.level-clear-burst span:nth-child(6) { --spin: 308; --travel: 136px; }

.tutorial-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 7, 18, 0.72);
  backdrop-filter: blur(12px);
}

.tutorial-backdrop[hidden] {
  display: none;
}

.tutorial-panel {
  position: relative;
  width: min(620px, 100%);
  padding: clamp(18px, 4vw, 28px);
  border-radius: 10px;
  border: 1px solid rgba(246, 241, 223, 0.22);
  background:
    linear-gradient(135deg, rgba(77, 167, 255, 0.16), rgba(98, 213, 139, 0.08)),
    rgba(9, 15, 30, 0.96);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 30px 90px rgba(0, 0, 0, 0.48);
}

.tutorial-panel h2 {
  margin: 4px 38px 16px 0;
  font-size: clamp(1.45rem, 4vw, 2.1rem);
}

.tutorial-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  color: var(--ink);
  background: rgba(246, 241, 223, 0.12);
  box-shadow: none;
}

.tutorial-steps {
  display: grid;
  gap: 10px;
}

.tutorial-steps article {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 4px 12px;
  align-items: center;
  padding: 12px;
  border-radius: 8px;
  background: rgba(236, 243, 255, 0.08);
  border: 1px solid rgba(236, 243, 255, 0.14);
}

.tutorial-steps strong {
  grid-row: span 2;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #101627;
  background: var(--amber);
  font-weight: 900;
}

.tutorial-steps span {
  font-weight: 900;
}

.tutorial-steps p {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.tutorial-primary {
  width: 100%;
  min-height: 46px;
  margin-top: 16px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--green), var(--teal));
}

.success-banner strong {
  color: #dfffe9;
  font-size: 1rem;
}

.success-banner span {
  color: var(--ink);
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1, h2, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.75rem, 5vw, 4.1rem);
  line-height: 1;
  letter-spacing: 0;
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(76px, 1fr));
  gap: 8px;
}

.hud div,
.mission-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 18px 40px rgba(0, 0, 0, 0.22);
}

.hud div {
  min-height: 58px;
  padding: 10px 12px;
  border-radius: 8px;
}

.hud span,
.mission-panel p {
  color: var(--muted);
}

.hud span {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  font-weight: 800;
}

.hud strong {
  display: block;
  margin-top: 4px;
  font-size: 1.25rem;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(330px, 820px) minmax(210px, 300px);
  gap: 14px;
  align-items: stretch;
}

.board-column {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.mission-panel {
  border-radius: 8px;
  padding: 14px;
}

.board-wrap {
  position: relative;
  width: min(100%, 42vh, 560px);
  min-width: 0;
  aspect-ratio: 1;
  align-self: center;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 8px;
  border: 8px solid rgba(255, 248, 223, 0.18);
  background: #10172a;
  box-shadow:
    inset 0 0 0 2px rgba(255, 248, 223, 0.17),
    inset 0 0 34px rgba(111, 186, 220, 0.1),
    0 26px 84px rgba(0, 0, 0, 0.42),
    0 0 38px rgba(77, 167, 255, 0.12);
  touch-action: none;
}

.board-wrap.solved canvas {
  box-shadow:
    inset 0 0 0 2px rgba(255, 248, 223, 0.17),
    inset 0 0 34px rgba(111, 186, 220, 0.1),
    0 0 42px rgba(98, 213, 139, 0.48),
    0 24px 80px rgba(0, 0, 0, 0.38);
}

.board-overlay {
  width: min(100%, 560px);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.board-overlay button {
  min-height: 44px;
  flex: 1;
  padding: 0 18px;
  border-radius: 8px;
}

#resetButton {
  background: rgba(246, 241, 223, 0.9);
}

.mission-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mission-panel h2 {
  margin-bottom: 0;
  font-size: 1.35rem;
}

.mission-panel p {
  line-height: 1.45;
}

.level-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(5, 12, 28, 0.54);
  border: 1px solid var(--line);
}

.level-card div {
  min-height: 48px;
  padding: 8px 9px;
  border-radius: 7px;
  background: rgba(236, 243, 255, 0.08);
}

.level-card span {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 900;
  text-transform: uppercase;
}

.level-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1rem;
}

.level-card div:nth-child(2) {
  background: color-mix(in srgb, var(--difficulty, var(--green)) 24%, rgba(236, 243, 255, 0.08));
  border: 1px solid color-mix(in srgb, var(--difficulty, var(--green)) 48%, transparent);
}

.meter {
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(246, 241, 223, 0.12);
}

.meter span {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--green), var(--amber));
}

.piece-tray {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.board-piece-tray {
  width: min(100%, 560px);
  min-height: 122px;
  padding: 12px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(236, 243, 255, 0.06), rgba(5, 12, 28, 0.34)),
    rgba(5, 12, 28, 0.44);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 18px 40px rgba(0, 0, 0, 0.18);
}

.piece-tray button {
  min-height: 92px;
  border-radius: 6px;
  color: var(--ink);
  background: rgba(236, 243, 255, 0.045);
  border: 1px dashed rgba(217, 248, 255, 0.22);
  text-align: center;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  user-select: none;
  touch-action: none;
  box-shadow: none;
}

.piece-tray button::before {
  content: none;
}

.piece-mini {
  width: 78px;
  height: 62px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 4px;
  border-radius: 4px;
  background: transparent;
}

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

.mini-plastic {
  fill: rgba(36, 174, 247, 0.6);
  stroke: rgba(190, 240, 255, 0.5);
  stroke-width: 0.8;
}

.mini-outline {
  fill: none;
  stroke: rgba(217, 248, 255, 0.92);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 3px rgba(36, 174, 247, 0.45));
}

.mini-beam {
  fill: rgba(255, 230, 78, 0.5);
  stroke: rgba(255, 250, 172, 0.34);
  stroke-width: 0.6;
  filter: drop-shadow(0 0 4px rgba(255, 225, 78, 0.5));
}

.mini-light {
  fill: rgba(255, 255, 235, 0.92);
  stroke: rgba(255, 226, 74, 0.72);
  stroke-width: 1.1;
  filter: drop-shadow(0 0 5px rgba(255, 230, 93, 0.45));
}

.mini-flashlight .mini-handle,
.mini-flashlight .mini-head {
  fill: var(--flashlight-color, #217cff);
  stroke: rgba(255, 248, 223, 0.78);
  stroke-width: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.32));
}

.mini-flashlight .mini-head {
  fill: color-mix(in srgb, var(--flashlight-color, #217cff) 86%, #ffffff);
}

.mini-flashlight .mini-lens,
.mini-fallback-flashlight {
  fill: rgba(255, 241, 126, 0.95);
  stroke: var(--flashlight-color, #217cff);
  stroke-width: 1.2;
}

.mini-flashlight .mini-shine {
  fill: rgba(255, 255, 255, 0.74);
  stroke: none;
}

.piece-tray-label {
  min-width: 0;
}

.piece-tray-label strong,
.piece-tray-label small {
  display: block;
}

.piece-tray-label strong {
  font-size: 0.76rem;
}

.piece-tray-label small {
  display: none;
  margin-top: 2px;
  color: color-mix(in srgb, var(--flashlight) 42%, var(--muted));
  font-size: 0.68rem;
  font-weight: 900;
}

.piece-tray button.active {
  outline: 2px solid var(--amber);
  border-color: color-mix(in srgb, var(--flashlight) 68%, #fff8d4);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--flashlight) 20%, rgba(255, 248, 223, 0.12)), rgba(255, 248, 223, 0.08));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.18),
    0 0 22px color-mix(in srgb, var(--flashlight) 36%, rgba(241, 196, 91, 0.2));
}

.piece-tray button:not(.active) {
  opacity: 0.92;
}

.piece-tray-empty {
  grid-column: 1 / -1;
  min-height: 86px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px dashed rgba(217, 248, 255, 0.24);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.tool-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tool-row button {
  min-height: 46px;
  border-radius: 8px;
}

#solveButton {
  background: rgba(246, 241, 223, 0.9);
}

.result {
  margin-top: auto;
  min-height: 82px;
  padding: 14px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(246, 241, 223, 0.06), rgba(77, 167, 255, 0.07)),
    var(--panel-deep);
  border: 1px solid rgba(246, 241, 223, 0.18);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 14px 34px rgba(0, 0, 0, 0.18);
  display: grid;
  align-items: center;
  font-weight: 800;
}

.dev-panel {
  margin-top: 14px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid rgba(246, 241, 223, 0.2);
  background: rgba(8, 13, 28, 0.9);
  backdrop-filter: blur(18px);
}

.dev-panel[hidden] {
  display: none;
}

.dev-panel-header,
.dev-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.dev-panel-header {
  justify-content: space-between;
  margin-bottom: 10px;
}

.dev-panel h2 {
  margin: 0;
  font-size: 1rem;
}

.dev-panel button {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
}

.dev-panel button.active {
  color: #0d2519;
  background: var(--green);
}

#devOutput {
  width: 100%;
  min-height: 150px;
  max-height: 320px;
  margin-top: 10px;
  padding: 12px;
  resize: vertical;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(2, 7, 18, 0.82);
  font: 0.86rem Consolas, "Courier New", monospace;
}

.app-header {
  display: grid;
  gap: 4px;
  justify-items: center;
  text-align: center;
}

.app-header .eyebrow {
  margin: 0;
}

.app-header strong {
  color: rgba(255, 248, 223, 0.92);
  font-size: clamp(1rem, 2.4vw, 1.32rem);
  line-height: 1.35;
}

.top-controls,
.hud,
.how-to-play,
.mission-panel {
  width: min(900px, 100%);
  margin-inline: auto;
}

.top-controls {
  display: grid;
  grid-template-columns: minmax(260px, 1.35fr) repeat(5, minmax(92px, auto));
  gap: 10px;
  align-items: stretch;
  margin-top: 10px;
}

.top-controls .level-picker {
  min-width: 0;
  width: 100%;
  padding: 8px;
}

.top-controls button {
  min-height: 52px;
  padding: 0 14px;
  border-radius: 8px;
}

.top-controls #startButton,
.top-controls #solveButton,
.top-controls #resetButton {
  background: var(--amber);
}

.top-controls #rotateButton {
  background: linear-gradient(135deg, var(--blue), var(--teal));
}

.top-controls #resetButton {
  background: rgba(246, 241, 223, 0.92);
}

.stage {
  display: grid;
  gap: 12px;
  width: min(1080px, calc(100vw - 2rem));
}

.game-shell {
  place-items: start center;
}

.hud {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.how-to-play {
  margin-bottom: 0;
}

.quick-actions {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.play-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  justify-items: center;
  align-items: start;
}

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

.board-column {
  width: min(900px, 100%);
  gap: 12px;
}

.board-wrap {
  width: min(100%, 56vh, 560px);
}

.board-piece-tray {
  width: min(900px, 100%);
  min-height: 118px;
}

.piece-tray {
  grid-template-columns: repeat(6, minmax(96px, 1fr));
}

.mission-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(360px, 1.3fr) minmax(180px, 0.8fr);
  gap: 10px;
  align-items: stretch;
  min-height: auto;
}

.mission-panel p {
  margin: 0;
  align-self: center;
}

.level-card {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.meter {
  grid-column: 1 / -1;
}

.result {
  min-height: 64px;
  margin-top: 0;
}

.status-bar {
  display: grid;
}

@media (max-width: 980px) {
  .top-controls,
  .play-layout,
  .how-to-play {
    grid-template-columns: 1fr;
  }

  .piece-tray {
    grid-template-columns: repeat(3, minmax(112px, 1fr));
  }

  .level-picker {
    width: 100%;
    min-width: 0;
  }

  .mission-panel {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .level-card {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  body {
    background:
      linear-gradient(180deg, rgba(12, 22, 43, 0.98), rgba(5, 10, 20, 0.99)),
      url("sucai/SmartGames_SG-433_Ghost-Hunters_product-shot_30c352.jpg") center top / cover fixed;
  }

  .game-shell {
    padding: 6px 8px 10px;
    place-items: start center;
  }

  .stage {
    width: 100%;
    gap: 7px;
  }

  .app-header {
    gap: 8px;
    margin-bottom: 5px;
    padding: 7px;
    border-radius: 8px;
    background: rgba(5, 12, 28, 0.58);
    border: 1px solid var(--line);
    backdrop-filter: blur(14px);
  }

  .top-controls {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 0;
  }

  .top-controls .level-picker {
    grid-column: 1 / -1;
  }

  .top-controls button {
    min-height: 44px;
    padding: 0 10px;
    font-size: 0.82rem;
    box-shadow: none;
  }

  .top-controls #solveButton {
    grid-column: auto;
  }

  .top-controls #resetButton {
    grid-column: 1 / -1;
  }

  .level-picker {
    padding: 6px;
    box-shadow: none;
  }

  .level-picker span {
    display: none;
  }

  .level-select {
    min-height: 40px;
    font-size: 0.82rem;
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: 1.42rem;
  }

  .hud {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .hud div {
    min-height: 42px;
    padding: 6px 7px;
    border-radius: 7px;
    box-shadow: none;
  }

  .hud span {
    font-size: 0.62rem;
  }

  .hud strong {
    margin-top: 2px;
    font-size: 0.98rem;
  }

  .how-to-play {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 3px;
    padding: 7px 9px;
    border-radius: 8px;
  }

  .how-to-play h2 {
    display: none;
  }

  .how-to-play p {
    margin-bottom: 0;
    font-size: 0.74rem;
    line-height: 1.26;
  }

  .quick-actions {
    display: none;
  }

  .quick-actions span {
    display: none;
  }

  .board-column {
    order: 1;
    gap: 6px;
  }

  .board-wrap {
    width: min(100%, 58svh, 430px);
  }

  .mission-panel {
    order: 2;
    padding: 8px;
    gap: 7px;
    box-shadow: none;
  }

  .mission-panel h2 {
    font-size: 0.95rem;
  }

  .mission-panel p {
    display: none;
    margin-bottom: 0;
    font-size: 0.8rem;
  }

  .level-card {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 5px;
  }

  .level-card div {
    min-height: 38px;
    padding: 5px 4px;
  }

  .level-card span {
    font-size: 0.56rem;
  }

  .level-card strong {
    font-size: 0.86rem;
  }

  .help-button {
    min-height: 34px;
    min-width: 52px;
    padding: 0 10px;
    font-size: 0.74rem;
    box-shadow: none;
  }

  .meter {
    height: 7px;
  }

  .tutorial-backdrop {
    align-items: end;
    padding: 10px;
  }

  .tutorial-panel {
    max-height: calc(100vh - 20px);
    overflow: auto;
  }

  .tutorial-steps article {
    grid-template-columns: 36px 1fr;
  }

  .tutorial-steps strong {
    width: 30px;
    height: 30px;
  }

  .piece-tray::-webkit-scrollbar {
    display: none;
  }

  .piece-tray {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow-y: auto;
    gap: 7px;
    padding-bottom: 0;
  }

  .board-piece-tray {
    position: static;
    z-index: 8;
    max-height: 188px;
    padding: 9px;
    background:
      linear-gradient(180deg, rgba(236, 243, 255, 0.09), rgba(5, 12, 28, 0.56)),
      rgba(5, 12, 28, 0.88);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.08),
      0 -12px 32px rgba(0, 0, 0, 0.26);
  }

  .piece-tray button {
    white-space: nowrap;
    min-height: 76px;
    padding: 5px 4px;
    gap: 4px;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    box-shadow: none;
  }

  .piece-mini {
    width: 68px;
    height: 50px;
    flex-basis: auto;
  }

  .piece-tray-label strong {
    font-size: 0.72rem;
  }

  .piece-tray-label small {
    display: none;
  }

  .board-overlay {
    gap: 7px;
    padding: 0 2px;
  }

  .board-overlay button {
    min-height: 48px;
    padding: 0 12px;
  }

  .result {
    min-height: 48px;
    padding: 10px;
    font-size: 0.86rem;
  }

  .tool-row button {
    min-height: 48px;
  }

  .dev-panel button,
  .dev-actions {
    width: 100%;
  }
}

.hud,
.how-to-play,
.mission-panel {
  display: none !important;
}

.board-wrap {
  width: min(100%, 560px, calc(100vw - 2rem));
}

@media (max-width: 560px) {
  .board-wrap {
    width: min(100%, 430px, calc(100vw - 16px));
  }
}

@media (max-width: 980px) {
  .board-piece-tray {
    height: 188px;
    min-height: 188px;
    max-height: 188px;
    overflow-y: auto;
  }
}
