:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f3f5);
  --text: var(--tg-theme-text-color, #16181b);
  --hint: var(--tg-theme-hint-color, #7a8189);
  --accent: var(--tg-theme-button-color, #2f7de1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--text) 12%, transparent);
  --temple: color-mix(in srgb, var(--text) 18%, var(--bg));
  --other: color-mix(in srgb, var(--text) 30%, var(--bg));
  --slot: color-mix(in srgb, var(--text) 45%, transparent);
  /* сила: от слабых к сильным */
  --s0: #c9def5; --s1: #94bfe8; --s2: #5c9bd6; --s3: #2f74b8; --s4: #154f8c;
  --good: #2e9e5b; --warn: #e08a1e; --bad: #d9443b; --none: #9aa1a8; --self: #2f74b8; --move: #8a5cd6;
}
:root[data-theme="dark"] {
  --s0: #22405f; --s1: #2f5f8f; --s2: #4381bd; --s3: #6aa6e0; --s4: #a9d0f7;
  --good: #4cc17c; --warn: #f0a443; --bad: #f06a5f; --none: #6c737a; --self: #6aa6e0; --move: #b08cf0;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.35 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; overflow: hidden;
  -webkit-tap-highlight-color: transparent; }
body { display: flex; flex-direction: column; position: relative; height: var(--tg-viewport-stable-height, 100%); }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.view[hidden] { display: none; }
header { padding: calc(8px + var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)) 12px 4px; background: var(--bg); border-bottom: 1px solid var(--line); z-index: 2; }
.top { display: flex; gap: 8px; }
#search { flex: 1; min-width: 0; height: 36px; padding: 0 12px; border: 0; border-radius: 10px;
  background: var(--bg2); color: var(--text); font: inherit; outline: none; }
button { font: inherit; color: inherit; }
.icon { width: 36px; height: 36px; border: 0; border-radius: 10px; background: var(--bg2); font-size: 18px; }
#modes { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; scrollbar-width: none; }
#modes button { flex: none; height: 30px; padding: 0 12px; border: 0; border-radius: 15px; background: var(--bg2); }
#modes button.on { background: var(--accent); color: var(--accent-text); }
#variants { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chips { flex-basis: 100%; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; }
#variants[hidden] { display: none; }
#variants button { height: 28px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: none; font-size: 13px; }
#variants button.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.seg { flex-basis: 100%; display: flex; background: var(--bg2); border-radius: 9px; padding: 2px; }
.seg button { flex: 1; height: 28px; border: 0; border-radius: 7px; background: none; font-size: 13px; }
.seg button.on { background: var(--bg); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 600; }
.vinfo { flex-basis: 100%; font-size: 12px; color: var(--hint); }
#legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 12px; color: var(--hint); }
#legend span { display: inline-flex; align-items: center; gap: 5px; }
#legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
main { position: relative; flex: 1; min-height: 0; background: var(--bg2); touch-action: none; }
svg { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-select: none; }
.msg { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--hint); }
.msg[hidden] { display: none; }
footer { padding: 4px 12px 6px; font-size: 12px; color: var(--hint);
  background: var(--bg); border-top: 1px solid var(--line); }

/* карта */
.temple { fill: var(--temple); }
.temple-label { fill: var(--hint); font-size: 2.6px; text-anchor: middle; dominant-baseline: middle; }
.slot { fill: none; stroke: var(--slot); stroke-width: .18; stroke-dasharray: .5 .4; }
.slot.free { stroke: var(--warn); stroke-width: .3; }
.other { fill: var(--other); }
.other-tag { fill: var(--bg); font-size: 1.2px; text-anchor: middle; dominant-baseline: central; font-weight: 600; }
.city { stroke: var(--bg); stroke-width: .25; }
.city.sel { stroke: var(--text); stroke-width: .45; }
.city.hit { stroke: var(--accent); stroke-width: .6; }
.move { stroke: var(--move); stroke-width: .2; fill: none; marker-end: url(#arrow); opacity: .3; }
.move.sel { stroke-width: .45; opacity: 1; }
.label { fill: var(--text); font-size: .95px; text-anchor: middle; pointer-events: none; display: none;
  paint-order: stroke; stroke: var(--bg2); stroke-width: .35px; }
.zoomed .label { display: block; }
.shield { fill: none; stroke: var(--accent); stroke-width: .2; }

/* карточка игрока */
#sheet { visibility: hidden; position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; max-height: 80%; overflow-y: auto; overscroll-behavior: contain; touch-action: none;
  background: var(--bg); border-radius: 16px 16px 0 0; box-shadow: 0 -4px 24px rgba(0,0,0,.18);
  padding: 6px 16px 16px; transform: translateY(105%); transition: transform .2s ease, visibility .2s; }
#sheet.open { transform: none; visibility: visible; }
#sheet.drag { transition: none; }
/* свёрнуто: ник и главное одной строкой, карта открыта; развёрнуто — вся карточка */
#sheet:not(.full) dl, #sheet:not(.full) .foot { display: none; }
#sheet.full .peek { display: none; }
.peek { margin-top: 6px; font-size: 14px; }
.more { color: var(--accent); font-size: 13px; margin-top: 6px; }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--hint); opacity: .5; margin: 2px auto 10px; }
.close { position: absolute; top: 10px; right: 12px; width: 30px; height: 30px; border: 0; border-radius: 15px;
  background: var(--bg2); color: var(--hint); font-size: 14px; line-height: 30px; padding: 0; }
.card h2 { padding-right: 36px; }
.card h2 { margin: 0; font-size: 19px; word-break: break-word; }
.card .sub { color: var(--hint); font-size: 13px; margin-top: 2px; }
.card dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 12px 0 0; }
.card dt { color: var(--hint); }
.card dd { margin: 0; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 9px; font-size: 12px; margin-left: 4px; vertical-align: 1px; }
.tag.good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.tag.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.tag.bad { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.list { margin: 10px 0 0; padding: 0; list-style: none; }
.list li { padding: 8px 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.list li button { all: unset; color: var(--accent); cursor: pointer; }

/* вкладки */
#tabs { display: flex; background: var(--bg); border-top: 1px solid var(--line); z-index: 6;
  padding-bottom: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px)); }
#tabs button { flex: 1; border: 0; background: none; padding: 6px 0 7px; font-size: 11px; color: var(--hint);
  display: flex; flex-direction: column; align-items: center; gap: 1px; }
#tabs button span { font-size: 19px; line-height: 1.2; filter: grayscale(1); opacity: .6; }
#tabs button.on { color: var(--accent); }
#tabs button.on span { filter: none; opacity: 1; }

/* страницы-списки */
.page { overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(12px + var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)) 16px 16px; }
.page h1 { font-size: 20px; margin: 0 0 2px; }
.page .sub { color: var(--hint); font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stats div { background: var(--bg2); border-radius: 12px; padding: 8px 10px; }
.stats b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stats small { color: var(--hint); font-size: 12px; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: grid; grid-template-columns: 2.2em 1fr auto; gap: 2px 10px; align-items: baseline;
  padding: 9px 0; border-bottom: 1px solid var(--line); }
.rows .n { color: var(--hint); font-variant-numeric: tabular-nums; text-align: right; }
.rows .nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .pts { font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.rows .avg { grid-column: 2 / 4; color: var(--hint); font-size: 12px; }
.rows li.low .pts { color: var(--warn); }
.rows li.left { opacity: .45; }
.rows li.cut { border-bottom: 2px dashed var(--warn); }
.cutnote { color: var(--warn); font-size: 12px; margin: 4px 0 0; }
.days { list-style: none; margin: 8px 0 18px; padding: 0; }
.days li { display: grid; grid-template-columns: 4.6em 1fr; gap: 2px 10px; padding: 9px 10px; border-radius: 10px; }
.days li:nth-child(odd) { background: var(--bg2); }
.days li.past { opacity: .45; }
.days li.today { outline: 2px solid var(--accent); }
.days .d { color: var(--hint); font-variant-numeric: tabular-nums; }
.days .who span { white-space: nowrap; }
.days em.tag { font-style: normal; }
.days .who span + span::before { content: " · "; color: var(--hint); }
