: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.95), rgba(13, 15, 26, 0.9));
}

.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: all 0.2s;
}

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

.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;
}

.tagline {
  font-family: "Space Mono", monospace;
  font-size: 18px;
  color: var(--accent-green);
  text-shadow: 0 0 10px var(--accent-green);
  white-space: nowrap;
}

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

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

.game-area {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  border-radius: 16px;
  box-shadow: var(--shadow);
  border: 1px solid #303560;
  position: relative;
  padding: 20px;
}

.canvas-container {
  position: relative;
  max-width: 800px;
  max-height: 800px;
  width: 100%;
  aspect-ratio: 1;
}

#graphCanvas {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  background: linear-gradient(135deg, #0a0c18 0%, #151829 100%);
  box-shadow: inset 0 2px 20px rgba(0, 0, 0, 0.6);
  cursor: crosshair;
}

.canvas-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

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

/* Status Box */
.status-box,
.players-box,
.controls-box,
.polynomials-box,
.history-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;
  color: var(--accent-yellow);
}

/* Players Box */
.players-box h3 {
  margin: 0 0 12px;
  text-align: center;
  color: var(--accent-blue);
}

.players-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #141938;
  border-radius: 8px;
  border: 2px solid transparent;
  transition: all 0.3s;
}

.player-item.active {
  border-color: var(--accent-green);
  background: linear-gradient(90deg, #1a2838, #141938);
  box-shadow: 0 0 12px rgba(111, 227, 162, 0.3);
}

.player-name {
  font-weight: 700;
  color: var(--text);
}

.player-score {
  font-family: "Space Mono";
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-yellow);
}

/* Controls Box */
.controls-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 120px;
}

.question {
  text-align: center;
  font-weight: 700;
  color: var(--accent-blue);
  font-size: 16px;
}

.game-prompt {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 8px;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

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

.chip:hover {
  background: #38406c;
  transform: translateY(-2px);
}

.chip:active {
  transform: translateY(0);
}

/* Polynomial Menu */
.polynomials-box {
  max-height: 300px;
  display: flex;
  flex-direction: column;
}

.polynomials-box h3 {
  margin: 0 0 12px;
  text-align: center;
  color: var(--accent-blue);
}

.polynomial-menu {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.poly-item {
  padding: 10px 12px;
  background: #141938;
  border-radius: 8px;
  border-left: 4px solid var(--accent-blue);
  font-family: "Space Mono";
  font-size: 13px;
  color: var(--text);
  transition: all 0.2s;
}

.poly-item.selectable {
  cursor: pointer;
}

.poly-item.selectable:hover {
  background: #1e2445;
  transform: translateX(4px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.poly-equation {
  display: block;
  word-break: break-word;
}

/* History Box */
.history-box h3 {
  margin: 0 0 8px;
  text-align: center;
  color: var(--accent-blue);
}

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

.history-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 2px 0;
  padding: 6px 8px;
  line-height: 20px;
  font-family: "Space Mono";
  font-size: 12px;
  background: #141938;
  border-radius: 6px;
  margin-bottom: 4px;
}

.history-list li .tag {
  color: var(--accent-pink);
  font-weight: 700;
}

.history-list li.good {
  color: var(--accent-green);
  border-left: 3px solid var(--accent-green);
}

.history-list li.bad {
  color: var(--accent-red);
  border-left: 3px solid var(--accent-red);
}

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

.overlay.visible {
  display: grid;
}

.overlay .card {
  width: min(1100px, 96vw);
  min-height: 40vh;
  max-height: 90vh;
  background: linear-gradient(135deg, #1a1d33 0%, #0d0f1a 100%);
  border: 1px solid #4a4f80;
  border-radius: 16px;
  padding: 32px;
  color: #fff;
  box-shadow: var(--shadow);
  overflow-y: auto;
  margin: 20px;
}

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

.overlay .card h2 {
  margin-top: 0;
  color: var(--accent-blue);
  text-align: center;
  font-size: 32px;
  text-shadow: 0 0 10px var(--accent-blue);
}

.overlay .card h3 {
  color: var(--accent-green);
  margin-top: 24px;
  margin-bottom: 12px;
}

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

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

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

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

/* Setup Form */
.card.setup {
  max-width: 500px;
}

.card.setup form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card.setup label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text);
  font-weight: 600;
}

.card.setup input {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px 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;
}

.card.setup input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(111, 168, 255, 0.2);
}

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 15px rgba(111, 168, 255, 0.3);
}

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

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

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

.winner-announcement {
  font-size: 24px;
  color: var(--accent-green);
  font-weight: 700;
  padding: 20px;
  background: linear-gradient(90deg, transparent, rgba(111, 227, 162, 0.15), transparent);
  border-radius: 12px;
  text-shadow: 0 0 10px var(--accent-green);
}

.final-scores {
  width: 100%;
}

.score-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 400px;
  margin: 0 auto;
}

.score-item {
  padding: 12px 20px;
  background: #141938;
  border-radius: 8px;
  font-family: "Space Mono";
  font-size: 16px;
  border-left: 4px solid var(--accent-blue);
}

.gameover-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  width: 100%;
  max-width: 400px;
}

.gameover-actions button {
  flex: 1;
}

/* Help overlay */
.card.help {
  width: min(1400px, 98vw);
  min-height: 70vh;
  max-height: 90vh;
}

.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: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

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

.help-content ul,
.help-content ol {
  margin: 12px 0;
  padding-left: 24px;
}

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

/* Utility */
.hidden {
  display: none !important;
}

/* Scrollbar styling */
.polynomial-menu::-webkit-scrollbar,
.history-list::-webkit-scrollbar,
.overlay .card::-webkit-scrollbar {
  width: 8px;
}

.polynomial-menu::-webkit-scrollbar-track,
.history-list::-webkit-scrollbar-track,
.overlay .card::-webkit-scrollbar-track {
  background: #0d112b;
  border-radius: 4px;
}

.polynomial-menu::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb,
.overlay .card::-webkit-scrollbar-thumb {
  background: #4a4f80;
  border-radius: 4px;
}

.polynomial-menu::-webkit-scrollbar-thumb:hover,
.history-list::-webkit-scrollbar-thumb:hover,
.overlay .card::-webkit-scrollbar-thumb:hover {
  background: #6fa8ff;
}

/* Responsive */
@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 1fr;
  }
  
  .game-area {
    min-height: 500px;
  }
  
  .right-panel {
    max-height: none;
  }
}

@media (max-width: 768px) {
  .title-wrap {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .limit-badge,
  .game-title {
    font-size: 24px;
  }
  
  .tagline {
    font-size: 14px;
  }
  
  .overlay .card {
    padding: 20px;
  }
}

