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

:root {
  color-scheme: dark;

  --bg: #17233f;
  --surface: #1c2c4c;
  --surface-2: #24365a;
  --surface-3: #121d36;

  --text: #e5e4e4;
  --text-secondary: #a9b3cc;
  --text-muted: #909bb8;
  --text-on-accent: #13203a;

  --border: #304368;
  --border-subtle: #243254;

  --accent: #bfcdea;
  --accent-strong: #9db3dd;
  --accent-soft: rgba(191, 205, 234, 0.14);
  --accent-border: rgba(191, 205, 234, 0.4);

  --danger: #ec8891;
  --danger-soft: rgba(224, 108, 117, 0.14);
  --danger-border: rgba(224, 108, 117, 0.4);
  --success: #98c379;
  --success-soft: rgba(152, 195, 121, 0.14);
  --purple: #c678dd;
  --cyan: #56b6c2;
  --orange: #d19a66;
  --blue: #61afef;

  --brand: #9fc131;
  --brand-strong: #8aab2a;
  --brand-ink: #13203a;

  --tag-bg: #28395e;
  --tag-text: #c7cee0;

  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  --code-font: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, ui-monospace, monospace;

  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

:root[data-theme='light'] {
  color-scheme: light;

  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f0f0ef;
  --surface-3: #f5f5f4;

  --text: #13203a;
  --text-secondary: #4f5872;
  --text-muted: #666e83;
  --text-on-accent: #ffffff;

  --border: #e1ded8;
  --border-subtle: #ececea;

  --accent: #3154a2;
  --accent-strong: #24407f;
  --accent-soft: rgba(49, 84, 162, 0.08);
  --accent-border: rgba(49, 84, 162, 0.30);

  --danger: #c0303a;
  --danger-soft: rgba(228, 86, 73, 0.12);
  --danger-border: rgba(192, 48, 58, 0.40);
  --success: #2f6f22;
  --success-soft: rgba(80, 161, 79, 0.16);
  --purple: #8d3aa8;
  --cyan: #0e7490;
  --orange: #a15319;
  --blue: #3367d6;

  --brand: #b7e425;
  --brand-strong: #a1c820;
  --brand-ink: #13203a;

  --tag-bg: #e8e6e2;
  --tag-text: #4f5872;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.08);
}

html, body { height: 100%; }
body { background: var(--bg); }

.ic { width: 1em; height: 1em; display: inline-block; vertical-align: middle; flex-shrink: 0; }
/* `.ic { display }` beats the UA `[hidden] { display:none }`, so toggled icons
   (e.g. the theme moon/sun) would both render – hide them explicitly. */
.ic[hidden] { display: none; }

/* ── Layout ── */

.app-shell { display: flex; flex-direction: column; height: 100vh; }

.app-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 30px; height: 30px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-title { font-size: 15px; font-weight: 700; letter-spacing: 0.01em; color: var(--text); }
.brand-sub { font-size: 11.5px; color: var(--text-muted); }

.header-actions { display: flex; align-items: center; gap: 10px; }

/* GitHub repo button (icon + name + star/fork counts), mkdocs-material style */
.repo-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-secondary);
  text-decoration: none;
  line-height: 1.15;
}
.repo-link:hover { color: var(--text); border-color: var(--accent-border); }
.repo-icon { width: 21px; height: 21px; flex-shrink: 0; }
.repo-meta { display: flex; flex-direction: column; gap: 1px; }
.repo-name { font-size: 12.5px; font-weight: 600; color: var(--text); }
.repo-stats { display: flex; gap: 11px; font-size: 11px; color: var(--text-muted); }
.repo-stat { display: inline-flex; align-items: center; gap: 3px; }
.repo-stat-ic { width: 12px; height: 12px; fill: currentColor; }

.icon-btn {
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}
.icon-btn:hover { background: var(--accent-soft); color: var(--text); }

/* Bordered square icon buttons (help + theme), matching the repo button height */
.theme-toggle,
.help-toggle {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.theme-toggle .ic,
.help-toggle .ic { width: 20px; height: 20px; }
.theme-toggle:hover,
.help-toggle:hover { background: var(--accent-soft); border-color: var(--accent-border); color: var(--text); }

/* ── Help / FAQ dialog ── */
.faq-dialog {
  /* `* { margin: 0 }` in the reset kills the UA margin:auto that centres a modal
     dialog, pinning it top-left – restore it. */
  margin: auto;
  width: min(640px, calc(100vw - 32px));
  max-height: min(80vh, 720px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.faq-dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.faq-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
}
.faq-head h2 { font-size: 16px; font-weight: 700; }
.faq-close { width: 32px; height: 32px; color: var(--text-secondary); }
.faq-close:hover { background: var(--accent-soft); color: var(--text); }
.faq-body { padding: 8px 20px 20px; overflow-y: auto; }
.faq-body section { padding: 12px 0; border-bottom: 1px solid var(--border-subtle); }
.faq-body h3 { font-size: 13.5px; font-weight: 600; color: var(--text); margin-bottom: 5px; }
.faq-body p { font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.faq-body ul { margin: 4px 0 0; padding-left: 18px; }
.faq-body li { font-size: 13px; color: var(--text-secondary); margin: 3px 0; }
.faq-body a { color: var(--accent-strong); text-decoration: none; }
.faq-body a:hover { text-decoration: underline; }
.faq-body code { font-family: var(--code-font); font-size: 12px; }
.faq-foot { padding-top: 12px; font-size: 12px; color: var(--text-muted); }

.app-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  text-decoration: none;
}
.footer-logo {
  display: block;
  height: 15px;
  width: 111px; /* preserves the 2322.4 x 314.3 aspect ratio */
  background-color: var(--text);
  -webkit-mask: url("neverblink-logo.svg") left center / contain no-repeat;
  mask: url("neverblink-logo.svg") left center / contain no-repeat;
}
.footer-links { display: flex; align-items: center; flex-wrap: wrap; }
.footer-links a,
.footer-links button {
  appearance: none;
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  padding: 0 12px;
  color: var(--text-muted);
  text-decoration: none;
}
.footer-links :first-child { padding-left: 0; }
.footer-links :not(:first-child) { border-left: 1px solid var(--border-subtle); }
.footer-links a:hover,
.footer-links button:hover { color: var(--text); }

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 24px;
  gap: 14px;
}

/* ── Toolbar ── */

.toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 10px;
}

.target-tabs { display: flex; flex-wrap: wrap; gap: 2px; }
.tab-btn {
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: background 0.1s, color 0.1s;
}
.tab-btn:hover { color: var(--text); background: var(--accent-soft); }
.tab-btn--active { color: var(--text-on-accent); background: var(--accent); font-weight: 600; }
.tab-btn--active:hover { color: var(--text-on-accent); background: var(--accent); }

.toolbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.options-row { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.opt-field { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; }
/* Divider after each option (incl. the last, to fence it off from the Auto
   toggle) so adjacent controls don't read as one blur. */
.opt-field::after {
  content: "";
  align-self: center;
  width: 1px;
  height: 22px;
  margin-left: 6px;
  background: var(--border);
}
.opt-field input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }
.opt-field input[type="text"],
.opt-field input[type="number"],
.opt-field select {
  font: inherit;
  font-size: 12.5px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}
.opt-field input[type="text"] { width: 168px; }
.opt-field input[type="number"] { width: 56px; }
.opt-field input:focus, .opt-field select:focus { border-color: var(--accent); }
.opt-field label { cursor: pointer; }

.auto-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 2px;
}
.auto-toggle input { accent-color: var(--brand); cursor: pointer; }

/* ── Buttons ── */

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.1s, background 0.1s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { font-size: 12px; padding: 5px 11px; }

.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover:not(:disabled) { background: var(--brand-strong); }

.btn-secondary { background: var(--tag-bg); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }

.btn-secondary--done { color: var(--success); }

/* ── Split panels ── */

.split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

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

.panel-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.panel-title { font-size: 13px; font-weight: 600; color: var(--text); display: flex; align-items: baseline; gap: 8px; }
.panel-title-sub { font-size: 11px; font-weight: 400; color: var(--text-muted); }
.panel-actions { display: flex; align-items: center; gap: 8px; }

.status-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 100px;
  background: var(--success-soft);
  color: var(--success);
  font-variant-numeric: tabular-nums;
}
.status-pill--error { background: var(--danger-soft); color: var(--danger); }

/* ── CodeMirror editor hosts (input + read-only output) ── */
.editor {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--surface-3);
}
.editor .cm-editor { height: 100%; }
.editor .cm-scroller { overflow: auto; }
.cm-output--error .cm-content { color: var(--danger); }

.file-tabs {
  flex-shrink: 0;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 6px 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}
/* `hidden` alone loses to `.file-tabs { display: flex }`; hide it explicitly so
   single-file / non-multifile output shows no empty tab bar. */
.file-tabs[hidden] { display: none; }
.file-tab {
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  padding: 6px 12px;
  font-size: 12px;
  font-family: var(--code-font);
  color: var(--text-secondary);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.file-tab:hover { color: var(--text); }
.file-tab--active { color: var(--accent); border-bottom-color: var(--accent); }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .toolbar-right { margin-left: 0; }
}

@media (max-width: 640px) {
  /* Tighter everywhere; reclaim the horizontal margins for content width. */
  .app-header { padding: 8px 12px; }
  .app-footer { padding: 8px 12px; }
  .workspace { padding: 8px 0 10px; gap: 8px; }
  .toolbar { padding: 6px 8px; gap: 8px; border-radius: 0; }
  .toolbar-right { gap: 8px; }
  .split { gap: 8px; }
  .panel { border-radius: 0; }

  .brand-mark { display: none; }
  .brand { gap: 8px; }
  .header-actions { gap: 8px; }
  .repo-link { padding: 4px 9px; }

  /* Footer: keep just the "Built by NeverBlink" mark; the link row is too much. */
  .footer-links { display: none; }
  .app-footer { justify-content: flex-start; }
}
