/* =================================================================
   THEMES
   ================================================================= */

:root[data-theme="cyberpunk"] {
  --bg: #0f0f1e;
  --surface: #1a1a2e;
  --surface-2: #251536;
  --accent: #ff6cb6;
  --accent-2: #7ae7ff;
  --accent-3: #ffd56c;
  --text: #e0e0ff;
  --dim: #888;
  --dimmer: #555;
  --border: #ff6cb6;
  --border-faint: #333;
  --good: #7ae7ff;
  --bad: #ff6cb6;
  --shadow: 0 0 20px rgba(255, 108, 182, 0.15);
}

:root[data-theme="vaporwave"] {
  --bg: #1a0b2e;
  --surface: #261447;
  --surface-2: #311b4f;
  --accent: #ff71ce;
  --accent-2: #b967ff;
  --accent-3: #01cdfe;
  --text: #fffcf9;
  --dim: #b5a8c9;
  --dimmer: #6b5c7e;
  --border: #b967ff;
  --border-faint: #3c2660;
  --good: #05ffa1;
  --bad: #ff71ce;
  --shadow: 0 0 20px rgba(185, 103, 255, 0.18);
}

:root[data-theme="matrix"] {
  --bg: #000800;
  --surface: #001a00;
  --surface-2: #002a00;
  --accent: #00ff41;
  --accent-2: #39ff14;
  --accent-3: #b2ff59;
  --text: #00ff41;
  --dim: #008f11;
  --dimmer: #003b00;
  --border: #00ff41;
  --border-faint: #003b00;
  --good: #00ff41;
  --bad: #ff3030;
  --shadow: 0 0 20px rgba(0, 255, 65, 0.2);
}

/* =================================================================
   BASE
   ================================================================= */

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

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 10px;
}

/* CRT scanline overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(0, 0, 0, 0.06) 2px,
    rgba(0, 0, 0, 0.06) 3px
  );
  z-index: 9999;
  mix-blend-mode: multiply;
}

/* =================================================================
   HEADER
   ================================================================= */

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border-faint);
}

.ascii {
  font-family: "VT323", "JetBrains Mono", monospace;
  font-size: 13px;
  line-height: 1.05;
  white-space: pre;
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent);
  letter-spacing: -0.5px;
}

.ascii .sub {
  color: var(--dim);
  text-shadow: none;
  font-size: 11px;
}

.theme-switcher {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.theme-switcher button {
  background: transparent;
  border: 1px solid var(--border-faint);
  color: var(--dim);
  font-family: inherit;
  font-size: 10px;
  padding: 4px 8px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.theme-switcher button:hover {
  border-color: var(--border);
  color: var(--text);
}

.theme-switcher button.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface-2);
}

/* =================================================================
   MAIN LAYOUT
   ================================================================= */

.main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 12px;
  min-height: 0;
  min-width: 0;
}

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

/* ---- LEFT: editor panel ---- */

.editor {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-wrap: wrap;
}

.tab {
  background: transparent;
  border: none;
  border-right: 1px dashed var(--border-faint);
  color: var(--dim);
  font-family: inherit;
  font-size: 11px;
  padding: 8px 14px;
  cursor: pointer;
  letter-spacing: 1px;
  text-transform: lowercase;
  transition: all 0.15s;
  position: relative;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  background: var(--surface-2);
}

.tab.active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
}

.tab .badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 5px;
  background: var(--surface-2);
  color: var(--dim);
  font-size: 10px;
  border-radius: 2px;
}

.tab.active .badge {
  color: var(--accent-2);
}

.cli-bar {
  background: var(--bg);
  border-bottom: 1px dashed var(--border-faint);
  padding: 7px 14px;
  font-size: 12px;

  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;

  overflow: hidden;
  white-space: normal;
}

.cli-bar .prompt {
  color: var(--accent-2);
  padding-top: 5px;
}

.cli-bar .cmd {
  color: var(--text);
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  white-space: normal;
}

.cli-bar .cmd .cmd,
.cli-bar .cmd .flag {
  display: inline-block;
  white-space: nowrap;
}

.cli-bar .cmd .flag {
  color: var(--accent-3);
}

.cli-bar .copy-btn {
  background: transparent;
  border: 1px solid var(--border-faint);
  color: var(--dim);
  font-family: inherit;
  font-size: 10px;
  padding: 2px 8px;
  cursor: pointer;
  flex-shrink: 0;
}

.code-area {
  flex: 1;
  min-height: 0;
  min-width: 0;
  position: relative;
  display: flex;
  overflow: hidden;
}

.code-area textarea,
.code-area pre {
  flex: 1;
  min-width: 0;
  width: 100%;
  height: 100%;
  background: var(--surface);
  color: var(--text);
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.7;
  padding: 14px 18px;
  resize: none;
  white-space: pre;
  overflow: auto;
  margin: 0;
}

.code-area pre {
  user-select: text;
}

.code-area textarea::placeholder {
  color: var(--dimmer);
  white-space: pre-wrap;
}

.code-area textarea:focus {
  background: var(--surface);
}

/* preview iframe wrapper */
.preview-pane {
  flex: 1;
  min-width: 0;
  width: 100%;
  height: 100%;
  background: #fff;
  overflow: hidden;
  position: relative;
}

.preview-pane iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.preview-pane .preview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--dimmer);
  font-size: 12px;
  text-align: center;
  padding: 20px;
}

/* Custom scrollbar */
.code-area textarea::-webkit-scrollbar,
.code-area pre::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.code-area textarea::-webkit-scrollbar-track,
.code-area pre::-webkit-scrollbar-track {
  background: var(--bg);
}
.code-area textarea::-webkit-scrollbar-thumb,
.code-area pre::-webkit-scrollbar-thumb {
  background: var(--border-faint);
  border: 2px solid var(--bg);
}
.code-area textarea::-webkit-scrollbar-thumb:hover,
.code-area pre::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* Generated class list view */
.classlist {
  padding: 14px 18px;
  font-size: 12px;
  overflow: auto;
  flex: 1;
  min-width: 0;
  width: 100%;
}

.classlist h3 {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border-faint);
}

.classlist .class-row {
  display: grid;
  grid-template-columns: minmax(140px, auto) 1fr auto;
  gap: 14px;
  padding: 6px 0;
  border-bottom: 1px dotted var(--border-faint);
}

.classlist .class-name {
  color: var(--accent);
}
.classlist .class-rule {
  color: var(--dim);
}
.classlist .class-count {
  color: var(--accent-3);
  text-align: right;
  font-size: 11px;
}

.classlist .empty {
  color: var(--dimmer);
  text-align: center;
  padding: 30px;
}

/* Run bar */
.run-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.size-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 10px;
  color: var(--dim);
  min-width: 0;
}

.size-bar .bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.size-bar .bar-label {
  flex-shrink: 0;
  width: 36px;
  font-size: 9px;
  color: var(--dim);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.size-bar .bar-track {
  position: relative;
  flex: 1;
  height: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border-faint);
  overflow: hidden;
  min-width: 0;
}

.size-bar .bar-before,
.size-bar .bar-after {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-size: 9px;
  white-space: nowrap;
}

.size-bar .bar-before {
  background: var(--accent);
  color: var(--bg);
  width: 100%;
  z-index: 1;
}

.size-bar .bar-after {
  background: var(--accent-2);
  color: var(--bg);
  z-index: 2;
  transition: width 0.5s ease;
}

.size-bar .bar-stats {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 10px;
  flex-wrap: wrap;
}

.run-btn {
  flex-shrink: 0;
  background: var(--accent);
  border: 2px solid var(--accent);
  color: var(--bg);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 12px 22px;
  cursor: pointer;
  letter-spacing: 2px;
  text-transform: uppercase;
  transition: all 0.15s;
  text-shadow: none;
}

.run-btn:hover {
  background: transparent;
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent);
}

.run-btn:active {
  transform: scale(0.97);
}

.run-btn.busy {
  background: transparent;
  color: var(--accent);
  cursor: wait;
}

.run-btn.busy::before {
  content: "⟳ ";
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

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

/* ---- RIGHT: flag pad ---- */

.flagpad {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  min-height: 0;
  min-width: 0;
}

.flagpad-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--accent);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.flagpad-header .reset-btn {
  background: transparent;
  border: 1px solid var(--border-faint);
  color: var(--dim);
  font-family: inherit;
  font-size: 9px;
  padding: 3px 8px;
  cursor: pointer;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: all 0.15s;
}

.flagpad-header .reset-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.flagpad-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.flagpad-body::-webkit-scrollbar {
  width: 8px;
}
.flagpad-body::-webkit-scrollbar-track {
  background: var(--surface);
}
.flagpad-body::-webkit-scrollbar-thumb {
  background: var(--border-faint);
}

/* ---- presets bar ---- */

.presets {
  border-bottom: 1px dashed var(--border-faint);
}

.presets .flag-section {
  padding: 10px 14px;
}

.presets .flag-section:last-child {
  border-bottom: none;
}

.presets-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 4px;
}

.preset-btn {
  padding: 6px 4px;
  font-size: 10px;
  font-family: inherit;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  background: transparent;
  transition: all 0.15s;
  text-align: center;
}

.preset-btn.safe {
  border: 1px solid var(--good);
  color: var(--good);
}
.preset-btn.safe:hover {
  background: var(--good);
  color: var(--bg);
}
.preset-btn.safe.active {
  background: var(--good);
  color: var(--bg);
  box-shadow: 0 0 10px var(--good);
}

.preset-btn.recommended {
  border: 1px solid var(--accent-3);
  color: var(--accent-3);
}
.preset-btn.recommended:hover {
  background: var(--accent-3);
  color: var(--bg);
}
.preset-btn.recommended.active {
  background: var(--accent-3);
  color: var(--bg);
  box-shadow: 0 0 10px var(--accent-3);
}

.preset-btn.dangerous {
  border: 1px solid var(--bad);
  color: var(--bad);
}
.preset-btn.dangerous:hover {
  background: var(--bad);
  color: var(--bg);
}
.preset-btn.dangerous.active {
  background: var(--bad);
  color: var(--bg);
  box-shadow: 0 0 10px var(--bad);
}

.preset-btn.one-line {
  border: 1px solid var(--accent-2);
  color: var(--accent-2);
}

.preset-btn.one-line:hover,
.preset-btn.one-line.active {
  background: var(--accent-2);
  color: var(--bg);
  box-shadow: 0 0 10px var(--accent-2);
}

.preset-btn.readable {
  border: 1px solid var(--good);
  color: var(--good);
}

.preset-btn.readable:hover,
.preset-btn.readable.active {
  background: var(--good);
  color: var(--bg);
  box-shadow: 0 0 10px var(--good);
}

.preset-btn.class-demo {
  border: 1px solid var(--accent-3);
  color: var(--accent-3);
}

.preset-btn.class-demo:hover,
.preset-btn.class-demo.active {
  background: var(--accent-3);
  color: var(--bg);
  box-shadow: 0 0 10px var(--accent-3);
}

.preset-btn.email-safe {
  border: 1px solid #b48cff;
  color: #b48cff;
}

.preset-btn.email-safe:hover,
.preset-btn.email-safe.active {
  background: #b48cff;
  color: var(--bg);
  box-shadow: 0 0 10px #b48cff;
}

.preset-btn.word-clean {
  border: 1px solid #ff9f43;
  color: #ff9f43;
}

.preset-btn.word-clean:hover,
.preset-btn.word-clean.active {
  background: #ff9f43;
  color: var(--bg);
  box-shadow: 0 0 10px #ff9f43;
}

/* ---- flag sections ---- */

.flag-section {
  border-bottom: 1px dashed var(--border-faint);
  padding: 10px 14px;
}

.flag-section:last-child {
  border-bottom: none;
}

.flag-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--accent-3);
  letter-spacing: 1.5px;
  margin-bottom: 10px;
  cursor: pointer;
  user-select: none;
}

.flag-section-title::before {
  content: "▼ ";
  margin-right: 4px;
  display: inline-block;
  transition: transform 0.15s;
}

.flag-section.collapsed .flag-section-title::before {
  transform: rotate(-90deg);
}

.flag-section.collapsed .flag-section-content {
  display: none;
}

.flag-section-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Toggle row */
.flag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border: 1px solid var(--border-faint);
  background: var(--bg);
  cursor: pointer;
  transition: all 0.1s;
  font-size: 11px;
  user-select: none;
}

.flag:hover {
  border-color: var(--dimmer);
}

.flag input[type="checkbox"] {
  display: none;
}

.flag .flag-label {
  color: var(--dim);
}

.flag .flag-state {
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 1px;
}

.flag.on {
  border-color: var(--accent);
  background: var(--surface-2);
}

.flag.on .flag-label {
  color: var(--text);
}

.flag.on .flag-state {
  color: var(--accent-2);
}

.flag-num,
.flag-text {
  padding: 5px 8px;
  border: 1px solid var(--border-faint);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
}

.flag-num label,
.flag-text label {
  color: var(--dim);
}

.flag-num input,
.flag-text input {
  background: transparent;
  border: none;
  color: var(--accent-2);
  font-family: inherit;
  font-size: 11px;
  text-align: right;
  outline: none;
}

.flag-num input {
  width: 60px;
}
.flag-text input {
  width: 90px;
}

.flag-num input:focus,
.flag-text input:focus {
  color: var(--accent);
}

/* =================================================================
   FOOTER STATUS
   ================================================================= */

.status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  color: var(--dim);
  padding: 4px 6px;
  border-top: 1px dashed var(--border-faint);
}

.status .group {
  display: flex;
  gap: 14px;
}

.status .ok {
  color: var(--good);
}
.status .err {
  color: var(--bad);
}

.status .pulse::before {
  content: "● ";
  animation: pulse 2s infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

/* =================================================================
   MISC
   ================================================================= */

.toast {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--accent);
  color: var(--bg);
  padding: 10px 18px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  border: 1px solid var(--accent);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.error-banner {
  background: var(--bad);
  color: var(--bg);
  padding: 8px 14px;
  font-size: 11px;
  display: none;
}

.error-banner.show {
  display: block;
}
