:root {
  --bg-dark: #0d0f1a;
  --bg-panel: #1a1d33;
  --text: #e0e8ff;
  --muted: #a0a8c8;
  --accent-blue: #6fa8ff;
  --accent-pink: #ff7ac2;
  --accent-green: #6fe3a2;
  --accent-red: #ff6f6f;
  --brick-color: #ffb36f;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: radial-gradient(circle at top, #1e2245, var(--bg-dark) 70%);
  color: var(--text);
  font-family: "Lexend", sans-serif;
  min-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Header */
.app-header {
  padding: 16px 24px;
  border-bottom: 1px solid #303560;
}
.title-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.limit-badge,
.game-title {
  font-size: 32px;
  font-weight: 900;
  color: var(--accent-blue);
  line-height: 1;
  text-shadow: 0 0 6px #1a1d33;
}
.limit-badge:after {
  display: none;
}
.bunny-digits {
  font-family: "Space Mono", monospace;
  font-size: 26px;
  color: var(--accent-green);
  text-shadow: 0 0 10px var(--accent-green);
  white-space: nowrap;
}
.hint-btn {
  appearance: none;
  border: 1px solid #303560;
  background: #1e2340;
  color: var(--text);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  font-weight: 900;
  font-size: 16px;
  line-height: 16px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.hint-btn:hover {
  filter: brightness(1.1);
}
.subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 16px;
  padding: 16px;
  min-height: calc(100vh - 85px);
}
.left-panel {
  height: fit-content;
  min-height: 100%;
  background: #000;
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: auto;
  border: 1px solid #303560;
}
.right-panel {
  height: fit-content;
}
#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
}
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Panels */
.status-box,
.primes-box,
.turn-box,
.explain,
.factorization-box {
  background: var(--bg-panel);
  border: 1px solid #303560;
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.status-box {
  display: flex;
  justify-content: space-around;
  text-align: center;
}
.status-item .label {
  font-size: 14px;
  color: var(--muted);
}
.status-item .value {
  display: block;
  font-size: 32px;
  font-weight: 700;
  font-family: "Space Mono";
  margin-top: 4px;
}
#timeDisplay {
  color: var(--accent-pink);
}
#primesLeftCount {
  color: var(--accent-green);
}
#partsCount {
  color: var(--accent-blue);
}

.primes-header,
.factorization-header {
  font-weight: 700;
  margin-bottom: 12px;
  text-align: center;
  color: var(--accent-blue);
}
.primes-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.prime-cell {
  background: #2a2d4a;
  border-radius: 6px;
  text-align: center;
  padding: 8px 0;
  font-family: "Space Mono";
  font-size: 16px;
  cursor: pointer;
  user-select: none;
}
.prime-cell.used {
  opacity: 0.3;
  cursor: default;
}

/* Guess input */
.guess-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}
.guess-input {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 8px;
}
.guess-input input {
  height: 42px;
  font-size: 20px;
  text-align: center;
  background: var(--bg-dark);
  border: 1px solid #4a4f80;
  color: var(--text);
  border-radius: 8px;
  font-family: "Space Mono", monospace;
}
button.primary {
  width: 100%;
  background: linear-gradient(45deg, var(--accent-blue), var(--accent-pink));
  border: none;
  color: #fff;
  padding: 12px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  text-shadow: 0 1px 3px #0005;
  transition: transform 0.2s;
}
button.primary:hover {
  transform: scale(1.02);
}

.explain {
  height: 150px;
  min-height: 150px;
  max-height: 150px;
  overflow: auto;
  font-size: 15px;
  line-height: 1.6;
}
.explain .math-display {
  font-family: "Space Mono";
  font-size: 18px;
  color: var(--accent-green);
  text-align: center;
  margin-bottom: 8px;
}

.factorization-display {
  font-family: "Space Mono";
  padding: 8px 10px;
  background: #262a47;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px #303560;
  text-align: center;
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: #0d0f1acc;
  backdrop-filter: blur(8px);
  z-index: 100;
}
.overlay.visible {
  display: grid;
}
.card {
  background: var(--bg-panel);
  border-radius: 16px;
  padding: 24px;
  width: min(520px, 92vw);
  text-align: center;
  box-shadow: var(--shadow);
}
.card h2 {
  margin-top: 0;
}
.card.instructions .instructions-text {
  text-align: left;
  font-size: 14px;
  line-height: 1;
  max-height: 50vh;
  overflow: auto;
}

/* Game over */
.crying-bunny {
  font-size: 48px;
  font-family: "Space Mono";
  animation: cry 2s infinite;
}
.final-factorization {
  margin: 16px 0;
}
.final-factorization .label {
  color: var(--muted);
  margin-bottom: 6px;
}
.fta-note {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}
@keyframes cry {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

/* Canvas niceties */
.canvas-watermark {
  position: absolute;
  right: 10px;
  bottom: 10px;
  font-size: 12px;
  color: #ffffff55;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }
  body {
    overflow-y: auto;
  }
  .left-panel {
    min-height: 46vh;
  }
  .right-panel {
    min-height: auto;
  }
}
