:root {
  --bg-dark: #0d0f1a;
  --bg-panel: #1a1d33;
  --text: #e0e8ff;
  --muted: #a0a8c8;
  --accent-blue: #6fa8ff;
  --accent-pink: #ff7ac2;
  --accent-green: #6fe3a2;
  --accent-yellow: #ffd86b;
  --accent-red: #ff6f6f;
  --accent-purple: #b77aff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: auto;
}

body {
  background: radial-gradient(circle at top, #1e2245, var(--bg-dark) 70%);
  color: var(--text);
  font-family: "Lexend", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

/* 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;
}

.help-btn {
  margin-left: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid #4a4f80;
  background: #2a2d4a;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  align-self: center;
  transition: all 0.2s ease;
}

.help-btn:hover {
  background: #38406c;
  transform: translateY(-1px);
}

.help-btn:active {
  transform: translateY(0);
}

.limit-badge,
.game-title {
  font-size: 32px;
  font-weight: 900;
  color: var(--accent-blue);
  line-height: 1;
  text-shadow: 0 0 6px #1a1d33;
}

.score-display {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.score-label {
  font-size: 18px;
  color: var(--muted);
  font-weight: 600;
}

.score-value {
  font-size: 36px;
  font-weight: 900;
  font-family: "Space Mono", monospace;
  color: var(--accent-green);
  text-shadow: 0 0 10px var(--accent-green);
}

.subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
  padding: 16px;
  min-height: calc(100vh - 90px);
}

.game-panel {
  background: var(--bg-panel);
  border: 1px solid #303560;
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Game Info */
.game-info {
  display: flex;
  justify-content: space-around;
  text-align: center;
  background: rgba(13, 15, 26, 0.5);
  border-radius: 12px;
  padding: 16px;
  border: 1px solid #303560;
}

.info-item .label {
  font-size: 13px;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

.info-item .value {
  display: block;
  font-size: 32px;
  font-weight: 700;
  font-family: "Space Mono", monospace;
}

.goal-value {
  color: var(--accent-yellow);
}

.sum-value {
  color: var(--accent-green);
}

/* Game Board */
.game-board {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  background: #000;
  border-radius: 12px;
  padding: 20px;
  position: relative;
  overflow-x: auto;
  border: 1px solid #303560;
}

.board-content {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 20px 0;
}

/* Bunny */
.bunny {
  font-size: 64px;
  animation: bunnyBounce 1s ease-in-out infinite;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
  transition: all 0.5s ease;
}

@keyframes bunnyBounce {
  0%,
  100% {
    transform: translate(-50%, 0);
  }
  50% {
    transform: translate(-50%, -10px);
  }
}

.bunny.hopping {
  animation: bunnyHop 0.6s ease-in-out;
}

@keyframes bunnyHop {
  0% {
    transform: translateX(0) translateY(0);
  }
  50% {
    transform: translateX(30px) translateY(-40px) scale(1.1);
  }
  100% {
    transform: translateX(60px) translateY(0);
  }
}

/* Hop up onto pillar top (pillar positions the bunny) */
.bunny.hopping-up {
  animation: bunnyHopUp 0.6s ease-in-out;
}

@keyframes bunnyHopUp {
  0% {
    transform: translateX(-50%) translateY(0) scale(1);
  }
  50% {
    transform: translateX(-50%) translateY(-80px) scale(1.15);
  }
  100% {
    transform: translateX(-50%) translateY(-70px) scale(1);
  }
}

/* Hop down from pillar toward the carrot patch */
.bunny.hopping-down {
  animation: bunnyHopDown 0.8s ease-in-out;
}

@keyframes bunnyHopDown {
  0% {
    transform: translateX(-50%) translateY(-70px) scale(1);
  }
  30% {
    transform: translateX(-50%) translateY(-90px) scale(1.1);
  }
  60% {
    transform: translateX(40px) translateY(0) scale(1.05);
  }
  100% {
    transform: translateX(80px) translateY(0) scale(1);
  }
}

.bunny.celebrating {
  animation: bunnyCelebrate 1s ease-in-out;
}

@keyframes bunnyCelebrate {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
  }
  25% {
    transform: rotate(-15deg) scale(1.1);
  }
  50% {
    transform: rotate(15deg) scale(1.2);
  }
  75% {
    transform: rotate(-15deg) scale(1.1);
  }
}

/* Dice Column */
.dice-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: linear-gradient(135deg, #1a1d33, #2a2d4a);
  border-radius: 12px;
  border: 2px solid #4a4f80;
  min-width: 80px;
  align-items: center;
  transition: all 0.5s ease;
}

.dice-column.current {
  border-color: var(--accent-yellow);
  box-shadow: 0 0 20px rgba(255, 216, 107, 0.5);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.dice-column.completed {
  background: linear-gradient(135deg, #2a2d4a, #4a4f80);
  border-color: var(--accent-green);
}

.column-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  font-family: "Space Mono", monospace;
}

.die {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  cursor: default;
  transition: all 0.2s ease;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.die.clickable {
  cursor: pointer;
  animation: clickablePulse 2s ease-in-out infinite;
}

@keyframes clickablePulse {
  0%,
  100% {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  }
  50% {
    box-shadow: 0 4px 20px rgba(255, 255, 255, 0.6),
      0 0 10px rgba(255, 255, 255, 0.4);
  }
}

.die.clickable:hover {
  transform: scale(1.15) rotate(5deg);
  box-shadow: 0 6px 20px rgba(255, 255, 255, 0.8),
    0 0 15px rgba(255, 255, 255, 0.5);
}

.die.clickable:active {
  transform: scale(1.05) rotate(2deg);
}

.die.d20 {
  background: linear-gradient(135deg, #ff7ac2, #ff6f6f);
}

.die.d12 {
  background: linear-gradient(135deg, #6fa8ff, #6fe3a2);
}

.die.d8 {
  background: linear-gradient(135deg, #ffd86b, #ffb86b);
}

.die.d4 {
  background: linear-gradient(135deg, #b77aff, #ff7ac2);
}

.die.d2 {
  background: linear-gradient(135deg, #6fe3a2, #6fa8ff);
  border-radius: 50%;
}

.die.rolling {
  animation: diceRoll 0.8s ease-in-out;
}

@keyframes diceRoll {
  0% {
    transform: rotate(0deg) scale(1);
  }
  25% {
    transform: rotate(90deg) scale(1.3);
  }
  50% {
    transform: rotate(180deg) scale(1.5);
  }
  75% {
    transform: rotate(270deg) scale(1.3);
  }
  100% {
    transform: rotate(360deg) scale(1);
  }
}

/* Pillar */
.pillar {
  width: 80px;
  min-height: 100px;
  background: linear-gradient(135deg, #4a4f80, #6fa8ff);
  border-radius: 8px;
  border: 2px solid var(--accent-green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 900;
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
  position: relative;
  animation: pillarRise 0.5s ease-out;
  overflow: visible;
}

@keyframes pillarRise {
  0% {
    transform: scaleY(0);
    opacity: 0;
  }
  100% {
    transform: scaleY(1);
    opacity: 1;
  }
}

@keyframes checkmark {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.5);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Carrot Patch */
.carrot-patch {
  font-size: 64px;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
}

/* Controls Panel */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: rgba(13, 15, 26, 0.5);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid #303560;
}

.action-prompt {
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent-blue);
  min-height: 30px;
}

.dice-selector {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 50px;
}

.dice-button {
  padding: 12px 20px;
  background: linear-gradient(45deg, var(--accent-blue), var(--accent-pink));
  border: none;
  color: white;
  border-radius: 10px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.dice-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

.dice-button:active {
  transform: translateY(0);
}

.dice-button.d20 {
  background: linear-gradient(45deg, #ff7ac2, #ff6f6f);
}

.dice-button.d12 {
  background: linear-gradient(45deg, #6fa8ff, #6fe3a2);
}

.dice-button.d8 {
  background: linear-gradient(45deg, #ffd86b, #ffb86b);
}

.dice-button.d4 {
  background: linear-gradient(45deg, #b77aff, #ff7ac2);
}

.dice-button.d2 {
  background: linear-gradient(45deg, #6fe3a2, #6fa8ff);
}

/* Sum Input */
.sum-input-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sum-input-container label {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-yellow);
  text-align: center;
}

.sum-form {
  display: flex;
  gap: 8px;
}

.sum-form input {
  flex: 1;
  height: 48px;
  font-size: 20px;
  text-align: center;
  background: var(--bg-dark);
  border: 2px solid #4a4f80;
  color: var(--text);
  border-radius: 8px;
  font-family: "Space Mono", monospace;
  font-weight: 700;
}

.sum-form input:focus {
  outline: none;
  border-color: var(--accent-green);
  box-shadow: 0 0 10px rgba(111, 227, 162, 0.5);
}

.feedback {
  min-height: 24px;
  text-align: center;
  font-family: "Space Mono", monospace;
  font-weight: 700;
  font-size: 16px;
}

.feedback.error {
  color: var(--accent-red);
}

.feedback.success {
  color: var(--accent-green);
}

/* Buttons */
button.primary {
  width: 100%;
  background: linear-gradient(45deg, var(--accent-blue), var(--accent-pink));
  border: none;
  color: white;
  padding: 12px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  transition: transform 0.2s;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

button.primary:hover {
  transform: scale(1.02);
}

button.primary:active {
  transform: scale(0.98);
}

/* Side Panels */
.leaderboard-box,
.tips-box {
  background: var(--bg-panel);
  border: 1px solid #303560;
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.leaderboard-box h3,
.tips-box h3 {
  margin: 0 0 12px;
  text-align: center;
  color: var(--accent-pink);
  font-size: 18px;
}

.lb-controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.lb-controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}

.lb-controls select {
  padding: 6px 10px;
  background: var(--bg-dark);
  color: var(--text);
  border: 1px solid #4a4f80;
  border-radius: 6px;
  font-family: "Lexend", sans-serif;
}

.leaderboard {
  margin: 0;
  padding-left: 20px;
  max-height: 240px;
  overflow: auto;
  font-size: 14px;
}

.leaderboard li {
  margin: 6px 0;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  font-family: "Space Mono", monospace;
}

.leaderboard li.me {
  color: var(--accent-green);
  font-weight: 700;
}

.tips-list {
  margin: 0;
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.6;
}

.tips-list li {
  margin: 8px 0;
  color: var(--muted);
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(13, 15, 26, 0.85);
  backdrop-filter: blur(8px);
  z-index: 100;
  overflow: auto;
  padding: 20px;
}

.overlay.visible {
  display: grid;
}

.card {
  background: var(--bg-panel);
  border-radius: 16px;
  padding: 24px;
  width: min(600px, 92vw);
  text-align: center;
  box-shadow: var(--shadow);
  border: 1px solid #303560;
  max-height: 90vh;
  overflow: auto;
}

.card h2 {
  margin-top: 0;
  color: var(--accent-blue);
  font-size: 28px;
}

.instructions-text {
  text-align: left;
  font-size: 14px;
  line-height: 1.6;
  max-height: 50vh;
  overflow: auto;
  padding: 0 10px;
}

.instructions-text ul,
.instructions-text ol {
  margin: 8px 0;
  padding-left: 24px;
}

.instructions-text li {
  margin: 6px 0;
}

.instructions-text strong {
  color: var(--accent-yellow);
}

.countdown {
  margin-top: 16px;
  color: var(--accent-yellow);
  font-family: "Space Mono", monospace;
  font-size: 18px;
  font-weight: 700;
}

.card label {
  display: block;
  text-align: left;
  margin-bottom: 16px;
  font-size: 15px;
  color: var(--text);
}

.card input,
.card select {
  width: 100%;
  padding: 12px;
  margin-top: 6px;
  border-radius: 8px;
  background: var(--bg-dark);
  color: var(--text);
  border: 1px solid #4a4f80;
  font-family: "Lexend", sans-serif;
  font-size: 15px;
}

.card input:focus,
.card select:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.final-score-display {
  margin: 16px 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-green);
}

.final-score-display span {
  font-size: 32px;
  font-family: "Space Mono", monospace;
}

/* Help overlay */
.card.help {
  width: min(1200px, 96vw);
  max-height: 88vh;
  overflow-y: auto;
  text-align: left;
}

.help-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  padding-bottom: 12px;
  border-bottom: 1px solid #303560;
  z-index: 10;
}

.help-header h2 {
  margin: 0;
  color: var(--accent-blue);
}

.close-btn {
  background: #2a2d4a;
  border: 1px solid #4a4f80;
  color: #fff;
  border-radius: 8px;
  font-size: 24px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  line-height: 1;
  padding: 0;
}

.close-btn:hover {
  background: #38406c;
  transform: scale(1.05);
}

.close-btn:active {
  transform: scale(0.95);
}

.help-content {
  line-height: 1.6;
}

.help-content h3 {
  color: var(--accent-yellow);
  margin-top: 24px;
  margin-bottom: 12px;
  font-size: 20px;
}

.help-content h4 {
  color: var(--accent-pink);
  margin-top: 16px;
  margin-bottom: 8px;
  font-size: 16px;
}

.help-content p {
  margin: 8px 0;
  color: var(--text);
}

.help-content ul,
.help-content ol {
  margin: 8px 0;
  padding-left: 24px;
  color: var(--text);
}

.help-content li {
  margin: 6px 0;
}

.help-content strong {
  color: var(--accent-green);
}

.help-content table.rules-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  background: rgba(13, 15, 26, 0.5);
  border-radius: 8px;
  overflow: hidden;
}

.help-content table.rules-table th {
  background: #2a2d4a;
  color: var(--accent-blue);
  padding: 12px;
  text-align: left;
  font-weight: 700;
  border-bottom: 2px solid #4a4f80;
}

.help-content table.rules-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #303560;
}

.help-content table.rules-table tr:last-child td {
  border-bottom: none;
}

.strategy-tips {
  background: rgba(13, 15, 26, 0.5);
  border-left: 3px solid var(--accent-green);
  padding: 16px;
  border-radius: 8px;
  margin: 12px 0;
}

.strategy-tips h4:first-child {
  margin-top: 0;
}

/* Mobile responsiveness */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .game-info {
    flex-direction: column;
    gap: 12px;
  }

  .board-content {
    gap: 8px;
  }

  .bunny,
  .carrot-patch {
    font-size: 48px;
  }

  .dice-column {
    min-width: 60px;
    padding: 8px;
  }

  .die {
    width: 48px;
    height: 48px;
    font-size: 12px;
  }

  .pillar {
    width: 60px;
    min-height: 80px;
  }
}

@media (max-width: 600px) {
  .title-wrap {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .limit-badge,
  .game-title {
    font-size: 24px;
  }

  .score-value {
    font-size: 28px;
  }
}
