:root {
    --bg: #0a0a0a;
    --surface: #111111;
    --surface2: #1a1a1a;
    --surface3: #222222;
    --border: #2a2a2a;
    --border2: #3a3a3a;
    --text: #e8e8e8;
    --muted: #666;
    --accent: #00ff88;
    --accent2: #00cc6a;
    --accent-dim: rgba(0,255,136,0.08);
    --accent-dim2: rgba(0,255,136,0.15);
    --warn: #ff6b35;
    --info: #3d9aff;
    --mono: 'Share Tech Mono', monospace;
    --sans: 'Syne', sans-serif;
  }

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

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

  /* Grid bg */
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
      linear-gradient(rgba(0,255,136,0.03) 1px, transparent 1px),
      linear-gradient(90deg, rgba(0,255,136,0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
  }

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

  /* HEADER */
  header {
    padding: 2.5rem 0 2rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2.5rem;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
  }

  .logo {
    font-family: var(--sans);
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.03em;
    line-height: 1;
  }

  .logo span {
    color: var(--accent);
  }

  .tagline {
    font-size: 0.75rem;
    color: var(--muted);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-top: 6px;
  }

  .badge {
    font-size: 0.7rem;
    padding: 4px 10px;
    border: 1px solid var(--accent);
    color: var(--accent);
    border-radius: 2px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    opacity: 0.7;
  }

  /* TABS */
  .tabs {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 2rem;
    width: fit-content;
  }

  .tab {
    padding: 10px 28px;
    font-family: var(--mono);
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    background: transparent;
    color: var(--muted);
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
  }

  .tab.active {
    background: var(--accent-dim2);
    color: var(--accent);
  }

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

  .tab + .tab {
    border-left: 1px solid var(--border);
  }

  /* LAYOUT */
  .main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
  }

  @media (max-width: 720px) {
    .main-grid { grid-template-columns: 1fr; }
  }

  /* PANELS */
  .panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
  }

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

  .panel-title {
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .panel-badge {
    font-size: 0.65rem;
    padding: 2px 8px;
    background: var(--surface3);
    border-radius: 2px;
    color: var(--muted);
    letter-spacing: 0.06em;
  }

  .panel-body {
    padding: 16px;
  }

  textarea {
    width: 100%;
    min-height: 180px;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.85rem;
    line-height: 1.7;
    resize: vertical;
    outline: none;
  }

  textarea::placeholder { color: var(--muted); }

  /* BUTTONS */
  .btn-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface2);
  }

  .btn {
    font-family: var(--mono);
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    padding: 8px 18px;
    border-radius: 3px;
    border: 1px solid var(--border2);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transition: all 0.12s;
    text-transform: uppercase;
  }

  .btn:hover { background: var(--surface3); border-color: var(--border2); }
  .btn:active { transform: scale(0.98); }

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

  .btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }

  .btn-ghost {
    border-color: transparent;
    color: var(--muted);
  }

  .btn-ghost:hover { color: var(--text); background: var(--surface3); border-color: var(--border); }

  /* STATS */
  .stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 1.5rem;
  }

  .stat-box {
    background: var(--surface);
    padding: 18px 16px;
    text-align: center;
  }

  .stat-val {
    font-family: var(--sans);
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
    margin-bottom: 6px;
  }

  .stat-val.neutral { color: var(--text); }
  .stat-val.warn { color: var(--warn); }

  .stat-label {
    font-size: 0.65rem;
    color: var(--muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }

  /* RATIO BAR */
  .ratio-section {
    padding: 16px;
    border-bottom: 1px solid var(--border);
  }

  .ratio-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--muted);
    margin-bottom: 8px;
    letter-spacing: 0.06em;
  }

  .ratio-track {
    height: 8px;
    background: var(--surface3);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
  }

  .ratio-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.5s cubic-bezier(0.4,0,0.2,1);
    position: relative;
  }

  .ratio-fill::after {
    content: '';
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 3px;
    background: #fff;
    opacity: 0.4;
  }

  /* CODE TABLE */
  .code-table-wrap {
    overflow-x: auto;
    max-height: 280px;
    overflow-y: auto;
  }

  table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
  }

  thead th {
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
    position: sticky;
    top: 0;
    text-align: left;
    white-space: nowrap;
  }

  tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
  }

  tbody tr:hover { background: var(--surface2); }
  tbody tr:last-child { border-bottom: none; }

  td {
    padding: 8px 12px;
    vertical-align: middle;
  }

  .char-cell {
    font-size: 0.9rem;
    background: var(--surface3);
    display: inline-block;
    width: 28px;
    height: 28px;
    text-align: center;
    line-height: 28px;
    border-radius: 3px;
    color: var(--text);
  }

  .code-bits {
    font-size: 0.75rem;
    color: var(--accent);
    letter-spacing: 0.06em;
    word-break: break-all;
  }

  .freq-mini-bar {
    display: inline-block;
    height: 6px;
    background: var(--info);
    border-radius: 2px;
    vertical-align: middle;
    opacity: 0.7;
  }

  .saved-pos { color: var(--accent); }
  .saved-neg { color: var(--warn); }

  /* BIT STREAM */
  .bitstream-wrap {
    font-size: 0.72rem;
    line-height: 2;
    word-break: break-all;
    max-height: 120px;
    overflow-y: auto;
    color: var(--muted);
    padding: 14px 16px;
    background: var(--surface2);
    border-top: 1px solid var(--border);
  }

  .bitstream-wrap .chunk { color: var(--text); margin-right: 4px; }
  .bitstream-wrap .ellipsis { color: var(--accent); opacity: 0.5; }

  /* TREE VIZ */
  .tree-panel {
    margin-bottom: 1.5rem;
  }

  #treeCanvas {
    width: 100%;
    display: block;
    background: var(--surface);
    border-radius: 0 0 6px 6px;
  }

  /* DECOMPRESS styles removed (section deleted from HTML) */

  /* FILE DROP */
  .drop-zone {
    border: 1px dashed var(--border2);
    border-radius: 4px;
    padding: 24px;
    text-align: center;
    color: var(--muted);
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.15s;
    margin: 16px;
    letter-spacing: 0.06em;
  }

  .drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
  }

  .drop-icon {
    font-size: 1.8rem;
    display: block;
    margin-bottom: 8px;
    opacity: 0.5;
  }

  /* EMPTY STATE */
  .empty-state {
    padding: 40px 16px;
    text-align: center;
    color: var(--muted);
    font-size: 0.78rem;
    letter-spacing: 0.06em;
  }

  .empty-state .big {
    font-family: var(--sans);
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--surface3);
    display: block;
    margin-bottom: 10px;
  }

  /* SCROLLBAR */
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: var(--surface2); }
  ::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

  /* ANIM */
  @keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
  .fade-in { animation: fadeIn 0.25s ease forwards; }

  @keyframes pulse {
    0%,100% { opacity: 1; }
    50% { opacity: 0.4; }
  }

  .processing { animation: pulse 1s infinite; color: var(--accent); }

  /* section toggle */
  .section { display: none; }
  .section.active { display: block; }

  /* copy toast */
  .toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--accent);
    color: #000;
    font-family: var(--mono);
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    padding: 10px 20px;
    border-radius: 4px;
    z-index: 999;
    opacity: 0;
    transform: translateY(8px);
    transition: all 0.2s;
    pointer-events: none;
  }

  .toast.show { opacity: 1; transform: none; }