@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible+Mono:wght@400;700&family=Fira+Code:wght@400;600;700&family=IBM+Plex+Mono:wght@400;500;600;700&family=JetBrains+Mono:wght@400;700;800&family=Major+Mono+Display&family=Space+Grotesk:wght@500;700&family=Space+Mono:wght@400;700&display=swap');

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

:root {
  --surface: #11111a;
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #2a2a2a;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --accent: #ff8c00;
  --accent-soft: #ffb347;
  --border: #333;
  --grain: radial-gradient(circle at 20% 20%, rgba(255, 140, 0, 0.08), transparent 45%), radial-gradient(circle at 80% 80%, rgba(255, 179, 71, 0.08), transparent 35%);
}

body {
  font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--bg-primary);
  background-image: linear-gradient(120deg, #09090f, #12121b 45%, #0d0f17), var(--grain);
  color: var(--text-primary);
  min-height: 100vh;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

header {
  text-align: center;
  margin-bottom: 1.5rem;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
}

header p {
  color: var(--text-secondary);
  margin-top: 0.25rem;
  font-size: 0.85rem;
}

main {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 768px) {
  main {
    grid-template-columns: 1fr;
  }

  .preview-section {
    position: static;
  }
}

/* Preview Section */
.preview-section {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  position: sticky;
  top: 1rem;
  overflow: hidden;
}

.preview-container {
  border-radius: 8px;
  overflow: hidden;
  max-width: 100%;
  max-height: 100%;
}

.logo {
  display: inline-block;
  text-align: center;
  padding: 60px 40px;
  font-family: 'Courier New', Courier, monospace;
}

.ascii {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 16px;
  line-height: 1.15;
  font-weight: 700;
  white-space: pre;
  margin-bottom: 8px;
}

.rule {
  font-size: 16px;
  white-space: pre;
  margin-bottom: 8px;
  opacity: 0.4;
}

.tagline {
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 4px;
  word-spacing: 8px;
  line-height: 1.6;
}

/* Controls Section */
.controls-section {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  height: fit-content;
}

/* Collapsible sections */
.section {
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

.section:first-child {
  border-top: none;
  padding-top: 0;
}

.section-header {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.4rem 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
  transition: color 0.15s;
}

.section-header::-webkit-details-marker {
  display: none;
}

.section-header::before {
  content: '\25B6';
  font-size: 0.5rem;
  line-height: 1;
  display: inline-block;
  width: 0.75rem;
  text-align: center;
  color: var(--accent);
  flex-shrink: 0;
}

.section[open] > .section-header::before {
  content: '\25BC';
}

.section-header:hover {
  color: var(--text-primary);
}

.section-body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding-top: 0.5rem;
}

/* Custom palette swatch */
.palette-swatch-custom {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.swatch-icon {
  width: 55%;
  height: 55%;
  color: rgba(255, 255, 255, 0.85);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.28));
  pointer-events: none;
}

/* Custom colour pickers */
.custom-color-row {
  display: flex;
  gap: 0.75rem;
}

.custom-color-row label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.custom-color-row input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 32px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
}

.custom-color-row input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.custom-color-row input[type="color"]::-webkit-color-swatch {
  border: 2px solid var(--border);
  border-radius: 6px;
}

/* Separator row */
.rule-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.rule-check {
  display: flex;
  align-items: center;
  white-space: nowrap;
  cursor: pointer;
  color: var(--text-primary) !important;
  font-size: 0.8rem !important;
}

.rule-select {
  flex: 1;
  min-width: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  color: var(--text-primary);
  font-size: 0.8rem;
  outline: none;
}

.rule-length-group {
  margin-top: 0.75rem;
}

.rule-custom-input {
  width: 3.5rem;
  flex-shrink: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  color: var(--text-primary);
  font-size: 0.8rem;
  text-align: center;
  outline: none;
}

.rule-custom-input:focus,
.rule-select:focus {
  border-color: var(--accent);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.control-group label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.control-group input[type="text"],
.control-group select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.control-group input[type="text"]:focus,
.control-group select:focus {
  border-color: var(--accent);
}

.control-group input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-tertiary);
  height: 6px;
  border-radius: 3px;
  cursor: pointer;
}

.control-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

.control-group input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 40px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
}

.control-group input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.control-group input[type="color"]::-webkit-color-swatch {
  border: 2px solid var(--border);
  border-radius: 8px;
}

.control-group input[type="checkbox"] {
  margin-right: 0.5rem;
  accent-color: var(--accent);
}

.control-group label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  cursor: pointer;
  color: var(--text-primary);
}

/* Palette swatches */
.palette-options {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.palette-swatch {
  width: 100%;
  aspect-ratio: 1.2;
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}

.palette-swatch:hover {
  border-color: var(--accent-soft);
  transform: scale(1.1);
}

.palette-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(255, 140, 0, 0.4);
}

.bg-options {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.bg-mode-options {
  margin-bottom: 0.15rem;
}

.bg-option {
  flex: 1;
  min-width: 50px;
  padding: 0.4rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.7rem;
  transition: border-color 0.2s;
}

.bg-option-custom {
  flex: 0 0 44px;
  min-width: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.bg-option:hover,
.bg-option.active {
  border-color: var(--accent);
}

/* Alignment options */
.align-options {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.align-option {
  flex: 1;
  min-width: 50px;
  padding: 0.4rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.7rem;
  transition: border-color 0.2s;
}

.align-option:hover,
.align-option.active {
  border-color: var(--accent);
}

/* Export Buttons */
.export-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.btn {
  padding: 0.6rem 0.75rem;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  min-width: 0;
}

.btn-full {
  grid-column: 1 / -1;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
  color: white;
}

.btn-primary:hover {
  box-shadow: 0 4px 20px rgba(255, 140, 0, 0.35);
}

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

.btn-secondary:hover {
  border-color: var(--accent);
}

/* Footer */
footer {
  text-align: center;
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
}
