/* ═══════════════════════════════════════════════════════════════════
   Base64 Encoder & Decoder - Scoped Styles
   Prefix: .b64-  (base64-tool)
   All rules scoped under #b64-root / .b64-root - ZERO global impact.
   ═══════════════════════════════════════════════════════════════════ */

/* ── CSS Variables (light mode) ──────────────────────────────────── */
.b64-root {
  --b64-brand:        #4f46e5;
  --b64-brand-mid:    #4338ca;
  --b64-brand-dark:   #3730a3;
  --b64-brand-glow:   rgba(79, 70, 229, 0.18);
  --b64-brand-light:  #eef2ff;
  --b64-brand-2:      #7c3aed;

  --b64-bg:           #f8f9ff;
  --b64-surface:      #ffffff;
  --b64-surface-2:    #f1f5f9;
  --b64-border:       #e2e8f0;
  --b64-border-focus: #4f46e5;

  --b64-text:         #1e1b4b;
  --b64-text-2:       #4a5568;
  --b64-text-3:       #94a3b8;

  --b64-success-bg:   #f0fdf4;
  --b64-success-text: #166534;
  --b64-success-bdr:  #86efac;
  --b64-error-bg:     #fff1f2;
  --b64-error-text:   #9f1239;
  --b64-error-bdr:    #fda4af;
  --b64-warn-bg:      #fffbeb;
  --b64-warn-text:    #92400e;

  --b64-radius:       14px;
  --b64-radius-sm:    8px;
  --b64-radius-xs:    6px;
  --b64-shadow:       0 1px 3px rgba(0,0,0,.06), 0 4px 20px rgba(79,70,229,.07);
  --b64-shadow-hover: 0 4px 24px rgba(79,70,229,.16);
  --b64-shadow-focus: 0 0 0 3px var(--b64-brand-glow);
  --b64-transition:   all .18s cubic-bezier(.4,0,.2,1);

  --b64-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
}

/* ── Dark Mode ───────────────────────────────────────────────────── */
.b64-root.b64-dark {
  --b64-bg:           #0d0f1a;
  --b64-surface:      #151828;
  --b64-surface-2:    #1e2235;
  --b64-border:       #2d3458;
  --b64-border-focus: #818cf8;
  --b64-brand:        #818cf8;
  --b64-brand-mid:    #6366f1;
  --b64-brand-light:  #1e1b4b;
  --b64-brand-glow:   rgba(129, 140, 248, 0.2);

  --b64-text:         #e2e8f0;
  --b64-text-2:       #94a3b8;
  --b64-text-3:       #64748b;

  --b64-success-bg:   #052e16;
  --b64-success-text: #86efac;
  --b64-success-bdr:  #166534;
  --b64-error-bg:     #1f0a0a;
  --b64-error-text:   #fda4af;
  --b64-error-bdr:    #9f1239;

  --b64-shadow:       0 1px 3px rgba(0,0,0,.4), 0 4px 20px rgba(0,0,0,.4);
  --b64-shadow-hover: 0 4px 24px rgba(79,70,229,.3);
}

/* ── Scoped Reset ────────────────────────────────────────────────── */
.b64-root *, .b64-root *::before, .b64-root *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Root Wrapper ────────────────────────────────────────────────── */
.b64-root {
  background: var(--b64-bg);
  color: var(--b64-text);
  font-family: 'Outfit', 'DM Sans', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  transition: background .25s, color .25s;
  padding-bottom: 72px;
}

/* ══════════════════════════════════════════════════════════════════
   HERO HEADER
══════════════════════════════════════════════════════════════════ */
.b64-hero {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 40%, #4338ca 80%, #4f46e5 100%);
  padding: 48px 24px 44px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.b64-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 20% 50%, rgba(124,58,237,.25) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 80% 30%, rgba(79,70,229,.35) 0%, transparent 60%);
  pointer-events: none;
}

.b64-hero::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 40px;
  background: var(--b64-bg);
  clip-path: ellipse(55% 100% at 50% 100%);
}

.b64-hero-top {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
  position: relative;
  z-index: 1;
}

.b64-toggle-dark {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  transition: var(--b64-transition);
  backdrop-filter: blur(8px);
}

.b64-toggle-dark:hover {
  background: rgba(255,255,255,.2);
  transform: scale(1.08);
}

.b64-toggle-dark svg { width: 18px; height: 18px; }

.b64-hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  color: rgba(255,255,255,.9);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 5px 14px;
  border-radius: 100px;
  margin-bottom: 20px;
  backdrop-filter: blur(8px);
  position: relative;
  z-index: 1;
}

.b64-hero-badge svg { width: 14px; height: 14px; }

.b64-hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 800;
  color: #fff;
  letter-spacing: -.02em;
  margin-bottom: 12px;
  line-height: 1.15;
  position: relative;
  z-index: 1;
}

.b64-hero h1 span {
  background: linear-gradient(135deg, #a5b4fc, #c7d2fe);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.b64-hero p {
  color: rgba(255,255,255,.75);
  max-width: 560px;
  margin: 0 auto;
  font-size: 15px;
  position: relative;
  z-index: 1;
}

/* ══════════════════════════════════════════════════════════════════
   MAIN CONTAINER
══════════════════════════════════════════════════════════════════ */
.b64-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 20px 0;
}

/* ══════════════════════════════════════════════════════════════════
   MODE TABS (Text / File)
══════════════════════════════════════════════════════════════════ */
.b64-mode-tabs {
  display: flex;
  gap: 0;
  background: var(--b64-surface-2);
  border-radius: var(--b64-radius-sm);
  border: 1px solid var(--b64-border);
  padding: 4px;
  width: fit-content;
  margin-bottom: 20px;
}

.b64-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--b64-text-2);
  transition: var(--b64-transition);
  letter-spacing: .01em;
}

.b64-tab svg { width: 15px; height: 15px; flex-shrink: 0; }

.b64-tab.b64-active {
  background: var(--b64-surface);
  color: var(--b64-brand);
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}

.b64-tab:hover:not(.b64-active) {
  color: var(--b64-text);
  background: rgba(79,70,229,.06);
}

/* ══════════════════════════════════════════════════════════════════
   TOOLBAR
══════════════════════════════════════════════════════════════════ */
.b64-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.b64-toolbar-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.b64-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Buttons */
.b64-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--b64-radius-xs);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: var(--b64-transition);
  white-space: nowrap;
  letter-spacing: .01em;
  position: relative;
  overflow: hidden;
}

.b64-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.b64-btn-primary {
  background: linear-gradient(135deg, var(--b64-brand) 0%, var(--b64-brand-2) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 10px var(--b64-brand-glow);
}

.b64-btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 18px var(--b64-brand-glow);
  filter: brightness(1.08);
}

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

.b64-btn-outline {
  background: var(--b64-surface);
  color: var(--b64-text-2);
  border-color: var(--b64-border);
}

.b64-btn-outline:hover {
  border-color: var(--b64-brand);
  color: var(--b64-brand);
  background: var(--b64-brand-light);
}

.b64-btn-danger {
  background: var(--b64-surface);
  color: #e11d48;
  border-color: var(--b64-border);
}

.b64-btn-danger:hover {
  border-color: #e11d48;
  background: #fff1f2;
}

.b64-btn-success {
  background: var(--b64-surface);
  color: #16a34a;
  border-color: var(--b64-border);
}

.b64-btn-success:hover {
  border-color: #16a34a;
  background: #f0fdf4;
}

/* Live Toggle */
.b64-live-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--b64-text-2);
  cursor: pointer;
  user-select: none;
}

.b64-live-toggle input[type=checkbox] { display: none; }

.b64-switch {
  width: 40px;
  height: 22px;
  background: var(--b64-border);
  border-radius: 100px;
  position: relative;
  transition: var(--b64-transition);
  flex-shrink: 0;
}

.b64-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: var(--b64-transition);
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}

.b64-live-toggle input:checked + .b64-switch {
  background: var(--b64-brand);
}

.b64-live-toggle input:checked + .b64-switch::after {
  transform: translateX(18px);
}

/* ══════════════════════════════════════════════════════════════════
   PANELS
══════════════════════════════════════════════════════════════════ */
.b64-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.b64-panel {
  background: var(--b64-surface);
  border: 1.5px solid var(--b64-border);
  border-radius: var(--b64-radius);
  box-shadow: var(--b64-shadow);
  overflow: hidden;
  transition: box-shadow .2s;
}

.b64-panel:focus-within {
  border-color: var(--b64-border-focus);
  box-shadow: var(--b64-shadow-focus);
}

.b64-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--b64-border);
  background: var(--b64-surface-2);
}

.b64-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--b64-text-3);
}

.b64-panel-title svg { width: 13px; height: 13px; }

.b64-panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.b64-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--b64-radius-xs);
  border: 1px solid var(--b64-border);
  background: var(--b64-surface);
  color: var(--b64-text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--b64-transition);
}

.b64-icon-btn svg { width: 13px; height: 13px; }

.b64-icon-btn:hover {
  border-color: var(--b64-brand);
  color: var(--b64-brand);
  background: var(--b64-brand-light);
}

.b64-char-count {
  font-size: 11.5px;
  color: var(--b64-text-3);
  font-variant-numeric: tabular-nums;
  font-family: var(--b64-mono);
}

/* Textarea */
.b64-textarea {
  width: 100%;
  min-height: 280px;
  border: none;
  outline: none;
  resize: vertical;
  padding: 16px;
  font-family: var(--b64-mono);
  font-size: 13px;
  line-height: 1.7;
  background: transparent;
  color: var(--b64-text);
  display: block;
}

.b64-textarea::placeholder { color: var(--b64-text-3); }

/* Output textarea (readonly) */
.b64-output-area {
  width: 100%;
  min-height: 280px;
  border: none;
  outline: none;
  resize: vertical;
  padding: 16px;
  font-family: var(--b64-mono);
  font-size: 13px;
  line-height: 1.7;
  background: transparent;
  color: var(--b64-text);
  display: block;
  cursor: text;
}

.b64-output-area::placeholder { color: var(--b64-text-3); }

/* ══════════════════════════════════════════════════════════════════
   FILE INPUT PANEL
══════════════════════════════════════════════════════════════════ */
.b64-file-drop {
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px 24px;
  cursor: pointer;
  transition: var(--b64-transition);
}

.b64-file-drop:hover {
  background: var(--b64-brand-light);
}

.b64-file-drop.b64-dragover {
  background: var(--b64-brand-light);
  border-color: var(--b64-brand);
}

.b64-file-icon {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--b64-brand-light), #ddd6fe);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--b64-brand);
}

.b64-file-icon svg { width: 26px; height: 26px; }

.b64-file-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--b64-text);
  text-align: center;
}

.b64-file-label span {
  color: var(--b64-brand);
  text-decoration: underline;
  cursor: pointer;
}

.b64-file-sub {
  font-size: 12.5px;
  color: var(--b64-text-3);
  text-align: center;
}

.b64-file-chosen {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 16px;
  min-height: 280px;
  justify-content: center;
}

.b64-file-chosen-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--b64-text);
  word-break: break-all;
  text-align: center;
}

.b64-file-chosen-meta {
  font-size: 12px;
  color: var(--b64-text-3);
}

/* ══════════════════════════════════════════════════════════════════
   STATUS BAR
══════════════════════════════════════════════════════════════════ */
.b64-status {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--b64-radius-xs);
  font-size: 13px;
  font-weight: 500;
  margin-top: 16px;
}

.b64-status.b64-show { display: flex; }

.b64-status-success {
  background: var(--b64-success-bg);
  color: var(--b64-success-text);
  border: 1px solid var(--b64-success-bdr);
}

.b64-status-error {
  background: var(--b64-error-bg);
  color: var(--b64-error-text);
  border: 1px solid var(--b64-error-bdr);
}

.b64-status svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ══════════════════════════════════════════════════════════════════
   IMAGE PREVIEW
══════════════════════════════════════════════════════════════════ */
.b64-preview-wrap {
  display: none;
  padding: 16px;
  border-top: 1px solid var(--b64-border);
}

.b64-preview-wrap.b64-show { display: block; }

.b64-preview-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--b64-text-3);
  margin-bottom: 10px;
}

.b64-preview-img {
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--b64-radius-sm);
  border: 1px solid var(--b64-border);
  display: block;
  object-fit: contain;
  background: repeating-conic-gradient(var(--b64-surface-2) 0% 25%, transparent 0% 50%) 0 0 / 14px 14px;
}

/* ══════════════════════════════════════════════════════════════════
   DOWNLOAD BUTTON (in output panel)
══════════════════════════════════════════════════════════════════ */
.b64-download-bar {
  display: none;
  padding: 12px 16px;
  border-top: 1px solid var(--b64-border);
  background: var(--b64-surface-2);
}

.b64-download-bar.b64-show { display: flex; gap: 8px; flex-wrap: wrap; }

/* ══════════════════════════════════════════════════════════════════
   STATS STRIP
══════════════════════════════════════════════════════════════════ */
.b64-stats {
  display: none;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--b64-border);
  margin-top: 20px;
}

.b64-stats.b64-show { display: flex; }

.b64-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--b64-text-2);
  background: var(--b64-surface);
  border: 1px solid var(--b64-border);
  border-radius: var(--b64-radius-xs);
  padding: 5px 12px;
}

.b64-stat-label { color: var(--b64-text-3); }

.b64-stat-val {
  font-weight: 700;
  color: var(--b64-brand);
  font-family: var(--b64-mono);
}

/* ══════════════════════════════════════════════════════════════════
   COPY FLASH
══════════════════════════════════════════════════════════════════ */
.b64-copy-flash {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: #1e1b4b;
  color: #fff;
  padding: 10px 20px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 24px rgba(0,0,0,.25);
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: all .22s cubic-bezier(.34,1.56,.64,1);
  z-index: 9999;
}

.b64-copy-flash svg { width: 15px; height: 15px; }

.b64-copy-flash.b64-show {
  transform: translateY(0);
  opacity: 1;
}

/* ══════════════════════════════════════════════════════════════════
   SEO CONTENT SECTION
══════════════════════════════════════════════════════════════════ */
.b64-info {
  max-width: 1200px;
  margin: 52px auto 0;
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.b64-info-card {
  background: var(--b64-surface);
  border: 1.5px solid var(--b64-border);
  border-radius: var(--b64-radius);
  padding: 28px 24px;
  box-shadow: var(--b64-shadow);
}

.b64-info-card h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--b64-text);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.b64-info-card h3 svg {
  width: 18px;
  height: 18px;
  color: var(--b64-brand);
  flex-shrink: 0;
}

.b64-info-card p,
.b64-info-card li {
  font-size: 14px;
  color: var(--b64-text-2);
  line-height: 1.7;
}

.b64-info-card ul {
  list-style: none;
  padding: 0;
  margin-top: 8px;
}

.b64-info-card ul li {
  padding: 4px 0;
  padding-left: 18px;
  position: relative;
}

.b64-info-card ul li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--b64-brand);
  font-weight: 700;
}

/* FAQ */
.b64-faq {
  max-width: 1200px;
  margin: 24px auto 0;
  padding: 0 20px;
}

.b64-faq h2 {
  font-size: 20px;
  font-weight: 800;
  color: var(--b64-text);
  margin-bottom: 16px;
}

.b64-faq-item {
  background: var(--b64-surface);
  border: 1.5px solid var(--b64-border);
  border-radius: var(--b64-radius-sm);
  margin-bottom: 10px;
  overflow: hidden;
  transition: var(--b64-transition);
}

.b64-faq-item:hover {
  border-color: var(--b64-brand);
}

.b64-faq-q {
  width: 100%;
  text-align: left;
  padding: 16px 20px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--b64-text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.b64-faq-q svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--b64-brand);
  transition: transform .2s;
}

.b64-faq-item.b64-open .b64-faq-q svg {
  transform: rotate(180deg);
}

.b64-faq-a {
  display: none;
  padding: 0 20px 16px;
  font-size: 14px;
  color: var(--b64-text-2);
  line-height: 1.7;
  border-top: 1px solid var(--b64-border);
}

.b64-faq-item.b64-open .b64-faq-a {
  display: block;
}

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE - MOBILE
══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .b64-hero { padding: 36px 16px 40px; }
  .b64-hero h1 { font-size: 1.7rem; }

  .b64-container { padding: 20px 12px 0; }

  .b64-panels {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .b64-toolbar { gap: 6px; }

  .b64-btn {
    padding: 9px 14px;
    font-size: 13px;
    flex: 1 1 auto;
    justify-content: center;
  }

  .b64-toolbar-left { width: 100%; }
  .b64-toolbar-right { width: 100%; justify-content: flex-end; }

  .b64-mode-tabs { width: 100%; }
  .b64-tab { flex: 1; justify-content: center; }

  .b64-textarea,
  .b64-output-area { min-height: 200px; font-size: 12.5px; }

  .b64-file-drop { min-height: 180px; }

  .b64-info { grid-template-columns: 1fr; gap: 14px; }

  .b64-copy-flash { bottom: 16px; right: 16px; }
}

@media (max-width: 480px) {
  .b64-hero h1 { font-size: 1.45rem; }
  .b64-btn { font-size: 12.5px; padding: 8px 12px; }
}
