:root {
  --bg: #0d0e10;
  --surface: #15171a;
  --surface-2: #1c1f23;
  --border: #262a30;
  --text: #e9eaec;
  --muted: #8b9099;
  --accent: #3fb37f;
  --accent-text: #08130d;
  --danger: #e5534b;
  --warn: #e0a83a;
  --radius: 12px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
code { font: 13px "JetBrains Mono", ui-monospace, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.logo { width: 30px; height: 30px; border-radius: 8px; display: block; box-shadow: 0 0 0 1px var(--border); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 9px; padding: 7px 14px; font: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer; text-decoration: none;
  transition: background-color 180ms var(--ease), border-color 180ms var(--ease), transform 150ms var(--ease), opacity 180ms;
}
.btn:hover { background: #24282d; border-color: #343941; transform: translateY(-1px); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn:focus-visible, .switch:focus-visible, .segmented button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: #4cc28d; border-color: #4cc28d; }
.btn-danger { background: transparent; border-color: #5a2b29; color: #f08a84; }
.btn-danger:hover { background: #2a1615; border-color: var(--danger); }
.btn-stop { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-stop:hover { background: #ec665f; border-color: #ec665f; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-lg { padding: 11px 18px; font-size: 15px; }
.btn-block { width: 100%; }
.btn .arrow { width: 16px; height: 16px; transition: transform 200ms var(--ease); }
.btn:hover .arrow { transform: translateX(3px); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; display: grid; gap: 14px; justify-items: start;
  animation: rise 600ms var(--ease) both;
}
.login-card .logo { width: 52px; height: 52px; border-radius: 12px; }
.login-card h1 { font-size: 24px; letter-spacing: -0.02em; }
.login-card p { color: var(--muted); }
.login-card .login-error { color: #f08a84; }

.topbar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; background: rgba(13, 14, 16, 0.92); border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text); text-decoration: none; }
.user { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; }

.crumb { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); min-width: 0; animation: rise 300ms var(--ease) both; }
.crumb svg { width: 14px; height: 14px; flex: none; }
.crumb-link { color: var(--muted); text-decoration: none; transition: color 180ms; }
.crumb-link:hover { color: var(--text); }
#crumb-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.home { max-width: 1100px; margin: 0 auto; padding: 40px 24px 80px; }
.home-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; animation: rise 500ms var(--ease) both; }
.home-head h1 { font-size: 26px; letter-spacing: -0.02em; }
.home-head .btn svg, .home-empty .btn svg { width: 16px; height: 16px; }
.note-line { font-size: 13px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; }
.link { color: var(--text); text-decoration: none; border-bottom: 1px solid var(--border); transition: border-color 180ms; }
.link:hover { border-color: var(--text); }

.server-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.server-grid li { animation: rise 450ms var(--ease) both; }
.server-card {
  display: flex; align-items: center; gap: 14px; padding: 16px; height: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
  transition: border-color 200ms var(--ease), transform 200ms var(--ease), box-shadow 200ms var(--ease);
}
a.server-card:hover { border-color: #3a4048; transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); }
a.server-card:active { transform: scale(0.99); }
.server-card.is-off .server-icon { filter: grayscale(1); opacity: 0.6; }
.server-icon {
  width: 48px; height: 48px; border-radius: 14px; object-fit: cover; flex: none;
  background: var(--surface-2); display: grid; place-items: center; font-weight: 600; color: var(--muted);
}
.server-text { flex: 1; min-width: 0; }
.server-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server-status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.server-status.is-live { color: #f08a84; }
.server-arrow { width: 18px; height: 18px; color: var(--muted); flex: none; transition: transform 200ms var(--ease), color 200ms; }
a.server-card:hover .server-arrow { transform: translateX(3px); color: var(--text); }
.add-card { border-style: dashed; background: transparent; }
a.add-card:hover { background: var(--surface); }
.add-icon { border: 1px dashed var(--border); background: transparent; }
.add-icon svg { width: 20px; height: 20px; color: var(--accent); transition: transform 250ms var(--ease); }
a.add-card:hover .add-icon svg { transform: rotate(90deg); }
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn-small svg { width: 14px; height: 14px; }
.live-dot.small { width: 8px; height: 8px; }

.home-empty {
  display: grid; justify-items: center; text-align: center; gap: 12px; padding: 72px 24px;
  background: var(--surface); border: 1px dashed var(--border); border-radius: 16px; animation: rise 500ms var(--ease) both;
}
.home-empty h2 { font-size: 20px; letter-spacing: -0.01em; }
.home-empty p { max-width: 380px; }
.home-empty .btn { margin-top: 8px; }
.logo-xl { width: 72px; height: 72px; border-radius: 18px; box-shadow: 0 0 0 1px var(--border); }

.empty-state { margin: 64px auto; text-align: center; color: var(--muted); max-width: 420px; }

.grid {
  display: grid; grid-template-columns: 320px 1fr 1fr; gap: 16px; padding: 24px;
  max-width: 1400px; margin: 0 auto; align-items: start;
}
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; display: grid; gap: 14px; animation: rise 600ms var(--ease) both;
}
.panel:nth-child(2) { animation-delay: 70ms; }
.panel:nth-child(3) { animation-delay: 140ms; }
.panel h2 {
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  display: flex; align-items: center; gap: 8px; margin-top: 6px;
}
.count {
  font-size: 12px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 0 8px; letter-spacing: 0; transition: transform 200ms var(--ease);
}
.count.bump { animation: bump 300ms var(--ease); }

.status { display: flex; align-items: center; gap: 14px; }
.live-dot { width: 12px; height: 12px; border-radius: 50%; background: #3a3f46; flex: none; transition: background-color 300ms; }
.live-dot.on { background: var(--danger); animation: pulse 1.6s ease-in-out infinite; }
.status-label { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.setting-stack { flex-direction: column; align-items: stretch; }
.switch {
  width: 42px; height: 24px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2);
  position: relative; cursor: pointer; flex: none; padding: 0; transition: background-color 200ms var(--ease), border-color 200ms;
}
.switch span {
  position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted);
  transition: transform 220ms var(--ease), background-color 200ms;
}
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"] span { transform: translateX(18px); background: var(--accent-text); }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 3px; }
.segmented button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; padding: 6px; border-radius: 7px; cursor: pointer;
  transition: background-color 180ms var(--ease), color 180ms;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked="true"] { background: var(--bg); color: var(--text); }
.slowmode { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.slowmode input {
  width: 72px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 4px 8px; font: inherit;
}

.meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; margin: 6px 0 0; padding-top: 12px; border-top: 1px solid var(--border); }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.search { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 0 10px; transition: border-color 180ms; }
.search:focus-within { border-color: var(--accent); }
.search svg { width: 16px; height: 16px; color: var(--muted); }
.search input { flex: 1; background: transparent; border: 0; color: var(--text); font: inherit; padding: 8px 0; outline: none; }

.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.person {
  display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid transparent; transition: border-color 180ms var(--ease), transform 180ms var(--ease), opacity 250ms var(--ease);
}
.person:hover { border-color: var(--border); }
.person.enter { animation: rise 400ms var(--ease) both; }
.person.leave { opacity: 0; transform: translateX(8px); }
.person .info { flex: 1; min-width: 0; }
.person .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .actions { display: flex; gap: 6px; }
.person .btn { padding: 5px 10px; font-size: 13px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--border); flex: none; display: grid; place-items: center; font-weight: 600; font-size: 13px; color: var(--muted); }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 5px; margin-left: 6px; border: 1px solid var(--border); color: var(--muted); }
.tag-warn { color: var(--warn); border-color: #4a3a1a; }
.empty { padding: 4px 2px; }

.toasts { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 10; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 10px 14px; font-size: 14px; max-width: 360px; white-space: pre-line;
  animation: rise 300ms var(--ease) both; transition: opacity 250ms, transform 250ms var(--ease);
}
.toast.error { border-left-color: var(--danger); }
.toast.leave { opacity: 0; transform: translateY(6px); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes bump { 50% { transform: scale(1.2); } }

@media (max-width: 1100px) { .grid { grid-template-columns: 1fr 1fr; } .grid .panel:first-child { grid-column: 1 / -1; } }
@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; padding: 16px; }
  .topbar { flex-wrap: wrap; padding: 12px 16px; }
  .user span { display: none; }
  .home { padding: 24px 16px 64px; }
  .home-head { flex-direction: column; align-items: stretch; }
  .crumb .crumb-link, .crumb svg:first-child { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
