:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --ink: #161a23;
  --muted: #5d6475;
  --line: #e2e5ee;
  --brand: #5b2a86;
  --brand-soft: #efe7f7;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b24;
    --ink: #eceef3;
    --muted: #9aa1b2;
    --line: #2a3040;
    --brand: #c9a5ec;
    --brand-soft: #2b2338;
    --danger: #f2877d;
    --danger-soft: #3a1f1d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: inherit; }
main { flex: 1; width: 100%; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 14px; font-weight: 400; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Шапка и футер */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar__inner { display: flex; align-items: center; justify-content: space-between; min-height: 64px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand span { display: flex; flex-direction: column; line-height: 1.2; }
.brand strong { font-size: 18px; }
.brand small { color: var(--muted); font-size: 13px; }

.footer { border-top: 1px solid var(--line); margin-top: 48px; font-size: 14px; }
.footer__inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 16px; }
.footer__school { display: flex; align-items: center; gap: 8px; font-weight: 600; text-decoration: none; }
.footer a:hover { color: var(--brand); }

/* Витрина */
.intro { padding: 40px 0 8px; }
.intro h1 { margin: 0 0 8px; font-size: clamp(26px, 3vw + 12px, 38px); line-height: 1.15; letter-spacing: -0.01em; }
.intro p { margin: 0; color: var(--muted); max-width: 640px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 24px 0 8px; }
.tabs__item {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  text-decoration: none;
  font-size: 15px;
}
.tabs__item:hover { color: var(--ink); }
.tabs__item.is-active { background: var(--brand-soft); border-color: transparent; color: var(--brand); font-weight: 600; }

.section { margin-top: 28px; }
.section h2 { font-size: 18px; margin: 0 0 12px; }

.grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card__head { display: flex; align-items: center; gap: 14px; }
.card__icon { flex: none; width: 48px; height: 48px; border-radius: 12px; object-fit: contain; }
.card__icon--letter { display: grid; place-items: center; font-weight: 700; font-size: 22px; color: #fff; }
.tone-0 { background: #5b2a86; }
.tone-1 { background: #1f6feb; }
.tone-2 { background: #0f8a6a; }
.tone-3 { background: #c2410c; }
.tone-4 { background: #be185d; }
.tone-5 { background: #475569; }
.card__title { margin: 0; font-size: 18px; font-weight: 650; }
.card__title a { text-decoration: none; }
.card__title a:hover, .card__title a:focus-visible { color: var(--brand); text-decoration: underline; text-underline-offset: 3px; }
.card__text { margin: 0; color: var(--muted); font-size: 15px; flex: 1; }
.card__foot { display: grid; gap: 10px; }
.card__actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Адрес с копированием */
.address {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font: 14px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.address__url { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; user-select: all; }
.address__copy {
  flex: none;
  min-height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: var(--brand-soft);
  color: var(--brand);
  font: 600 13px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  cursor: pointer;
}
.address__copy.is-done { background: #dcfce7; color: #166534; }

/* Окно «Подробнее» */
.modal {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 64px -24px rgba(0, 0, 0, .45);
}
.modal::backdrop { background: rgba(15, 18, 24, .55); }
.modal__head { display: flex; align-items: center; gap: 14px; padding: 20px 20px 0; }
.modal__head h3 { margin: 0; font-size: 20px; }
.modal__head p { margin: 2px 0 0; font-size: 14px; }
.modal__close {
  margin-left: auto;
  align-self: flex-start;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.modal__close:hover { background: var(--bg); color: var(--ink); }
.modal__body { padding: 8px 20px; font-size: 15.5px; }
.modal__body ul { padding-left: 1.2em; }
.modal__body li + li { margin-top: 4px; }
.modal__foot { display: flex; gap: 10px; align-items: center; padding: 16px 20px 20px; border-top: 1px solid var(--line); }
.modal__foot .address { flex: 1; }
.empty { color: var(--muted); padding: 32px 0; }

/* Админка */
.panel { margin-top: 24px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel--narrow { max-width: 640px; }
.panel h1 { margin: 0 0 12px; font-size: 24px; }
.panel__head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.panel__head h1 { margin: 0; }
.table-caption { font-size: 17px; margin: 28px 0 8px; display: flex; gap: 12px; align-items: baseline; }

.table { width: 100%; border-collapse: collapse; font-size: 15px; table-layout: fixed; }
.table .col-small { width: 140px; }
.table .col-actions { width: 230px; }
.table td { overflow-wrap: anywhere; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 13px; padding: 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr.is-hidden td { opacity: .55; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.actions form { margin: 0; }

.form { display: grid; gap: 16px; }
.form label { display: grid; gap: 6px; font-weight: 500; }
.form label.check { display: flex; align-items: center; gap: 8px; }
.form__actions { display: flex; gap: 8px; }
input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  width: 100%;
}
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.inline-form { display: flex; gap: 8px; align-items: center; margin: 0; }
.new-section { margin-top: 20px; max-width: 520px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.button:disabled { opacity: .4; cursor: default; }
.button--primary { background: var(--brand); border-color: var(--brand); color: var(--surface); font-weight: 600; }
.button--ghost { background: transparent; }
.button--icon { width: 38px; padding: 0; }
.button--danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }

.alert { margin: 0 0 16px; padding: 10px 14px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); list-style: none; }
.danger-zone { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 14px; }

@media (max-width: 640px) {
  .modal__foot { flex-direction: column; align-items: stretch; }
  .card__actions .button { flex: 1; }
  .panel { padding: 16px; }
  .table { table-layout: auto; }
  .table thead { display: none; }
  .table tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .table td { border: 0; padding: 0; }
  .table td:last-child { grid-column: 1 / -1; }
  .actions { justify-content: flex-start; }
  .inline-form { flex-wrap: wrap; }
}
