:root {
  --bg: #0b1020;
  --panel: #101827;
  --panel-2: #172033;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --good: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
  --tile: #1e3a8a;
  --tile-hover: #2563eb;
  --tile-cleared: #14532d;
  --tile-wrong: #581c1c;
  --tile-hinted: #334155;
  --border: rgba(255,255,255,0.12);
  --shadow: 0 24px 80px rgba(0,0,0,0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(56,189,248,0.18), transparent 35%),
    radial-gradient(circle at bottom right, rgba(245,158,11,0.12), transparent 35%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

#app {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 20px;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4rem);
  letter-spacing: -0.05em;
}

.app-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-weight: 600;
}

.status-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(78px, 1fr));
  gap: 10px;
}

.status-panel div {
  background: rgba(16,24,39,0.78);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  text-align: center;
  box-shadow: var(--shadow);
}

.status-panel span {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.status-panel strong {
  display: block;
  margin-top: 4px;
  font-size: 1.15rem;
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.controls button,
.choices button {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  background: var(--accent);
  color: #00111f;
  font-weight: 800;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

.controls button:hover,
.choices button:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.board-viewport {
  width: 100%;
  max-height: 68vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px;
  background: rgba(16, 24, 39, 0.42);
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--board-cols, 5), minmax(112px, 112px));
  gap: 10px;
  width: max-content;
}

.category-cell,
.tile {
  border-radius: 16px;
  min-height: 76px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.1;
  padding: 6px;
  overflow: hidden;
  gap: 2px;
}

.category-cell {
  background: var(--panel);
  color: var(--accent);
  font-weight: 900;
  padding: 10px;
  font-size: clamp(0.7rem, 1.2vw, 1rem);
  overflow-wrap: anywhere;
}

.tile {
  background: linear-gradient(180deg, var(--tile), #172554);
  color: white;
  font-size: clamp(0.75rem, 1.2vw, 1.2rem);
  font-weight: 900;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 140ms ease, background 140ms ease, opacity 140ms ease;
  white-space: normal;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 2px rgba(0,0,0,0.65);
}

.tile:hover {
  background: linear-gradient(180deg, var(--tile-hover), var(--tile));
  transform: translateY(-2px);
}

.tile.cleared {
  background: var(--tile-cleared);
  cursor: default;
}

.tile.wrong {
  background: var(--tile-wrong);
  cursor: default;
}

.tile.hinted {
  background: var(--tile-hinted);
}

.tile.locked {
  opacity: 0.55;
  cursor: not-allowed;
}

.tile small {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.1;
  white-space: nowrap;   /* keeps "2 risk nearby" together */
}

.message {
  margin-top: 18px;
  background: rgba(16,24,39,0.76);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  color: var(--muted);
}

.question-dialog {
  width: min(640px, calc(100% - 30px));
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.question-dialog::backdrop {
  background: rgba(0,0,0,0.7);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

#questionForm {
  padding: 22px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.modal-header h2 {
  margin: 0;
}

.modal-header p {
  margin: 4px 0 0;
  color: var(--accent);
  font-weight: 900;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
}

.question-prompt {
  font-size: 1.25rem;
  line-height: 1.45;
  margin: 24px 0;
}

.choices {
  display: grid;
  gap: 12px;
}

.choices button {
  text-align: left;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.choices button.correct {
  background: var(--good);
  color: #052e16;
}

.choices button.incorrect {
  background: var(--bad);
  color: white;
}

.scan-button {
  background: linear-gradient(135deg, #38bdf8, #22c55e) !important;
}

.scan-button.active {
  outline: 3px solid rgba(56, 189, 248, 0.65);
  box-shadow:
    0 0 0 6px rgba(56, 189, 248, 0.18),
    0 0 28px rgba(56, 189, 248, 0.55);
  animation: scanPulse 1.2s ease-in-out infinite;
}

.tile.scan-target {
  outline: 3px solid rgba(56, 189, 248, 0.85);
  box-shadow:
    0 0 0 6px rgba(56, 189, 248, 0.15),
    0 0 30px rgba(56, 189, 248, 0.6);
}

.tile.scanned-safe {
  background: linear-gradient(180deg, #166534, #14532d);
}

.tile.scanned-risk {
  background: linear-gradient(180deg, #92400e, #451a03);
  animation: mineWarning 900ms ease-in-out 2;
}

.tile.mine-warning {
  animation: mineWarning 800ms ease-in-out 3;
}

.tile.category-flash {
  animation: categoryFlash 900ms ease-in-out 2;
}

.reward-banner {
  margin-top: 14px;
  border: 1px solid rgba(56, 189, 248, 0.38);
  border-radius: 18px;
  padding: 14px 16px;
  background:
    radial-gradient(circle at top left, rgba(56,189,248,0.26), transparent 40%),
    rgba(16,24,39,0.92);
  box-shadow:
    0 18px 60px rgba(0,0,0,0.35),
    0 0 24px rgba(56,189,248,0.2);
  color: var(--text);
  animation: rewardPop 420ms ease-out;
}

.reward-banner strong {
  display: block;
  color: var(--accent);
  font-size: 1.05rem;
}

.reward-banner span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

@keyframes scanPulse {
  0%, 100% {
    transform: translateY(0);
    filter: brightness(1);
  }

  50% {
    transform: translateY(-1px);
    filter: brightness(1.18);
  }
}

@keyframes mineWarning {
  0%, 100% {
    transform: translateY(0) scale(1);
    box-shadow: var(--shadow);
  }

  25% {
    transform: translateY(-2px) scale(1.03);
    box-shadow:
      0 0 0 5px rgba(239, 68, 68, 0.25),
      0 0 26px rgba(239, 68, 68, 0.7);
  }

  50% {
    transform: translateY(1px) scale(0.99);
    box-shadow:
      0 0 0 7px rgba(245, 158, 11, 0.2),
      0 0 34px rgba(245, 158, 11, 0.65);
  }
}

@keyframes categoryFlash {
  0%, 100% {
    filter: brightness(1);
  }

  50% {
    filter: brightness(1.6);
    box-shadow:
      0 0 0 5px rgba(34,197,94,0.22),
      0 0 28px rgba(34,197,94,0.55);
  }
}

@keyframes rewardPop {
  0% {
    transform: translateY(8px) scale(0.97);
    opacity: 0;
  }

  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@media (max-width: 760px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .status-panel {
    grid-template-columns: repeat(2, 1fr);
  }

  .board {
    grid-template-columns: repeat(var(--board-cols, 5), minmax(72px, 72px));
    gap: 6px;
  }

  .category-cell,
  .tile {
    min-height: 58px;
    border-radius: 12px;
    font-size: 0.8rem;
  }

  .tile {
    font-size: clamp(0.6rem, 2.4vw, 0.85rem);
    padding: 4px;
  }
}

.scan-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
}

.scan-ring {
  position: fixed;
  border: 2px solid rgba(56, 189, 248, 0.95);
  border-radius: 999px;
  transform: translate(-50%, -50%) scale(0.2);
  animation: scanRing 900ms ease-out forwards;
  box-shadow:
    0 0 18px rgba(56, 189, 248, 0.85),
    inset 0 0 18px rgba(56, 189, 248, 0.45);
}

.scan-sweep {
  position: fixed;
  width: 120px;
  height: 120px;
  border-radius: 999px;
  background: conic-gradient(
    from 0deg,
    rgba(56,189,248,0.0),
    rgba(56,189,248,0.55),
    rgba(56,189,248,0.0)
  );
  transform: translate(-50%, -50%);
  animation: scanSweep 900ms linear forwards;
  mix-blend-mode: screen;
}

.scan-readout {
  position: fixed;
  transform: translate(-50%, -130%);
  background: rgba(11,16,32,0.94);
  border: 1px solid rgba(56,189,248,0.65);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 900;
  font-size: 0.8rem;
  box-shadow: 0 0 24px rgba(56,189,248,0.45);
  animation: scanReadout 1100ms ease-out forwards;
}

@keyframes scanRing {
  to {
    transform: translate(-50%, -50%) scale(1.35);
    opacity: 0;
  }
}

@keyframes scanSweep {
  from {
    transform: translate(-50%, -50%) rotate(0deg) scale(0.4);
    opacity: 0.95;
  }

  to {
    transform: translate(-50%, -50%) rotate(720deg) scale(1.15);
    opacity: 0;
  }
}

@keyframes scanReadout {
  0% {
    opacity: 0;
    transform: translate(-50%, -90%);
  }

  20%, 70% {
    opacity: 1;
    transform: translate(-50%, -130%);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -165%);
  }
}

.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: #020617;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.splash-screen.hidden {
  display: none;
}

.splash-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.62;
}

.splash-content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 24px;
  color: white;
  text-shadow: 0 4px 24px rgba(0,0,0,0.85);
}

.splash-content h1 {
  margin: 0;
  font-size: clamp(3rem, 10vw, 7rem);
  letter-spacing: -0.07em;
}

.splash-content p {
  margin: 8px 0 24px;
  color: var(--accent);
  font-weight: 900;
}

.splash-content button {
  border: 0;
  border-radius: 999px;
  padding: 14px 24px;
  background: var(--accent);
  color: #00111f;
  font-weight: 900;
  cursor: pointer;
}