/*
  Sudoku Solver - Modern Purple Theme
  © 2025 Miloš Sarić. All rights reserved.
*/

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #faf8ff;
  --text-primary: #1a0b2e;
  --text-secondary: #6b5b95;
  --border-color: #e5d9f2;
  --input-bg: #ffffff;
  --input-border: #d4c5e8;
  --input-focus: #7c3aed;
  --button-primary: #7c3aed;
  --button-hover: #6d28d9;
  --button-success: #10b981;
  --button-warning: #f59e0b;
  --button-danger: #ef4444;
  --button-info: #8b5cf6;
  --button-disabled: #d1d1d1;
  --shadow-sm: 0 2px 12px rgba(124, 58, 237, 0.08);
  --shadow-md: 0 4px 20px rgba(124, 58, 237, 0.12);
  --shadow-lg: 0 8px 40px rgba(124, 58, 237, 0.16);
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --primary-gradient: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
  --clue-bg: #f3f0ff;
  --clue-text: #1a0b2e;
  --cell-highlight: #fef3c7;
  --cell-selected: #ede9fe;
  --purple-glow: 0 0 30px rgba(124, 58, 237, 0.15);
}

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

html, body {
  height: 100%;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  background: linear-gradient(180deg, #faf8ff, #f5f3ff);
  color: var(--text-primary);
  overflow-x: hidden;
}

.main-content {
  min-height: 100vh;
  padding: 2rem;
}

/* Sudoku Section */
.sudoku-section {
  width: 100%;
  max-width: 1800px;
  margin: 0 auto;
  animation: fadeIn 0.6s ease-out;
}

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

.sudoku-container {
  width: 100%;
}

/* Page Header */
.page-header {
  text-align: center;
  margin-bottom: 2.5rem;
  animation: fadeIn 0.6s ease-out;
}

.page-header h1 {
  font-size: 3rem;
  font-weight: 800;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.03em;
  margin: 0 0 0.75rem 0;
  filter: drop-shadow(0 2px 8px rgba(124, 58, 237, 0.2));
}

.page-subtitle {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin: 0;
  font-weight: 500;
}

/* Main Layout */
.sudoku-layout {
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  gap: 2rem;
  align-items: start;
  animation: fadeIn 0.6s ease-out 0.2s backwards;
}

/* Panels - Larger and More Modern */
.controls-panel,
.info-panel {
  background: var(--input-bg);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  transition: all 0.3s ease;
}

.controls-panel:hover,
.info-panel:hover {
  box-shadow: var(--shadow-lg), var(--purple-glow);
  border-color: rgba(124, 58, 237, 0.4);
  transform: translateY(-2px);
}

.panel-section {
  margin-bottom: 2rem;
}

.panel-section:last-child {
  margin-bottom: 0;
}

.panel-section h3 {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--button-primary);
  margin: 0 0 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.panel-section h3 svg {
  color: var(--button-primary);
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

/* Button Styles - Larger */
.button-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

button {
  padding: 1rem 1.25rem;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  position: relative;
  overflow: hidden;
}

button::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

button:hover::before {
  width: 300px;
  height: 300px;
}

button svg {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  z-index: 1;
}

.btn-primary {
  background: var(--primary-gradient);
  color: white;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.4);
}

.btn-secondary {
  background: white;
  color: var(--text-primary);
  border: 2px solid var(--border-color);
}

.btn-secondary:hover {
  border-color: var(--button-primary);
  color: var(--button-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.btn-success {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-warning {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-warning:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.btn-info {
  background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-info:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
}

.btn-full {
  width: 100%;
}

button:active {
  transform: translateY(0) scale(0.98);
}

button:disabled,
button.disabled {
  background: var(--button-disabled);
  color: #999;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  opacity: 0.5;
}

button:disabled::before,
button.disabled::before {
  display: none;
}

/* Form Group */
.form-group {
  margin-bottom: 0;
}

.form-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

.form-group label svg {
  width: 18px;
  height: 18px;
  color: var(--button-primary);
}

/* Difficulty Buttons - Modern Pills */
.difficulty-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.difficulty-btn {
  padding: 0.875rem 1rem;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  position: relative;
  overflow: hidden;
}

.difficulty-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: var(--primary-gradient);
  transition: left 0.3s ease;
  opacity: 0.1;
}

.difficulty-btn:hover::before {
  left: 0;
}

.difficulty-btn:hover {
  border-color: var(--button-primary);
  color: var(--button-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.difficulty-btn.active {
  background: var(--primary-gradient);
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
}

.difficulty-btn.active::before {
  display: none;
}

.difficulty-btn.active:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.4);
}

/* Sudoku Grid */
.grid-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem 0;
}

.sudoku-grid-wrapper {
  background: var(--input-bg);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
  transition: all 0.3s ease;
}

.sudoku-grid-wrapper:hover {
  box-shadow: var(--shadow-lg), var(--purple-glow);
  transform: translateY(-4px);
}

.sudoku-grid {
  border-collapse: collapse;
  border-spacing: 0;
  user-select: none;
  background: white;
  border: 3px solid var(--button-primary);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.sudoku-grid td {
  width: 55px;
  height: 55px;
  padding: 0;
  border: 1px solid var(--border-color);
  text-align: center;
  vertical-align: middle;
  position: relative;
  background: white;
  transition: all 0.2s ease;
}

/* 3x3 block borders */
.sudoku-grid tr td:nth-child(3n) {
  border-right: 3px solid var(--button-primary);
}

.sudoku-grid tr:nth-child(3n) td {
  border-bottom: 3px solid var(--button-primary);
}

.sudoku-grid tr td:nth-child(1) {
  border-left: 3px solid var(--button-primary);
}

.sudoku-grid tr:nth-child(1) td {
  border-top: 3px solid var(--button-primary);
}

/* Cell Input */
.cell {
  width: 100%;
  height: 100%;
  border: 0;
  margin: 0;
  padding: 0;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  outline: none;
  background: transparent;
  transition: all 0.2s ease;
}

.cell:focus {
  background: var(--cell-selected);
  box-shadow: inset 0 0 0 2px var(--button-primary);
}

.cell:disabled {
  cursor: default;
}

/* Clue cells */
.cell.clue {
  font-weight: 800;
  color: var(--clue-text);
  background: var(--clue-bg);
}

/* Highlight animation for hints */
@keyframes hintBlink {
  0%, 100% {
    background: var(--cell-highlight);
    transform: scale(1);
  }
  50% {
    background: #fbbf24;
    transform: scale(1.08);
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.5);
  }
}

.highlight-cell {
  animation: hintBlink 1s ease-in-out;
}

/* History Container */
.history-container {
  max-height: 250px;
  overflow-y: auto;
  border: 2px solid var(--border-color);
  padding: 1rem;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
}

.history-container::-webkit-scrollbar {
  width: 6px;
}

.history-container::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 3px;
}

.history-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
  transition: background 0.3s ease;
}

.history-container::-webkit-scrollbar-thumb:hover {
  background: var(--button-primary);
}

#history-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

#history-list li {
  padding: 0.625rem 0;
  border-bottom: 1px dashed rgba(124, 58, 237, 0.15);
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
  animation: slideIn 0.3s ease-out;
}

#history-list li:last-child {
  border-bottom: none;
}

.history-empty {
  color: var(--text-secondary);
  font-style: italic;
  text-align: center;
  font-size: 0.875rem;
}

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

/* Analysis Container */
.analysis-container {
  padding: 1rem;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  min-height: 100px;
  font-size: 0.875rem;
  color: var(--text-primary);
  line-height: 1.6;
  white-space: pre-wrap;
  max-height: 280px;
  overflow-y: auto;
}

.analysis-placeholder {
  color: var(--text-secondary);
  font-style: italic;
  text-align: center;
  margin: 0;
  font-size: 0.875rem;
}

/* Credit Section */
.credit-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 2px dashed var(--border-color);
  text-align: center;
}

.credit-section p {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0;
}

.credit-section strong {
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
}

/* Success Overlay */
.success-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease-out;
}

.success-content {
  background: var(--input-bg);
  border: 3px solid var(--button-success);
  border-radius: var(--radius-lg);
  padding: 3.5rem 3rem;
  max-width: 550px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg), 0 0 80px rgba(16, 185, 129, 0.4);
  animation: successBounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  position: relative;
  overflow: hidden;
}

.success-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  animation: shimmer 2s linear infinite;
}

@keyframes successBounce {
  0% {
    opacity: 0;
    transform: scale(0.5) rotate(-10deg);
  }
  50% {
    transform: scale(1.05) rotate(2deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

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

.success-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, rgba(16, 185, 129, 0.05) 100%);
  margin: 0 auto 2rem;
  position: relative;
  animation: successIconPulse 2s ease-in-out infinite;
}

.success-icon::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  opacity: 0.3;
  animation: successPulse 2s ease-in-out infinite;
}

@keyframes successIconPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

@keyframes successPulse {
  0%, 100% {
    transform: scale(1);
    opacity: 0.3;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.5;
  }
}

.success-icon svg {
  color: var(--button-success);
  position: relative;
  z-index: 1;
  animation: successCheck 0.8s ease-out;
}

@keyframes successCheck {
  0% {
    transform: scale(0) rotate(-45deg);
  }
  50% {
    transform: scale(1.2) rotate(5deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

.success-content h2 {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0 0 1rem 0;
}

.success-content p {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin: 0 0 2rem 0;
  line-height: 1.6;
}

/* Server Wake-Up Overlay */
.server-wakeup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease-out;
}

.wakeup-content {
  background: var(--input-bg);
  border: 3px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 3.5rem 3rem;
  max-width: 550px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg), var(--purple-glow);
  animation: scaleIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  position: relative;
  overflow: hidden;
}

.wakeup-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: var(--primary-gradient);
  animation: shimmer 2s linear infinite;
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.8) rotate(-5deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

.wakeup-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.15) 0%, rgba(124, 58, 237, 0.05) 100%);
  margin: 0 auto 2rem;
  position: relative;
}

.wakeup-icon::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background: var(--primary-gradient);
  opacity: 0.3;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 0.3;
  }
  50% {
    transform: scale(1.15);
    opacity: 0.5;
  }
}

.wakeup-icon svg {
  color: var(--button-primary);
  animation: bounce 2s ease-in-out infinite;
  position: relative;
  z-index: 1;
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

.wakeup-icon.success {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.15) 0%, rgba(34, 197, 94, 0.05) 100%);
}

.wakeup-icon.success::before {
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  animation: successPulse 0.6s ease-out;
}

.wakeup-icon.success svg {
  color: #22c55e;
  animation: successCheck 0.6s ease-out;
}

.wakeup-icon.error {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.15) 0%, rgba(239, 68, 68, 0.05) 100%);
}

.wakeup-icon.error::before {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  animation: none;
}

.wakeup-icon.error svg {
  color: #ef4444;
  animation: shake 0.5s ease-out;
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-10px);
  }
  75% {
    transform: translateX(10px);
  }
}

.wakeup-content h3 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0 0 1rem 0;
  letter-spacing: -0.02em;
}

.wakeup-content p {
  font-size: 1.125rem;
  color: var(--text-secondary);
  margin: 0 0 1.5rem 0;
  line-height: 1.6;
}

.wakeup-progress {
  width: 100%;
  height: 10px;
  background: var(--bg-secondary);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
  margin-bottom: 1rem;
}

.wakeup-progress-bar {
  height: 100%;
  background: var(--primary-gradient);
  border-radius: 5px;
  transition: width 0.3s ease;
  position: relative;
  overflow: hidden;
}

.wakeup-progress-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  animation: progressShine 1.5s ease-in-out infinite;
}

@keyframes progressShine {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

.wakeup-timer {
  font-size: 1rem;
  color: var(--text-secondary);
  margin: 0;
  font-family: 'Courier New', monospace;
  font-weight: 600;
}

.wakeup-timer span {
  color: var(--button-primary);
  font-weight: 700;
}

/* Responsive Design */
@media (max-width: 1600px) {
  .sudoku-layout {
    grid-template-columns: 300px 1fr 320px;
    gap: 1.75rem;
  }
}

@media (max-width: 1400px) {
  .sudoku-layout {
    grid-template-columns: 280px 1fr 300px;
    gap: 1.5rem;
  }
  
  .controls-panel,
  .info-panel {
    padding: 1.5rem;
  }
}

@media (max-width: 1200px) {
  .sudoku-layout {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .controls-panel,
  .info-panel {
    position: static;
    max-height: none;
  }

  .controls-panel {
    order: 1;
  }

  .grid-container {
    order: 2;
  }

  .info-panel {
    order: 3;
  }
}

@media (max-width: 768px) {
  .main-content {
    padding: 1rem;
  }

  .page-header h1 {
    font-size: 2rem;
  }

  .page-subtitle {
    font-size: 1rem;
  }

  .sudoku-grid td {
    width: 48px;
    height: 48px;
  }

  .cell {
    font-size: 1.3rem;
  }

  .sudoku-grid-wrapper {
    padding: 1.5rem;
  }
  
  .controls-panel,
  .info-panel {
    padding: 1.25rem;
  }
  
  button {
    padding: 0.875rem 1rem;
    font-size: 0.875rem;
  }
}

@media (max-width: 480px) {
  .page-header h1 {
    font-size: 1.75rem;
  }

  .sudoku-grid td {
    width: 38px;
    height: 38px;
  }

  .cell {
    font-size: 1.1rem;
  }

  .success-content,
  .wakeup-content {
    padding: 2.5rem 2rem;
  }
  
  .difficulty-group {
    grid-template-columns: 1fr;
  }
}

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