  :root {
    --bg: #04090d;
    --surface: #081420;
    --surface2: #0d1f30;
    --border: #1a3a5c;
    --border2: #0f2540;
    --blue: #38bdf8;
    --blue-dim: #1e6fa8;
    --blue-glow: rgba(56, 189, 248, 0.15);
    --blue-glow2: rgba(56, 189, 248, 0.08);
    --white: #e8f4fc;
    --white-dim: #6b8fa8;
    --green: #34d399;
    --red: #f87171;
    --yellow: #fbbf24;
    --mono: 'JetBrains Mono', monospace;
    --head: 'Oxanium', sans-serif;
  }

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

  body {
    background: var(--bg);
    color: var(--white);
    font-family: var(--mono);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
  }

  /* Background grid */
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
      linear-gradient(var(--border2) 1px, transparent 1px),
      linear-gradient(90deg, var(--border2) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
    opacity: 0.4;
  }

  body::after {
    content: '';
    position: fixed;
    top: -200px; left: 50%; transform: translateX(-50%);
    width: 800px; height: 400px;
    background: radial-gradient(ellipse, rgba(56,189,248,0.06) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
  }

  .container {
    position: relative;
    z-index: 1;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px 60px;
  }

  /* Header */
  header {
    padding: 36px 0 32px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 32px;
  }

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

  .logo-icon {
    width: 44px; height: 44px;
    border: 2px solid var(--blue);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    background: var(--blue-glow);
    box-shadow: 0 0 20px var(--blue-glow);
    font-family: var(--head);
    font-size: 18px;
    font-weight: 800;
    color: var(--blue);
  }

  h1 {
    font-family: var(--head);
    font-size: 26px;
    font-weight: 700;
    color: var(--white);
    letter-spacing: 1px;
  }

  h1 span {
    color: var(--blue);
  }

  .header-sub {
    font-size: 11px;
    color: var(--white-dim);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-top: 3px;
  }

  .badge {
    font-size: 10px;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid;
    font-family: var(--mono);
    letter-spacing: 1px;
    font-weight: 500;
  }
  .badge-blue { border-color: var(--blue); color: var(--blue); background: var(--blue-glow2); }

  .lang-switch {
    display: flex;
    gap: 2px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px;
  }
  .lang-switch a {
    color: var(--white-dim);
    text-decoration: none;
    padding: 4px 10px;
    border-radius: 5px;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    transition: all 0.2s;
  }
  .lang-switch a:hover { color: var(--white); }
  .lang-switch a.active { background: var(--blue-glow); color: var(--blue); }

  /* Mode tabs */
  .mode-tabs {
    display: flex;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 5px;
    width: fit-content;
    margin-bottom: 24px;
  }

  .tab-btn {
    padding: 10px 28px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--white-dim);
    font-family: var(--head);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
  }

  .tab-btn.active {
    background: var(--blue);
    color: #000;
    box-shadow: 0 0 16px rgba(56,189,248,0.4);
  }

  .tab-btn:hover:not(.active) {
    color: var(--white);
    background: var(--surface2);
  }

  /* Options bar */
  .options-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    align-items: center;
  }

  .option-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 14px;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
  }

  .option-toggle:hover { border-color: var(--blue-dim); }
  .option-toggle.active { border-color: var(--blue); background: var(--blue-glow); }

  .option-toggle input {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
  }
  .option-toggle:has(input:focus-visible) { outline: 2px solid var(--blue); outline-offset: 2px; }

  .toggle-dot {
    width: 28px; height: 16px;
    border-radius: 8px;
    background: var(--border);
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
  }

  .toggle-dot::after {
    content: '';
    position: absolute;
    left: 2px; top: 2px;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: var(--white-dim);
    transition: all 0.2s;
  }

  .option-toggle.active .toggle-dot { background: var(--blue); }
  .option-toggle.active .toggle-dot::after { left: 14px; background: #000; }

  .option-label {
    font-size: 11px;
    color: var(--white-dim);
    letter-spacing: 1px;
    text-transform: uppercase;
  }
  .option-toggle.active .option-label { color: var(--blue); }

  .option-select {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 14px;
    color: var(--white);
    font-family: var(--mono);
    font-size: 11px;
    cursor: pointer;
    outline: none;
    letter-spacing: 1px;
  }
  .option-select:focus { border-color: var(--blue); }

  /* Main layout */
  .main-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
  }

  @media (max-width: 720px) {
    .main-layout { grid-template-columns: 1fr; }
    header { flex-direction: column; align-items: flex-start; }
  }

  .panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: border-color 0.2s;
  }

  .panel:focus-within { border-color: var(--blue-dim); }

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

  .panel-title {
    font-family: var(--head);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
  }
  .input-title { color: var(--blue); }
  .output-title { color: var(--white-dim); }

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

  .stat-pill {
    font-size: 10px;
    color: var(--white-dim);
    background: var(--bg);
    border: 1px solid var(--border2);
    border-radius: 4px;
    padding: 2px 8px;
    letter-spacing: 0.5px;
  }

  .stat-pill.valid { color: var(--green); border-color: rgba(52,211,153,0.3); }
  .stat-pill.invalid { color: var(--red); border-color: rgba(248,113,113,0.3); }
  .stat-pill.warn { color: var(--yellow); border-color: rgba(251,191,36,0.3); }

  textarea {
    width: 100%;
    flex: 1;
    min-height: 220px;
    background: transparent;
    border: none;
    outline: none;
    color: var(--white);
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.7;
    padding: 16px;
    resize: none;
    letter-spacing: 0.3px;
  }

  textarea::placeholder { color: var(--white-dim); opacity: 0.5; }

  textarea.output-area {
    color: var(--blue);
    cursor: default;
    user-select: all;
  }

  /* Center action bar */
  .action-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 4px 0;
  }

  .action-btn {
    padding: 12px 32px;
    border-radius: 10px;
    border: 2px solid var(--blue);
    background: var(--blue-glow);
    color: var(--blue);
    font-family: var(--head);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    position: relative;
    overflow: hidden;
  }

  .action-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--blue);
    opacity: 0;
    transition: opacity 0.2s;
  }

  .action-btn:hover { box-shadow: 0 0 24px var(--blue-glow); color: #000; }
  .action-btn:hover::before { opacity: 1; }
  .action-btn span { position: relative; z-index: 1; }

  .action-btn.secondary {
    border-color: var(--border);
    background: transparent;
    color: var(--white-dim);
    font-size: 11px;
    padding: 9px 20px;
  }
  .action-btn.secondary:hover { border-color: var(--white-dim); color: var(--white); }
  .action-btn.secondary:hover::before { opacity: 0; }

  .swap-icon {
    font-size: 20px;
    color: var(--white-dim);
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
    line-height: 1;
    padding: 6px;
  }
  .swap-icon:hover { color: var(--blue); transform: rotate(180deg); }

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

footer {
  margin-top: 200px;
  padding: 20px 0 15px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-bottom: 30px;
}

.footer-links a {
  text-decoration: none;
  color: inherit;
  font-family: 'Space Mono', monospace;
  font-size: 0.55rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.footer-links a:hover {
  opacity: 1;
  color: #e8f542;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 0;
  align-items: center;
}

.footer-links a:not(:last-child)::after {
  content: '|';
  margin: 0 0.6em;
  opacity: 0.3;
  color: inherit;
}

  .icon-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--white-dim);
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
  }

  .icon-btn:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-glow2); }
  .icon-btn.success { border-color: var(--green); color: var(--green); background: rgba(52,211,153,0.08); }
  .icon-btn svg { width: 13px; height: 13px; }

  /* File drop zone */
  .drop-zone {
    min-height: 280px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 30px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
  }

  .drop-zone.has-file { justify-content: flex-start; padding: 20px; }

  .drop-zone.dragover {
    background: var(--blue-glow);
    border-color: var(--blue) !important;
  }

  .drop-icon {
    width: 56px; height: 56px;
    border-radius: 14px;
    border: 2px dashed var(--blue-dim);
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
    color: var(--blue-dim);
    transition: all 0.2s;
    background: var(--blue-glow2);
  }

  .drop-zone:hover .drop-icon, .drop-zone.dragover .drop-icon {
    border-color: var(--blue);
    color: var(--blue);
    box-shadow: 0 0 20px var(--blue-glow);
  }

  .drop-text { font-size: 13px; color: var(--white-dim); text-align: center; line-height: 1.6; }
  .drop-text strong { color: var(--blue); }

  .drop-hint { font-size: 10px; color: var(--white-dim); opacity: 0.5; letter-spacing: 1px; text-transform: uppercase; }

  /* File info card */
  .file-info-card {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    display: none;
  }
  .file-info-card.visible { display: block; }

  .file-info-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
  }

  .file-type-icon {
    width: 40px; height: 40px;
    border-radius: 8px;
    background: var(--blue-glow);
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
  }

  .file-name { font-size: 13px; font-weight: 500; color: var(--white); word-break: break-all; }
  .file-meta { font-size: 10px; color: var(--white-dim); margin-top: 2px; letter-spacing: 0.5px; }

  .file-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
  }

  .file-stat {
    background: var(--surface);
    border-radius: 6px;
    padding: 8px 10px;
    border: 1px solid var(--border2);
  }

  .file-stat-label { font-size: 9px; color: var(--white-dim); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 3px; }
  .file-stat-value { font-size: 13px; color: var(--blue); font-weight: 500; }

  /* Image preview */
  .img-preview-wrap {
    width: 100%; margin-top: 10px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    max-height: 180px;
    display: none;
    background: repeating-conic-gradient(#1a3a5c 0% 25%, transparent 0% 50%) 0 0 / 12px 12px;
  }
  .img-preview-wrap.visible { display: block; }
  .img-preview-wrap img { width: 100%; max-height: 180px; object-fit: contain; display: block; }

  /* Progress bar */
  .progress-bar-wrap {
    width: 100%; height: 3px;
    background: var(--border2);
    border-radius: 2px;
    overflow: hidden;
    display: none;
    margin-top: 8px;
  }
  .progress-bar-wrap.visible { display: block; }
  .progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--blue-dim), var(--blue));
    border-radius: 2px;
    transition: width 0.3s;
    width: 0%;
    box-shadow: 0 0 6px var(--blue);
  }

  /* Info strip */
  .info-strip {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 16px;
    font-size: 11px;
  }

  .info-item {
    display: flex; align-items: center; gap: 7px;
  }

  .info-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--blue-dim);
    flex-shrink: 0;
  }

  .info-item.ok .info-dot { background: var(--green); }
  .info-item.err .info-dot { background: var(--red); }
  .info-item.warn .info-dot { background: var(--yellow); }

  .info-key { color: var(--white-dim); }
  .info-val { color: var(--white); font-weight: 500; }
  .info-val.blue { color: var(--blue); }
  .info-val.green { color: var(--green); }
  .info-val.red { color: var(--red); }

  /* History panel */
  .history-section {
    margin-top: 20px;
  }

  .section-title {
    font-family: var(--head);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--white-dim);
    margin-bottom: 10px;
    display: flex; align-items: center; gap: 8px;
  }

  .section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
  }

  .history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .history-item {
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 11px;
  }

  .history-item:hover { border-color: var(--blue-dim); background: var(--surface2); }

  .hist-op {
    font-family: var(--head);
    font-weight: 700;
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 2px 7px;
    border-radius: 4px;
    flex-shrink: 0;
  }
  .hist-op.enc { background: rgba(56,189,248,0.15); color: var(--blue); }
  .hist-op.dec { background: rgba(52,211,153,0.12); color: var(--green); }

  .hist-preview { flex: 1; color: var(--white-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); }
  .hist-meta { color: var(--white-dim); opacity: 0.5; flex-shrink: 0; }
  .hist-load-btn {
    color: var(--blue); font-size: 10px; cursor: pointer;
    border: 1px solid var(--border); border-radius: 4px;
    padding: 2px 8px; flex-shrink: 0;
    transition: all 0.15s;
    background: none; font-family: var(--mono);
  }
  .hist-load-btn:hover { background: var(--blue-glow2); border-color: var(--blue-dim); }

  /* Error / notification */
  .notification {
    position: fixed;
    bottom: 24px; right: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    font-size: 12px;
    display: flex; align-items: center; gap: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    z-index: 100;
    transform: translateY(80px);
    opacity: 0;
    transition: all 0.3s;
    max-width: 320px;
  }
  .notification.show { transform: translateY(0); opacity: 1; }
  .notification.success { border-color: var(--green); }
  .notification.error { border-color: var(--red); }
  .notif-icon { font-size: 18px; }
  .notif-text { flex: 1; line-height: 1.4; }
  .notif-title { color: var(--white); font-weight: 600; margin-bottom: 2px; }
  .notif-sub { color: var(--white-dim); font-size: 10px; }

  /* Live indicator */
  @keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
  }
  .live-dot {
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--green);
    animation: blink 1.5s infinite;
    margin-right: 4px;
  }

  /* Scrollbar */
  ::-webkit-scrollbar { width: 4px; height: 4px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--blue-dim); }

  /* Decode from file output */
  .decode-output-section {
    margin-top: 16px;
    display: none;
  }
  .decode-output-section.visible { display: block; }

  /* Floating line count */
  .char-counter { font-size: 10px; color: var(--white-dim); opacity: 0.6; padding: 0 16px 8px; text-align: right; }

  /* Input hidden */
  #fileInput { display: none; }

  /* Formerly inline styles, moved here for CSP style-src compliance */
  .header-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
  #decodeInput { min-height: 240px; }
  #decodeValidIndicator { padding: 4px 0; }
  #decodedInfoArea { padding: 16px; flex: 1; }
  #decodeStats { margin-bottom: 12px; }
  #decodeTextOutput { min-height: 80px; }

  /* Animated border on drag */
  @keyframes border-dance {
    0% { background-position: 0 0, 100% 100%, 0 100%, 100% 0; }
    100% { background-position: 100% 0, 0 100%, 0 0, 100% 100%; }
  }

  .full-width { grid-column: 1 / -1; }
  .center-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 8px 0;
  }

  /* three-col layout for text mode */
  .text-layout {
    display: grid;
    grid-template-columns: 1fr 120px 1fr;
    gap: 14px;
    margin-bottom: 14px;
    align-items: stretch;
  }

  @media (max-width: 760px) {
    .text-layout {
      grid-template-columns: 1fr;
    }
    .center-col { padding: 4px 0; flex-direction: row; flex-wrap: wrap; justify-content: center; }
    .action-btn { width: auto; }
  }

  .output-placeholder {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 180px; color: var(--white-dim); opacity: 0.4; font-size: 12px; gap: 8px; text-align: center;
  }
  .output-placeholder svg { width: 32px; height: 32px; opacity: 0.5; }

  /* Utility decode section */
  .decode-panel { margin-top: 16px; }

  .section-divider {
    display: flex; align-items: center; gap: 12px;
    margin: 22px 0 16px;
    font-size: 10px; letter-spacing: 2px; text-transform: uppercase; color: var(--white-dim);
  }
  .section-divider::before, .section-divider::after {
    content: ''; flex: 1; height: 1px; background: var(--border);
  }

