:root {
  --bg-dark: #0d0f1a;
  --bg-panel: #1a1d33;
  --text: #e0e8ff;
  --muted: #a0a8c8;
  --accent-blue: #6fa8ff;
  --accent-pink: #ff7ac2;
  --accent-green: #6fe3a2;
  --accent-red: #ff6f6f;
  --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;
  height: 100%;
  overflow: auto;
}

/* Header & Layout */
.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 {
  font-size: 32px;
  font-weight: 900;
  color: var(--accent-blue);
  line-height: 1;
  text-shadow: 0 0 6px #1a1d33;
}
.game-title {
  font-size: 32px;
  font-weight: 900;
  color: var(--accent-blue);
  line-height: 1;
  text-shadow: 0 0 6px #1a1d33;
}
.bunny-digits {
  font-family: "Space Mono", monospace;
  font-size: 18px;
  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: 32px;
  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 {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 85px);
}
.left-panel,
.right-panel {
  height: 100%;
}
.left-panel {
  background: #000;
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: auto;
  border: 1px solid #303560;
}
#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
}
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Panels */
.status-box,
.positions-box,
.turn-box,
.equations-box,
.leaderboard-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: 28px;
  font-weight: 700;
  font-family: "Space Mono";
  margin-top: 4px;
}
#scoreDisplay {
  color: var(--accent-green);
}
#timeDisplay {
  color: var(--accent-pink);
}

.positions-header,
.leaderboard-header,
.equations-header,
.turn-header {
  font-weight: 700;
  margin-bottom: 12px;
  text-align: center;
  color: var(--accent-blue);
}
.pos-row {
  display: flex;
  justify-content: space-between;
  font-family: "Space Mono";
  font-size: 14px;
  background: #262a47;
  padding: 6px 10px;
  border-radius: 8px;
  margin-bottom: 6px;
}

.turn-box .mode-toggle {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 10px;
  font-size: 14px;
}
.turn-box .mode-panel.hidden {
  display: none;
}
.turn-box .input-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.turn-box label {
  font-size: 12px;
  color: var(--muted);
  display: grid;
  gap: 4px;
}
.turn-box input {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #4a4f80;
  background: var(--bg-dark);
  color: var(--text);
  font-family: "Space Mono";
}
.turn-box .eq-preview {
  text-align: center;
  font-family: "Space Mono";
  color: var(--accent-green);
  margin-bottom: 8px;
}
.note {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.equations-box .equation {
  font-family: "Space Mono";
  background: #262a47;
  padding: 6px 10px;
  border-radius: 8px;
  margin-bottom: 6px;
  text-align: center;
}
.equation-timer {
  text-align: center;
  font-family: "Space Mono";
  color: var(--accent-pink);
  font-weight: 700;
}
.equation-timer.hidden {
  display: none;
}

.leaderboard-list {
  display: grid;
  gap: 6px;
  font-family: "Space Mono";
  font-size: 13px;
}
.leaderboard-list .row {
  display: flex;
  justify-content: space-between;
  background: #262a47;
  padding: 6px 10px;
  border-radius: 8px;
}

/* Buttons */
button.primary {
  width: 100%;
  background: linear-gradient(45deg, var(--accent-blue), var(--accent-pink));
  border: none;
  color: #fff;
  padding: 14px;
  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);
}

/* 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.setup input,
.card.setup select {
  width: 100%;
  padding: 10px;
  margin-top: 4px;
  border-radius: 8px;
  border: 1px solid #4a4f80;
  background: var(--bg-dark);
  color: var(--text);
  font-family: "Space Mono";
}
.card.setup select {
  cursor: pointer;
}
.card.setup label {
  display: block;
  margin-bottom: 12px;
  text-align: left;
}
.card h2 {
  margin-top: 0;
}
.tips-list {
  margin: 8px 0 16px;
  padding-left: 18px;
  text-align: left;
  font-size: 14px;
  line-height: 1.5;
}
.instructions-text {
  font-size: 14px;
  color: var(--text);
  text-align: left;
}
.countdown {
  font-family: "Space Mono";
  color: var(--accent-pink);
  margin: 8px 0 0;
}

/* Game Over / Win */
.crying-bunny {
  font-size: 48px;
  font-family: "Space Mono";
  animation: cry 2s infinite;
}
.final-score-display {
  margin: 16px 0;
  font-size: 18px;
}
#finalScore,
#winScore {
  color: var(--accent-green);
  font-weight: 700;
}
@keyframes cry {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

/* Canvas theming helpers */
.axis-label {
  color: var(--muted);
}

@media (max-width: 740px) {
  .game-title {
    font-size: 26px;
  }
  .limit-badge {
    font-size: 26px;
  }
  .layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  body {
    overflow: auto;
  }
}
