:root {
  --bg-color: #050511;
  --panel-bg: rgba(20, 25, 40, 0.8);
  --panel-border: rgba(100, 116, 139, 0.2);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #00f2fe;
  --accent-glow: rgba(0, 242, 254, 0.4);
  --danger: #ff0055;
  --gradient-main: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Outfit', 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-color);
  background-image:
    radial-gradient(circle at 10% 20%, rgba(79, 172, 254, 0.1) 0%, transparent 20%),
    radial-gradient(circle at 90% 80%, rgba(255, 0, 85, 0.08) 0%, transparent 25%);
  color: var(--text-main);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  /* Dynamic viewport height for mobile */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.site-header {
  padding: 1.25rem 2rem;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
  min-height: 0;
}

.site-header h1 {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: 1px;
  background: var(--gradient-main);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
  text-transform: uppercase;
  margin-right: auto;
}

.scoreboard {
  display: flex;
  gap: 2rem;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
}

.scoreboard div span {
  color: var(--accent);
  font-weight: 700;
  margin-left: 0.5rem;
  text-shadow: 0 0 10px var(--accent-glow);
}

.game-wrap {
  flex: 1 1 auto;
  width: 100%;
  max-width: min(900px, 100%);
  margin: 0 auto;
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  padding: 1rem;
  align-items: flex-start;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

/* Custom scrollbar za game-wrap */
.game-wrap::-webkit-scrollbar {
  width: 8px;
}

.game-wrap::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.3);
}

.game-wrap::-webkit-scrollbar-thumb {
  background: rgba(0, 242, 254, 0.3);
  border-radius: 4px;
}

.game-wrap::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 242, 254, 0.5);
}


#board {
  background: rgba(10, 15, 30, 0.95);
  border: 2px solid #334155;
  border-radius: 4px;
  /* Slight round, but mostly sharp for grid feel */
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.5),
    0 20px 40px -5px rgba(0, 0, 0, 0.6);
  max-width: 100%;
  height: auto;
  display: block;
}

.side {
  flex: 0 0 280px;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.next {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  padding: 1rem;
  border-radius: 12px;
  text-align: center;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.next strong {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
}

.next canvas {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
}

.controls,
.top3 {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  padding: 1.25rem;
  border-radius: 12px;
  backdrop-filter: blur(8px);
}

.controls strong,
.top3 strong {
  display: block;
  margin-bottom: 0.75rem;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.9rem;
}

.controls ul {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.controls li {
  margin: 0.4rem 0;
  display: flex;
  justify-content: space-between;
}

.controls li b {
  color: var(--text-main);
}

.top3 ol {
  margin: 0;
  padding-left: 1.5rem;
  color: var(--text-main);
}

.top3 li {
  margin-bottom: 0.4rem;
  font-weight: 500;
}

#restart {
  width: 100%;
  padding: 14px;
  border: none;
  background: var(--gradient-main);
  color: #0f172a;
  font-weight: 800;
  font-size: 1rem;
  border-radius: 12px;
  cursor: pointer;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 15px var(--accent-glow);
}

#restart:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px var(--accent-glow);
}

#restart:active {
  transform: translateY(0);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 17, 0.85);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.3s;
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: #1e293b;
  border: 1px solid #334155;
  padding: 2rem;
  border-radius: 16px;
  width: min(420px, 90vw);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.modal-content h2 {
  margin: 0 0 1rem;
  color: var(--accent);
  font-size: 2rem;
}

.modal-content p {
  font-size: 1.2rem;
  margin-bottom: 1.5rem;
}

.modal-content input[type="text"] {
  width: 100%;
  padding: 12px;
  margin: 1rem 0;
  border-radius: 8px;
  border: 1px solid #475569;
  background: #0f172a;
  color: white;
  font-size: 1.1rem;
  text-align: center;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.modal-content input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 242, 254, 0.2);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}

.actions button {
  padding: 12px;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.2s;
}

.actions button[type="submit"] {
  background: var(--accent);
  color: #0f172a;
}

#skipSave {
  background: #334155;
  color: white;
}

.actions button:hover {
  filter: brightness(1.1);
}

.status {
  margin-top: 1rem;
  font-size: 0.9rem;
  min-height: 1.4em;
}

.play-again {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid #334155;
}

.play-again p {
  margin-bottom: 1rem;
  font-size: 1rem;
  color: var(--text-muted);
}

#playAgainBtn {
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--accent);
  padding: 10px 24px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

#playAgainBtn:hover {
  background: var(--accent);
  color: #0f172a;
}

@media (max-width: 768px) {
  .site-header {
    padding: 0.75rem 1rem;
    flex-direction: column;
    gap: 0.75rem;
  }

  .site-header h1 {
    font-size: 1.4rem;
    margin-right: 0;
  }

  .scoreboard {
    gap: 1rem;
    font-size: 0.85rem;
  }

  .game-wrap {
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem;
  }

  .side {
    width: 100%;
    max-width: 100%;
    flex: 0 0 auto;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .next,
  .controls,
  .top3 {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: 180px;
  }

  #restart {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .site-header h1 {
    font-size: 1.2rem;
  }

  .scoreboard {
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
  }

  .game-wrap {
    gap: 1rem;
    padding: 0.5rem;
  }

  .side {
    flex-direction: column;
  }

  .next,
  .controls,
  .top3 {
    flex: 1 1 100%;
  }
}