@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800&family=Orbitron:wght@700;900&display=swap');

: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;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #070714;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  position: relative;
}

#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% 10%, rgba(226, 185, 111, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 80% 20%, rgba(96, 165, 250, 0.06) 0%, transparent 35%),
    radial-gradient(circle at 50% 90%, rgba(110, 228, 154, 0.05) 0%, transparent 45%),
    radial-gradient(circle at 10% 80%, rgba(226, 185, 111, 0.05) 0%, transparent 30%);
}

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

h1 {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: clamp(2.4rem, 9vw, 4.5rem);
  letter-spacing: 0.18em;
  color: var(--gold);
  margin: 1.8rem 0 0.4rem;
  text-shadow:
    0 0 10px var(--gold-glow),
    0 0 24px var(--gold-glow),
    0 0 48px rgba(226, 185, 111, 0.15);
  text-align: center;
}

#subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.22em;
  margin: 0 0 1.2rem;
  text-align: center;
  max-width: min(90vw, 520px);
}

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

.diff-btn {
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.55rem 1.2rem;
  border-radius: 30px;
  border: 1.5px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.diff-btn:hover {
  background: rgba(226, 185, 111, 0.08);
  color: #cbd5e1;
}

.diff-btn.active {
  border-color: var(--gold-dim);
  color: var(--gold);
  background: rgba(226, 185, 111, 0.12);
  box-shadow: 0 0 18px rgba(226, 185, 111, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

#card {
  width: min(96vw, 560px);
  max-width: min(96vw, 560px);
  padding: clamp(1rem, 4vw, 1.6rem);
  border-radius: 22px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow:
    0 30px 80px var(--shadow-deep),
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 -1px 0 rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#stats-row {
  display: flex;
  gap: 0.6rem;
  width: 100%;
}

.stat-box {
  flex: 1;
  text-align: center;
  padding: 0.7rem 0.3rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

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

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

#timer-box .stat-value {
  color: #a5b4fc;
}

#steps-box .stat-value {
  color: var(--gold);
}

#bt-box .stat-value {
  color: var(--red-back);
}

#board-wrapper {
  position: relative;
  border-radius: 12px;
  padding: 4px;
  background: linear-gradient(135deg, rgba(226, 185, 111, 0.18), rgba(96, 165, 250, 0.12), rgba(226, 185, 111, 0.18));
  background-size: 200% 200%;
  animation: boardGlow 4s ease-in-out infinite;
  overflow: hidden;
}

@keyframes boardGlow {
  0%,
  100% {
    box-shadow: 0 0 18px rgba(226, 185, 111, 0.12);
    background-position: 0% 50%;
  }

  50% {
    box-shadow: 0 0 34px rgba(226, 185, 111, 0.28);
    background-position: 100% 50%;
  }
}

#board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(86vw, 486px);
  height: min(86vw, 486px);
  margin: 0 auto;
  border: 3px solid var(--gold-dim);
  border-radius: 8px;
  overflow: hidden;
  background: var(--grid-line);
  gap: 1px;
}

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

.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[data-box="0"],
.cell[data-box="2"],
.cell[data-box="4"],
.cell[data-box="6"],
.cell[data-box="8"] {
  background: var(--cell-alt);
}

.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 12px rgba(96, 165, 250, 0.6);
  transform: scale(1.02);
  z-index: 1;
}

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

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

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

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

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

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

  60% {
    transform: scale(1.18);
  }

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

#overlay {
  position: absolute;
  inset: 4px;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: radial-gradient(circle at center, rgba(10, 30, 20, 0.94), rgba(5, 10, 15, 0.98));
  z-index: 10;
  animation: overlayIn 0.6s ease-out;
}

#overlay.show {
  display: flex;
}

@keyframes overlayIn {
  from {
    opacity: 0;
    transform: scale(0.92);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.trophy {
  font-size: clamp(3rem, 12vw, 5.5rem);
  line-height: 1;
  margin-bottom: 0.5rem;
  animation: trophySpin 1.2s ease-in-out infinite;
}

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

  50% {
    transform: rotate(12deg) scale(1.12);
  }
}

.solved-label {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: clamp(1.6rem, 7vw, 2.6rem);
  color: var(--green-done);
  text-shadow: 0 0 20px var(--green-glow);
  letter-spacing: 0.12em;
}

#overlay-time {
  margin-top: 0.6rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
}

#commentary {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.8rem 1rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  border-left: 3px solid var(--gold-dim);
  font-size: 0.85rem;
  line-height: 1.5;
  min-height: 3.2rem;
}

#commentary-icon {
  flex-shrink: 0;
  font-size: 1.1rem;
  margin-top: 0.05rem;
}

#commentary-text {
  color: #cbd5e1;
}

.hl-gold {
  color: var(--gold);
}

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

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

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

#status-bar {
  text-align: center;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-muted);
  min-height: 1.2rem;
}

#status-text.solving {
  color: var(--blue-try);
  text-shadow: 0 0 10px rgba(96, 165, 250, 0.4);
}

#status-text.done {
  color: var(--green-done);
  text-shadow: 0 0 10px var(--green-glow);
}

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

#speed-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

#speed-row label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
}

#speed-slider {
  width: min(50vw, 220px);
  accent-color: var(--gold);
  cursor: pointer;
}

#speed-label {
  min-width: 5.2rem;
  text-align: right;
  color: var(--gold);
  font-weight: 700;
}

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

#controls button {
  position: relative;
  overflow: hidden;
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 0.65rem 0.4rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  color: #f8fafc;
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

#controls button::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transform: skewX(-20deg);
  transition: left 0.45s ease;
}

#controls button:hover:not(:disabled)::after {
  left: 150%;
}

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

#controls button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.6);
}

#btn-new {
  background: linear-gradient(135deg, var(--gold-dim), var(--gold));
  color: #0f0f1a;
  box-shadow: 0 4px 14px rgba(226, 185, 111, 0.25);
}

#btn-solve {
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.25);
}

#btn-pause {
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.25);
}

#btn-reset {
  background: transparent;
  border-color: rgba(226, 185, 111, 0.35);
  color: var(--gold-bright);
  box-shadow: 0 4px 12px rgba(226, 185, 111, 0.1);
}

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

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

#btn-load.has-save {
  border-color: var(--gold-dim);
  box-shadow: 0 0 14px rgba(226, 185, 111, 0.2);
}

#footer {
  font-size: 0.68rem;
  color: var(--text-dim);
  text-align: center;
  letter-spacing: 0.06em;
  margin: 1rem 0 2rem;
  max-width: min(90vw, 520px);
}

@media (max-width: 420px) {
  #controls {
    grid-template-columns: repeat(2, 1fr);
  }

  #stats-row {
    gap: 0.4rem;
  }

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

  #speed-slider {
    width: 38vw;
  }
}
