:root {
  --bg: #12140f;
  --elev: #1c2116;
  --soft: #262c1d;
  --line: #3c4430;
  --text: #f7f7f2;
  --muted: #b7bea8;
  --gold: #fac333;
  --gold-ink: #2b2308;
  --green: #42661c;
  --green-bright: #9dcc55;
  --danger: #e07a6e;
  --warn: #e0a84a;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  --radius: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Open Sans", sans-serif;
}

body {
  border-top: 4px solid var(--gold);
}

button, input, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card, .card, .result, .host {
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(440px, 100%);
  padding: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
  letter-spacing: -0.03em;
  font-size: 1.35rem;
}

.brand span, .brand-lg span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--gold);
  color: var(--gold-ink);
}

.brand-lg {
  font-size: 1.8rem;
  margin-bottom: 8px;
}

h1, h2 { margin: 0 0 8px; letter-spacing: -0.03em; }

h1 { font-size: 1.7rem; }

h2 { font-size: 1.15rem; }

.lead, .panel-head p, .hint, .who, .meta {
  color: var(--muted);
  line-height: 1.45;
}

.lead { margin-top: 0; }

label { display: grid; gap: 6px; font-size: 0.92rem; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #12160e;
  border-radius: 12px;
  padding: 12px 14px;
}

textarea {
  min-height: 220px;
  resize: vertical;
  font-family: Consolas, "Cascadia Mono", monospace;
  line-height: 1.45;
}

input:focus, textarea:focus {
  outline: 2px solid var(--gold);
  border-color: transparent;
}

.auth-card label, .form-grid label { margin-top: 14px; }

.btn {
  border: 0;
  border-radius: 999px;
  padding: 11px 18px;
  font-weight: 700;
}

.btn:disabled { opacity: 0.55; cursor: wait; }

.btn-gold { background: var(--gold); color: var(--gold-ink); }

.btn-gold:hover { background: #ffd45a; }

.btn-green { background: var(--green); color: #f3ffe4; }

.btn-green:hover { background: #527a26; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-danger { background: transparent; color: var(--danger); border: 1px solid #6d3530; }

.form-error { color: var(--danger); min-height: 1.2em; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  width: 100%;
  padding: 16px 28px 8px;
}

.topbar-side {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  margin: 0;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--soft);
  border: 1px solid var(--line);
  font-size: 0.85rem;
}

.who { margin: 0; }

.app-frame {
  width: auto;
  margin: 0;
  padding: 4px 28px 48px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0 0;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
}

.tab.is-active {
  background: var(--gold);
  color: var(--gold-ink);
}

main { padding: 18px 0 0; }

.panel { width: 100%; }

.panel:not(#panel-debrid) { max-width: 860px; }

#panel-debrid {
  width: min(720px, 100%);
  margin-inline: auto;
}

#panel-hosts {
  display: grid;
  align-items: start;
}

#panel-hosts:has(#quotas:not([hidden])) {
  grid-template-columns: minmax(0, 1fr) 280px;
  column-gap: 40px;
  max-width: none;
}

#panel-hosts > .panel-head,
#panel-hosts > #host-search,
#panel-hosts > #hosts-list {
  grid-column: 1;
}

.quota-side {
  grid-column: 2;
  grid-row: 1 / span 6;
  position: sticky;
  top: 16px;
}

.quota-side h2 { margin-bottom: 12px; }

.quotas {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.quota {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 0;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}

.quota-left {
  color: var(--muted);
  white-space: nowrap;
}

.panel-head { margin-bottom: 16px; }

.unlock-meta, .actions, .result-top, .user-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.inline {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.unlock-meta { justify-content: flex-start; margin-top: 8px; }

.inline input { width: 220px; }

.actions { margin-top: 12px; }

.stack { display: grid; gap: 12px; margin-top: 16px; }

.result, .card, .host, .user-row { padding: 16px; }

.result { border-left: 4px solid var(--line); }

.result.is-ready { border-left-color: var(--green-bright); }

.result.is-delayed, .result.is-streams { border-left-color: var(--warn); }

.result.is-error, .result.is-password { border-left-color: var(--danger); }

.filename { font-weight: 700; overflow-wrap: anywhere; }

.meta { margin: 4px 0 0; font-size: 0.92rem; }

.chips, .quality { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.pass-row { display: flex; gap: 8px; margin-top: 12px; }

.pass-row input { max-width: 280px; }

.host-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.host strong { display: block; }

.host .ok { color: var(--green-bright); }

.host .down { color: var(--danger); }

.form-grid { width: 100%; }

.check { display: flex; align-items: center; gap: 8px; }

.check input { width: auto; }

.user-row { background: var(--elev); border: 1px solid var(--line); border-radius: 14px; }

#toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 5;
  max-width: min(420px, calc(100% - 32px));
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--gold);
  color: var(--gold-ink);
  box-shadow: var(--shadow);
}

#toast.is-error { background: #5c2a26; color: #ffd7d2; }

@media (max-width: 699px) {
  .topbar { padding: 14px 16px 8px; align-items: stretch; flex-direction: column; }
  .topbar-side { justify-content: flex-start; }
  .app-frame { padding: 4px 16px 40px; }
  #panel-debrid { width: 100%; }
  #panel-hosts,
  #panel-hosts:has(#quotas:not([hidden])) {
    grid-template-columns: 1fr;
    max-width: none;
  }
  .quota-side { grid-column: 1; grid-row: auto; position: static; order: 5; }
  .inline, .pass-row, .user-row, .result-top, .unlock-meta { align-items: stretch; flex-direction: column; }
  .inline { width: 100%; }
  .inline input, .pass-row input, .actions .btn { width: 100%; max-width: none; }
  textarea { min-height: 160px; }
  h1 { font-size: 1.45rem; }
  .host-grid { grid-template-columns: 1fr; }
  .user-row .chips { flex-direction: column; align-items: stretch; }
}

@media (min-width: 700px) and (max-width: 1024px) {
  .topbar { padding-left: 24px; padding-right: 24px; }
  .app-frame { padding-left: 24px; padding-right: 24px; }
  #panel-hosts:has(#quotas:not([hidden])) {
    grid-template-columns: minmax(0, 1fr) 220px;
    column-gap: 24px;
    max-width: none;
  }
}
