/* ============================================================
   Bookmarklet Builder — styles
   ============================================================ */

:root {
  --bg: #0e1116;
  --bg-soft: #151a22;
  --panel: #1a2130;
  --panel-edge: #2a3446;
  --ink: #e8edf5;
  --ink-dim: #9aa7ba;
  --ink-faint: #6b788c;
  --accent: #ffb224;
  --accent-ink: #1a1206;
  --good: #3ddc97;
  --bad: #ff6b6b;
  --caution: #ffb224;
  --esc-bg: rgba(255, 178, 36, 0.16);
  --esc-ink: #ffcf70;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

body {
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(255, 178, 36, 0.07), transparent 60%),
    radial-gradient(900px 500px at -10% 0%, rgba(61, 220, 151, 0.05), transparent 55%),
    var(--bg);
  min-height: 100vh;
}

/* ---------- header ---------- */

.site-header {
  border-bottom: 1px solid var(--panel-edge);
  background: rgba(14, 17, 22, 0.85);
  backdrop-filter: blur(6px);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  font-size: 30px;
  filter: drop-shadow(0 2px 6px rgba(255, 178, 36, 0.35));
}

.site-header h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.2px;
}

.tagline {
  margin: 2px 0 0;
  color: var(--ink-dim);
  font-size: 13.5px;
}

.header-note {
  margin: 0;
  color: var(--ink-faint);
  font-size: 12.5px;
  max-width: 300px;
  text-align: right;
}

/* ---------- layout ---------- */

.layout {
  max-width: 1280px;
  margin: 24px auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: 20px;
  align-items: start;
}

/* ---------- editor card ---------- */

.editor-card, .install-card, .panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: 16px;
}

.card-head {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.name-field { flex: 1 1 240px; display: flex; flex-direction: column; gap: 5px; }

.field-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}

#bm-name {
  background: var(--bg-soft);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  color: var(--ink);
  font-size: 15px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 120ms;
}

#bm-name:focus { border-color: var(--accent); }

.iife-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--ink-dim);
  cursor: pointer;
  padding-bottom: 8px;
  user-select: none;
}

.iife-field em { color: var(--ink-faint); font-style: normal; font-size: 12px; }
.iife-field input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

.editor-wrap {
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  overflow: hidden;
}

.CodeMirror {
  height: 340px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.55;
  background: var(--bg-soft);
  color: var(--ink);
}

.CodeMirror-gutters { background: var(--bg-soft); border-right: 1px solid var(--panel-edge); }
.CodeMirror-linenumber { color: var(--ink-faint); }
.CodeMirror-cursor { border-left: 2px solid var(--accent); }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: rgba(255, 178, 36, 0.14); }
.CodeMirror-activeline-background { background: rgba(255, 255, 255, 0.03); }

/* syntax palette (cm-s-bookmarklet theme) */
.cm-s-bookmarklet .cm-keyword   { color: #ff7b93; }
.cm-s-bookmarklet .cm-atom      { color: #c792ea; }
.cm-s-bookmarklet .cm-number    { color: #f78c6c; }
.cm-s-bookmarklet .cm-def       { color: #82aaff; }
.cm-s-bookmarklet .cm-variable  { color: #e8edf5; }
.cm-s-bookmarklet .cm-variable-2 { color: #7fdbca; }
.cm-s-bookmarklet .cm-property  { color: #addb67; }
.cm-s-bookmarklet .cm-operator  { color: #89ddff; }
.cm-s-bookmarklet .cm-string    { color: #ecc48d; }
.cm-s-bookmarklet .cm-string-2  { color: #ecc48d; }
.cm-s-bookmarklet .cm-comment   { color: #697098; font-style: italic; }
.cm-s-bookmarklet .cm-meta      { color: #9aa7ba; }
.cm-s-bookmarklet .cm-error     { color: #ff6b6b; }

/* ---------- status & actions ---------- */

.status-line {
  min-height: 22px;
  margin: 10px 2px 0;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--ink-dim);
}

.status-line.ok { color: var(--good); }
.status-line.err { color: var(--bad); }
.status-line.idle { color: var(--ink-faint); }

.editor-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--panel-edge);
  background: var(--bg-soft);
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-family: var(--sans);
  cursor: pointer;
  transition: background 120ms, border-color 120ms, transform 80ms;
}

.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.btn-accent:hover { background: #ffc14d; }

.btn-ghost { background: transparent; color: var(--ink-dim); }

.btn-small { padding: 5px 10px; font-size: 12px; }

.btn.copied {
  background: var(--good);
  border-color: var(--good);
  color: #062b1c;
  font-weight: 600;
}

/* ---------- examples ---------- */

.examples { margin-top: 14px; }

.examples summary {
  cursor: pointer;
  font-size: 13.5px;
  color: var(--ink-dim);
  padding: 4px 2px;
  user-select: none;
}

.summary-hint { color: var(--ink-faint); font-size: 12px; }

.example-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.example-chip {
  text-align: left;
  background: var(--bg-soft);
  border: 1px solid var(--panel-edge);
  border-radius: 9px;
  padding: 9px 11px;
  cursor: pointer;
  color: var(--ink);
  font-family: var(--sans);
  transition: border-color 120ms, background 120ms;
}

.example-chip:hover { border-color: var(--accent); }
.example-chip.active { border-color: var(--accent); background: rgba(255, 178, 36, 0.08); }

.example-chip .ex-name { display: block; font-size: 13px; font-weight: 600; }
.example-chip .ex-blurb { display: block; font-size: 11.5px; color: var(--ink-faint); margin-top: 2px; }

/* ---------- install card ---------- */

.output-col { display: flex; flex-direction: column; gap: 20px; }

.install-card h2, .panel h2 {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-faint);
}

.pill-stage {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.025) 0 10px, transparent 10px 20px),
    var(--bg-soft);
  border: 1px dashed var(--panel-edge);
  border-radius: 10px;
  padding: 22px 16px;
  display: flex;
  justify-content: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, #2c3a55, #212c42);
  border: 1px solid #3d4f74;
  border-radius: 999px;
  padding: 10px 20px;
  color: var(--ink);
  font-size: 14.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: grab;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  transition: box-shadow 150ms, border-color 150ms;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill:hover { border-color: var(--accent); box-shadow: 0 4px 20px rgba(255, 178, 36, 0.25); }
.pill:active { cursor: grabbing; }

.pill.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  border-style: dashed;
}

.pill-grip { color: var(--ink-faint); font-size: 11px; letter-spacing: -2px; }

.install-hint { margin: 14px 0 0; font-size: 13.5px; color: var(--ink-dim); }

.mobile-note {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--ink-faint);
  border-left: 3px solid var(--panel-edge);
  padding-left: 10px;
}

.warnings { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.warnings li {
  font-size: 12.5px;
  border-radius: 8px;
  padding: 8px 11px;
}

.warnings li.caution { background: rgba(255, 178, 36, 0.1); color: var(--caution); border: 1px solid rgba(255, 178, 36, 0.3); }
.warnings li.warning { background: rgba(255, 107, 107, 0.1); color: var(--bad); border: 1px solid rgba(255, 107, 107, 0.35); }

/* ---------- output panels ---------- */

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.panel-head h2 { margin: 0; }

.panel-head-right { display: flex; align-items: center; gap: 8px; }

.chip-stat {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-faint);
}

.code-out {
  margin: 0;
  background: var(--bg-soft);
  border: 1px solid var(--panel-edge);
  border-radius: 9px;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 220px;
  overflow: auto;
  color: var(--ink-dim);
}

.code-out .placeholder { color: var(--ink-faint); font-style: italic; }

.code-out.encoded { color: #b7c5da; }

.code-out .url-scheme { color: var(--good); font-weight: 600; }

.code-out .esc {
  background: var(--esc-bg);
  color: var(--esc-ink);
  border-radius: 3px;
  padding: 0 1px;
}

.panel-foot { margin: 8px 0 0; font-size: 12px; color: var(--ink-faint); }

.esc-demo {
  font-family: var(--mono);
  background: var(--esc-bg);
  color: var(--esc-ink);
  border-radius: 3px;
  padding: 0 3px;
}

/* stale (last-good) state */
.stale .code-out, .stale .pill { opacity: 0.55; }

.stale-badge {
  display: inline-block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--caution);
  border: 1px solid rgba(255, 178, 36, 0.4);
  border-radius: 999px;
  padding: 2px 8px;
  margin-left: 8px;
  vertical-align: middle;
}

/* flash on update */
@keyframes flash {
  0% { background: rgba(255, 178, 36, 0.12); }
  100% { background: transparent; }
}

.flash { animation: flash 500ms ease-out; }

/* ---------- stats strip ---------- */

.stats-strip {
  max-width: 1280px;
  margin: 0 auto 8px;
  padding: 0 24px 8px;
}

.bars {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 140px 1fr 90px;
  gap: 12px;
  align-items: center;
}

.bar-label { font-size: 12.5px; color: var(--ink-dim); }

.bar-track {
  background: var(--bg-soft);
  border-radius: 999px;
  height: 14px;
  overflow: hidden;
}

.bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  transition: width 250ms ease-out;
  min-width: 2px;
}

.bar-source { background: #4a628a; }
.bar-min { background: var(--good); }
.bar-url { background: var(--accent); }

.bar-num { font-family: var(--mono); font-size: 12px; color: var(--ink-dim); text-align: right; }

.savings-line {
  margin: 10px 4px 0;
  font-size: 13px;
  color: var(--good);
  min-height: 20px;
}

.savings-line.muted { color: var(--ink-faint); }

/* ---------- error banner ---------- */

.error-banner {
  position: sticky;
  bottom: 12px;
  max-width: 1280px;
  margin: 8px auto 0;
  padding: 0 24px 12px;
  z-index: 40;
}

.error-inner {
  background: rgba(60, 16, 20, 0.96);
  border: 1px solid rgba(255, 107, 107, 0.5);
  border-radius: 10px;
  padding: 12px 16px;
  color: #ffc9c9;
  font-size: 13.5px;
  display: flex;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.error-inner strong { color: var(--bad); }
.error-note { color: rgba(255, 201, 201, 0.65); font-size: 12px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #22304a;
  border: 1px solid var(--panel-edge);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13.5px;
  opacity: 0;
  transition: transform 200ms ease-out, opacity 200ms;
  pointer-events: none;
  z-index: 60;
  max-width: min(90vw, 520px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error { border-color: rgba(255, 107, 107, 0.6); color: #ffc9c9; }

/* ---------- footer ---------- */

.site-footer {
  max-width: 1280px;
  margin: 12px auto 40px;
  padding: 0 24px;
  color: var(--ink-dim);
  font-size: 13px;
}

.site-footer code {
  font-family: var(--mono);
  background: var(--bg-soft);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}

.footer-fine { color: var(--ink-faint); font-size: 12px; }

/* ---------- focus ---------- */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- responsive ---------- */

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .header-note { display: none; }
}

/* Never let code/editor min-content push a track wider than the viewport. */
.layout > *, .editor-card, .output-col > *, .panel { min-width: 0; }
.CodeMirror { max-width: 100%; }

@media (max-width: 640px) {
  .layout, .stats-strip, .error-banner, .site-footer, .header-inner { padding-left: 14px; padding-right: 14px; }
  .CodeMirror { height: 260px; font-size: 13px; }
  .bar-row { grid-template-columns: 96px 1fr 74px; gap: 8px; }
  .mobile-note {
    border-left-color: var(--accent);
    color: var(--ink-dim);
  }
  .pill { font-size: 13.5px; padding: 12px 18px; }
  .btn { padding: 11px 14px; }
  .btn-small {
    min-height: 41px;
    display: inline-flex;
    align-items: center;
  }
  .card-head { flex-direction: column; align-items: stretch; }
  .iife-field { padding-bottom: 0; }
}
