/* Afterfog — спільна основа дизайну (docs/design.md): токени, тихий фон, верхня панель, меню під аватаркою.
   Підключають усі сторінки: застосунок (web/public/index.html), адмін-панель (web/admin/index.html) і сторінка входу
   (src/access.ts). Стилі окремих сторінок лишаються в їхніх файлах і беруть кольори лише звідси.
   Правило кольору: блакитний (--good) — добре / сильна сторона, помаранчевий (--bad) — проблема. */

:root {
  color-scheme: dark;
  /* поверхні */
  --bg: #0e1114;
  --surface: rgba(19, 24, 29, 0.85);   /* картки: крізь них ледь видно фон */
  --panel: #13181d;                     /* суцільна поверхня: поля, спливні вікна */
  --panel-2: #1b2229;                   /* наведення, вибране, мітки */
  --border: #232b33;
  --border-strong: #2c353e;
  /* текст */
  --text: #f2f4f6;
  --text-2: #b7c0c8;
  --muted: #8f9aa4;
  --faint: #6f7a85;
  /* акцент і смисл кольору */
  --accent: #7fb8d6;
  --on-accent: #0b1418;
  --accent-bg: #18252d;
  --link: #a9d2e6;
  --link-hover: #d4ebf5;
  --good: #7fb8d6;                      /* добре, сильна сторона, перемога */
  --good-dim: rgba(127, 184, 214, 0.72);/* слабше «добре» (поруч, дрібний успіх) */
  --good-text: #a9d2e6;
  --good-bg: rgba(127, 184, 214, 0.14);
  --bad: #e8a05c;                       /* проблема, мінус, поразка */
  --bad-text: #f0b27a;
  --bad-bg: rgba(232, 160, 92, 0.14);
  /* форми */
  --r-card: 16px;
  --r-ctl: 10px;
  --ctl-h: 44px;                        /* мінімальна висота кнопок і клікабельних рядків */
  /* шрифти: Manrope — увесь текст; Space Grotesk — лише лого й великі цифри (оцінки, KPI) */
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-num: 'Space Grotesk', 'Manrope', system-ui, sans-serif;
}

* { box-sizing: border-box; }
/* атрибут hidden ховає завжди, навіть коли клас задає display */
[hidden] { display: none !important; }
/* фон — лише на html: тоді шар .af-bg (z-index −1) лягає між фоном і вмістом */
html { background: var(--bg); }
body { margin: 0; background: transparent; color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); }
a:hover { color: var(--link-hover); }

/* видимий фокус лише з клавіатури */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; border-color: var(--accent); }

.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* кнопки й поля: 44 px заввишки, радіус 10 px */
button, .btn {
  min-height: var(--ctl-h); padding: 0 14px; border-radius: var(--r-ctl);
  background: var(--panel); border: 1px solid var(--border-strong); color: var(--text); font-weight: 600; cursor: pointer;
}
button:hover, .btn:hover { border-color: #3a4651; background: var(--panel-2); }
button:disabled, .btn:disabled { opacity: .45; cursor: default; }
.btn-primary, button.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 800; }
.btn-primary:hover, button.btn-primary:hover { background: #95c6df; border-color: #95c6df; }
select, input[type=text], input[type=search], input[type=number], input[type=password], input:not([type]) {
  min-height: var(--ctl-h); padding: 0 12px; border-radius: var(--r-ctl);
  background: var(--panel); border: 1px solid var(--border-strong); color: var(--text);
}
input::placeholder { color: var(--faint); }
input[type=checkbox], input[type=radio], input[type=range] { accent-color: var(--accent); }

/* ---------- Тихий фон: крапкова сітка, мʼякі світіння, лінії туману ---------- */
.af-bg {
  position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden;
  background:
    radial-gradient(circle 560px at 96% -6%, rgba(127, 184, 214, 0.06), transparent 70%) no-repeat,
    radial-gradient(circle 520px at -8% 52%, rgba(127, 184, 214, 0.05), transparent 70%) no-repeat,
    radial-gradient(circle 520px at 104% 78%, rgba(232, 160, 92, 0.035), transparent 70%) no-repeat,
    radial-gradient(circle 600px at 50% 118%, rgba(127, 184, 214, 0.045), transparent 70%) no-repeat,
    radial-gradient(circle, rgba(22, 29, 35, 0.7) 1px, transparent 1.3px) 0 0 / 28px 28px;
}
/* дві смуги туману: кожна — дві тонкі хвилі; плитка шириною в екран, смуга вдвічі ширша й зсувається на плитку */
.af-bg::before, .af-bg::after {
  content: ''; position: absolute; left: 0; width: 200%; height: 420px; will-change: transform;
  background-repeat: repeat-x; background-size: 50% 100%;
}
.af-bg::before {
  top: 18%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2880 420' preserveAspectRatio='none'%3E%3Cg fill='none' stroke='%231a2229' stroke-width='1.2' vector-effect='non-scaling-stroke'%3E%3Cpath vector-effect='non-scaling-stroke' d='M0 140 C 360 110, 1080 170, 1440 140 C 1800 110, 2520 170, 2880 140'/%3E%3Cpath vector-effect='non-scaling-stroke' d='M0 280 C 360 305, 1080 255, 1440 280 C 1800 305, 2520 255, 2880 280'/%3E%3C/g%3E%3C/svg%3E");
  animation: af-fog-back 120s linear infinite;
}
.af-bg::after {
  top: 58%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2880 420' preserveAspectRatio='none'%3E%3Cg fill='none' stroke='%231a2229' stroke-width='1.2'%3E%3Cpath vector-effect='non-scaling-stroke' d='M0 120 C 360 150, 1080 95, 1440 120 C 1800 150, 2520 95, 2880 120'/%3E%3Cpath vector-effect='non-scaling-stroke' d='M0 300 C 360 275, 1080 325, 1440 300 C 1800 275, 2520 325, 2880 300'/%3E%3C/g%3E%3C/svg%3E");
  animation: af-fog 80s linear infinite;
}
@keyframes af-fog { from { transform: translateX(0); } to { transform: translateX(-50%); } }
@keyframes af-fog-back { from { transform: translateX(-50%); } to { transform: translateX(0); } }
@media (prefers-reduced-motion: reduce) {
  .af-bg::before, .af-bg::after { animation: none; }
  *, *::before, *::after { scroll-behavior: auto !important; }
}

/* ---------- Верхня панель ---------- */
.af-top { position: relative; z-index: 30; border-bottom: 1px solid #1f262d; background: rgba(14, 17, 20, 0.8); }
.af-top-in { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; padding: 10px 24px; }
.af-logo { display: flex; align-items: center; min-height: var(--ctl-h); border-radius: var(--r-ctl); flex: none; }
.af-logo img { display: block; height: 29px; width: auto; }

/* пошук гравця або матчу: іконка-кнопка, поле, підказка під полем */
.af-search { position: relative; flex: 1 1 320px; max-width: 560px; min-width: 0; display: flex; align-items: center;
  min-height: var(--ctl-h); border-radius: var(--r-ctl); background: var(--panel); border: 1px solid var(--border); }
.af-search:focus-within { border-color: var(--accent); }
.af-search-go { flex: none; display: grid; place-items: center; width: 42px; min-height: 42px; padding: 0; border: 0; background: none; color: var(--muted); border-radius: var(--r-ctl) 0 0 var(--r-ctl); }
.af-search-go:hover { background: none; color: var(--text); }
.af-search-go:focus-visible { outline-offset: -2px; color: var(--text); }
.af-search input { flex: 1; min-width: 0; min-height: 42px; padding: 0 12px 0 0; border: 0; background: transparent; font-size: 14px; }
.af-search input:focus-visible { outline: none; }
.af-search input::-webkit-search-cancel-button { filter: grayscale(1) brightness(.8); }

.af-nav { display: flex; align-items: center; gap: 2px; flex: none; }
.af-nav a { display: inline-flex; align-items: center; min-height: var(--ctl-h); padding: 0 10px; border-radius: var(--r-ctl);
  color: var(--text-2); text-decoration: none; font-weight: 600; font-size: 14px; white-space: nowrap; }
.af-nav a:hover { color: var(--text); background: var(--panel-2); }
.af-nav a[aria-current=page] { color: var(--text); background: var(--accent-bg); }

.af-user { position: relative; margin-left: auto; display: flex; align-items: center; gap: 10px; min-width: 0; }
.af-user:empty { display: none; }
.af-login { display: inline-flex; align-items: center; gap: 8px; min-height: var(--ctl-h); padding: 0 16px; border-radius: var(--r-ctl);
  border: 1px solid var(--border-strong); color: var(--text); text-decoration: none; font-weight: 700; white-space: nowrap; }
.af-login:hover { color: var(--text); border-color: #3a5566; background: var(--accent-bg); }

/* кнопка-аватарка: аватар + нік + стрілка */
.af-me { display: flex; align-items: center; gap: 8px; min-height: var(--ctl-h); padding: 0 10px 0 5px; border-radius: var(--r-ctl);
  border: 1px solid #2c3a45; background: #151d23; color: var(--text); font-weight: 700; max-width: 260px; }
.af-me:hover, .af-me[aria-expanded=true] { border-color: #3a5566; background: var(--accent-bg); }
.af-me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; font-size: 14px; }
.af-me svg { flex: none; transition: transform .15s; }
.af-me[aria-expanded=true] svg { transform: rotate(180deg); }
.af-ava { width: 32px; height: 32px; border-radius: 8px; flex: none; object-fit: cover; display: block; }
.af-ava.none { display: grid; place-items: center; background: linear-gradient(135deg, #2b3f4c, #1c272f); color: var(--accent); font-weight: 800; font-size: 13px; }
.af-ava.big { width: 40px; height: 40px; border-radius: 10px; font-size: 14px; }

/* меню під аватаркою */
.af-menu { position: absolute; top: calc(100% + 8px); right: 0; z-index: 60; width: 300px; padding: 8px; border-radius: 14px;
  background: #151b20; border: 1px solid #2a333b; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55); display: flex; flex-direction: column; gap: 2px; }
.af-menu[hidden] { display: none; }
.af-menu-head { display: flex; align-items: center; gap: 12px; padding: 10px 10px 12px; border-bottom: 1px solid #222a31; margin-bottom: 6px; min-width: 0; }
.af-menu-who { min-width: 0; }
.af-menu-who b { display: block; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.af-menu-who span { display: block; font-size: 12px; color: var(--muted); }
.af-menu a { display: flex; align-items: center; gap: 12px; min-height: var(--ctl-h); padding: 0 10px; border-radius: 9px;
  color: #d7dde2; text-decoration: none; font-weight: 600; }
.af-menu a svg { flex: none; }
.af-menu a:hover, .af-menu a:focus-visible { background: #1b262e; color: var(--text); }
.af-menu a:focus-visible { outline-offset: -2px; }
.af-menu a[aria-current=page] { background: #1b262e; color: var(--text); font-weight: 700; }
.af-menu a[aria-current=page] svg { color: var(--accent); }
.af-menu hr { border: 0; height: 1px; background: #222a31; margin: 6px 4px; }
.af-menu a.af-logout { color: var(--bad-text); font-weight: 700; }

/* рядок контексту під панеллю: що за сторінка (матч, гравець) і бейдж якості даних */
.af-ctx { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 8px 24px; border-bottom: 1px solid #1a2127; min-height: 48px; }
.af-ctx:has(> .summary:empty):has(> .source[hidden]) { display: none; }

/* планшет: лого, пункти й аватарка — перший рядок, пошук — другий на всю ширину */
@media (max-width: 1040px) {
  .af-search { order: 3; flex-basis: 100%; max-width: none; }
}
/* телефон: лого й аватарка — перший рядок, пошук — другий, пункти — третій */
@media (max-width: 860px) {
  .af-top-in { padding: 10px 16px; }
  .af-ctx { padding: 8px 16px; }
  .af-user { order: 2; }
  .af-nav { order: 4; flex-basis: 100%; overflow-x: auto; scrollbar-width: none; margin: -4px 0 -2px -10px; }
}
@media (max-width: 600px) {
  .af-me { max-width: 200px; }
  .af-me-name { max-width: 110px; }
  /* меню — на всю ширину під панеллю */
  .af-menu { position: fixed; left: 0; right: 0; top: var(--af-menu-top, 64px); width: auto; border-radius: 0 0 14px 14px; border-left: 0; border-right: 0;
    max-height: calc(100vh - var(--af-menu-top, 64px)); overflow-y: auto; }
}
@media (max-width: 380px) {
  .af-me-name { max-width: 84px; }
  .af-login { padding: 0 12px; }
}
