:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #252525;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --error: #ef4444;
  --border: #2a2a2a;
  --cell-bg: #1a1a1a;
  --cell-prefilled: #252525;
  --cell-focus: #1f2937;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --cell-size: 56px;
  --grid-total-border-width: 14px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px;
  line-height: 1.6;
}

/* Welcome Screen */
#welcome {
  text-align: center;
  max-width: 480px;
  width: 100%;
  animation: fadeIn 0.6s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

h1 {
  font-family: "Space Mono", monospace;
  font-size: clamp(3rem, 8vw, 5rem);
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #ffffff 0%, #a0a0a0 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 48px;
  font-weight: 400;
}

#select-difficulty {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
}

label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#difficulty {
  width: 100%;
  padding: 16px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

#difficulty:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent);
}

#difficulty:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#start-button {
  width: 100%;
  padding: 16px 32px;
  background: var(--accent);
  color: var(--text-primary);
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-md);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#start-button:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

#start-button:active {
  transform: translateY(0);
}

/* Game Board Container */
#board-container {
  animation: fadeIn 0.6s ease-out;
  max-width: 600px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#game-status {
  text-align: center;
  margin-bottom: 24px;
  font-size: 1.125rem;
  font-weight: 600;
  min-height: 28px;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#game-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 0 auto 24px;
  padding: 16px 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  width: calc((var(--cell-size) * 9) + var(--grid-total-border-width));
  max-width: 100%;
}

#timer,
#error-display {
  font-family: "Space Mono", monospace;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

#timer {
  color: var(--text-secondary);
}

#error-display {
  color: var(--error);
}

/* Board Grid */
.board-grid {
  display: inline-flex;
  flex-direction: column;
  background: var(--bg-secondary);
  padding: 0;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  border: none;
  overflow: hidden;
}

.board-row {
  display: flex;
}

.board-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  padding: 0;
  line-height: 1;
  appearance: textfield;
  border: none;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--cell-bg);
  text-align: center;
  font-family: "Space Mono", monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
  caret-color: var(--accent);
}

.board-row:first-child .board-cell {
  border-top: 2px solid var(--accent);
}

.board-cell:first-child {
  border-left: 2px solid var(--accent);
}

.board-cell:nth-child(3),
.board-cell:nth-child(6),
.board-cell:last-child {
  border-right: 2px solid var(--accent);
}

.board-row:nth-child(3) .board-cell,
.board-row:nth-child(6) .board-cell,
.board-row:last-child .board-cell {
  border-bottom: 2px solid var(--accent);
}

.board-cell.prefilled {
  background: var(--cell-prefilled);
  color: var(--text-secondary);
  cursor: default;
  font-weight: 600;
}

.board-cell.editable {
  cursor: text;
}

.board-cell.editable:hover:not(:disabled) {
  background: var(--cell-focus);
}

.board-cell.editable:focus {
  background: var(--cell-focus);
  box-shadow: inset 0 0 0 1px var(--accent);
  position: relative;
  z-index: 1;
}

.board-cell.invalid {
  color: var(--error);
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-2px); }
  20%, 40%, 60%, 80% { transform: translateX(2px); }
}

.board-cell:disabled {
  cursor: not-allowed;
  opacity: 1;
}

/* Responsive Design */
@media (max-width: 768px) {
  body {
    padding: 16px;
  }

  h1 {
    font-size: clamp(2.5rem, 10vw, 4rem);
  }

  .subtitle {
    font-size: 0.875rem;
    margin-bottom: 32px;
  }

  #game-info {
    padding: 12px 16px;
    gap: 12px;
  }

  #timer,
  #error-display {
    font-size: 0.875rem;
  }

  :root {
    --cell-size: 48px;
  }

  .board-cell {
    font-size: 1.25rem;
  }
}

@media (max-width: 480px) {
  body {
    padding: 12px;
  }

  h1 {
    font-size: clamp(2rem, 12vw, 3rem);
    margin-bottom: 8px;
  }

  .subtitle {
    font-size: 0.75rem;
    margin-bottom: 24px;
  }

  #select-difficulty {
    gap: 16px;
  }

  #difficulty,
  #start-button {
    padding: 12px 16px;
    font-size: 0.875rem;
  }

  #game-status {
    font-size: 1rem;
    margin-bottom: 16px;
  }

  #game-info {
    flex-direction: column;
    padding: 12px;
    gap: 8px;
    margin-bottom: 16px;
  }

  #timer,
  #error-display {
    font-size: 0.75rem;
  }

  :root {
    --cell-size: 34px;
  }

  .board-cell {
    font-size: 1rem;
  }
}
