: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;
  --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;
  background: linear-gradient(
    180deg,
    rgba(26, 29, 51, 0.8) 0%,
    rgba(13, 15, 26, 0.6) 100%
  );
}

.title-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.help-btn {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid #4a4f80;
  background: #2a2d4a;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.help-btn:hover {
  background: #38406c;
  border-color: var(--accent-blue);
  transform: translateY(-1px);
}

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

.limit-badge,
.game-title {
  font-size: 36px;
  font-weight: 900;
  color: var(--accent-blue);
  line-height: 1;
  text-shadow: 0 0 12px rgba(111, 168, 255, 0.6);
}

.limit-badge {
  color: var(--accent-pink);
  text-shadow: 0 0 12px rgba(255, 122, 194, 0.6);
}

.stats-row {
  display: flex;
  gap: 32px;
  align-items: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
}

.stat-value {
  font-size: 32px;
  font-weight: 900;
  font-family: "Space Mono", monospace;
  color: var(--accent-yellow);
  text-shadow: 0 0 10px rgba(255, 216, 107, 0.5);
}

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

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

.canvas-section {
  background: #000;
  border-radius: 16px;
  box-shadow: var(--shadow);
  border: 1px solid #303560;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
}

#gameCanvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 0 30px rgba(111, 168, 255, 0.15);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 142px);
}

/* Controls box */
.controls-box,
.info-box {
  background: var(--bg-panel);
  border: 1px solid #303560;
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.controls-box {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.question {
  text-align: center;
  font-weight: 700;
  font-size: 18px;
  color: var(--accent-blue);
  text-shadow: 0 0 8px rgba(111, 168, 255, 0.4);
}

.play-prompt {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-group label {
  font-size: 14px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-hint {
  font-size: 11px;
  color: var(--muted);
  font-family: "Space Mono", monospace;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

#functionInput {
  height: 48px;
  padding: 0 14px;
  border-radius: 10px;
  border: 2px solid #4a4f80;
  background: linear-gradient(180deg, #141938 0%, #0d112b 100%);
  color: var(--text);
  font-size: 16px;
  font-family: "Space Mono", monospace;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.6);
  outline: none;
  transition: all 0.2s ease;
}

#functionInput::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

#functionInput:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(111, 168, 255, 0.2),
    inset 0 2px 8px rgba(0, 0, 0, 0.7);
}

button.primary {
  height: 48px;
  padding: 0 20px;
  background: linear-gradient(45deg, var(--accent-blue), var(--accent-pink));
  border: none;
  color: #fff;
  border-radius: 10px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  box-shadow: 0 4px 12px rgba(111, 168, 255, 0.3);
  transition: all 0.2s ease;
  white-space: nowrap;
}

button.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(111, 168, 255, 0.4);
}

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

.feedback {
  min-height: 24px;
  text-align: center;
  font-family: "Space Mono", monospace;
  font-size: 14px;
  font-weight: 700;
  padding: 4px;
  border-radius: 6px;
}

.feedback.error {
  color: var(--accent-red);
  background: rgba(255, 111, 111, 0.1);
}

.feedback.success {
  color: var(--accent-green);
  background: rgba(111, 227, 162, 0.1);
  animation: pulse-success 0.6s ease;
}

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

.helper-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid #4a4f80;
  background: #2a2d4a;
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chip:hover {
  background: #38406c;
  border-color: var(--accent-blue);
}

.chip:active {
  transform: translateY(1px);
}

/* Info boxes */
.info-box h3 {
  margin: 0 0 10px 0;
  text-align: center;
  color: var(--accent-blue);
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.wickets-display {
  max-height: 180px;
  overflow-y: auto;
  font-family: "Space Mono", monospace;
  font-size: 13px;
  line-height: 1.8;
  color: var(--text);
  padding: 8px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
}

.wicket-item {
  padding: 4px 8px;
  margin: 2px 0;
  border-left: 3px solid var(--accent-pink);
  background: rgba(255, 122, 194, 0.05);
  border-radius: 4px;
}

.wicket-item.hit {
  border-left-color: var(--accent-green);
  background: rgba(111, 227, 162, 0.1);
  color: var(--accent-green);
}

.instructions-brief {
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.instructions-brief p {
  margin: 6px 0;
}

.leaderboard-list {
  max-height: 180px;
  overflow-y: auto;
  font-family: "Space Mono", monospace;
  font-size: 13px;
}

.leaderboard-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  margin: 4px 0;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  border-left: 3px solid var(--accent-yellow);
}

.leaderboard-item .rank {
  color: var(--accent-pink);
  font-weight: 700;
}

.leaderboard-item .name {
  flex: 1;
  margin: 0 10px;
  color: var(--text);
}

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

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

.overlay.visible {
  display: grid;
}

.overlay .card {
  width: min(900px, 96vw);
  max-height: 90vh;
  background: linear-gradient(180deg, #1a1d33 0%, #0d0f1a 100%);
  border: 2px solid #303560;
  border-radius: 20px;
  padding: 32px;
  color: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
  overflow-y: auto;
}

.overlay .card h2 {
  color: var(--accent-blue);
  text-align: center;
  font-size: 32px;
  margin-top: 0;
  text-shadow: 0 0 12px rgba(111, 168, 255, 0.5);
}

.help-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.help-header h2 {
  margin: 0;
  flex: 1;
}

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

.close-btn:hover {
  background: #38406c;
  border-color: var(--accent-pink);
  transform: scale(1.1);
}

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

.overlay .card.instructions {
  max-width: 1100px;
  width: min(1100px, 96vw);
}

.instructions-text {
  line-height: 1.7;
  color: var(--text);
}

.instructions-text h3 {
  color: var(--accent-pink);
  margin-top: 24px;
  margin-bottom: 12px;
  font-size: 20px;
}

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

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

.instructions-text code {
  background: rgba(111, 168, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "Space Mono", monospace;
  color: var(--accent-yellow);
}

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

.countdown {
  text-align: center;
  font-size: 18px;
  color: var(--accent-yellow);
  margin-top: 20px;
  font-family: "Space Mono", monospace;
}

.countdown span {
  font-size: 24px;
  font-weight: 900;
  color: var(--accent-pink);
}

/* Setup form */
.setup form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 500px;
  margin: 0 auto;
}

.setup label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 16px;
  color: var(--text);
}

.setup input[type="text"],
.setup select {
  height: 50px;
  padding: 0 16px;
  border-radius: 10px;
  border: 2px solid #4a4f80;
  background: linear-gradient(180deg, #141938 0%, #0d112b 100%);
  color: var(--text);
  font-size: 16px;
  font-family: "Lexend", sans-serif;
  outline: none;
  transition: all 0.2s ease;
}

.setup input[type="text"]:focus,
.setup select:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(111, 168, 255, 0.2);
}

.setup select {
  cursor: pointer;
}

/* Game over */
.gameover {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.gameover h2 {
  font-size: 48px;
  margin: 0;
}

.gameover p {
  font-size: 20px;
  margin: 0;
  color: var(--muted);
}

.final-score-display {
  font-size: 28px;
  font-family: "Space Mono", monospace;
  color: var(--accent-yellow);
  padding: 16px 32px;
  background: rgba(255, 216, 107, 0.1);
  border-radius: 12px;
  border: 2px solid var(--accent-yellow);
  text-shadow: 0 0 10px rgba(255, 216, 107, 0.4);
}

.final-score-display span {
  font-size: 36px;
  font-weight: 900;
}

.gameover-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.gameover-actions .primary {
  width: auto;
  padding: 0 32px;
}

.hidden {
  display: none !important;
}

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

  .control-panel {
    max-height: none;
  }

  #gameCanvas {
    width: 100%;
  }
}

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

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

  .stat-value {
    font-size: 24px;
  }

  .stats-row {
    gap: 20px;
  }
}
