: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;
  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;
  font-family: inherit;
}
.limit-badge:after {
  display: none;
}
.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: 26px;
  color: var(--accent-green);
  text-shadow: 0 0 10px var(--accent-green);
  white-space: nowrap;
}
@media (max-width: 740px) {
  .game-title {
    font-size: 26px;
  }
  .limit-badge {
    font-size: 26px;
  }
  .bunny-digits {
    font-size: 22px;
  }
  .title-wrap {
    gap: 12px;
  }
}
.subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}
.layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  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: hidden;
  border: 1px solid #303560;
}
#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
}
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* --- UI Panels --- */
.status-box,
.digits-box,
.turn-box,
.explain,
.bomb-info-box {
  background: var(--bg-panel);
  border: 1px solid #303560;
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.bomb-info-box #bombList {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}
.bomb-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #262a47;
  padding: 6px 10px;
  border-radius: 8px;
  font-family: "Space Mono";
  font-size: 14px;
}
.bomb-item .strength {
  color: var(--accent-green);
  font-weight: 700;
}
.bomb-item .place {
  color: var(--accent-blue);
  font-weight: 700;
}
.bomb-item.pending {
  opacity: 0.8;
}
.bomb-item.resolved {
  opacity: 0.5;
}
.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;
}
#scoreDisplay {
  color: var(--accent-green);
}
#timeDisplay {
  color: var(--accent-pink);
}
.digits-header {
  font-weight: 700;
  margin-bottom: 12px;
  text-align: center;
  color: var(--accent-blue);
}
.digits-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 8px;
}
.digit-cell {
  background: #2a2d4a;
  border-radius: 6px;
  text-align: center;
  padding: 8px 0;
  font-family: "Space Mono";
  font-size: 18px;
}
.digit-cell .count {
  font-size: 10px;
  color: var(--muted);
  display: block;
  margin-top: -2px;
}

/* --- Fraction Input --- */
.fraction-input {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}
.fraction-input input {
  width: 80px;
  height: 60px;
  font-size: 32px;
  text-align: center;
  background: var(--bg-dark);
  border: 1px solid #4a4f80;
  color: var(--text);
  border-radius: 8px;
  font-family: "Space Mono", monospace;
}
.fraction-bar {
  width: 40px;
  height: 3px;
  background: var(--muted);
}

/* --- Buttons & Explanation --- */
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);
}
.explain {
  /* Fixed-size window with scroll to prevent layout jump when content grows */
  height: 150px;
  min-height: 150px;
  max-height: 150px;
  overflow-y: auto;
  overflow-x: hidden;
  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;
}

/* --- Bomb Info --- */
.bomb-info-box {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bomb-info-box h3 {
  margin: 0 0 4px;
  font-size: 18px;
  color: var(--accent-pink);
  text-align: center;
}
.bomb-row {
  display: flex;
  justify-content: space-between;
  background: #262a47;
  padding: 6px 10px;
  border-radius: 8px;
  font-family: "Space Mono";
  font-size: 14px;
}
.bomb-row .label {
  color: var(--muted);
}
#bombStrength,
#bombPlace {
  font-weight: 700;
  color: var(--accent-green);
}
.bomb-hint {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

/* --- 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(400px, 90vw);
  text-align: center;
  box-shadow: var(--shadow);
}
.card h2 {
  margin-top: 0;
}
.card label {
  display: block;
  text-align: left;
  margin-bottom: 12px;
}
.card input {
  width: 100%;
  padding: 10px;
  margin-top: 4px;
  border-radius: 8px; /* ... */
}

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