:root {
  --bg-color: #0f172a;
  --bg-grad-1: #1e1b4b;
  --bg-grad-2: #0f172a;
  --panel-bg: rgba(30, 41, 59, 0.7);
  --modal-bg: rgba(15, 23, 42, 0.95);
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --secondary: #475569;
  --secondary-hover: #334155;
  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --tile-bg: linear-gradient(145deg, #1e293b, #0f172a);
  --tile-border: #334155;
  --tile-shadow: 5px 5px 15px rgba(0, 0, 0, 0.5), -5px -5px 15px rgba(255, 255, 255, 0.05);
  --target-bg: #000;
  --target-text: #fff;
  --target-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
  --tile-text: #ffffff;
  --tile-text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  --tile-hover-shadow: 0 15px 30px rgba(0, 0, 0, 0.4), 0 0 15px rgba(139, 92, 246, 0.4);
  --tile-empty-bg: rgba(0, 0, 0, 0.2);
  --tile-empty-border: rgba(255, 255, 255, 0.2);
  --tile-empty-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
  --tile-empty-text: rgba(255, 255, 255, 0.1);
  --btn-secondary-border: rgba(255, 255, 255, 0.2);
  --btn-secondary-hover: rgba(255, 255, 255, 0.05);
  --btn-secondary-text: #ffffff;
  --modal-inner-bg: rgba(0, 0, 0, 0.4);
  --modal-inner-border: rgba(255, 255, 255, 0.05);
  --modal-inner-text: #e2e8f0;
  --modal-inner-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
  --font-main: 'Outfit', sans-serif;
}

body.light-mode {
  --bg-color: #f8fafc;
  --bg-grad-1: #e0e7ff;
  --bg-grad-2: #f1f5f9;
  --panel-bg: rgba(255, 255, 255, 0.85);
  --modal-bg: rgba(255, 255, 255, 0.95);
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #94a3b8;
  --secondary-hover: #cbd5e1;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --text-main: #0f172a;
  --text-muted: #475569;
  --tile-bg: linear-gradient(145deg, #e2e8f0, #f8fafc);
  --tile-border: #94a3b8;
  --tile-shadow: 5px 5px 15px rgba(0, 0, 0, 0.05), -5px -5px 15px rgba(255, 255, 255, 1);
  --target-bg: #f8fafc;
  --target-text: #0f172a;
  --target-shadow: inset 0 0 20px rgba(0, 0, 0, 0.1);
  --tile-text: #0f172a;
  --tile-text-shadow: 0 2px 4px rgba(255, 255, 255, 0.5);
  --tile-hover-shadow: 0 15px 30px rgba(15, 23, 42, 0.15), 0 0 15px rgba(139, 92, 246, 0.4);
  --tile-empty-bg: rgba(15, 23, 42, 0.05);
  --tile-empty-border: rgba(15, 23, 42, 0.2);
  --tile-empty-shadow: inset 0 2px 4px rgba(15, 23, 42, 0.1);
  --tile-empty-text: rgba(15, 23, 42, 0.2);
  --btn-secondary-border: rgba(15, 23, 42, 0.3);
  --btn-secondary-hover: rgba(15, 23, 42, 0.05);
  --btn-secondary-text: #0f172a;
  --modal-inner-bg: rgba(15, 23, 42, 0.05);
  --modal-inner-border: rgba(15, 23, 42, 0.1);
  --modal-inner-text: #334155;
  --modal-inner-shadow: inset 0 0 10px rgba(15, 23, 42, 0.05);
}

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

body {
  font-family: var(--font-main);
  background: var(--bg-color);
  background-image: radial-gradient(circle at top right, var(--bg-grad-1) 0%, transparent 40%),
    radial-gradient(circle at bottom left, var(--bg-grad-2) 0%, transparent 40%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.app-container {
  width: 100%;
  max-width: 800px;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

header {
  padding: 2rem;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

h1 {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(to right, #60a5fa, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 1.5rem;
}

/* Material UI Theme Switch */
.theme-switch {
  display: inline-block;
  width: 54px;
  height: 30px;
}

.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--secondary);
  transition: 0.4s;
  border-radius: 30px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.slider:before {
  position: absolute;
  content: "☀️";
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  height: 22px;
  width: 22px;
  left: 4px;
  bottom: 4px;
  background-color: #f8fafc;
  transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

input:checked+.slider {
  background-color: var(--primary);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

input:checked+.slider:before {
  transform: translateX(24px);
  content: "🌒";
}


.tabs {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.tab {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  padding: 0.75rem 2rem;
  border-radius: 999px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.tab:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 0 15px rgba(139, 92, 246, 0.5);
}

main {
  padding: 2rem;
}

.game-section {
  display: none;
  animation: fadeIn 0.4s ease forwards;
}

.game-section.active {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

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

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 12px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

button:active {
  transform: scale(0.95);
}

.action-btn {
  background: var(--primary);
  color: white;
  padding: 0.75rem 1.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

.action-btn:hover {
  background: var(--primary-hover);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  transform: translateY(-2px);
}

.action-btn.secondary {
  background: transparent;
  border: 1px solid var(--btn-secondary-border);
  color: var(--btn-secondary-text);
}

.action-btn.secondary:hover {
  background: var(--btn-secondary-hover);
}

.board {
  display: flex;
  justify-content: center;
  min-height: 100px;
}

.tiles-container {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.tile {
  width: 65px;
  height: 85px;
  background: var(--tile-bg);
  border: 1px solid var(--tile-border);
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--tile-text);
  text-shadow: var(--tile-text-shadow);
  box-shadow: var(--tile-shadow);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: tilePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
  transform: scale(0.5);
}

.tile.empty {
  background: var(--tile-empty-bg);
  border: 1px dashed var(--tile-empty-border);
  box-shadow: var(--tile-empty-shadow);
  animation: none;
  opacity: 1;
  transform: scale(1);
  color: var(--tile-empty-text);
}

@keyframes tilePop {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.tile:not(.empty):hover {
  transform: translateY(-5px) scale(1.05);
  box-shadow: var(--tile-hover-shadow);
  border-color: rgba(139, 92, 246, 0.6);
  z-index: 10;
}

.target-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

.target-label {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.target-number {
  font-size: 4rem;
  font-weight: 800;
  background: var(--target-bg);
  padding: 1rem 3rem;
  border-radius: 16px;
  border: 2px solid var(--accent);
  box-shadow: 0 0 20px rgba(139, 92, 246, 0.3), var(--target-shadow);
  letter-spacing: 5px;
  font-variant-numeric: tabular-nums;
  color: var(--target-text);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.solve-controls {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}

.solve-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  padding: 1rem 3rem;
  font-size: 1.25rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-radius: 999px;
  box-shadow: 0 10px 20px rgba(16, 185, 129, 0.3);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.solve-btn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 15px 25px rgba(16, 185, 129, 0.4), 0 0 15px rgba(16, 185, 129, 0.5);
}

.solve-btn:disabled {
  background: #334155;
  color: #94a3b8;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.results {
  background: var(--panel-bg);
  border-radius: 20px;
  padding: 1rem 0;
  display: none;
  box-sizing: border-box;
  width: 100%;
}

.results.visible {
  display: block;
  animation: fadeIn 0.4s ease forwards;
}

.game-section.showing-results .controls,
.game-section.showing-results .board,
.game-section.showing-results .solve-controls,
.game-section.showing-results .target-container {
  display: none !important;
}

.dict-modal {
  background: var(--panel-bg);
  border-radius: 20px;
  padding: 1rem 0;
  display: none;
  box-sizing: border-box;
  width: 100%;
}

.dict-modal.visible {
  display: block;
  animation: fadeIn 0.4s ease forwards;
}

body.showing-dict #lettersResults,
body.showing-dict #numbersResults {
  display: none !important;
}

.close-results {
  position: sticky;
  top: 0px;
  float: right;
  margin: 0;
  z-index: 10;
  background: var(--secondary);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-results:hover {
  background: #ef4444;
  transform: scale(1.1) rotate(90deg);
}

.close-results:hover {
  background: #ef4444;
  transform: scale(1.1) rotate(90deg);
}

.results::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.output-content {
  font-family: monospace;
  font-size: 1.1rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.dict-output {
  font-family: inherit;
  font-size: 1.1rem;
  line-height: 1.6;
  padding: 0 10px;
}

.spinner {
  display: inline-block;
  width: 30px;
  height: 30px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}