/* Base64 — permanent dark "editor" theme + tool styling.
   Violet/emerald palette (distinct from the sibling tools' blue/amber).
   Declared in both modes so the palette is identical regardless of
   prefers-color-scheme and load order. */

:root {
  --bg: #0f0d1a;
  --surface: #171429;
  --surface-2: #211d3a;
  --text: #eceaf6;
  --text-dim: #9b95b8;
  --border: #322d52;
  --b64-green: #34d399;
  --b64-red: #fb7185;
  --b64-red-soft: #fda4af;
  --b64-amber: #fbbf24;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0d1a;
    --surface: #171429;
    --surface-2: #211d3a;
    --text: #eceaf6;
    --text-dim: #9b95b8;
    --border: #322d52;
  }
}
html {
  color-scheme: dark; /* native controls (select/checkbox/scrollbars) go dark */
}

/* ---------- tool shell ---------- */
.b64 {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1rem;
  margin: 1.4rem 0 1.8rem;
  box-shadow: 0 8px 30px -18px rgba(0, 0, 0, 0.7);
}
/* On wide screens the editor breaks out of the narrow prose column —
   aligned to the column's left edge and capped to the viewport, so it
   can never overflow horizontally. */
@media (min-width: 54rem) {
  .prose .b64 {
    width: min(68rem, calc(100vw - 2.5rem));
  }
}

.b64-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--border);
}
.b64-sp { flex: 1 1 auto; }

.b64-btn {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  padding: 0.42rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, filter 0.15s;
}
.b64-btn:hover {
  border-color: color-mix(in srgb, var(--primary) 60%, var(--border));
}
.b64-btn.primary {
  background: var(--b64-green);
  border-color: transparent;
  color: #04140a;
}
.b64-btn.primary:hover { filter: brightness(1.12); }
.b64-btn.ghost { background: transparent; color: var(--text-dim); }
.b64-btn.ghost:hover { color: var(--text); }

/* direction segmented control */
.b64-seg {
  display: inline-flex;
  gap: 0.15rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.15rem;
}
.b64-seg button {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: none;
  border-radius: 7px;
  padding: 0.4rem 1rem;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.b64-seg button.on {
  /* violet-600: white text on it is 5.7:1 — the brand primary (#8b5cf6)
     only reaches 4.23, under the 4.5 AA floor for the primary mode control */
  background: #7c3aed;
  color: #fff;
}

/* ---------- options row ---------- */
.b64-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  padding: 0.7rem 0 0.2rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.b64-opt { display: inline-flex; align-items: center; gap: 0.45rem; font-weight: 550; min-height: 2rem; }
.b64-opts select {
  font: inherit;
  font-size: 0.85rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.55rem; /* ≥32px effective tap height */
}
.b64-check {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2rem; /* the label is the tap target — keep it ≥32px */
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}
.b64-check input {
  accent-color: var(--b64-green);
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
}
.b64-file {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
  font-weight: 550;
}
.b64-file input[type="file"] {
  font: inherit;
  font-size: 0.8rem;
  color: var(--text-dim);
  max-width: 15rem;
}
.b64-file input[type="file"]::file-selector-button {
  font: inherit;
  font-size: 0.8rem;
  font-weight: 650;
  padding: 0.35rem 0.7rem;
  margin-right: 0.5rem;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.b64-file input[type="file"]::file-selector-button:hover {
  border-color: color-mix(in srgb, var(--primary) 60%, var(--border));
}

/* ---------- panes ---------- */
.b64-panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
  margin-top: 0.7rem;
}
@media (max-width: 46rem) {
  .b64-panes { grid-template-columns: 1fr; }
}
.b64-pane { min-width: 0; }
.b64-pane.b64-drop textarea,
.b64-pane.b64-drop .b64-filecard {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}
.b64-panehead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}
.b64-panehead .b64-stat {
  font-family: var(--mono);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.78rem;
  text-align: right;
}
.b64 textarea {
  display: block;
  width: 100%;
  min-height: 16rem;
  resize: vertical;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text);
  background: #0a0813;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem;
  tab-size: 2;
  overflow-wrap: break-word;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.b64 textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}
.b64 textarea[readonly] { color: #c7c2dd; }
#b64-out { overflow-wrap: anywhere; }

/* ---------- file card (replaces textarea while a file is loaded) ---------- */
.b64-filecard:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-height: 4.4rem;
  background: #0a0813;
  border: 1px dashed color-mix(in srgb, var(--primary) 55%, var(--border));
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.9rem;
}
.b64-filecard .b64-fc-body { min-width: 0; flex: 1 1 auto; }
.b64-filecard strong {
  display: block;
  font-size: 0.9rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.b64-filecard span {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-dim);
}
.b64-filecard .b64-btn { flex: none; }
.b64-filehint {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 0.45rem;
}
.b64-filehint kbd {
  font-family: var(--mono);
  font-size: 0.74rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.05em 0.4em;
}

/* ---------- image preview ---------- */
.b64-preview:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-top: 0.6rem;
  padding: 0.6rem 0.8rem;
  background: #0a0813;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.b64-preview img {
  display: block;
  max-width: 9rem;
  max-height: 6rem;
  width: auto;
  height: auto;
  border-radius: 6px;
  /* checkerboard so transparency is visible */
  background:
    repeating-conic-gradient(#3a3558 0% 25%, #2a2646 0% 50%) 0 0 / 16px 16px;
}
.b64-preview-meta {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-dim);
  margin: 0;
}

/* ---------- status + errors ---------- */
.b64-status {
  margin-top: 0.75rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-dim);
  min-height: 1.5em;
}
.b64-badge {
  display: inline-block;
  padding: 0.08em 0.6em;
  margin-right: 0.35em;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.76rem;
  font-family: var(--font);
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.b64-badge.ok {
  background: rgba(52, 211, 153, 0.13);
  color: var(--b64-green);
  border: 1px solid rgba(52, 211, 153, 0.45);
}
.b64-badge.bad {
  background: rgba(251, 113, 133, 0.13);
  color: var(--b64-red-soft);
  border: 1px solid rgba(251, 113, 133, 0.45);
}
.b64-badge.warn {
  background: rgba(251, 191, 36, 0.13);
  color: var(--b64-amber);
  border: 1px solid rgba(251, 191, 36, 0.45);
}

.b64-err:not([hidden]) {
  display: block;
}
.b64-err {
  margin-top: 0.7rem;
  border: 1px solid rgba(251, 113, 133, 0.5);
  background: rgba(251, 113, 133, 0.08);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
}
.b64-err-head { font-size: 0.92rem; color: var(--text); }
.b64-err-head strong { color: var(--b64-red-soft); font-weight: 650; }
.b64-err-loc { color: var(--text-dim); font-family: var(--mono); font-size: 0.82rem; }
.b64-err-snip {
  margin: 0.55rem 0 0;
  padding: 0.55rem 0.7rem;
  background: #0a0813;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
  color: var(--b64-red-soft);
}

/* ---------- article code samples ---------- */
.prose pre {
  background: #0a0813;
  border: 1px solid var(--border);
}
.prose code {
  background: var(--surface-2);
  overflow-wrap: break-word; /* long base64 strings must not overflow narrow viewports */
}
.prose pre code {
  background: none;
}
.prose table code { white-space: nowrap; }

@media (max-width: 480px) {
  .b64 { padding: 0.8rem; }
  .b64 textarea { min-height: 12rem; }
  .b64-file { margin-left: 0; }
}
