:root {
  --bg: #24162f;
  --panel: #321f42;
  --panel2: #43285a;
  --text: #fffaf4;
  --muted: #b9aec2;
  --gold: #ffd166;
  --pink: #ff75a0;
  --mint: #73f0bc;
  --line: rgba(255, 255, 255, .12);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 18% -8%, rgba(255, 117, 160, .22), transparent 34%),
    radial-gradient(circle at 88% 14%, rgba(115, 240, 188, .15), transparent 30%),
    linear-gradient(180deg, #24162f, #1d172b);
  font-family: "Be Vietnam Pro", Inter, system-ui, sans-serif;
  font-size: 16px;
}

button { font: inherit; -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin-top: 0; }
h1, h2 { letter-spacing: -.055em; line-height: 1.06; }
h1 { margin-bottom: 0; font-size: clamp(46px, 9vw, 76px); }
h2 { margin-bottom: 8px; font-size: clamp(24px, 4vw, 36px); }
h3 { margin-bottom: 12px; }
p { color: var(--muted); line-height: 1.7; }

.app-shell {
  width: min(1240px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 22px 34px;
}

.topbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}
.brand span,
.hero-icons span {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--panel2);
}
.brand span {
  width: 42px;
  height: 42px;
  border-radius: 15px;
  font-size: 24px;
}
.brand strong { font-size: 20px; letter-spacing: -.04em; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--mint);
  background: rgba(50, 31, 66, .74);
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
}
.best-score {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(50, 31, 66, .62);
  font-size: 14px;
  font-weight: 800;
}
.best-score strong { color: var(--gold); }

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--mint);
  background: rgba(50, 31, 66, .74);
  text-decoration: none;
  font-weight: 900;
}

.title-block { text-align: right; }
.eyebrow {
  margin: 0 0 9px;
  color: var(--gold);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

main {
  min-height: calc(100vh - 152px);
  display: grid;
  align-items: center;
}

.screen {
  display: none;
  width: 100%;
  animation: enter .25s ease;
}
.screen.active { display: block; }
@keyframes enter { from { opacity: 0; transform: translateY(10px); } }

.welcome {
  width: min(100%, 780px);
  margin: 0 auto;
  padding: 32px 0 54px;
  text-align: center;
}
.hero-icons {
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}
.hero-icons span {
  width: 94px;
  height: 94px;
  border-radius: 24px;
  color: var(--text);
  font-size: 46px;
  font-weight: 900;
  box-shadow: 0 20px 55px rgba(0, 0, 0, .2);
  transform: rotate(-7deg);
}
.hero-icons span:nth-child(2) {
  z-index: 2;
  width: 110px;
  height: 110px;
  color: #24162f;
  background: var(--gold);
  transform: translateY(-10px) rotate(4deg);
}
.hero-icons span:nth-child(3) { transform: rotate(8deg); }
.intro {
  max-width: 680px;
  margin: 22px auto 30px;
  color: var(--muted);
  font-size: 17px;
  font-weight: 750;
}
.welcome .primary-button,
.secondary-button {
  width: 100%;
  min-height: 66px;
  border-radius: 17px;
  font-size: 18px;
}
.secondary-button {
  margin-top: 12px;
  border: 1px solid var(--line);
  color: var(--text);
  background: transparent;
  cursor: pointer;
  font-weight: 900;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(250px, 318px) minmax(0, 1fr);
  gap: 16px;
}

.control-rail,
.play-stage {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(50, 31, 66, .84);
  box-shadow: 0 22px 60px rgba(0, 0, 0, .18);
}
.control-rail { display: flex; flex-direction: column; gap: 18px; padding: 18px; }
.play-stage { min-width: 0; padding: 16px; }

footer {
  padding: 18px 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}
footer a { color: var(--mint); text-decoration: none; }

.level-list { display: grid; gap: 9px; }
.level-card {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: rgba(67, 40, 90, .78);
  text-align: left;
  cursor: pointer;
  font-weight: 800;
}
.level-card strong { font-size: 1rem; }
.level-card span { color: var(--muted); font-size: .82rem; font-weight: 800; }
.level-card.active {
  border-color: rgba(255, 209, 102, .8);
  color: #24162f;
  background: var(--gold);
  box-shadow: 0 12px 30px rgba(255, 209, 102, .16);
}
.level-card.active span { color: rgba(36, 22, 47, .7); }

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
}
.metrics div {
  min-width: 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(29, 23, 43, .48);
}
.metrics strong { display: block; color: var(--gold); font-size: 1.35rem; line-height: 1; }
.metrics span { color: var(--muted); font-size: .78rem; font-weight: 800; }

.stage-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.action-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.ghost-button,
.primary-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 900;
}
.ghost-button {
  color: var(--text);
  background: rgba(67, 40, 90, .9);
}
.primary-button {
  border-color: transparent;
  color: #24162f;
  background: var(--gold);
}
.ghost-button:hover,
.level-card:hover,
.choice:hover { transform: translateY(-1px); }

.detective-layout {
  display: grid;
  grid-template-columns: minmax(230px, .72fr) minmax(0, 1.28fr);
  gap: 14px;
  align-items: start;
}
.clue-sheet {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(29, 23, 43, .38);
}
.clue-sheet h3 { color: var(--gold); }
.clue-sheet ol {
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
  font-weight: 780;
  line-height: 1.62;
}
.clue-sheet li + li { margin-top: 9px; }

.matrix-frame {
  display: grid;
  justify-content: center;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(29, 23, 43, .46);
  padding: clamp(10px, 2vw, 18px);
}
.matrix-frame.complete {
  border-color: rgba(255, 209, 102, .72);
  box-shadow: 0 0 0 4px rgba(255, 209, 102, .12), 0 20px 60px rgba(255, 209, 102, .14);
  animation: completeGlow 1s ease both;
}
.matrix {
  display: grid;
  grid-template-columns: minmax(116px, 1.08fr) repeat(var(--count), minmax(58px, 76px));
  width: max-content;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 14px;
  overflow: hidden;
}
.matrix-cell {
  min-height: 56px;
  border-right: 1px solid rgba(255, 255, 255, .16);
  border-bottom: 1px solid rgba(255, 255, 255, .16);
  background: rgba(255, 250, 244, .96);
}
.matrix-cell.header,
.matrix-cell.row-head {
  display: grid;
  place-items: center;
  padding: 8px;
  color: var(--text);
  background: rgba(67, 40, 90, .94);
  font-size: .88rem;
  font-weight: 950;
  text-align: center;
}
.matrix-cell.header { color: var(--gold); }
.matrix-cell.row-head { justify-content: start; text-align: left; }
.choice {
  display: grid;
  place-items: center;
  color: #24162f;
  cursor: pointer;
  font-size: 1.55rem;
  font-weight: 950;
}
.choice.yes { background: #dcfce7; color: #15803d; }
.matrix-frame.complete .choice.yes {
  animation: cellWin .62s ease both;
}
.choice.no { background: #ffe4ec; color: #db2777; }
.choice.hint { outline: 3px solid var(--gold); outline-offset: -4px; }

.answers {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.answer {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(67, 40, 90, .8);
  padding: 8px 11px;
  color: var(--muted);
  font-weight: 900;
}
.answer.done { background: rgba(115, 240, 188, .18); color: var(--mint); }
.answer.wrong { background: rgba(255, 117, 160, .16); color: var(--pink); }

.message {
  min-height: 50px;
  margin-top: 12px;
  border: 1px solid rgba(255, 209, 102, .22);
  border-radius: 14px;
  background: rgba(255, 209, 102, .1);
  padding: 13px;
  color: var(--text);
  font-weight: 850;
  line-height: 1.55;
}

.complete-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(8, 5, 14, .7);
  backdrop-filter: blur(8px);
}
.complete-modal.open { display: grid; }
.complete-panel {
  position: relative;
  width: min(500px, 100%);
  padding: 30px 24px 24px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 209, 102, .24), transparent 42%),
    rgba(50, 31, 66, .98);
  box-shadow: 0 30px 100px rgba(0, 0, 0, .38);
  text-align: center;
  animation: modalPop .3s cubic-bezier(.2, 1.35, .32, 1) both;
}
.complete-burst {
  position: relative;
  width: 118px;
  height: 118px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
}
.complete-burst span {
  position: relative;
  z-index: 2;
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  border: 6px solid rgba(255, 255, 255, .88);
  border-radius: 28px;
  color: #24162f;
  background: var(--gold);
  box-shadow: 0 18px 38px rgba(255, 209, 102, .26);
  font-size: 48px;
  font-weight: 950;
  transform: rotate(-5deg);
  animation: checkPop .5s .08s cubic-bezier(.2, 1.35, .32, 1) both;
}
.complete-burst i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 24px;
  border-radius: 999px;
  background: var(--mint);
  transform-origin: 50% 58px;
  animation: confettiPop .72s .12s ease both;
}
.complete-burst i:nth-child(2) { transform: translate(-50%, -50%) rotate(0deg); background: var(--gold); }
.complete-burst i:nth-child(3) { transform: translate(-50%, -50%) rotate(60deg); background: var(--mint); }
.complete-burst i:nth-child(4) { transform: translate(-50%, -50%) rotate(120deg); background: var(--pink); }
.complete-burst i:nth-child(5) { transform: translate(-50%, -50%) rotate(180deg); background: var(--gold); }
.complete-burst i:nth-child(6) { transform: translate(-50%, -50%) rotate(240deg); background: var(--mint); }
.complete-burst i:nth-child(7) { transform: translate(-50%, -50%) rotate(300deg); background: var(--pink); }
.complete-panel p:not(.eyebrow) {
  max-width: 380px;
  margin: 0 auto 20px;
  color: var(--muted);
  font-weight: 800;
}
.complete-actions {
  display: grid;
  gap: 10px;
}
.complete-actions .primary-button,
.complete-actions .secondary-button {
  min-height: 54px;
  font-size: 16px;
}

@keyframes modalPop {
  from { opacity: 0; transform: translateY(12px) scale(.96); }
}

@keyframes checkPop {
  from { opacity: 0; transform: scale(.58) rotate(-14deg); }
}

@keyframes confettiPop {
  0% { opacity: 0; height: 0; }
  40% { opacity: 1; height: 26px; }
  100% { opacity: .85; height: 18px; }
}

@keyframes completeGlow {
  0% { transform: scale(.992); }
  55% { transform: scale(1.006); }
  100% { transform: scale(1); }
}

@keyframes cellWin {
  0% { transform: scale(.92); }
  55% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@media (max-width: 940px) {
  .game-layout,
  .detective-layout { grid-template-columns: 1fr; }
  .stage-head { align-items: flex-start; flex-direction: column; }
  .action-row { justify-content: flex-start; }
}

@media (max-width: 560px) {
  .app-shell { padding-inline: 16px; }
  .topbar { align-items: flex-start; flex-direction: column; padding: 14px 0; }
  .brand strong { font-size: 17px; }
  .title-block { text-align: left; }
  main { min-height: auto; }
  .welcome { padding-top: 18px; }
  .hero-icons span { width: 72px; height: 72px; font-size: 34px; }
  .hero-icons span:nth-child(2) { width: 86px; height: 86px; }
  .metrics { grid-template-columns: 1fr; }
  .action-row { display: grid; grid-template-columns: 1fr; width: 100%; }
  .matrix-frame { justify-content: start; padding: 10px; }
  footer { flex-direction: column; text-align: center; }
}
