/* CS2 2D-реплей — Telegram Mini App. Mobile-first; карта всегда тёмная. */

:root {
  --bg-d: #0f1115;
  --panel-d: #1a1d24;
  --panel2-d: #22262f;
  --text-d: #e8eaef;
  --hint-d: #8b92a1;
  --line-d: rgba(150, 160, 180, 0.16);

  --bg: var(--tg-bg2, var(--bg-d));
  --panel: var(--tg-section, var(--tg-bg, var(--panel-d)));
  --panel2: var(--panel2-d);
  --text: var(--tg-text, var(--text-d));
  --hint: var(--tg-hint, var(--hint-d));
  --line: var(--line-d);
  --accent: var(--tg-button, #3d8bfd);
  --accent-text: var(--tg-button-text, #ffffff);
  --link: var(--tg-link, #5ea2ff);
  --danger: var(--tg-destructive, #e5484d);
  --good: #3fb950;

  --ct: #5b9bd5;
  --t: #e0b441;
  --ct-text: #6aaae4;
  --t-text: #e8bf52;
  --ct-soft: rgba(91, 155, 213, 0.16);
  --t-soft: rgba(224, 180, 65, 0.16);

  --map-bg: #16181d;
  --radius: 14px;

  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-inset-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--tg-inset-left, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--tg-inset-right, 0px));

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg-d: #eef0f4;
  --panel-d: #ffffff;
  --panel2-d: #f2f4f7;
  --text-d: #111318;
  --hint-d: #6b7280;
  --line-d: rgba(20, 30, 50, 0.1);
  --ct-text: #2f78bd;
  --t-text: #9a7000;
  --ct-soft: rgba(91, 155, 213, 0.14);
  --t-soft: rgba(224, 180, 65, 0.2);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* clip вместо hidden: не делает body контейнером прокрутки, иначе не работает position: sticky (вкладки) */
@supports (overflow: clip) {
  html, body { overflow-x: clip; }
}

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button:disabled { opacity: 0.5; cursor: default; }
a { color: var(--link); }

.ic { width: 14px; height: 14px; flex: none; vertical-align: -2px; }

.app {
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

/* ---------- общие элементы ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--panel2);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 13px; }

.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
.spinner.small { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
  position: relative;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.2s linear;
}
.progress-fill.indeterminate {
  width: 35% !important;
  animation: indet 1.3s ease-in-out infinite;
}
@keyframes indet {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(30, 33, 40, 0.96);
  color: #fff;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  font-weight: 500;
}
.toast.error { background: #b3261e; }

/* =================== Экран «Матчи» =================== */

.screen-matches { padding: 16px 16px 32px; max-width: 760px; margin: 0 auto; }

.m-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.m-title h1 { margin: 0; font-size: 24px; letter-spacing: -0.01em; }
.m-sub { margin: 2px 0 0; color: var(--hint); font-size: 13px; }

.upload-panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
}
.upload-panel.error { border-color: var(--danger); }
.upload-panel.error .progress-fill { background: var(--danger); }
.upload-panel.error .up-meta { color: var(--danger); }
.up-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.up-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.up-meta { margin-top: 8px; color: var(--hint); font-size: 13px; font-variant-numeric: tabular-nums; }

.m-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 16px;
  text-align: center;
  color: var(--hint);
}
.m-state.error { color: var(--danger); }
.m-state.empty b { color: var(--text); font-size: 16px; }
.m-state .empty-ic { font-size: 40px; }

.matches-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.mc {
  position: relative;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
}
.mc-link {
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 10px 52px 10px 10px;
  color: inherit;
  text-decoration: none;
  min-height: 84px;
}
.mc-link:active { background: var(--panel2); }
.mc-map {
  flex: none;
  width: 72px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2b3340, #1b2029);
  display: flex;
  align-items: flex-end;
  padding: 6px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.mc-map.map-de_ancient { background: linear-gradient(135deg, #4d6b3a, #243322); }
.mc-map.map-de_mirage { background: linear-gradient(135deg, #9a7a45, #4a3820); }
.mc-map.map-de_inferno { background: linear-gradient(135deg, #9b5a3a, #4a2517); }
.mc-map.map-de_nuke { background: linear-gradient(135deg, #3f6a86, #1c3140); }
.mc-map.map-de_dust2 { background: linear-gradient(135deg, #b39157, #5a4726); }
.mc-map.map-de_anubis { background: linear-gradient(135deg, #b0874a, #3d4f63); }
.mc-map.map-de_vertigo { background: linear-gradient(135deg, #6b7a8c, #2a323c); }
.mc-map.map-de_overpass { background: linear-gradient(135deg, #5a7d6a, #26352d); }
.mc-map.map-de_train { background: linear-gradient(135deg, #6e6a5d, #2e2c26); }
.mc-body { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.mc-teams { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; }
.mc-team {
  flex: 1; min-width: 0; overflow: hidden; font-size: 13px; line-height: 1.2;
  /* до двух строк: на узком экране «Команда A» иначе обрезалось до «Коман…» */
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow-wrap: anywhere;
}
.mc-team-b { text-align: right; }
.mc-score { flex: none; font-size: 18px; font-variant-numeric: tabular-nums; display: inline-flex; gap: 3px; }
.mc-score i { font-style: normal; color: var(--hint); }
.mc-score-empty { color: var(--hint); }
.mc-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--hint); min-width: 0; }
.mc-demo { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.mc-status {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 11px;
}
.st-ready { background: rgba(63, 185, 80, 0.16); color: var(--good); }
.st-wait { background: rgba(61, 139, 253, 0.16); color: var(--link); }
.st-wait::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px; margin-right: 5px;
  border-radius: 50%;
  background: currentColor;
  vertical-align: 1px;
  animation: blink 1s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.25; } }
.st-error { background: rgba(229, 72, 77, 0.16); color: var(--danger); }
.mc-del {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--hint);
  display: grid;
  place-items: center;
}
.mc-del:active { background: var(--panel2); color: var(--danger); }

/* =================== Экран реплея =================== */

.replay-status {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
  padding: 24px 16px;
}
.rs-box {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}
.rs-title { font-size: 17px; font-weight: 700; }
.rs-text { color: var(--hint); white-space: pre-line; font-size: 13px; }
.rs-progress { width: 100%; }
.replay-status.error .rs-title { color: var(--danger); }

.rp-top { padding: 6px 12px 0; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 36px;
  padding-right: 8px;
  color: var(--hint);
  text-decoration: none;
  font-weight: 500;
}
.in-telegram .back-link { display: none; }

/* табло */
.scoreboard {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 4px 2px 10px;
}
.sb-team { display: flex; flex-direction: column; min-width: 0; }
.sb-b { align-items: flex-end; text-align: right; }
.sb-name {
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.sb-name.side-ct { color: var(--ct-text); }
.sb-name.side-t { color: var(--t-text); }
.sb-side {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--hint);
}
.sb-score {
  font-size: 34px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 26px;
  text-align: center;
}
.sb-clock-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 12px;
  text-align: center;
  min-width: 88px;
}
.sb-clock { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sb-round { font-size: 11px; font-weight: 600; color: var(--hint); letter-spacing: 0.04em; }
.mode-freeze .sb-clock { color: var(--hint); }
.mode-bomb { border-color: rgba(229, 72, 77, 0.6); background: rgba(229, 72, 77, 0.12); }
.mode-bomb .sb-clock { color: #ff5a55; }
.mode-bomb .sb-clock::before { content: "💣 "; font-size: 15px; }

/* раунды */
.rounds { display: flex; align-items: center; gap: 6px; padding-bottom: 10px; }
.rounds-arrow {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  place-items: center;
}
.rounds-track {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px;
  scroll-snap-type: x proximity;
}
.rounds-track::-webkit-scrollbar { display: none; }
.rbtn {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--panel);
  font-weight: 700;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  scroll-snap-align: center;
}
.rbtn.win-ct { border-color: var(--ct); }
.rbtn.win-t { border-color: var(--t); }
.rbtn.current { color: #0f1115; }
.rbtn.current.win-ct, .rbtn.current:not(.win-t) { background: var(--ct); border-color: var(--ct); }
.rbtn.current.win-t { background: var(--t); border-color: var(--t); }
.rounds-sep { flex: none; width: 2px; height: 22px; border-radius: 1px; background: var(--hint); opacity: 0.5; }

/* основная раскладка (телефон) */
.rp-main { display: block; }
.rp-stage { display: flex; flex-direction: column; }

.map-wrap {
  position: relative;
  margin: 0 10px;
  aspect-ratio: 1 / 1;
  max-height: calc(100dvh - 120px);
  background: var(--map-bg);
  border-radius: var(--radius);
  overflow: hidden;
  order: 1;
  color: #e8eaef;
}
.map-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
.map-canvas:active { cursor: grabbing; }

.killfeed {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  pointer-events: none;
  max-width: calc(100% - 16px);
}
.kf {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(12, 14, 18, 0.78);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  max-width: 100%;
  animation: kfIn 0.18s ease-out;
}
.kf.mine { box-shadow: inset 0 0 0 1.5px #ff4d4d; }
@keyframes kfIn { from { opacity: 0; transform: translateX(8px); } }
.kf-n { overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.kf-n.side-ct { color: var(--ct); }
.kf-n.side-t { color: var(--t); }
.kf-w { color: #cfd3db; font-weight: 500; font-size: 11px; }
.kf-i { display: inline-flex; color: #ff6b6b; }
.kf-txt { font-size: 10px; font-weight: 800; }

.map-tools {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip-btn {
  min-height: 32px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(12, 14, 18, 0.72);
  color: #aeb4c0;
  font-size: 12px;
  font-weight: 600;
}
.chip-btn.active { color: #fff; border-color: rgba(255, 255, 255, 0.45); background: rgba(40, 46, 58, 0.9); }

.follow-chip {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding-left: 11px;
  border-radius: 999px;
  background: rgba(12, 14, 18, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 12px;
  font-weight: 600;
  max-width: calc(100% - 16px);
}
.follow-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.follow-chip button {
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: #fff;
  border-radius: 50%;
}

.round-banner {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 16px;
  border-radius: 10px;
  background: rgba(12, 14, 18, 0.85);
  border: 1px solid;
  font-size: 13px;
  pointer-events: none;
  white-space: nowrap;
}
.round-banner span { color: #b8bec9; font-size: 12px; }
.round-banner.side-ct { border-color: var(--ct); }
.round-banner.side-ct b { color: var(--ct); }
.round-banner.side-t { border-color: var(--t); }
.round-banner.side-t b { color: var(--t); }
.follow-chip:not([hidden]) ~ .round-banner { bottom: 52px; }

.map-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
  background: rgba(16, 18, 22, 0.72);
  color: #e8eaef;
}
.map-msg.error span { color: #ff8a85; }

/* панель управления */
.controls { order: 2; padding: 10px 10px 4px; display: flex; flex-direction: column; gap: 8px; }
.ctl-row { display: flex; align-items: center; gap: 8px; }
.ctl-main { justify-content: space-between; }
.ctl-sub { justify-content: space-between; }
.cbtn {
  flex: 1 1 0;
  min-width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.cbtn svg { width: 22px; height: 22px; }
.cbtn:active { background: var(--panel2); }
.cbtn-play { flex: 1.4 1 0; background: var(--accent); color: var(--accent-text); border-color: transparent; }
.cbtn-play:active { background: var(--accent); filter: brightness(0.9); }
.cbtn-play .ic-pause { display: none; }
.cbtn-play.playing .ic-play { display: none; }
.cbtn-play.playing .ic-pause { display: inline; }
.cbtn-sm { flex: none; width: 44px; }
.ctl-tools { display: flex; gap: 6px; flex: none; }

.speeds {
  display: flex;
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
}
.speeds button {
  flex: 1;
  min-width: 0;
  height: 36px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 0 2px;
}
.speeds button.active { background: var(--panel2); color: var(--text); box-shadow: 0 0 0 1px var(--line); }

/* таймлайн */
.timeline {
  order: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 8px;
}
.tl-time {
  flex: none;
  width: 36px;
  font-size: 12px;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.tl-track {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 44px;
  touch-action: none;
  cursor: pointer;
}
.tl-bar {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 8px;
  margin-top: -4px;
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
}
.tl-zone { position: absolute; top: 0; bottom: 0; }
.tl-freeze { background: repeating-linear-gradient(45deg, rgba(140, 150, 170, 0.25) 0 4px, transparent 4px 8px); }
.tl-bomb { background: rgba(229, 72, 77, 0.35); }
.tl-after { background: rgba(0, 0, 0, 0.25); }
.tl-progress { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(61, 139, 253, 0.55); }
.tl-marks { position: absolute; left: 0; right: 0; top: 0; bottom: 0; pointer-events: none; }
.tl-mark {
  position: absolute;
  top: 10px;
  bottom: 10px;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 2px;
  background: #9aa1ad;
}
.tl-mark.k-kill.s-ct { background: var(--ct); }
.tl-mark.k-kill.s-t { background: var(--t); }
.tl-mark.k-bomb { background: #ffffff; top: 7px; bottom: 7px; }
.tl-mark.k-utility { background: #7c8391; top: 15px; bottom: 15px; opacity: 0.8; }
.tl-mark.k-analysis { background: #c05bff; top: 4px; bottom: auto; height: 8px; width: 8px; margin-left: -4px; border-radius: 50%; }
.tl-mark.hover { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7); }
.tl-head {
  position: absolute;
  top: 6px;
  bottom: 6px;
  width: 4px;
  margin-left: -2px;
  border-radius: 2px;
  background: var(--text);
  box-shadow: 0 0 0 2px var(--bg);
  pointer-events: none;
}
.tl-track.dragging .tl-head { width: 6px; margin-left: -3px; }
.tl-tip {
  position: absolute;
  bottom: 100%;
  margin-bottom: 4px;
  max-width: min(320px, 100%);
  padding: 6px 9px;
  border-radius: 8px;
  background: rgba(20, 22, 28, 0.96);
  color: #eef0f4;
  font-size: 12px;
  line-height: 1.3;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  z-index: 5;
}
.tip-t { color: #9aa1ad; font-variant-numeric: tabular-nums; }
.tip-tags { display: block; color: #d69cff; margin-top: 2px; }

/* карточки игроков */
.rp-side { padding: 6px 10px 24px; }
.teams { display: flex; flex-direction: column; gap: 14px; }
.team-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 4px 6px;
  font-weight: 700;
}
.side-ct .team-head .th-name { color: var(--ct-text); }
.side-t .team-head .th-name { color: var(--t-text); }
.th-side { font-size: 11px; color: var(--hint); letter-spacing: 0.06em; }
.cards { display: flex; flex-direction: column; gap: 8px; }

.pcard {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  transition: opacity 0.2s, border-color 0.15s;
}
.pcard.selected { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); }
.pcard.dead { opacity: 0.4; }
.pcard.absent { opacity: 0.25; }
.pc-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pc-num { flex: none; width: 16px; color: var(--hint); font-weight: 600; font-size: 13px; text-align: center; }
.pc-name { flex: 1; min-width: 0; font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-kad { flex: none; display: flex; gap: 9px; font-variant-numeric: tabular-nums; font-size: 13px; }
.pc-kad span { display: inline-flex; align-items: center; gap: 3px; }
.pc-kad .pc-a { color: var(--hint); }
.pc-row2 { margin-top: 2px; padding-left: 24px; font-size: 13px; }
.pc-money { color: var(--good); font-weight: 600; font-variant-numeric: tabular-nums; }
.pc-weapon { flex: 1; min-width: 0; text-align: right; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pc-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
  height: 26px;
  padding: 0 8px 0 0;
  border-radius: 8px;
  background: var(--panel2);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}
.pc-hp {
  flex: none;
  min-width: 38px;
  height: 100%;
  display: grid;
  place-items: center;
  color: #111318;
  background: var(--t);
}
.side-ct .pc-hp { background: var(--ct); }
.pcard.low .pc-hp { background: var(--danger); color: #fff; }
.pc-track { flex: 1; min-width: 24px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.pc-fill { display: block; height: 100%; width: 0; background: var(--t); border-radius: 3px; transition: width 0.15s; }
.side-ct .pc-fill { background: var(--ct); }
.pcard.low .pc-fill { background: var(--danger); }
.pc-armor, .pc-helmet, .pc-kit, .pc-c4 { display: inline-flex; align-items: center; gap: 2px; color: var(--text); }
.pc-armor.off, .pc-helmet.off { opacity: 0.25; }
.pc-nades { display: inline-flex; gap: 1px; }
.pc-nades .ic { width: 15px; height: 15px; }
:root[data-theme="light"] .pc-nades .ic { filter: drop-shadow(0 0 0.6px rgba(0, 0, 0, 0.9)); }

/* разбор */
.analysis {
  margin-top: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 10px 6px;
}
.an-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 2px 6px; }
.an-head h2 { margin: 0; font-size: 16px; }
.an-filter {
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel2);
  font-size: 12px;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.an-list { list-style: none; margin: 0; padding: 0; }
.an-item + .an-item { border-top: 1px solid var(--line); }
.an-btn {
  display: flex;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 8px 4px;
  border: 0;
  background: transparent;
  text-align: left;
  align-items: flex-start;
  border-radius: 8px;
}
.an-btn:active { background: var(--panel2); }
.an-time {
  flex: none;
  min-width: 48px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--hint);
  padding-top: 1px;
}
.an-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.an-label { font-weight: 600; overflow-wrap: anywhere; }
.an-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.tag-bad { background: rgba(229, 72, 77, 0.15); color: #ff6b6b; }
.tag-good { background: rgba(63, 185, 80, 0.15); color: var(--good); }
:root[data-theme="light"] .tag-bad { color: #c62828; }
.an-time.bomb { color: #ff5a55; }
.an-empty { color: var(--hint); font-size: 13px; padding: 6px 4px 10px; }

/* подсказка */
.help-pop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.help-box {
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  overflow: auto;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding: 14px 18px calc(18px + var(--safe-bottom));
}
.help-head { display: flex; align-items: center; justify-content: space-between; }
.help-head h3 { margin: 0; font-size: 17px; }
.help-close { width: 40px; height: 40px; border: 0; background: transparent; font-size: 18px; border-radius: 50%; }
.help-cols h4 { margin: 12px 0 6px; font-size: 13px; color: var(--hint); text-transform: uppercase; letter-spacing: 0.04em; }
.help-cols ul { margin: 0; padding-left: 18px; }
.help-cols li { margin: 4px 0; }
.help-cols .keys { list-style: none; padding: 0; }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  background: var(--panel2);
  font: 600 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
}

/* =================== Десктоп =================== */

@media (min-width: 901px) {
  .screen-matches { padding-top: 28px; }

  body[data-screen="replay"] { overflow: hidden; }
  .screen-replay { height: calc(100vh - var(--safe-top) - var(--safe-bottom)); height: calc(100dvh - var(--safe-top) - var(--safe-bottom)); }
  .replay { height: 100%; display: flex; flex-direction: column; }
  .rp-top {
    flex: none;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    column-gap: 12px;
    padding: 8px 16px 0;
  }
  .back-link { grid-row: 1; grid-column: 1; align-self: center; }
  .scoreboard { grid-row: 1; grid-column: 2; max-width: 720px; justify-self: center; width: 100%; padding-bottom: 6px; }
  .rounds { grid-row: 2; grid-column: 1 / -1; }
  .in-telegram .scoreboard { grid-column: 1 / -1; }

  .rp-main {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(360px, 38vw, 540px);
    gap: 14px;
    padding: 0 16px 12px;
  }
  .rp-stage { min-height: 0; }
  .map-wrap {
    flex: 1;
    min-height: 0;
    margin: 0;
    aspect-ratio: auto;
    max-height: none;
  }
  .timeline { order: 2; padding: 8px 0 2px; }
  .controls { order: 3; flex-direction: row; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; padding: 4px 0 0; }
  .ctl-main { flex: 0 1 auto; }
  .ctl-main .cbtn { flex: none; width: 56px; }
  .ctl-main .cbtn-play { width: 72px; }
  .ctl-sub { flex: 0 1 auto; gap: 10px; }
  .speeds { flex: none; }
  .speeds button { width: 50px; flex: none; }

  .rp-side { min-height: 0; overflow-y: auto; padding: 0 2px 0 0; scrollbar-width: thin; }
  .teams { flex-direction: row; gap: 10px; }
  .team-col { flex: 1; min-width: 0; }
  .pcard { padding: 8px 9px 9px; }
  .pc-name { font-size: 14px; }
  .pc-row2 { padding-left: 0; }
  .pc-kad { gap: 6px; font-size: 12px; }
  .pc-kad .pc-a { display: none; }

  .help-pop { align-items: center; }
  .help-box { border-radius: 16px; }
  .help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

  .mc-link:hover { background: var(--panel2); }
  .cbtn:hover, .rounds-arrow:hover, .rbtn:hover { filter: brightness(1.15); }
  .an-btn:hover { background: var(--panel2); }
}

@media (min-width: 1300px) {
  .pc-kad .pc-a { display: inline-flex; }
}

@media (max-width: 900px) {
  .sb-name {
    font-size: 15px;
    line-height: 1.15;
    white-space: normal;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
}

@media (max-width: 360px) {
  .sb-score { font-size: 28px; }
  .sb-name { font-size: 14px; }
  .sb-clock-box { min-width: 76px; padding: 4px 8px; }
  .speeds button { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* =====================================================================
   Этапы разбора, вкладки «Реплей / Разбор / Отчёт», эпизоды, отчёты.
   Всё ниже — отдельные компоненты с собственными классами, чтобы их
   было легко перекрашивать и переставлять независимо от остального.
   ===================================================================== */

/* ---------- сегментированный переключатель (вкладки, «раунд / матч», «ИИ / базовый») ---------- */
.seg {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.seg > button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--hint);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seg > button.active { background: var(--panel2); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.seg-sm > button { min-height: 32px; font-size: 13px; }

/* ---------- индикатор этапов ---------- */
.stg-bar { display: inline-flex; gap: 3px; flex: none; }
.stg-seg { width: 16px; height: 5px; border-radius: 3px; background: var(--line); }
.stg-seg.stg-done { background: var(--good); }
.stg-seg.stg-cur { background: var(--accent); animation: blink 1.2s ease-in-out infinite; }
.stg-seg.stg-error { background: var(--danger); }

.stg-list { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 4px; text-align: left; }
.stg-item { display: flex; align-items: center; gap: 10px; min-height: 34px; padding: 4px 10px; border-radius: 10px; color: var(--hint); }
.stg-item.stg-cur { background: var(--panel); color: var(--text); font-weight: 600; }
.stg-item.stg-done { color: var(--text); }
.stg-item.stg-error { background: rgba(229, 72, 77, 0.12); color: var(--danger); font-weight: 600; }
.stg-mark {
  flex: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  border: 1.5px solid var(--line);
}
.stg-done .stg-mark { background: var(--good); border-color: var(--good); color: #fff; }
.stg-cur .stg-mark { border-color: var(--accent); color: var(--accent); }
.stg-error .stg-mark { background: var(--danger); border-color: var(--danger); color: #fff; }
.stg-label { flex: 1; min-width: 0; }
.rs-stages { width: 100%; margin: 4px 0 6px; }

/* карточка матча */
.mc-stages { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--hint); min-width: 0; }
.mc-stage-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.st-partial { background: rgba(63, 185, 80, 0.16); color: var(--good); }
.mc-ai { flex: none; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.mc-ai.ai-ready { background: rgba(192, 91, 255, 0.16); color: #c98bff; }
.mc-ai.ai-wait { background: rgba(61, 139, 253, 0.16); color: var(--link); }
.mc-ai.ai-error { background: rgba(229, 72, 77, 0.16); color: var(--danger); }

/* ---------- баннер «Идёт анализ» ---------- */
.an-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 10px 8px;
  padding: 6px 8px 6px 12px;
  min-height: 36px;
  border-radius: 10px;
  background: rgba(61, 139, 253, 0.12);
  border: 1px solid rgba(61, 139, 253, 0.3);
  font-size: 13px;
  font-weight: 500;
}
.an-banner-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-banner.error { background: rgba(229, 72, 77, 0.12); border-color: rgba(229, 72, 77, 0.35); }
.an-banner.error .an-banner-text { white-space: normal; }
.an-banner-close { flex: none; width: 30px; height: 30px; border: 0; border-radius: 50%; background: transparent; }

/* ---------- вкладки и панели ---------- */
.rp-tabs { margin: 0 10px 10px; }
.pane { display: none; }
.pane.active { display: block; }

@media (max-width: 900px) {
  /* телефон: вкладки закреплены под шапкой, карта видна только во вкладке «Реплей» */
  .rp-tabs {
    position: sticky;
    top: 0;
    z-index: 6;
    box-shadow: 0 6px 12px -8px rgba(0, 0, 0, 0.5);
    background: var(--panel);
  }
  .replay:not([data-tab="replay"]) .rp-stage { display: none; }
  .replay:not([data-tab="replay"]) .rp-side { padding-top: 0; }
}

/* ---------- «Разбор» ---------- */
.pane-breakdown.analysis { margin-top: 0; }
.an-head .seg { flex: 1 1 auto; max-width: 280px; }
.bd-note {
  margin: 2px 2px 8px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(61, 139, 253, 0.1);
  color: var(--hint);
  font-size: 12px;
}
.bd-progress { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px; color: var(--hint); font-size: 13px; }
/* миниатюра — в правом верхнем углу эпизода; причина и числа занимают всю ширину под ней */
.an-row { position: relative; }
.an-row .an-thumb { position: absolute; top: 8px; right: 4px; margin: 0; }
.an-item.has-thumb .an-label,
.an-item.has-thumb .an-tags { padding-right: 76px; }
.an-item.has-thumb .an-btn { min-height: 86px; }
.an-rnum { display: block; font-size: 11px; color: var(--link); }
.an-reason { color: var(--hint); font-size: 12.5px; line-height: 1.3; overflow-wrap: anywhere; }
.an-stats { display: flex; flex-direction: column; gap: 1px; font-size: 12px; }
.an-stat { display: flex; gap: 6px; min-width: 0; }
.an-stat i { flex: none; font-style: normal; color: var(--hint); }
.an-stat b { font-weight: 600; font-variant-numeric: tabular-nums; }
.tag-sev { background: rgba(140, 150, 170, 0.16); color: var(--hint); }
.tag-sev.sev-mid { background: rgba(255, 170, 60, 0.16); color: #ffae42; }
.tag-sev.sev-high { background: rgba(229, 72, 77, 0.2); color: #ff6b6b; }
.an-thumb {
  flex: none;
  width: 68px;
  height: 68px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--map-bg);
  overflow: hidden;
  display: grid;
  place-items: center;
  cursor: zoom-in;
}
.an-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.an-thumb-err { font-size: 10px; color: var(--hint); padding: 4px; text-align: center; }
.an-round-head { padding: 12px 2px 4px; border-top: 0 !important; }
.an-round-head + .an-item { border-top: 0; }
.an-round-btn {
  border: 0;
  background: transparent;
  padding: 2px 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--hint);
}

/* ---------- «Отчёт» ---------- */
.pane-report { padding-bottom: 12px; }
.rep-bundle { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.rep-bundle-btn { width: 100%; }
.rep-bundle-hint { color: var(--hint); font-size: 12px; text-align: center; }
.rep-switch { margin-bottom: 10px; }
.rep-body {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-height: 120px;
}
.rep-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px 8px;
  text-align: center;
}
.rep-state-title { font-weight: 700; font-size: 15px; }
.rep-state-text { color: var(--hint); font-size: 13px; max-width: 420px; }
.rep-state-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.rep-error .rep-state-title { color: var(--danger); }
.rep-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.rep-meta { color: var(--hint); font-size: 12px; }

/* markdown */
.md { font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 18px 0 8px; line-height: 1.25; }
.md h1 { font-size: 20px; }
.md h2 { font-size: 17px; }
.md h3 { font-size: 15px; }
.md h4, .md h5, .md h6 { font-size: 14px; color: var(--hint); }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li { margin: 3px 0; }
.md code { font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel2); padding: 1px 5px; border-radius: 5px; }
.md-pre { background: var(--panel2); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
.md-pre code { background: none; padding: 0; white-space: pre; }
.md blockquote { margin: 8px 0; padding: 2px 12px; border-left: 3px solid var(--line); color: var(--hint); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md-table-wrap { overflow-x: auto; margin: 8px 0; }
.md table { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.md th, .md td { padding: 5px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.md th { color: var(--hint); font-weight: 600; text-align: left; }
.md-ref {
  display: inline;
  padding: 0 5px;
  margin: 0 1px;
  border: 1px solid rgba(94, 162, 255, 0.35);
  border-radius: 6px;
  background: rgba(94, 162, 255, 0.1);
  color: var(--link);
  font: inherit;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
  white-space: nowrap;
}
.md-ref:active { background: rgba(94, 162, 255, 0.25); }
.md-ref-round { font-size: 12px; vertical-align: 2px; margin-left: 6px; }

/* ---------- полноэкранная картинка ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}
.lb-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  cursor: zoom-in;
}
.lightbox.zoomed .lb-stage { cursor: grab; }
.lb-img {
  max-width: 100%;
  max-height: 100%;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.lb-bar { flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 12px; color: #e8eaef; }
.lb-caption { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-close { flex: none; width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.12); color: #fff; font-size: 18px; }
body.lb-open { overflow: hidden; }

/* ---------- десктоп: вкладки — над правой панелью, карта всегда слева ---------- */
@media (min-width: 901px) {
  .an-banner { margin: 0 16px 8px; }
  .rp-main { grid-template-rows: auto minmax(0, 1fr); row-gap: 10px; }
  .rp-stage { grid-column: 1; grid-row: 1 / span 2; }
  .rp-tabs { grid-column: 2; grid-row: 1; margin: 0; }
  .rp-side { grid-column: 2; grid-row: 2; }
  .pane-breakdown.analysis { min-height: 100%; }
  .an-thumb:hover, .md-ref:hover { filter: brightness(1.2); }
  .seg > button:not(.active):hover { color: var(--text); }
}

/* Кнопка «Скопировать мастер-промпт» и ручное копирование, если буфер обмена недоступен */
.rep-prompt-btn { width: 100%; margin-top: 10px; justify-content: center; gap: 8px; }
.prompt-sheet { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.7); display: flex; align-items: flex-end; justify-content: center; }
.prompt-sheet-box { width: 100%; max-width: 720px; max-height: 85vh; display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); color: var(--text); border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.prompt-sheet-title { font-weight: 700; }
.prompt-sheet textarea { flex: 1; min-height: 40vh; width: 100%; resize: none; border-radius: 10px; padding: 10px;
  background: var(--bg); color: var(--text); border: 1px solid var(--line); font: 12px/1.4 ui-monospace, Menlo, monospace; }
