:root {
  color-scheme: dark;
  --bg: #101114;
  --panel: #1b1f24;
  --panel-2: #242931;
  --line: #3b414b;
  --text: #f4f0e8;
  --muted: #aeb6c2;
  --accent: #ffcc4d;
  --red: #d74d4d;
  --green: #4eb87f;
  --blue: #4d8fd7;
  --violet: #8c66d9;
  --steel: #6c7684;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 204, 77, 0.08), transparent 38%),
    radial-gradient(circle at 20% 10%, rgba(215, 77, 77, 0.16), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  padding: 24px;
}

.stage {
  position: relative;
  width: min(1240px, 100%);
  margin: 0 auto;
  border: 1px solid var(--line);
  background: rgba(16, 17, 20, 0.9);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  -webkit-touch-callout: none;
  touch-action: manipulation;
  user-select: none;
}

h1,
h2,
p {
  margin: 0;
}

.play-area {
  display: grid;
  grid-template-columns: 1fr;
  padding: 24px;
}

.stage.briefing-mode .board-wrap {
  display: none;
}

.stage:not(.briefing-mode) .briefing-screen {
  display: none;
}

.briefing-screen {
  display: grid;
  min-height: min(620px, calc(100vh - 210px));
  place-items: center;
}

.briefing-card {
  display: grid;
  justify-items: center;
  gap: 18px;
  width: min(560px, 100%);
  padding: 32px 20px;
}

.briefing-label {
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
}

.current-objective {
  display: grid;
  place-items: center;
  width: min(760px, 100%);
  min-height: clamp(150px, 28vw, 260px);
  color: var(--text);
}

.objective-sequence {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vw, 28px);
  width: 100%;
}

.current-objective .objective-icon {
  width: clamp(150px, 28vw, 260px);
  height: clamp(150px, 28vw, 260px);
  border: 2px solid var(--accent);
  background: #20242a;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
}

.objective-arrow {
  color: var(--accent);
  font-size: clamp(42px, 8vw, 76px);
  font-weight: 950;
}

.objective-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  container-type: inline-size;
}

.objective-icon::before,
.objective-icon::after {
  content: "";
  position: absolute;
}

.objective-icon.color::before {
  width: 62%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--red), var(--accent), var(--green), var(--blue), var(--violet), var(--red));
}

.objective-icon.color::after {
  width: 30%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #20242a;
}

.objective-icon.shape {
  display: block;
  padding: 0;
  overflow: hidden;
}

.objective-icon.shape::before,
.objective-icon.shape::after {
  display: none;
}

.shape-mark {
  position: absolute;
  display: block;
}

.shape-mark.circle {
  left: 20%;
  top: 21%;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--green);
}

.shape-mark.square {
  right: 20%;
  top: 22%;
  width: 25%;
  height: 25%;
  border-radius: 8%;
  background: var(--blue);
  transform: rotate(-8deg);
}

.shape-mark.triangle {
  left: 22%;
  bottom: 20%;
  width: 30%;
  height: 30%;
  background: var(--accent);
  clip-path: polygon(50% 6%, 94% 92%, 6% 92%);
  transform: rotate(11deg);
}

.shape-mark.diamond {
  right: 23%;
  bottom: 23%;
  width: 25%;
  height: 25%;
  background: var(--violet);
  transform: rotate(38deg);
}

.objective-icon.letter::before {
  width: 56%;
  height: 66%;
  border: 3px solid var(--line);
  background: #15181d;
}

.objective-icon.letter::after {
  content: "A";
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--accent);
  font-size: 56cqw;
  font-weight: 950;
}

.objective-text {
  position: absolute;
  left: 50%;
  bottom: 8%;
  z-index: 1;
  min-width: 42%;
  transform: translateX(-50%);
  padding: 1cqw 3cqw;
  background: rgba(16, 17, 20, 0.78);
  text-align: center;
  font-size: 13cqw;
  font-weight: 950;
}

.next-preview {
  display: grid;
  justify-items: center;
  gap: 8px;
  min-height: 70px;
}

.next-preview > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.next-objectives {
  display: grid;
  place-items: center;
  min-height: 48px;
}

.next-objectives .objective-sequence {
  gap: 6px;
}

.next-objectives .objective-icon {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}

.next-objectives .objective-arrow {
  font-size: 22px;
}

.briefing-card .primary-button {
  width: min(260px, 100%);
  margin-top: 4px;
}

.log {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.primary-button,
.ghost-button {
  width: 100%;
  min-height: 44px;
  margin-top: 10px;
  font-weight: 900;
}

.primary-button {
  background: var(--accent);
  color: #17120a;
}

.ghost-button {
  border: 1px solid var(--line);
  background: #292e36;
}

.board-wrap {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 12px;
  min-width: 0;
}

.board-objective {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(100%, 620px);
  min-height: 58px;
}

.board-objective .objective-icon {
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}

.hidden {
  display: none !important;
}

.board-shell {
  position: relative;
  width: min(100%, 620px);
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, minmax(44px, 1fr));
  grid-template-rows: repeat(7, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
  aspect-ratio: 1 / 0.86;
  padding: 8px;
  border: 1px solid var(--line);
  background: #171a1f;
  touch-action: none;
}

.phase-toast {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 30;
  transform: translate(-50%, -50%);
  padding: 10px 22px;
  border: 2px solid var(--accent);
  background: rgba(16, 17, 20, 0.86);
  color: var(--accent);
  font-size: clamp(28px, 7vw, 58px);
  font-weight: 950;
  pointer-events: none;
}

.timer-bar {
  width: min(100%, 620px);
  height: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #15181d;
}

.timer-bar span {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--accent), var(--red));
  transform-origin: left center;
  transform: scaleX(1);
  transition: transform 100ms linear;
}

.result-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(16, 17, 20, 0.78);
}

.result-panel {
  display: grid;
  justify-items: center;
  align-items: center;
  gap: 14px;
  width: min(520px, calc(100% - 40px));
  padding: 34px 24px;
  border: 2px solid var(--accent);
  background: #181b20;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
  text-align: center;
}

.result-panel span {
  color: var(--accent);
  font-size: 13px;
  font-weight: 950;
}

.result-panel strong {
  width: 100%;
  text-align: center;
  white-space: nowrap;
  font-size: clamp(28px, 7vw, 48px);
  line-height: 1;
}

.result-reason {
  width: 100%;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.5;
}

.result-panel .primary-button {
  width: min(260px, 100%);
}

.result-overlay.game-over .result-panel {
  border-color: var(--red);
}

.result-overlay.game-over .result-panel span {
  color: var(--red);
}

.result-overlay.game-over .primary-button {
  background: var(--red);
  color: #fff;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  border: 1px solid #414852;
  background: #2b3038;
  transition: transform 140ms ease, border-color 140ms ease, opacity 220ms ease;
}

.cell.path {
  background: #30363f;
}

.cell.empty {
  border-color: #47505c;
  background:
    radial-gradient(circle at 50% 50%, rgba(78, 184, 127, 0.18), transparent 62%),
    #20252c;
}

.cell.route-open {
  border-color: var(--green);
  background: rgba(78, 184, 127, 0.26);
  box-shadow: inset 0 0 0 2px rgba(78, 184, 127, 0.55), 0 0 16px rgba(78, 184, 127, 0.3);
}

.cell.route-scan {
  border-color: var(--accent);
  background: rgba(255, 204, 77, 0.3);
  box-shadow: inset 0 0 0 2px rgba(255, 204, 77, 0.62), 0 0 18px rgba(255, 204, 77, 0.28);
}

.cell.selected {
  border-color: var(--accent);
  transform: translateY(-3px);
}

.cell.dragging {
  border-color: var(--accent);
  transform: scale(0.98);
}

.cell.swap-hidden .piece {
  visibility: hidden;
}

.cell.explode {
  z-index: 4;
  opacity: 1;
  transform: scale(1.05);
  border-color: var(--accent);
}

.cell.explode::after {
  content: "";
  position: absolute;
  inset: -18%;
  z-index: 4;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.95) 0 12%, rgba(255, 204, 77, 0.9) 13% 26%, rgba(215, 77, 77, 0.65) 27% 44%, transparent 45%),
    conic-gradient(from 10deg, transparent 0 8%, rgba(255, 255, 255, 0.9) 9% 12%, transparent 13% 24%, rgba(255, 204, 77, 0.95) 25% 29%, transparent 30% 44%, rgba(215, 77, 77, 0.8) 45% 50%, transparent 51%);
  pointer-events: none;
  animation: blast 620ms ease-out forwards;
}

.cell.explode .piece {
  animation: piece-pop 620ms ease-out forwards;
}

.cell.bomb-area {
  box-shadow: inset 0 0 0 3px rgba(215, 77, 77, 0.8);
}

.piece {
  position: relative;
  display: grid;
  place-items: center;
  width: 78%;
  aspect-ratio: 1;
  color: #fff;
  font-weight: 950;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  transform: translate3d(0, 0, 0);
  transition: transform 240ms cubic-bezier(0.2, 0.9, 0.2, 1.2);
  will-change: transform;
}

.piece.swapping {
  z-index: 5;
  transition-duration: 260ms;
  filter: brightness(1.22);
}

.piece.falling {
  transition: transform 460ms cubic-bezier(0.2, 0.82, 0.18, 1);
}

.swap-ghost {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  opacity: 1;
  transition: transform 260ms cubic-bezier(0.2, 0.9, 0.2, 1.2);
}

.piece::before {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
}

.piece.circle::before {
  border-radius: 50%;
}

.piece.square::before {
  border-radius: 5px;
}

.piece.diamond::before {
  transform: rotate(45deg) scale(0.82);
}

.piece.triangle::before {
  clip-path: polygon(50% 5%, 96% 92%, 4% 92%);
}

.piece span {
  position: relative;
  z-index: 1;
  color: white;
  font-size: clamp(15px, 3vw, 26px);
}

.red {
  color: var(--red);
}

.green {
  color: var(--green);
}

.blue {
  color: var(--blue);
}

.violet {
  color: var(--violet);
}

@keyframes blast {
  0% {
    opacity: 0;
    transform: scale(0.25) rotate(0deg);
  }

  22% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: scale(1.65) rotate(38deg);
  }
}

@keyframes piece-pop {
  0% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }

  28% {
    opacity: 1;
    transform: scale(1.2) rotate(-7deg);
  }

  100% {
    opacity: 0;
    transform: scale(0.18) rotate(24deg);
  }
}

@media (max-width: 980px) {
  .play-area {
    grid-template-columns: 1fr;
  }

  .play-area {
    display: flex;
    flex-direction: column;
  }

  .board {
    grid-template-columns: repeat(8, minmax(34px, 1fr));
  }
}

@media (max-width: 560px) {
  .shell {
    padding: 10px;
  }

  .play-area {
    padding: 14px;
  }

  .board {
    gap: 4px;
    padding: 5px;
  }
}
