:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #15181d;
  --muted: #5d6573;
  --border: #dfe3e8;
  --accent: #2456e8;
  --accent-text: #ffffff;
  --accent-soft: #e6edff;
  --success: #12773d;
  --success-soft: #e3f5ea;
  --warning: #8a5a00;
  --warning-soft: #fdf1d8;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --info: #1d5bbf;
  --info-soft: #e5efff;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --text: #eceef2;
    --muted: #9aa3b2;
    --border: #2b303a;
    --accent: #6e93ff;
    --accent-text: #0b1020;
    --accent-soft: #1c2848;
    --success: #4cc584;
    --success-soft: #133222;
    --warning: #f0b84a;
    --warning-soft: #3a2c10;
    --danger: #ff7b6e;
    --danger-soft: #3d1715;
    --info: #7fb0ff;
    --info-soft: #172741;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0 0 12px; }
p { margin: 0 0 8px; }
code, .mono { font-family: var(--mono); font-size: 0.85em; }

/* Layout */
.header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--accent), #8f5cf6); }
.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav-link { padding: 6px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.lang { margin: 0 4px; padding: 5px 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-size: 0.85rem; }

.main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px 16px 48px; outline: none; }
.page { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.page.narrow { max-width: 620px; }
.page.wide { max-width: none; }
.page > h1 { margin-bottom: 0; }
.footer { padding: 16px; text-align: center; font-size: 0.85rem; color: var(--muted); }

.auth { max-width: 420px; margin: 6vh auto 0; display: flex; flex-direction: column; gap: 12px; }
.auth h1 { margin-bottom: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; margin-top: 12px; flex-wrap: wrap; }
.columns { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .columns { grid-template-columns: minmax(0, 1fr); } }

/* Text */
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.break { overflow-wrap: anywhere; }
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 0.85rem; font-weight: 600; }
.field-hint { font-size: 0.8rem; color: var(--muted); }
.input {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
.input:focus-visible, .btn:focus-visible, .tab:focus-visible, .lang:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.input[readonly] { background: var(--surface-2); }
.input-small { width: 90px; }
.select { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-soft); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-soft); }
.btn-block { width: 100%; }
.stack > .btn { align-self: flex-start; }
.auth .stack > .btn { align-self: stretch; }

.tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 4px; background: var(--surface-2); border-radius: 9px; width: fit-content; max-width: 100%; }
.tab { padding: 6px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.card > .tabs { margin-bottom: 16px; }

.msg { margin: 8px 0 0; font-size: 0.9rem; }
.msg:empty { display: none; }
.msg-error { color: var(--danger); }
.msg-success { color: var(--success); }
.msg-info { color: var(--muted); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar .input[type="search"] { flex: 1 1 240px; width: auto; }

/* Badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; line-height: 1.6; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }

/* Library */
.grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 4px; height: 100%; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; box-shadow: var(--shadow); }
.tile:hover { border-color: var(--accent); }
.tile-kind { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.tile-title { font-weight: 600; overflow-wrap: anywhere; }
.tile-meta { font-size: 0.85rem; color: var(--muted); }
.tile .row { margin-top: auto; padding-top: 6px; flex-wrap: wrap; }

.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: 0.9rem; }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); overflow-wrap: anywhere; }
.list-row:first-child { border-top: 0; }

/* Admin */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 700px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.85rem; color: var(--muted); }
.stat-success .stat-value { color: var(--success); }
.stat-warning .stat-value { color: var(--warning); }
.stat-danger .stat-value { color: var(--danger); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card .table-wrap { border: 0; border-radius: 0; margin: 0 -16px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 12px; border-top: 1px solid var(--border); vertical-align: top; }
.table tbody tr:first-child td { border-top: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.details { min-width: 180px; overflow-wrap: anywhere; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Static pages (privacy policy) */
.prose { max-width: 720px; margin: 0 auto; }
.prose h1 { margin-top: 8px; }
.prose h2 { margin-top: 28px; font-size: 1.1rem; }
.prose li { margin-bottom: 4px; }
.prose .todo { background: var(--warning-soft); color: var(--warning); padding: 0 4px; border-radius: 4px; }
