:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #171a21;
  --muted: #5d6573;
  --link: #2563eb;
  --accent: #2563eb;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --idle: #8a93a3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --link: #7aa7ff;
    --accent: #7aa7ff;
    --ok: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    --idle: #6b7280;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; padding-top: 28px; padding-bottom: 48px; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: .92em; }
h1 { font-size: 1.9rem; line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; margin: 1.6em 0 .6em; }
.wrap { width: 100%; max-width: 1040px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.inline { display: inline; margin: 0; }
[hidden] { display: none !important; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 58px; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); display: inline-flex; align-items: center; gap: 10px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: radial-gradient(circle at 35% 50%, var(--ok) 0 32%, transparent 33%),
              radial-gradient(circle at 65% 50%, var(--link) 0 32%, transparent 33%), var(--surface-2);
}
.nav { display: flex; align-items: center; gap: 14px; font-size: .95rem; }
.nav-user { color: var(--text); font-weight: 600; }
.link-btn { background: none; border: 0; padding: 0; color: var(--link); font: inherit; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.footer { color: var(--muted); font-size: .85rem; padding-top: 18px; padding-bottom: 24px; border-top: 1px solid var(--border); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 9px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer; text-decoration: none;
  transition: filter .15s, background .15s, opacity .15s;
}
.btn:hover { text-decoration: none; filter: brightness(1.07); }
.btn:disabled { opacity: .4; cursor: not-allowed; filter: none; }
.btn-small { min-height: 30px; padding: 0 10px; font-size: .85rem; border-radius: 7px; }
.btn-primary { background: var(--ok); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #06210f; } }
.btn-danger { background: transparent; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
form.auth button, .form .btn { width: 100%; }

/* status */
.status {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  font-size: .82rem; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); flex: none; }
.status-online { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); background: color-mix(in srgb, var(--ok) 10%, var(--surface)); }
.status-online .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.status-starting, .status-stopping { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: color-mix(in srgb, var(--warn) 10%, var(--surface)); }
.status-starting .dot, .status-stopping .dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.status-failed, .status-error { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); background: color-mix(in srgb, var(--bad) 10%, var(--surface)); }
.status-failed .dot, .status-error .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .status .dot { animation: none !important; } }

/* intro + grid */
.intro { margin-bottom: 24px; }
.intro .prose { color: var(--muted); max-width: 70ch; }
.grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(290px, 100%), 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; position: relative; transition: border-color .15s, transform .15s;
}
.card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent); opacity: .9; }
.card:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); transform: translateY(-1px); }
.card-link { display: block; color: inherit; height: 100%; }
.card-link:hover { text-decoration: none; }
.card-image { height: 130px; background: var(--surface-2) center/cover no-repeat; }
.card-body { padding: 16px 18px 18px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card-title { font-size: 1.15rem; margin: 0; line-height: 1.3; }
.card-game { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.card-summary { margin: 10px 0 0; color: var(--text); font-size: .95rem; }
.card-address { margin-top: 12px; }
.card-address code, .facts code { background: var(--surface-2); border: 1px solid var(--border); padding: 2px 7px; border-radius: 6px; word-break: break-all; }
.empty { text-align: center; padding: 48px 16px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* server page */
.crumbs { margin-bottom: 14px; font-size: .95rem; }
.server-hero { height: 200px; border-radius: var(--radius); background: var(--surface-2) center/cover no-repeat; margin-bottom: 20px; }
.server-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.server-head h1 { margin: 0; }
.server-head .status { font-size: .95rem; padding: 6px 14px; }
.server-panel {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 28px;
}
.facts { margin: 0; display: grid; gap: 10px; }
.facts > div { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: baseline; }
.facts dt { color: var(--muted); font-size: .92rem; }
.facts dd { margin: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.server-panel > p.muted { margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--border); }
@media (max-width: 560px) {
  .facts > div { grid-template-columns: 1fr; gap: 2px; }
  .controls form, .controls .btn { flex: 1 1 100%; width: 100%; }
}

/* prose (Markdown из шаблонов) */
.prose { max-width: 75ch; overflow-wrap: anywhere; }
.prose img, .prose video, .prose iframe { max-width: 100%; height: auto; border-radius: 8px; }
.prose pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; overflow-x: auto; }
.prose :not(pre) > code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.prose blockquote { margin: 1em 0; padding: 2px 16px; border-left: 3px solid var(--border); color: var(--muted); }
.prose h1 { font-size: 1.6rem; } .prose h2 { font-size: 1.3rem; } .prose h3 { font-size: 1.1rem; }

/* events */
.events ul { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.events li { display: flex; gap: 14px; padding: 9px 14px; border-top: 1px solid var(--border); font-size: .92rem; flex-wrap: wrap; }
.events li:first-child { border-top: 0; }
.events time { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 9.5em; }
.events .err { color: var(--bad); }

/* forms */
.auth { max-width: 400px; margin: 0 auto; }
.form { display: grid; gap: 14px; margin: 18px 0; }
.form label { display: grid; gap: 6px; font-size: .92rem; font-weight: 600; }
.form input {
  font: inherit; font-weight: 400; padding: 10px 12px; min-height: 44px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.form input:focus { outline: 2px solid color-mix(in srgb, var(--link) 55%, transparent); outline-offset: 1px; border-color: var(--link); }
.form input[name="code"] { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .06em; text-transform: uppercase; }

/* notices */
.notice, .flash { padding: 12px 14px; border-radius: 10px; margin: 0 0 18px; border: 1px solid var(--border); background: var(--surface); }
.notice ul { margin: 8px 0 0; padding-left: 20px; }
.notice-error { border-color: color-mix(in srgb, var(--bad) 45%, transparent); background: color-mix(in srgb, var(--bad) 9%, var(--surface)); }
.notice-warn { border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 9%, var(--surface)); }
.notice-ok, .flash { border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 8%, var(--surface)); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 10;
  max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: .93rem; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.toast-error { background: var(--bad); color: #fff; }
