:root{
  --ink: #0a0a0a;
  --ink-soft: #a0a0a0;
  --paper: #f5f5f5;
  --paper-card: #1e1e1e;
  --rule: #404040;
  --gold: #d4a017;
  --gold-dim: #a68012;
  --highlight: #ffd700;
  --highlight-text: #0a0a0a;
  --red-tab: #c74e42;
  --shadow: rgba(0, 0, 0, 0.6);
}

  * { box-sizing: border-box; }

  html, body {
    margin: 0;
    padding: 0;
    background: var(--ink);
    color: var(--paper);
    font-family: 'Iowan Old Style','Palatino Linotype',Palatino,Georgia,serif;
    min-height: 100vh;
  }

  body {
    background-image:
      radial-gradient(circle at 15% 10%, rgba(212,160,23,0.1), transparent 40%),
      radial-gradient(circle at 85% 90%, rgba(212,160,23,0.08), transparent 45%);
  }

  .wrap {
    max-width: 920px;
    margin: 0 auto;
    padding: 48px 24px 80px;
  }

  header.hero {
    text-align: center;
    margin-bottom: 40px;
    position: relative;
  }

  .eyebrow {
    font-family: 'Courier New', monospace;
    letter-spacing: 0.35em;
    text-transform: uppercase;
    font-size: 11px;
    color: var(--gold);
    margin-bottom: 14px;
  }

  h1 {
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: 700;
    font-size: clamp(36px, 6vw, 56px);
    margin: 0 0 10px;
    letter-spacing: -0.01em;
    color: var(--red-tab);
  }

  h1 em {
    color: var(--gold);
    font-style: italic;
  }

  .subtitle {
    color: #fff;
    font-size: 16px;
    max-width: 520px;
    margin: 0 auto;
    line-height: 1.5;
  }

  .card {
    background: var(--paper-card);
    color: var(--paper);
    border-radius: 3px;
    box-shadow: 0 18px 40px var(--shadow), 0 1px 0 rgba(255,255,255,0.4) inset;
    position: relative;
    margin-bottom: 28px;
    overflow: hidden;
  }

  .card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 6px;
    background: linear-gradient(90deg, var(--red-tab), var(--gold));
  }

  .card-body { padding: 28px 30px 30px; }

  .card-label {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: #fff;
    margin: 0 0 14px;
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .card-label .num {
    background: var(--ink);
    color: var(--red-tab);
    border-radius: 50%;
    width: 20px; height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
  }

  .dropzone {
    border: 2px dashed var(--rule);
    border-radius: 3px;
    padding: 26px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
    background: rgba(212,160,23,0.05);
  }
  .dropzone:hover, .dropzone.dragover {
    border-color: var(--gold);
    background: rgba(212,160,23,0.1);
  }
  .dropzone input[type=file] { display:none; }
  .dz-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
  .dz-sub { font-size: 13px; color: var(--ink-soft); }
  .dz-icon { font-size: 26px; margin-bottom: 8px; opacity: 0.7; }

  .file-status {
    margin-top: 12px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: var(--ink-soft);
    display: none;
    align-items: center;
    gap: 8px;
  }
  .file-status.active { display: flex; }
  .file-status .dot { width:8px; height:8px; border-radius:50%; background:#3a7d44; flex-shrink:0; }

  .or-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px 0;
    color: #fff;
    font-size: 11px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
  }
  .or-divider::before, .or-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--rule);
  }

  textarea {
    width: 100%;
    min-height: 110px;
    resize: vertical;
    border: 1px solid var(--rule);
    border-radius: 3px;
    padding: 12px 14px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    background: var(--paper-card);
    color: var(--paper);
    line-height: 1.5;
  }
  textarea:focus, input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

  .search-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
  }

  .search-input-wrap {
    position: relative;
    flex: 1 1 260px;
  }

  .search-input-wrap input[type=text] {
    width: 100%;
    padding: 14px 16px;
    font-size: 18px;
    font-family: Georgia, serif;
    border: 2px solid var(--ink);
    border-radius: 3px;
    background: var(--paper-card);
    color: var(--paper);
  }

  .search-btn {
    background: var(--gold);
    color: var(--ink);
    border: none;
    border-radius: 3px;
    padding: 0 26px;
    font-family: 'Courier New', monospace;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 13px;
    cursor: pointer;
    transition: background .15s ease;
  }
  .search-btn:hover { background: var(--gold-dim); }
  .search-btn:disabled { opacity: 0.4; cursor: not-allowed; }

  .options-row {
    display: flex;
    gap: 20px;
    margin-top: 14px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--ink-soft);
  }
  .options-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
  }
  .options-row input[type=checkbox] { accent-color: var(--gold-dim); width:14px; height:14px; }

  .results-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 18px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .results-count {
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #fff;
    letter-spacing: 0.05em;
  }
  .results-count b { color: var(--gold); font-size: 15px; }

  .export-btn {
    background: transparent;
    border: 1px solid var(--rule);
    color: #fff;
    padding: 6px 14px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
  }
  .export-btn:hover { border-color: var(--gold); color: var(--gold); }
  .export-btn:disabled { opacity: 0.3; cursor: not-allowed; }

  .results-list {
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .result-item {
    background: var(--paper-card);
    color: var(--paper);
    border-left: 3px solid var(--gold);
    padding: 14px 20px 14px 18px;
    font-size: 15.5px;
    line-height: 1.6;
    border-bottom: 1px solid var(--rule);
    position: relative;
    animation: fadeIn .25s ease both;
  }
  .result-item:first-child { border-top-left-radius: 3px; border-top-right-radius: 3px; }
  .result-item:last-child { border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-bottom: none;}

  .result-index {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: var(--gold-dim);
    margin-right: 8px;
  }

  mark {
    background: var(--highlight);
    color: var(--highlight-text);
    padding: 1px 3px;
    border-radius: 2px;
    font-weight: 700;
  }

  @keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #fff;
    font-size: 14px;
  }
  .empty-state .big { font-size: 30px; margin-bottom: 10px; opacity: .6; color: #fff;}

  footer {
    text-align: center;
    margin-top: 40px;
    font-size: 12px;
    color: var(--ink-soft);
    font-family: 'Courier New', monospace;
    letter-spacing: 0.05em;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
  }

  @media (max-width: 560px) {
    .card-body { padding: 20px 18px 22px; }
    .search-row { flex-direction: column; }
    .search-btn { padding: 12px; }
  }

  mark.mark-0 { background: var(--highlight); color: var(--highlight-text); }
  mark.mark-1 { background: #a9c98f; color: var(--ink); }
  mark.mark-2 { background: #e2a0a0; color: var(--ink); }
  mark.mark-3 { background: #9dc3e6; color: var(--ink); }
  mark { padding: 1px 3px; border-radius: 2px; font-weight: 700; }

  .regex-hint {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: var(--ink-soft);
    margin-top: 10px;
    display: none;
    line-height: 1.5;
  }
  .regex-hint.active { display: block; }
  .options-row label.disabled { opacity: 0.4; cursor: not-allowed; }

  .result-item { display: flex; flex-direction: column; gap: 6px; }
  .result-main { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
  .result-text { flex: 1; }

  .context-line {
    display: block;
    color: var(--ink-soft);
    font-size: 13.5px;
    line-height: 1.5;
    opacity: 0.75;
    padding-left: 22px;
  }
  .context-marker {
    font-family: 'Courier New', monospace;
    font-size: 10px;
    color: var(--rule);
    margin-right: 6px;
  }

  .copy-btn {
    background: transparent;
    border: 1px solid var(--rule);
    color: var(--ink-soft);
    border-radius: 3px;
    width: 28px; height: 28px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    font-size: 13px;
    transition: all .15s ease;
  }
  .copy-btn:hover { border-color: var(--gold); color: var(--gold-dim); background: rgba(212,160,23,0.1); }
  .copy-btn.copied { border-color: #3a7d44; color: #3a7d44; }

  .header-actions { display: flex; gap: 8px; }

  .stats-panel {
    background: var(--paper-card);
    color: var(--paper);
    border-radius: 3px;
    padding: 22px 26px;
    margin-bottom: 20px;
    box-shadow: 0 14px 30px var(--shadow);
    display: none;
    position: relative;
    overflow: hidden;
  }
  .stats-panel::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 6px;
    background: linear-gradient(90deg, var(--gold), var(--red-tab));
  }
  .stats-panel.active { display: block; }

  .stats-summary {
    display: flex;
    gap: 32px;
    flex-wrap: wrap;
    margin-bottom: 18px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--rule);
  }
  .stats-summary .stat-num {
    font-size: 26px;
    font-weight: 700;
    color: var(--gold-dim);
    display: block;
    font-family: Georgia, serif;
    line-height: 1.1;
  }
  .stats-summary .stat-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-soft);
    font-family: 'Courier New', monospace;
  }

  .stat-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
  .stat-bar-row:last-child { margin-bottom: 0; }
  .stat-bar-word {
    font-family: 'Courier New', monospace;
    font-size: 12.5px;
    width: 130px;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .stat-bar-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
  .stat-bar-track { flex: 1; height: 14px; background: rgba(255,255,255,0.05); border-radius: 2px; overflow: hidden; }
  .stat-bar-fill { height: 100%; border-radius: 2px; transition: width .5s ease; }
  .stat-bar-count { font-family: 'Courier New', monospace; font-size: 12px; color: var(--ink-soft); width: 92px; text-align: right; flex-shrink: 0; }

  .toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--ink);
    color: var(--paper);
    padding: 10px 20px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: all .25s ease;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

  .page-badge {
    display: inline-flex;
    align-items: center;
    font-family: 'Courier New', monospace;
    font-size: 10.5px;
    letter-spacing: 0.03em;
    color: var(--red-tab);
    border: 1px solid var(--red-tab);
    border-radius: 10px;
    padding: 1px 8px;
    margin-right: 8px;
    white-space: nowrap;
    cursor: default;
  }
  .page-badge.approx { color: var(--gold-dim); border-color: var(--gold-dim); }

  .options-row select {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    border: 1px solid var(--rule);
    border-radius: 3px;
    padding: 2px 4px;
    background: var(--paper-card);
    color: var(--paper);
  }

  .file-list { display: none; margin-top: 14px; }
  .file-list.active { display: block; }

  .file-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-soft);
    margin-bottom: 8px;
  }

  .clear-all-btn {
    background: none;
    border: none;
    color: var(--red-tab);
    font-family: 'Courier New', monospace;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
  }
  .clear-all-btn:hover { color: var(--gold-dim); }

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

  .file-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--paper-card);
    border: 1px solid var(--rule);
    border-radius: 3px;
    padding: 8px 10px;
  }
  .file-chip.loading { border-color: var(--gold); background: rgba(212,160,23,0.1); }
  .file-chip.error { border-color: var(--red-tab); background: rgba(199,78,66,0.1); }

  .file-chip-icon { font-size: 15px; flex-shrink: 0; }

  .file-chip-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .file-chip-name {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--paper);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .file-chip-meta {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: var(--ink-soft);
  }
  .file-chip.error .file-chip-meta { color: var(--red-tab); }

  .file-chip-remove {
    background: transparent;
    border: 1px solid var(--rule);
    color: var(--ink-soft);
    border-radius: 3px;
    width: 24px; height: 24px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    font-size: 12px;
    transition: all .15s ease;
  }
  .file-chip-remove:hover { border-color: var(--red-tab); color: var(--red-tab); background: rgba(199,78,66,0.1); }

  .file-tag {
    display: inline-flex;
    align-items: center;
    font-family: 'Courier New', monospace;
    font-size: 10.5px;
    color: var(--ink-soft);
    border: 1px solid var(--rule);
    border-radius: 10px;
    padding: 1px 8px;
    margin-right: 6px;
    white-space: nowrap;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sort-filter-panel {
    background: var(--paper-card);
    color: var(--paper);
    border-radius: 3px;
    padding: 16px 22px;
    margin-bottom: 20px;
    box-shadow: 0 10px 22px var(--shadow);
    display: none;
  }
  .sort-filter-panel.active { display: block; }

  .sfp-row {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
  }
  .sfp-row + .sfp-row { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--rule); }

  .sfp-label {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-soft);
    flex-shrink: 0;
  }

  .segmented {
    display: inline-flex;
    border: 1px solid var(--ink);
    border-radius: 3px;
    overflow: hidden;
  }
  .segmented-btn {
    background: transparent;
    border: none;
    color: var(--paper);
    padding: 6px 14px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
  }
  .segmented-btn + .segmented-btn { border-left: 1px solid var(--ink); }
  .segmented-btn.active { background: var(--ink); color: var(--paper-card); }
  .segmented-btn:not(.active):hover { background: rgba(255,255,255,0.05); }

  .file-filter-chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
  .file-filter-chip {
    background: var(--paper-card);
    border: 1px solid var(--rule);
    color: var(--ink-soft);
    border-radius: 12px;
    padding: 4px 12px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    cursor: pointer;
    transition: all .15s ease;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .file-filter-chip.active { background: var(--gold); border-color: var(--gold-dim); color: var(--ink); font-weight: 600; }
  .file-filter-chip:not(.active):hover { border-color: var(--gold-dim); color: var(--gold-dim); }

  .sfp-quick-link {
    background: none;
    border: none;
    color: var(--rule);
    font-family: 'Courier New', monospace;
    font-size: 11px;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
  }
  .sfp-quick-link:hover { color: var(--gold-dim); }

  .group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 18px 0 8px;
    font-family: 'Courier New', monospace;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--gold-dim);
  }
  .group-header:first-child { margin-top: 0; }
  .group-header::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--rule);
  }