/* =========================================
   Self-Playing Sudoku — Space Theme Styles
   ========================================= */

:root {
  --gold: #e2b96f;
  --gold-dim: #b8954e;
  --gold-bright: #f0d090;
  --gold-glow: rgba(226, 185, 111, 0.4);

  --blue-try: #60a5fa;
  --blue-bg: #0c1f3a;

  --red-back: #f87171;
  --red-bg: #2d0f0f;

  --green-done: #6ee49a;
  --green-glow: rgba(110, 228, 154, 0.5);

  --cell-bg: #10102a;
  --cell-alt: #14143a;
  --cell-given-bg: #1a1640;
  --grid-line: #1e2048;

  --card-bg: rgba(10, 10, 30, 0.72);
  --card-border: rgba(226, 185, 111, 0.12);

  --text-muted: #4a5568;
  --text-dim: #2a3045;
  --shadow-deep: rgba(0, 0, 0, 0.8);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 1.5rem 0.75rem;
  background: #070714;
  font-family: 'Inter', sans-serif;
  color: #e2e8f0;
  overflow-x: hidden;
}

#starfield {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(circle at 20% 20%, rgba(226, 185, 111, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(96, 165, 250, 0.06) 0%, transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(110, 228, 154, 0.04) 0%, transparent 50%);
}

h1,
#subtitle,
#diff-row,
#card,
#footer {
  position: relative;
  z-index: 2;
}

h1 {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(2.5rem, 8vw, 4.5rem);
  font-weight: 900;
  color: var(--gold);
  text-align: center;
  margin: 0.5rem 0 0.25rem;
  letter-spacing: 0.15em;
  text-shadow:
    0 0 10px var(--gold-glow),
    0 0 30px rgba(226, 185, 111, 0.3),
    0 0 60px rgba(226, 185, 111, 0.15);
}

#subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.25em;
  text-align: center;
  margin: 0 0 1.25rem;
}

#diff-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  justify-content: center;
}

.diff-btn {
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.5rem 1.1rem;
  border-radius: 30px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.diff-btn:hover {
  color: var(--gold-bright);
  border-color: rgba(226, 185, 111, 0.3);
}

.diff-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(226, 185, 111, 0.08);
  box-shadow: 0 0 15px var(--gold-glow);
}

#card {
  width: min(96vw, 560px);
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 1.5rem;
  box-shadow:
    0 25px 80px var(--shadow-deep),
    0 0 0 1px rgba(255, 255, 255, 0.03) inset,
    0 0 40px rgba(226, 185, 111, 0.05) inset;
}

#stats-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-box {
  flex: 1;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 0.75rem 0.5rem;
  text-align: center;
}

.stat-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.stat-value {
  font-family: 'Orbitron', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
}

#timer-display {
  color: #a5b4fc;
}

#step-counter {
  color: var(--gold);
}

#bt-counter {
  color: var(--red-back);
}

#board-wrapper {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  animation: boardGlow 4s ease-in-out infinite;
}

#board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(86vw, 486px);
  height: min(86vw, 486px);
  border: 3px solid var(--gold-dim);
  border-radius: 12px;
  overflow: hidden;
  background: var(--cell-bg);
}

.cell {
  background: var(--cell-bg);
  border: 1px solid var(--grid-line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Inter', sans-serif;
  font-size: clamp(12px, 3vw, 23px);
  font-weight: 700;
  color: #e2e8f0;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
  position: relative;
  user-select: none;
}

.cell[data-box="0"],
.cell[data-box="2"],
.cell[data-box="4"],
.cell[data-box="6"],
.cell[data-box="8"] {
  background: var(--cell-alt);
}

.cell[data-col="0"],
.cell[data-col="3"],
.cell[data-col="6"] {
  border-left: 2.5px solid var(--gold-dim);
}

.cell[data-col="8"] {
  border-right: 2.5px solid var(--gold-dim);
}

.cell[data-row="0"],
.cell[data-row="3"],
.cell[data-row="6"] {
  border-top: 2.5px solid var(--gold-dim);
}

.cell[data-row="8"] {
  border-bottom: 2.5px solid var(--gold-dim);
}

.cell.given {
  background: var(--cell-given-bg);
  color: var(--gold-bright);
  text-shadow: 0 0 10px var(--gold-glow);
}

.cell.trying {
  background: var(--blue-bg);
  color: var(--blue-try);
  text-shadow: 0 0 10px rgba(96, 165, 250, 0.5);
}

.cell.backtrack {
  background: var(--red-bg);
  color: var(--red-back);
  text-shadow: 0 0 10px rgba(248, 113, 113, 0.4);
  animation: shake 0.4s ease-in-out;
}

.cell.solved {
  color: var(--green-done);
  text-shadow: 0 0 12px var(--green-glow);
  animation: solvedPop 0.4s ease-out;
}

#overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: radial-gradient(circle at center, rgba(10, 30, 20, 0.95), rgba(5, 10, 20, 0.98));
  z-index: 10;
  animation: overlayIn 0.5s ease-out;
}

#overlay.show {
  display: flex;
}

#overlay .trophy {
  font-size: 3.5rem;
  animation: trophySpin 2s ease-in-out infinite;
}

#overlay .solved-label {
  font-family: 'Orbitron', sans-serif;
  font-size: 2rem;
  font-weight: 900;
  color: var(--green-done);
  text-shadow: 0 0 20px var(--green-glow);
}

#overlay #overlay-time {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

#commentary {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 0.9rem 1rem;
  background: rgba(0, 0, 0, 0.3);
  border-left: 3px solid var(--gold-dim);
  border-radius: 0 10px 10px 0;
  min-height: 3rem;
}

#commentary-icon {
  font-size: 1.2rem;
  line-height: 1.4;
  flex-shrink: 0;
}

#commentary-text {
  font-size: 0.9rem;
  line-height: 1.5;
  color: #cbd5e1;
}

#commentary-text .hl-gold {
  color: var(--gold-bright);
}

#commentary-text .hl-blue {
  color: var(--blue-try);
}

#commentary-text .hl-red {
  color: var(--red-back);
}

#commentary-text .hl-green {
  color: var(--green-done);
}

#commentary-text strong {
  font-weight: 700;
}

#status-bar {
  margin-top: 1rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 1.2rem;
}

#status-text.solving {
  color: var(--blue-try);
}

#status-text.done {
  color: var(--green-done);
}

#status-text.error {
  color: var(--red-back);
}

#speed-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 0.5rem 0;
}

#speed-row label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

#speed-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

#speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
  box-shadow: 0 0 10px var(--gold-glow);
}

#speed-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
  box-shadow: 0 0 10px var(--gold-glow);
  border: none;
}

#speed-label {
  font-size: 0.8rem;
  color: var(--gold);
  font-weight: 600;
  min-width: 5.5rem;
  text-align: right;
}

#controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-top: 1rem;
}

#controls button {
  position: relative;
  overflow: hidden;
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.75rem 0.4rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#controls button:not(:disabled):hover {
  transform: translateY(-2px);
}

#controls button:not(:disabled):active {
  transform: translateY(0);
}

#controls button::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);
  transform: translateX(-100%) skewX(-15deg);
  pointer-events: none;
}

#controls button:not(:disabled):hover::after {
  animation: shimmer 0.7s ease-in-out;
}

#btn-new {
  background: linear-gradient(135deg, var(--gold-dim), var(--gold));
  color: #0a0a1e;
  box-shadow: 0 4px 15px var(--gold-glow);
}

#btn-solve {
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #fff;
  box-shadow: 0 4px 15px rgba(96, 165, 250, 0.3);
}

#btn-pause {
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  color: #fff;
  box-shadow: 0 4px 15px rgba(168, 85, 247, 0.3);
}

#btn-reset {
  background: transparent;
  color: #cbd5e1;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

#btn-save {
  background: transparent;
  color: var(--green-done);
  border: 1px solid rgba(110, 228, 154, 0.25);
  box-shadow: 0 4px 15px rgba(110, 228, 154, 0.1);
}

#btn-load {
  background: transparent;
  color: var(--blue-try);
  border: 1px solid rgba(96, 165, 250, 0.25);
  box-shadow: 0 4px 15px rgba(96, 165, 250, 0.1);
}

#footer {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: 1.25rem;
  letter-spacing: 0.05em;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

@media (max-width: 480px) {
  #card {
    padding: 1rem;
    border-radius: 18px;
  }

  #controls {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-value {
    font-size: 1.05rem;
  }

  #commentary-text {
    font-size: 0.8rem;
  }

  #speed-label {
    min-width: 4.5rem;
  }
}

@keyframes boardGlow {
  0%, 100% {
    box-shadow: 0 0 20px rgba(226, 185, 111, 0.12), inset 0 0 30px rgba(226, 185, 111, 0.02);
  }

  50% {
    box-shadow: 0 0 45px rgba(226, 185, 111, 0.3), inset 0 0 30px rgba(226, 185, 111, 0.05);
  }
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0) scale(1);
  }

  20% {
    transform: translateX(-3px) scale(0.96);
  }

  40% {
    transform: translateX(3px) scale(0.96);
  }

  60% {
    transform: translateX(-3px) scale(0.96);
  }

  80% {
    transform: translateX(3px) scale(0.96);
  }
}

@keyframes solvedPop {
  0% {
    transform: scale(0.6);
    opacity: 0.5;
  }

  60% {
    transform: scale(1.18);
    opacity: 1;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes trophySpin {
  0% {
    transform: rotate(0deg) scale(1);
  }

  50% {
    transform: rotate(180deg) scale(1.15);
  }

  100% {
    transform: rotate(360deg) scale(1);
  }
}

@keyframes overlayIn {
  0% {
    opacity: 0;
    transform: scale(0.95);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%) skewX(-15deg);
  }

  100% {
    transform: translateX(200%) skewX(-15deg);
  }
}
