:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #6b7584;
  --border: #e3e6eb;
  --accent: #1f5fbf;
  --accent-soft: #e8f0fc;
  --row-alt: #fafbfc;
  --gold: #fdf3d3;
  --silver: #e9edf3;
  --bronze: #f8e8dc;
  --pos: #1e7d3c;
  --neg: #b42318;
  --live: #d92d20;
  --running-bg: #fff4e5;
  --running-fg: #a25b00;
  --finished-bg: #e7f6ec;
  --finished-fg: #1e7d3c;
  --idle-bg: #eef0f3;
  --idle-fg: #6b7584;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --surface: #1a2029;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --border: #2b3340;
    --accent: #7fb0ff;
    --accent-soft: #1d2a3f;
    --row-alt: #1d242e;
    --gold: #3a3220;
    --silver: #2a3039;
    --bronze: #3a2a20;
    --pos: #5fd38a;
    --neg: #ff8a80;
    --live: #ff6b5e;
    --running-bg: #3a2c14;
    --running-fg: #ffc46b;
    --finished-bg: #173323;
    --finished-fg: #6fdc97;
    --idle-bg: #2a3039;
    --idle-fg: #98a2b3;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: .4rem 0 .3rem; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 .6rem; }

.container { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header .container { display: flex; align-items: baseline; gap: 12px; padding-top: 12px; padding-bottom: 12px; flex-wrap: wrap; }
.logo { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.logo-sub { color: var(--muted); font-size: .9rem; }
main.container { padding-top: 16px; padding-bottom: 32px; }
.site-footer { color: var(--muted); font-size: .85rem; padding: 24px 0; border-top: 1px solid var(--border); }

.crumbs { font-size: .9rem; color: var(--muted); margin-bottom: 4px; }
.meta { color: var(--muted); margin: 0 0 .4rem; }
.updated { color: var(--muted); font-size: .85rem; margin: .2rem 0 1rem; }
.muted { color: var(--muted); font-weight: 400; }
.empty { color: var(--muted); }
.note { font-size: .8rem; color: var(--neg); font-weight: 400; }

.cards { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card a { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; color: var(--text); height: 100%; }
.card a:hover { border-color: var(--accent); text-decoration: none; }
.card-live a { border-left: 4px solid var(--live); }
.card-title { display: block; font-weight: 600; margin-bottom: 4px; }
.plain-list { color: var(--muted); padding-left: 1.2rem; margin: 0; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: .6rem 0 .4rem; }
.tab { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: .92rem; }
.tab.active { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.tab:hover { text-decoration: none; border-color: var(--accent); }

.badge { display: inline-block; font-size: .72rem; line-height: 1.5; padding: 0 6px; border-radius: 999px; font-weight: 500; vertical-align: 1px; white-space: nowrap; }
.badge-running { background: var(--running-bg); color: var(--running-fg); }
.badge-finished { background: var(--finished-bg); color: var(--finished-fg); }
.badge-not_started { background: var(--idle-bg); color: var(--idle-fg); }
.badge-draft { background: var(--idle-bg); color: var(--idle-fg); margin-top: 6px; }
.seg-link { margin-right: 10px; white-space: nowrap; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 14px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table tbody tr:nth-child(even) { background: var(--row-alt); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { border-top: 2px solid var(--border); border-bottom: 0; font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .center { text-align: center; }
.table .rank { font-weight: 700; width: 3.5rem; }
.table .total { font-weight: 700; }
.table .club { color: var(--muted); }
.table .sub { color: var(--muted); font-size: .85rem; }
/* tbody в селекторе — чтобы перебить чередование строк */
.table tbody tr.podium-1 { background: var(--gold); }
.table tbody tr.podium-2 { background: var(--silver); }
.table tbody tr.podium-3 { background: var(--bronze); }
.seg-rank { display: inline-block; min-width: 1.6em; margin-left: 6px; color: var(--muted); font-size: .8rem; text-align: right; }
.start-order tr.skated td { color: var(--muted); }
/* Протокол элементов: строки по центру по вертикали, «Инфо» — отдельный узкий столбец с отступом от названия */
.elements td { vertical-align: middle; }
.elements .element > span:first-child { white-space: nowrap; }
.table .elements th.info, .elements th.info, .elements td.info { padding-left: 14px; text-align: left; width: 3.5em; }
.elements td.info { color: var(--neg); font-weight: 600; white-space: nowrap; }
.elements .bonus { color: var(--accent); font-weight: 600; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.summary { display: flex; flex-wrap: wrap; gap: 8px; margin: .4rem 0 .8rem; }
.summary > div { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; min-width: 110px; }
.summary .label { display: block; color: var(--muted); font-size: .78rem; }
.summary .value { display: block; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.protocol { margin-top: 1rem; }

.show-sm { display: none; }
.show-sm-inline { display: none; }
@media (max-width: 640px) {
  body { font-size: 14px; }
  h1 { font-size: 1.3rem; }
  .hide-sm { display: none; }
  .show-sm { display: block; }
  .container { padding: 0 12px; }
  .table { font-size: 13px; }
  .table th, .table td { padding: 6px 5px; }
  .table thead th { font-size: .66rem; letter-spacing: 0; }
  /* Клуб под именем — в одну строку, чтобы таблица оставалась компактной */
  .table .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 28vw; }
  .table .rank { width: auto; }
  .seg-rank { margin-left: 2px; min-width: 1.2em; font-size: .7rem; }
  .show-sm-inline { display: inline; }
  .elements .element .badge { display: block; width: max-content; margin-top: 2px; }
  .table .elements th.info, .elements th.info, .elements td.info { padding-left: 8px; width: auto; }
  .summary { gap: 6px; }
  .summary > div { flex: 1 1 0; min-width: 0; padding: 6px 8px; }
  .summary .label { font-size: .7rem; }
  .summary .value { font-size: 1.05rem; }
}

/* Узкие телефоны (360px): убираем второстепенное, таблица остаётся без прокрутки */
@media (max-width: 380px) {
  .hide-xs, .seg-rank, .logo-sub { display: none; }
}

/* Живое обновление */
.live-status { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.live-status::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); vertical-align: 1px; }
.live-status[data-state="online"]::before { background: var(--finished-fg); }
.live-status[data-state="offline"]::before { background: var(--running-fg); }
@keyframes flash { from { background-color: var(--running-bg); } to { background-color: transparent; } }
.flash { animation: flash 2.5s ease-out; }
@media (prefers-reduced-motion: reduce) { .flash { animation: none; outline: 2px solid var(--running-fg); } }

/* Вход на сайт */
.user-nav { margin-left: auto; display: flex; align-items: baseline; gap: 10px; font-size: .9rem; white-space: nowrap; }
.live-status:not([hidden]) + .user-nav { margin-left: 14px; }
.live-status:not([hidden]) { margin-left: auto; }
.user-nav form { margin: 0; }
.user-name { color: var(--muted); max-width: 12em; overflow: hidden; text-overflow: ellipsis; }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.link-button:hover { text-decoration: underline; }
.login-box { max-width: 360px; margin: 24px auto; }
.login-form { display: grid; gap: 12px; margin-top: 12px; }
.login-form label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.login-form input { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; }
.login-form input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.login-form button { font: inherit; font-weight: 600; color: var(--surface); background: var(--accent); border: 0; border-radius: 8px; padding: 10px; cursor: pointer; }
.form-error { color: var(--neg); background: var(--surface); border: 1px solid var(--neg); border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-size: .9rem; }
.form-error p { margin: 0; }
@media (max-width: 380px) { .user-name { display: none; } }
