/* ---------------------------------------------------------
   VARIABLES & RESET
--------------------------------------------------------- */
:root {
  /* Dark theme (default) */
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-tertiary: #1a1a1a;
  --bg-card: #1e1e1e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent: #f472b6;
  --accent-hover: #f9a8d4;
  --border: #2a2a2a;
  --border-light: #333333;
  --success: #10b981;
  --success-dark: #059669;
  --error: #ef4444;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light theme */
[data-theme="light"] {
  --bg-primary: #f8f9fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f3f4;
  --bg-card: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #5f6368;
  --text-muted: #9aa0a6;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --border: #e0e0e0;
  --border-light: #d0d0d0;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.16);
}

* {
  box-sizing: border-box;
}

/* ---------------------------------------------------------
   BODY & LAYOUT
--------------------------------------------------------- */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  padding: 40px 24px;
  background: var(--bg-primary);
  color: var(--text-primary);
  max-width: 1600px;
  margin: auto;
  min-height: 100vh;
  line-height: 1.5;
}

/* ---------------------------------------------------------
   TYPOGRAPHY
--------------------------------------------------------- */
h1 {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #fff 0%, #a0a0a0 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 40px;
}

/* ---------------------------------------------------------
   INPUT SECTION
--------------------------------------------------------- */
.input-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
  margin-bottom: 24px;
}

textarea {
  width: 100%;
  height: 180px;
  font-size: 14px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  padding: 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  resize: vertical;
  transition: var(--transition);
  line-height: 1.6;
}

textarea::placeholder {
  color: var(--text-muted);
}

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

/* ---------------------------------------------------------
   BUTTONS
--------------------------------------------------------- */
button {
  padding: 14px 28px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

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

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

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

button.secondary {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

button.secondary:hover {
  background: var(--bg-card);
  border-color: var(--border-light);
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

/* ---------------------------------------------------------
   CONTROLS ROW
--------------------------------------------------------- */
.controls-row {
  margin-top: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: flex-start;
  padding: 24px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.controls-row .field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}

.controls-row label {
  color: var(--text-secondary);
  font-weight: 500;
}

.controls-row input[type="text"] {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 14px;
  min-width: 140px;
  transition: var(--transition);
}

.controls-row input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* ---------------------------------------------------------
   MODE GROUP (Radio buttons)
--------------------------------------------------------- */
.mode-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 14px;
}

.mode-group strong {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mode-group label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: var(--transition);
  color: var(--text-primary);
}

.mode-group label:hover {
  border-color: var(--border-light);
  background: var(--bg-card);
}

.mode-group input[type="radio"] {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-light);
  border-radius: 50%;
  transition: var(--transition);
  position: relative;
}

.mode-group input[type="radio"]:checked {
  border-color: var(--accent);
  background: var(--accent);
}

.mode-group input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* ---------------------------------------------------------
   SWITCH TOGGLE
--------------------------------------------------------- */
.switch-container {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 24px;
  cursor: pointer;
  user-select: none;
  font-size: 15px;
  padding: 16px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: var(--transition);
  color: var(--text-secondary);
}

.switch-container:hover {
  border-color: var(--border-light);
  color: var(--text-primary);
}

.switch {
  position: relative;
  width: 52px;
  height: 28px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  transition: var(--transition);
  flex-shrink: 0;
}

.switch::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  background: var(--text-secondary);
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: var(--transition);
}

.switch.on {
  background: var(--accent);
  border-color: var(--accent);
}

.switch.on::after {
  transform: translateX(24px);
  background: white;
}

/* ---------------------------------------------------------
   TABLE
--------------------------------------------------------- */
#result {
  margin-top: 32px;
  overflow: auto;
  border-radius: var(--radius-lg);
  max-height: 80vh;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

th, td {
  border: 1px solid var(--border);
  padding: 0;
  text-align: center;
  min-width: 140px;
  font-size: 13px;
  background: var(--bg-secondary);
}

th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-tertiary);
}

th.corner-header {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 20;
  background: var(--bg-tertiary);
}

.row-header {
  position: sticky;
  left: 0;
  background: var(--bg-tertiary);
  z-index: 5;
  box-shadow: 4px 0 8px rgba(0, 0, 0, 0.3);
}

.header-box {
  height: 40px;
  border-bottom: 1px solid var(--border);
}

.header-name {
  font-weight: 600;
  font-size: 12px;
  padding-top: 8px;
  color: var(--text-primary);
}

.header-hex {
  font-size: 11px;
  padding-bottom: 8px;
  color: var(--text-secondary);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ---------------------------------------------------------
   CELL
--------------------------------------------------------- */
.cell {
  margin: 8px;
  border-radius: var(--radius-md);
  padding: 14px;
  height: 90px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.label {
  padding: 4px 12px;
  font-size: 10px;
  border-radius: 20px;
  font-weight: 700;
  color: white;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---------------------------------------------------------
   ACCESSIBLE VIEW
--------------------------------------------------------- */
#accessibleView {
  margin-top: 40px;
  display: flex;
  flex-direction: column;
  gap: 48px;
}

.background-group {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 32px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
}

.background-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 12px;
}

.background-title::before {
  content: "";
  width: 4px;
  height: 24px;
  background: var(--accent);
  border-radius: 2px;
}

.background-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.accessible-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: var(--transition);
}

.accessible-card:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.accessible-swatch {
  width: 100%;
  height: 130px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  text-align: center;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.accessible-swatch .lt-big {
  font-size: 24px;
  font-weight: 300;
}

.accessible-swatch .lt-bold {
  font-size: 18px;
  font-weight: 700;
}

.accessible-swatch .nt {
  font-size: 14px;
  margin-top: 4px;
}

.accessible-info {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.accessible-info strong {
  color: var(--text-primary);
}

.accessible-info .ratio {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 12px 0;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.accessible-labels {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.accessible-label {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.accessible-info code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 4px;
}

/* ---------------------------------------------------------
   DOWNLOAD BUTTONS
--------------------------------------------------------- */
#downloadSvgBtn,
#downloadPngBtn,
#downloadAccessibleSvgBtn,
#downloadAccessiblePngBtn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  margin-top: 16px;
  margin-right: 8px;
}

#downloadSvgBtn:hover,
#downloadPngBtn:hover,
#downloadAccessibleSvgBtn:hover,
#downloadAccessiblePngBtn:hover {
  background: var(--bg-card);
  border-color: var(--accent);
}

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

  h1 {
    font-size: 1.75rem;
  }

  .input-section {
    padding: 20px;
  }

  .controls-row {
    flex-direction: column;
    gap: 20px;
  }

  .background-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------------------------------------------------------
   SCROLLBAR
--------------------------------------------------------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ---------------------------------------------------------
   THEME TOGGLE
--------------------------------------------------------- */
.theme-toggle {
  position: fixed;
  top: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  z-index: 100;
  padding: 0;
}

.theme-toggle:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-light);
  transform: scale(1.05);
}

.theme-toggle svg {
  width: 22px;
  height: 22px;
  color: var(--text-primary);
  transition: var(--transition);
}

.theme-toggle .icon-sun {
  display: block;
}

.theme-toggle .icon-moon {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: block;
}

/* Light theme specific adjustments */
[data-theme="light"] h1 {
  background: linear-gradient(135deg, #1a1a1a 0%, #5f6368 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

[data-theme="light"] .row-header {
  box-shadow: 4px 0 8px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .cell {
  border: 1px solid rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .accessible-swatch {
  border: 1px solid rgba(0, 0, 0, 0.1);
}

/* ---------------------------------------------------------
   IMPORT TABS
--------------------------------------------------------- */
.import-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.import-tab {
  flex: 1;
  padding: 14px 20px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.import-tab:hover {
  background: var(--bg-card);
  border-color: var(--border-light);
  color: var(--text-primary);
}

.import-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.import-tab.active:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.import-tab svg {
  flex-shrink: 0;
}

/* ---------------------------------------------------------
   IMPORT MODES
--------------------------------------------------------- */
.import-mode {
  display: none;
}

.import-mode.active {
  display: block;
}

.generator-description {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
  line-height: 1.6;
}

/* ---------------------------------------------------------
   BASE COLOR INPUTS (Generator mode)
--------------------------------------------------------- */
.base-color-inputs {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.base-color-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.base-color-name {
  flex: 1;
  max-width: 200px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 14px;
  transition: var(--transition);
}

.base-color-name:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.color-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 12px 4px 4px;
  transition: var(--transition);
}

.color-input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.base-color-picker {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  background: none;
}

.base-color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.base-color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 6px;
}

.base-color-hex {
  width: 100px;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 14px;
}

.base-color-hex:focus {
  outline: none;
}

.base-step-select {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  min-width: 80px;
}

.base-step-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.base-step-select:hover {
  border-color: var(--border-light);
}

.remove-color-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.remove-color-btn:hover {
  background: var(--error);
  border-color: var(--error);
  color: white;
  transform: none;
  box-shadow: none;
}

.add-color-btn {
  width: 100%;
  padding: 14px;
  background: var(--bg-tertiary);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition);
  margin-bottom: 24px;
}

.add-color-btn:hover {
  background: var(--bg-card);
  border-color: var(--accent);
  border-style: solid;
  color: var(--accent);
  transform: none;
  box-shadow: none;
}

/* ---------------------------------------------------------
   GENERATED PREVIEW
--------------------------------------------------------- */
.generated-preview {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-scale {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.preview-scale-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.preview-base-indicator {
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: normal;
}

.preview-scale-colors {
  display: flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.preview-color {
  flex: 1;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  transition: var(--transition);
  cursor: default;
  position: relative;
}

.preview-color:hover {
  transform: scaleY(1.1);
  z-index: 1;
}

.preview-color.is-base {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  z-index: 2;
}

.preview-color.is-base span {
  opacity: 1;
  font-weight: 700;
}

.preview-color span {
  opacity: 0;
  transition: var(--transition);
}

.preview-color:hover span {
  opacity: 1;
}

.preview-scale-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.scale-action-btn {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: var(--transition);
}

.scale-action-btn:hover {
  background: var(--bg-card);
  border-color: var(--accent);
  color: var(--accent);
  transform: none;
  box-shadow: none;
}

.scale-action-btn.copied {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.scale-action-btn svg {
  flex-shrink: 0;
}

/* Responsive for generator */
@media (max-width: 768px) {
  .import-tabs {
    flex-direction: column;
  }

  .base-color-row {
    flex-wrap: wrap;
  }

  .base-color-name {
    max-width: none;
    width: 100%;
  }

  .color-input-wrapper {
    flex: 1;
  }
}
