:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-variant: #f1f5f9;
  --canvas-bg: #ffffff; /* Default Canvas Background */
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --border: #e2e8f0;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow:
    0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-variant: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --border: #334155;
  --shadow: 0 10px 15px -3px rgb(0 0 0 / 0.3);
}

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

body {
  font-family: "Plus Jakarta Sans", "Inter", sans-serif;
  background-color: var(--bg);
  color: var(--text);
  transition:
    background-color 0.3s,
    color 0.3s;
  min-height: 100vh;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
}

/* Splash Screen */
#splash {
  position: fixed;
  inset: 0;
  background: var(--primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  color: white;
  transition:
    opacity 0.8s ease,
    visibility 0.8s;
}

#splash.fade-out {
  opacity: 0;
  visibility: hidden;
}

.splash-logo {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -1px;
  animation: pulse 2s infinite;
}

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

/* Layout */
.header {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.5rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text);
  transition: var(--transition);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
  display: grid;
  grid-template-columns: 1fr 350px;
  gap: 2rem;
}

@media (max-width: 900px) {
  .container {
    grid-template-columns: 1fr;
  }
}

.main-content,
.sidebar {
  min-width: 0;
  max-width: 100%;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.section-title {
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Input Area */
textarea {
  width: 100%;
  height: 200px;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-variant);
  color: var(--text);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
  resize: vertical;
  outline: none;
  transition: var(--transition);
}

textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Controls */
.controls-group {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.control-item label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

select,
input[type="number"] {
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-variant);
  color: var(--text);
  font-family: inherit;
  outline: none;
}

/* Color Grid */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.2s;
}

.swatch:hover {
  transform: translateY(-2px);
}
.swatch.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--bg);
}

.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

input[type="color"] {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  width: 32px;
  height: 32px;
  cursor: pointer;
  background: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
input[type="color"]::-webkit-color-swatch {
  border: 1px solid var(--border);
  border-radius: 50%;
}

/* Actions */
.actions {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
}

button.btn {
  flex: 1;
  padding: 1rem;
  border-radius: var(--radius-md);
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface-variant);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--border);
}

/* Preview */
#tableContainerWrapper {
  margin-top: 2rem;
  overflow-x: auto;
  border-radius: var(--radius-lg);
  background: var(--canvas-bg);
  padding: 2.5rem;
  border: 1px solid var(--border);
  display: flex;
  justify-content: center;
  max-width: 100%;
  box-sizing: border-box;
}

#tableContainer {
  background: var(--canvas-bg);
  padding: 1rem;
  width: 100%;
  min-width: 600px; /* Ensure table isn't too small with little data */
}

table {
  width: 100%;
  border-collapse: collapse;
  color: #1e293b;
  border: 2px solid #cbd5e1; /* Thicker outer border */
}

th {
  padding: 1.25rem 1.5rem; /* Increased padding */
  text-align: left;
  border: 1px solid #cbd5e1;
  font-weight: 700;
}

td {
  padding: 1rem 1.5rem; /* Increased padding */
  border: 1px solid #cbd5e1;
  background: inherit;
}

.empty-state {
  text-align: center;
  padding: 4rem;
  color: #64748b;
  font-style: italic;
}

/* Font Preview Bar */
.font-preview-bar {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--surface-variant);
  border-radius: var(--radius-sm);
  display: flex;
  gap: 1.5rem;
  font-size: 0.8rem;
}

/* SVG Icons Simulation */
.icon {
  width: 1.2rem;
  height: 1.2rem;
  fill: currentColor;
}

[data-theme="dark"] .logo img.icon {
  filter: invert(1);
}

/* Adblock Modal */
#adblockModal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
}

#adblockModal.active {
  display: flex;
}

.adblock-card {
  background: var(--surface);
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  text-align: center;
  max-width: 450px;
  width: 90%;
  border: 1px solid var(--border);
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.5);
  color: var(--text);
}

.adblock-card h2 {
  margin-bottom: 1rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.adblock-card p {
  color: var(--text-muted);
  line-height: 1.5;
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
  .header {
    padding: 1.5rem 1rem;
  }
  
  .logo {
    font-size: 1.25rem;
  }

  .container {
    padding: 0 1rem 3rem;
  }

  .actions {
    flex-direction: column;
  }
  
  button.btn {
    width: 100%;
  }

  #tableContainerWrapper {
    padding: 1rem;
    display: block; /* Fixes left-cutoff issues when a flex-centered child overflows */
  }

  table th, table td {
    padding: 0.75rem 1rem;
  }
  
  .empty-state {
    padding: 2rem 1rem;
  }
}
