:root {
  --board-size: min(100%, 440px);
  --accent: #60a5fa;
  --accent-light: #bfdbfe;
  --accent-dark: #2563eb;
  --surface: rgba(255, 255, 255, 0.035);
  --line: rgba(255, 255, 255, 0.1);
  --grid-line: #334155;
  --grid-strong: #93c5fd;
  --text: #f3f4f6;
  --muted: #9ca3af;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  padding: 12px;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 0%, rgba(37, 99, 235, 0.12), transparent 30rem),
    linear-gradient(135deg, #111827 0%, #030712 58%, #000 100%);
  background-attachment: fixed;
  color: var(--text);
}

button,
input { font: inherit; }

.page-shell {
  width: min(100%, 576px);
  margin: 0 auto;
}

.banner,
.game-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.banner { margin-bottom: 24px; }

.banner img {
  display: block;
  width: 100%;
  height: auto;
}

.game-card {
  display: grid;
  justify-items: center;
  gap: 16px;
  padding: 24px;
}

.game-heading,
.difficulty-control { width: 100%; }

.game-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #6b7280;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: #93c5fd;
  font-size: clamp(1.35rem, 5vw, 1.65rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.primary-button {
  flex: 0 0 auto;
  border: 1px solid rgba(96, 165, 250, 0.34);
  border-radius: 10px;
  padding: 10px 14px;
  background: rgba(37, 99, 235, 0.18);
  color: #dbeafe;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.primary-button:hover {
  border-color: rgba(147, 197, 253, 0.7);
  background: rgba(37, 99, 235, 0.3);
  transform: translateY(-1px);
}

.primary-button:focus-visible,
.keypad button:focus-visible,
.cell:focus-visible {
  outline: 2px solid var(--accent-light);
  outline-offset: 3px;
}

.difficulty-control {
  display: grid;
  grid-template-columns: auto minmax(100px, 1fr) auto;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
  color: #d1d5db;
  font-size: 0.8rem;
}

.difficulty-control label { font-weight: 600; }

.difficulty-control output {
  min-width: 74px;
  color: var(--muted);
  text-align: right;
}

.difficulty-control input[type="range"] {
  width: 100%;
  accent-color: var(--accent-dark);
  cursor: pointer;
}

.board-wrap {
  width: var(--board-size);
  padding: 4px;
  border: 1px solid rgba(147, 197, 253, 0.35);
  border-radius: 12px;
  background: rgba(96, 165, 250, 0.06);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 2px solid var(--grid-strong);
  border-radius: 8px;
  background: rgba(3, 7, 18, 0.72);
}

.board::before,
.board::after {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.45s ease;
}

.board::before {
  content: "";
  inset: -12%;
  background: conic-gradient(from 120deg, rgba(37, 99, 235, 0.42), rgba(96, 165, 250, 0.32), rgba(255, 255, 255, 0.3), rgba(37, 99, 235, 0.42));
  filter: blur(24px);
  transform: scale(0.7) rotate(-14deg);
  mix-blend-mode: screen;
}

.board::after {
  content: "Glückwunsch! Du hast das Sudoku gelöst.";
  inset: 8%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  border: 1px solid rgba(147, 197, 253, 0.35);
  border-radius: 14px;
  background: rgba(17, 24, 39, 0.95);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  color: #dbeafe;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: center;
  transform: translateY(18px) scale(0.92);
}

.board.solved { animation: solved-tilt 0.5s ease; }

.board.solved::before {
  opacity: 0.75;
  transform: scale(1.05) rotate(12deg);
  animation: solved-shimmer 1.6s ease forwards;
}

.board.solved::after {
  opacity: 1;
  transform: translateY(0) scale(1);
  animation: solved-pop 1.4s ease forwards;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--grid-line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: clamp(1rem, 5.5vw, 1.55rem);
  font-weight: 400;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s ease, color 0.12s ease;
}

.cell:nth-child(3n + 1) { border-left-width: 2px; border-left-color: var(--grid-strong); }
.cell:nth-child(3n) { border-right-width: 2px; border-right-color: var(--grid-strong); }
.cell.block-bottom { border-bottom-width: 2px; border-bottom-color: var(--grid-strong); }
.cell.block-top { border-top-width: 2px; border-top-color: var(--grid-strong); }

.cell.given {
  background: rgba(255, 255, 255, 0.045);
  color: #f3f4f6;
  font-weight: 600;
  cursor: default;
}

.cell.same-number { background: rgba(59, 130, 246, 0.14); }

.cell.selected {
  background: rgba(59, 130, 246, 0.26);
  outline: 2px solid var(--accent-light);
  outline-offset: -2px;
}

.cell.conflict { color: #fca5a5; }

.keypad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 8px;
  width: var(--board-size);
}

.keypad button {
  padding: 12px 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.keypad button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.14);
}

.keypad button:active { transform: translateY(0); }

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.status {
  min-height: 20px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

footer {
  padding: 20px 0 10px;
  border-bottom: 1px dotted rgba(255, 255, 255, 0.15);
  color: #6b7280;
  font-size: 0.75rem;
  text-align: center;
}

footer a {
  color: inherit;
  text-decoration: none;
  transition: color 0.15s ease;
}

footer a:hover { color: #d1d5db; }

@keyframes solved-shimmer {
  0% { opacity: 0.3; transform: scale(0.9) rotate(-8deg); }
  60% { opacity: 0.85; transform: scale(1.12) rotate(8deg); }
  100% { opacity: 0.4; transform: scale(1) rotate(0); }
}

@keyframes solved-pop {
  0% { transform: translateY(18px) scale(0.92); opacity: 0; }
  45% { transform: translateY(-6px) scale(1.04); }
  75% { transform: translateY(0) scale(0.98); }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes solved-tilt {
  0% { transform: scale(1); }
  40% { transform: scale(1.01) rotate(-1deg); }
  100% { transform: scale(1); }
}

@media (max-width: 640px) {
  .banner { margin-bottom: 16px; }
  .game-card { padding: 16px; }
}

@media (max-width: 390px) {
  .game-heading { align-items: flex-start; }
  .primary-button { padding: 9px 11px; font-size: 0.8rem; }
  .difficulty-control { grid-template-columns: 1fr auto; }
  .difficulty-control input { grid-column: 1 / -1; grid-row: 2; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}