:root {
  --bg: #0d130f;
  --bg-soft: #121912;
  --panel: #171f1a;
  --panel-raised: #1b241f;
  --ink: #ede1c0;
  --ink-dim: #b6a882;
  --ink-mute: #7a7056;
  --gold: #d4a855;
  --gold-bright: #ead08a;
  --gold-deep: #8f6b26;
  --moss: #748a3f;
  --moss-deep: #4d6025;
  --crimson: #b85449;
  --border: rgba(212, 168, 85, 0.18);
  --border-soft: rgba(212, 168, 85, 0.08);
  --shadow-warm: 0 10px 30px rgba(143, 107, 38, 0.08), 0 2px 8px rgba(0, 0, 0, 0.4);
}

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

body {
  background:
    radial-gradient(1200px 600px at 15% -5%, rgba(212, 168, 85, 0.05), transparent 60%),
    radial-gradient(900px 500px at 85% 5%, rgba(117, 138, 62, 0.04), transparent 60%),
    linear-gradient(180deg, #0a100c 0%, var(--bg) 40%, #080c09 100%);
  color: var(--ink);
  font-family: 'Crimson Pro', 'Iowan Old Style', Georgia, serif;
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 3.5rem 2rem 4rem;
}

/* ---------- Hero ---------- */
.hero { margin-bottom: 3rem; }
.hero-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2.5rem;
  align-items: end;
}
.hero-text { min-width: 0; }
.hero-art {
  width: 240px;
  align-self: end;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.45));
  transform: rotate(-4deg);
  transition: transform 400ms cubic-bezier(.2,.8,.2,1);
}
.hero-art:hover { transform: rotate(-2deg) translateY(-3px); }
.hero-art img { width: 100%; height: auto; display: block; }
.hero-rule {
  height: 1px;
  width: 100%;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: 0.4;
  margin-bottom: 1.75rem;
}
.hero-eyebrow {
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.9rem;
  font-weight: 500;
}
.hero-title {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: clamp(2.8rem, 6vw, 4.2rem);
  letter-spacing: 0.02em;
  margin: 0 0 0.6rem;
  color: var(--ink);
  line-height: 1.02;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}
.hero-sub {
  font-size: 1.12rem;
  color: var(--ink-dim);
  margin: 0;
  max-width: 640px;
  line-height: 1.55;
}
.ornament {
  margin-top: 1.6rem;
  color: var(--gold);
  opacity: 0.45;
  max-width: 220px;
}
.ornament svg { width: 100%; height: 14px; display: block; }

.hero-actions {
  margin-top: 1.4rem;
  display: flex;
  align-items: baseline;
  gap: 1.2rem;
  flex-wrap: wrap;
}
.text-link {
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 0 0 2px 0;
  color: var(--gold);
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease;
}
.text-link:hover { color: var(--gold-bright); border-bottom-color: var(--gold); }
.kbd-hint {
  color: var(--ink-mute);
  font-size: 0.82rem;
  font-style: italic;
  letter-spacing: 0.02em;
}
.kbd-hint kbd {
  font-family: 'JetBrains Mono', monospace;
  font-style: normal;
  font-size: 0.7rem;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  margin: 0 1px;
  color: var(--ink-dim);
  box-shadow: 0 1px 0 rgba(0,0,0,0.3);
}

/* ---------- Panel base ---------- */
.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-raised) 100%);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow-warm);
  position: relative;
}
.panel::before,
.panel::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  pointer-events: none;
  opacity: 0.7;
}
.panel::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid var(--gold);
  border-left: 2px solid var(--gold);
}
.panel::after {
  bottom: -1px;
  right: -1px;
  border-bottom: 2px solid var(--gold);
  border-right: 2px solid var(--gold);
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--border-soft);
}
.panel-head h2 {
  font-family: 'Cinzel', serif;
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  margin: 0;
  color: var(--gold-bright);
}
.hint {
  font-size: 0.78rem;
  color: var(--ink-mute);
  letter-spacing: 0.03em;
  font-style: italic;
  font-family: 'Crimson Pro', serif;
}

/* ---------- Settings ---------- */
.settings {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0 2rem;
  margin-bottom: 1.5rem;
  padding: 1.4rem 1.6rem;
  align-items: start;
}
.setting { display: flex; flex-direction: column; }
.setting label {
  display: block;
  font-family: 'Cinzel', serif;
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.65rem;
  font-weight: 500;
}
.setting input[type="number"] {
  width: 100%;
  background: #0a0f0c;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--ink);
  padding: 0.65rem 0.8rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.setting input[type="number"]:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(212, 168, 85, 0.15);
}
.setting.is-disabled { opacity: 0.45; pointer-events: none; }
.setting.is-disabled input { cursor: not-allowed; }

/* Segmented control */
.segmented {
  display: inline-flex;
  background: #0a0f0c;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px;
  width: 100%;
}
.seg-opt {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--ink-dim);
  padding: 0.55rem 0.5rem;
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  cursor: pointer;
  border-radius: 2px;
  transition: color 120ms ease, background 160ms ease, box-shadow 160ms ease;
}
.seg-opt.is-active {
  background: linear-gradient(180deg, var(--gold) 0%, var(--gold-deep) 100%);
  color: #1a1208;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.22) inset, 0 2px 6px rgba(0, 0, 0, 0.3);
  font-weight: 600;
}
.seg-opt:hover:not(.is-active) { color: var(--ink); }

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  margin: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: #0a0f0c;
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}
.slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 20px;
  height: 20px;
  background: var(--ink-dim);
  border-radius: 50%;
  transition: left 160ms ease, background 160ms ease;
}
.switch input:checked + .slider {
  background: linear-gradient(180deg, var(--moss) 0%, var(--moss-deep) 100%);
  border-color: var(--moss);
}
.switch input:checked + .slider::before {
  left: 25px;
  background: var(--ink);
}

/* ---------- Inputs ---------- */
.inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}
.input-panel { display: flex; flex-direction: column; }

.mono-area {
  flex: 1;
  min-height: 240px;
  background: #0a0f0c;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--ink);
  font-family: 'JetBrains Mono', Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  padding: 0.9rem 1rem;
  resize: vertical;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.mono-area:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(212, 168, 85, 0.12);
}
.mono-area.drag-over {
  border-color: var(--gold-bright);
  box-shadow: 0 0 0 3px rgba(234, 208, 138, 0.18);
}
.mono-area::placeholder {
  color: var(--ink-mute);
  font-style: italic;
}

.panel-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
  font-size: 0.78rem;
  color: var(--ink-mute);
}
.stat-line { font-family: 'JetBrains Mono', monospace; letter-spacing: 0.04em; }
.link-btn {
  background: none;
  border: none;
  color: var(--gold);
  font-family: 'Cinzel', serif;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0;
  font-weight: 500;
}
.link-btn:hover { color: var(--gold-bright); }

/* ---------- Action row ---------- */
.action-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  margin: 2.2rem 0 2.5rem;
  flex-wrap: wrap;
}

.btn-primary {
  background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold) 55%, var(--gold-deep) 100%);
  color: #1a1308;
  border: 1px solid var(--gold-deep);
  border-radius: 3px;
  padding: 1rem 2.8rem;
  font-family: 'Cinzel', serif;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.4) inset,
    0 -1px 0 rgba(0, 0, 0, 0.3) inset,
    0 8px 22px rgba(143, 107, 38, 0.38),
    0 2px 6px rgba(0, 0, 0, 0.45);
  transition: transform 90ms ease, filter 140ms ease, box-shadow 140ms ease;
}
.btn-primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); filter: brightness(0.96); }
.btn-primary:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 3px;
}

.btn-secondary {
  background: #0c110e;
  color: var(--gold-bright);
  border: 1px solid var(--gold);
  border-radius: 3px;
  padding: 0.55rem 1.2rem;
  font-family: 'Cinzel', serif;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.btn-secondary:hover {
  background: var(--gold);
  color: #1a1208;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.55rem 1.2rem;
  font-family: 'Cinzel', serif;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease;
}
.btn-ghost:hover {
  border-color: var(--gold);
  color: var(--gold-bright);
}

.status {
  font-size: 0.98rem;
  min-height: 1.4em;
  font-style: italic;
  color: var(--ink-dim);
}
.status.status-ok { color: var(--moss); font-style: normal; }
.status.status-err { color: var(--crimson); font-style: normal; }

/* ---------- Results ---------- */
.results { animation: fade-in 220ms ease; }
.results.hidden { display: none; }
@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* Metrics */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  margin-bottom: 1.5rem;
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-raised) 100%);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow-warm);
}
.metric {
  padding: 1.4rem 1.2rem;
  text-align: center;
  border-right: 1px solid var(--border-soft);
}
.metric:last-child { border-right: none; }
.metric-val {
  font-family: 'Cinzel', serif;
  font-size: 2.3rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1;
}
.metric-lbl {
  font-family: 'Cinzel', serif;
  font-size: 0.64rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-top: 0.6rem;
  font-weight: 500;
}
.metric-accent .metric-val { color: var(--gold-bright); }

/* Output panel */
.output-panel { margin-bottom: 1.5rem; padding: 1.25rem 1.4rem 1.4rem; }
.panel-actions { display: flex; gap: 0.6rem; }

.mono-out {
  background: #0a0f0c;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1rem 1.15rem;
  font-family: 'JetBrains Mono', Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.68;
  color: #dccb9c;
  max-height: 540px;
  overflow: auto;
  white-space: pre;
  margin: 0;
  tab-size: 4;
}
.mono-out:focus { outline: none; border-color: var(--gold); }
.mono-out:empty::before {
  content: 'No merged proxies yet.';
  color: var(--ink-mute);
  font-style: italic;
}
.mono-out::-webkit-scrollbar { width: 10px; height: 10px; }
.mono-out::-webkit-scrollbar-track { background: #070a08; }
.mono-out::-webkit-scrollbar-thumb {
  background: rgba(212, 168, 85, 0.25);
  border-radius: 3px;
}
.mono-out::-webkit-scrollbar-thumb:hover { background: rgba(212, 168, 85, 0.4); }

/* Invalid */
.invalid-panel { padding: 0; overflow: hidden; }
.invalid-panel summary {
  padding: 1rem 1.4rem;
  cursor: pointer;
  list-style: none;
  margin: 0;
  user-select: none;
}
.invalid-panel summary::-webkit-details-marker,
.invalid-panel summary::marker { display: none; content: ''; }
.invalid-panel .summary-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.invalid-panel summary::before {
  content: '▸';
  color: var(--gold);
  margin-right: 0.7rem;
  display: inline-block;
  transition: transform 160ms ease;
  font-size: 0.9rem;
}
.invalid-panel[open] summary::before { transform: rotate(90deg); }
.invalid-panel[open] summary { border-bottom: 1px solid var(--border-soft); }
.invalid-out {
  border: none;
  border-radius: 0;
  max-height: 280px;
  color: #e2b8a6;
}

/* Footer */
.page-foot {
  margin-top: 3rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-mute);
  letter-spacing: 0.04em;
  font-style: italic;
}
.foot-rule {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin-bottom: 1.2rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .container { padding: 2.2rem 1.25rem 3rem; }
  .settings { grid-template-columns: 1fr 1fr; gap: 1.3rem 1.5rem; }
  .inputs { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric { border-right: none; }
  .metric:nth-child(1), .metric:nth-child(2) { border-bottom: 1px solid var(--border-soft); }
  .metric:nth-child(odd) { border-right: 1px solid var(--border-soft); }
  .hero-body { grid-template-columns: 1fr; gap: 1rem; align-items: start; }
  .hero-art { width: 140px; justify-self: end; margin-top: -2rem; order: -1; }
}

@media (max-width: 540px) {
  .settings { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: 1fr; }
  .metric { border-right: none !important; }
  .metric:not(:last-child) { border-bottom: 1px solid var(--border-soft); }
  .hero-title { font-size: 2.4rem; }
  .action-row { flex-direction: column; gap: 0.9rem; }
  .btn-primary { padding: 0.9rem 1.8rem; letter-spacing: 0.18em; }
  .panel-head { flex-direction: column; align-items: flex-start; gap: 0.3rem; }
  .panel-actions { width: 100%; }
  .panel-actions button { flex: 1; }
}
