: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: #b39dff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

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

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;
  transition: background 0.2s;
}

.help-btn:hover {
  background: #38406c;
}

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

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

.stats-bar {
  display: flex;
  gap: 24px;
  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: 0.5px;
}

.stat-value {
  font-family: "Space Mono", monospace;
  font-size: 28px;
  font-weight: 700;
}

.stat-value.health {
  color: var(--accent-red);
}

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

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

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

.game-canvas-container {
  background: #000;
  border-radius: 16px;
  box-shadow: var(--shadow);
  border: 1px solid #303560;
  position: relative;
  overflow: hidden;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.phase-info {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 29, 51, 0.95);
  border: 1px solid #303560;
  border-radius: 12px;
  padding: 12px 24px;
  font-family: "Space Mono", monospace;
  font-size: 16px;
  color: var(--accent-yellow);
  text-align: center;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.right-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

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

.info-box h3,
.calculator-box h3,
.controls-box h3,
.history-box h3 {
  margin: 0 0 12px;
  text-align: center;
  color: var(--accent-blue);
  font-size: 16px;
}

.triangle-details {
  font-family: "Space Mono", monospace;
  font-size: 14px;
  line-height: 1.8;
  color: var(--text);
}

/* Calculator */
.calc-display {
  background: linear-gradient(180deg, #141938 0%, #0d112b 100%);
  border: 1px solid #4a4f80;
  border-radius: 10px;
  padding: 16px;
  font-family: "Space Mono", monospace;
  font-size: 24px;
  text-align: right;
  color: var(--accent-yellow);
  margin-bottom: 12px;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
  word-break: break-all;
}

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

.mode-btn {
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid #4a4f80;
  background: #2a2d4a;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn.active {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.calc-btn {
  padding: 12px 8px;
  border-radius: 8px;
  border: 1px solid #4a4f80;
  background: #2a2d4a;
  color: #fff;
  font-family: "Space Mono", monospace;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}

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

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

.calc-btn.func {
  background: linear-gradient(135deg, #4a4f80, #2a2d4a);
  font-size: 12px;
}

.calc-btn.op {
  background: linear-gradient(135deg, #6fa8ff, #4a7acc);
  color: #fff;
  font-weight: 700;
}

.calc-btn.clear {
  background: linear-gradient(135deg, #ff6f6f, #cc5555);
  color: #fff;
  font-weight: 700;
}

.calc-note {
  text-align: center;
  color: var(--accent-pink);
  font-size: 13px;
  margin-bottom: 12px;
  font-style: italic;
}

/* Controls */
.question-box {
  margin-bottom: 16px;
}

.question-label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
  text-align: center;
}

.question-text {
  background: linear-gradient(180deg, #141938 0%, #0d112b 100%);
  border: 1px solid #4a4f80;
  border-radius: 10px;
  padding: 16px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 12px;
  min-height: 80px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
}

.answer-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
}

#answerInput {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #4a4f80;
  background: linear-gradient(180deg, #141938 0%, #0d112b 100%);
  color: var(--text);
  font-family: "Space Mono", monospace;
  font-size: 16px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
  outline: none;
  transition: border-color 0.2s;
}

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

.shoot-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.aim-mode-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  justify-content: center;
}

.mouse-controls {
  text-align: center;
}

.mouse-instruction {
  color: var(--accent-pink);
  font-size: 14px;
  padding: 12px;
  background: rgba(255, 122, 194, 0.1);
  border-radius: 8px;
  font-style: italic;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-group label {
  font-size: 13px;
  color: var(--muted);
}

#angleInput,
#distanceInput {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #4a4f80;
  background: linear-gradient(180deg, #141938 0%, #0d112b 100%);
  color: var(--text);
  font-family: "Space Mono", monospace;
  font-size: 18px;
  text-align: center;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
  outline: none;
  transition: border-color 0.2s;
}

#angleInput:focus,
#distanceInput:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(111, 168, 255, 0.2),
    inset 0 2px 6px rgba(0, 0, 0, 0.55);
}

.fire-instruction {
  text-align: center;
  color: var(--accent-green);
  font-weight: 700;
  font-size: 14px;
  padding: 12px;
  background: rgba(111, 227, 162, 0.1);
  border-radius: 8px;
  animation: pulse-text 2s ease-in-out infinite;
}

@keyframes pulse-text {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

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

.chip:hover {
  background: #38406c;
}

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

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

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

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

.feedback.info {
  color: var(--accent-yellow);
}

/* 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;
  box-shadow: 0 4px 12px rgba(111, 168, 255, 0.3);
}

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

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

button.small-primary {
  padding: 10px;
  font-size: 14px;
}

.hidden {
  display: none !important;
}

/* History */
.history-box {
  max-height: 180px;
  overflow-y: auto;
}

.history-list {
  margin: 0;
  padding-left: 20px;
  max-height: 140px;
  overflow-y: auto;
  overflow-x: hidden;
}

.history-list li {
  margin: 2px 0;
  padding: 4px 0;
  line-height: 20px;
  font-family: "Space Mono", monospace;
  font-size: 13px;
  color: var(--text);
}

.history-list li.good {
  color: var(--accent-green);
}

.history-list li.bad {
  color: var(--accent-red);
}

.history-list li.info {
  color: var(--accent-yellow);
}

/* Leaderboard tabs */
.level-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  justify-content: center;
}

.level-tab {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid #4a4f80;
  background: #2a2d4a;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.level-tab.active {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: #0d0f1acc;
  backdrop-filter: blur(8px);
  z-index: 100;
}

.overlay.visible {
  display: grid;
}

.overlay .card {
  width: min(900px, 96vw);
  max-height: 90vh;
  background: var(--bg-panel);
  border: 1px solid #303560;
  border-radius: 16px;
  padding: 32px;
  color: var(--text);
  box-shadow: var(--shadow);
  overflow-y: auto;
}

.overlay .card h2 {
  margin-top: 0;
  color: var(--accent-blue);
  text-align: center;
}

.overlay .card.instructions {
  min-height: 60vh;
}

.overlay .card.setup {
  max-width: 500px;
}

.overlay .card.gameover {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.overlay .card.help {
  width: min(1000px, 98vw);
  max-height: 90vh;
}

.instructions-text {
  line-height: 1.6;
  font-size: 15px;
}

.instructions-text h3 {
  color: var(--accent-green);
  margin-top: 20px;
  margin-bottom: 8px;
}

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

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

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

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

.help-header h2 {
  margin: 0;
}

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

.close-btn:hover {
  background: #38406c;
}

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

.help-content h3 {
  color: var(--accent-green);
  margin-top: 20px;
  margin-bottom: 8px;
}

/* Setup form */
#setupForm {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#setupForm label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

#setupForm input,
#setupForm select {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #4a4f80;
  background: linear-gradient(180deg, #141938 0%, #0d112b 100%);
  color: var(--text);
  font-family: "Lexend", sans-serif;
  font-size: 16px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
  outline: none;
  transition: border-color 0.2s;
}

#setupForm input:focus,
#setupForm select:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(111, 168, 255, 0.2),
    inset 0 2px 6px rgba(0, 0, 0, 0.55);
}

/* Game over */
.final-score-display {
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-family: "Space Mono", monospace;
  font-size: 18px;
  padding: 24px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  border: 1px solid #303560;
}

.final-score-display .highlight {
  color: var(--accent-yellow);
  font-size: 24px;
  font-weight: 700;
}

.gameover-actions {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 500px;
}

.gameover-actions button {
  flex: 1;
}

@media (max-width: 1000px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .game-canvas-container {
    min-height: 60vh;
  }
}
