:root {
  --bg: #0b1020;
  --panel: #111a33;
  --panel2: #0f1730;
  --text: #e9eefc;
  --muted: #a7b3d6;
  --accent: #7aa7ff;
  --good: #bfffc6;
  --warn: #ffd28a;
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font-family:
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Arial;
  background: linear-gradient(180deg, #070b17, #0b1020);
  color: var(--text);
}

.topbar {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  padding: 18px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

h1 {
  margin: 0;
  font-size: 20px;
}
.sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 18px;
}

.panel {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}

.panel.subtle {
  background: rgba(255, 255, 255, 0.02);
}
.hidden {
  display: none;
}

.hud {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.chip {
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 13px;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--accent);
  color: #06102a;
  font-weight: 800;
  cursor: pointer;
}
.btn.secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.btn:active {
  transform: translateY(1px);
}

.input {
  width: 100%;
  max-width: 320px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  outline: none;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.row.space {
  justify-content: space-between;
}

.inline {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
  flex-wrap: wrap;
}

.prompt {
  margin: 12px 0 14px;
  line-height: 1.45;
  color: var(--text);
}
.answerRow {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.msg {
  min-height: 22px;
  color: var(--muted);
}
.big {
  font-size: 18px;
}
.small {
  font-size: 13px;
}
.muted {
  color: var(--muted);
}

.lockHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.hintBox {
  display: flex;
  gap: 10px;
  align-items: center;
}
.hintText {
  color: #cfe0ff;
  background: rgba(122, 167, 255, 0.12);
  border: 1px solid rgba(122, 167, 255, 0.25);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  max-width: 520px;
}

.footer {
  padding: 12px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
}

code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 6px;
}

/* Map */
.mapBar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 10px 0 12px;
}
.mapTitle {
  font-weight: 800;
}
.mapDots {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.dot {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
}
.dot.done {
  background: rgba(191, 255, 198, 0.35);
  border-color: rgba(191, 255, 198, 0.7);
}
.dot.current {
  background: rgba(122, 167, 255, 0.35);
  border-color: rgba(122, 167, 255, 0.8);
}

/* Story box */
.storyBox {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 12px;
  margin: 10px 0 12px;
}
.storyTitle {
  font-weight: 900;
  margin-bottom: 6px;
}
.storyText {
  color: var(--text);
  line-height: 1.45;
  min-height: 36px;
}
.cursor {
  display: inline-block;
  width: 10px;
  color: var(--accent);
  animation: blink 1s steps(2, end) infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* Certificate */
.cert {
  margin: 14px 0 16px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(
    180deg,
    rgba(122, 167, 255, 0.08),
    rgba(255, 255, 255, 0.02)
  );
  padding: 16px;
}
.certTitle {
  font-size: 20px;
  font-weight: 1000;
  margin-bottom: 10px;
}
.certBody {
  display: grid;
  gap: 8px;
}
.certRow {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.certFooter {
  margin-top: 10px;
}

/* ===== FINAL MODAL ===== */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(2px);
  z-index: 9999;
}

/* ✅ IMPORTANT: keeps modal hidden until JS opens it */
.modal.hidden {
  display: none;
}

.modalCard {
  width: min(720px, 100%);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(
    180deg,
    rgba(122, 167, 255, 0.14),
    rgba(255, 255, 255, 0.03)
  );
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  padding: 16px;
  position: relative;
  overflow: hidden;
  animation: popIn 0.18s ease-out;
}

@keyframes popIn {
  from {
    transform: scale(0.96);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.modalTop h2 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 1000;
}
.modalText {
  margin: 0;
  color: rgba(233, 238, 252, 0.85);
  line-height: 1.4;
}

.modalStats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}
@media (max-width: 560px) {
  .modalStats {
    grid-template-columns: 1fr;
  }
}

.stat {
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.18);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat strong {
  font-size: 16px;
}

.modalActions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.confetti {
  position: absolute;
  inset: -40px -40px auto -40px;
  height: 140px;
  background:
    radial-gradient(
      circle at 10% 30%,
      rgba(255, 210, 138, 0.9) 0 2px,
      transparent 3px
    ),
    radial-gradient(
      circle at 30% 70%,
      rgba(191, 255, 198, 0.9) 0 2px,
      transparent 3px
    ),
    radial-gradient(
      circle at 50% 30%,
      rgba(122, 167, 255, 0.9) 0 2px,
      transparent 3px
    ),
    radial-gradient(
      circle at 70% 60%,
      rgba(255, 210, 138, 0.9) 0 2px,
      transparent 3px
    ),
    radial-gradient(
      circle at 90% 40%,
      rgba(191, 255, 198, 0.9) 0 2px,
      transparent 3px
    );
  opacity: 0.55;
  filter: blur(0.1px);
  pointer-events: none;
}

/* Print */
@media print {
  body {
    background: #fff;
    color: #000;
  }
  .topbar,
  .footer,
  #playAgainBtn,
  #printBtn,
  #resetBtn,
  #timerChip,
  #lockChip,
  #finalModal {
    display: none !important;
  }
  .panel {
    border: 1px solid #ddd;
    background: #fff;
  }
  .cert {
    border: 2px solid #000;
  }
}
