:root {
  --bg: #0f1115;
  --panel: #161920;
  --panel2: #1c2029;
  --line: #262b36;
  --text: #e6e8ec;
  --muted: #8a92a3;
  --accent: #4c8dff;
  --good: #3fb950;
  --mid: #d29922;
  --bad: #f85149;
  --fold: #2b303b;
  --fold-btn: #4a5160;
  --felt: #13261d;
  --card: #f5f3ee;
  --radius: 10px;
  --side-w: 290px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7; --panel: #ffffff; --panel2: #eef0f4; --line: #dde1e8; --text: #1b1f27; --muted: #69707e;
    --fold: #d9dde5; --fold-btn: #7b8494; --felt: #1d4430; color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
code { font: 12px ui-monospace, Menlo, monospace; background: var(--panel2); padding: 1px 4px; border-radius: 4px; }
[hidden] { display: none !important; }

/* ---------- каркас ---------- */
.app { display: flex; min-height: 100dvh; }
.side {
  width: var(--side-w); flex: none; background: var(--panel); border-right: 1px solid var(--line);
  height: 100dvh; position: sticky; top: 0; display: flex; flex-direction: column;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top {
  display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--line);
  background: var(--bg); position: sticky; top: 0; z-index: 5;
}
.title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 2px; background: var(--panel2); padding: 3px; border-radius: 9px; }
.tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; color: var(--muted); }
.tabs button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px #0003; }
.view { padding: 20px; flex: 1; }
.icon-btn { border: 0; background: none; width: 32px; height: 32px; border-radius: 8px; color: var(--muted); font-size: 16px; }
.icon-btn:hover { background: var(--panel2); color: var(--text); }
.menu-btn, .scrim { display: none; }

/* ---------- боковая панель ---------- */
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 16px; font-weight: 600; }
.side-list { overflow-y: auto; padding: 0 8px 24px; }
.row {
  position: relative; display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none;
  text-align: left; padding: 7px 8px; border-radius: 8px; min-height: 36px;
}
.row:hover, .grp-row:hover { background: var(--panel2); }
.row.sel { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.lvl1 { padding-left: 30px; font-size: 14px; }
.grp-row { padding: 0 8px 0 0; gap: 0; }
.grp-row .caret { border: 0; background: none; width: 26px; height: 36px; color: var(--muted); flex: none; }
.grp-row .grp-name { flex: 1; display: flex; align-items: center; gap: 8px; border: 0; background: none; text-align: left; min-width: 0; padding: 7px 0; font-weight: 600; }
.cnt { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.pill {
  min-width: 46px; text-align: center; font-size: 12.5px; font-weight: 600; padding: 2px 6px; border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.pill.good { background: color-mix(in srgb, var(--good) 22%, transparent); color: var(--good); }
.pill.mid { background: color-mix(in srgb, var(--mid) 22%, transparent); color: var(--mid); }
.pill.bad { background: color-mix(in srgb, var(--bad) 22%, transparent); color: var(--bad); }
.pill.na { color: var(--muted); background: var(--panel2); }
.empty-side { color: var(--muted); padding: 12px; font-size: 13px; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel2);
  padding: 8px 14px; border-radius: 8px; text-decoration: none; color: var(--text); font-size: 14px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; margin-top: 16px; }
.k { font-size: 11px; opacity: .55; font-weight: 500; }
.chip { border: 1px dashed var(--line); background: none; padding: 4px 10px; border-radius: 99px; font-size: 13px; color: var(--c); }

/* ---------- тренажёр ---------- */
.trainer { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.spot-line { text-align: center; }
.spot-name { font-size: 18px; font-weight: 600; }
.spot-note { color: var(--muted); font-size: 13px; margin-top: 2px; }
.felt {
  position: relative; background: radial-gradient(ellipse at center, color-mix(in srgb, var(--felt) 80%, #3a7) 0%, var(--felt) 75%);
  border-radius: 18px; padding: 28px 16px; display: flex; justify-content: center; align-items: center; min-height: 170px;
}
.cards { display: flex; gap: 10px; }
.card {
  width: 74px; height: 104px; background: var(--card); border-radius: 9px; box-shadow: 0 6px 14px #0006;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; font-weight: 700;
}
.card .r { font-size: 36px; letter-spacing: -2px; }
.card .s { font-size: 30px; margin-top: 2px; }
.su-s { color: #1b1f27; } .su-h { color: #d0312d; } .su-d { color: #1f6feb; } .su-c { color: #1a8f3c; }
.rng {
  position: absolute; right: 14px; top: 12px; display: flex; flex-direction: column; align-items: center;
  background: #0006; color: #fff; border-radius: 10px; padding: 5px 10px; min-width: 52px;
}
.rng span { font-size: 10px; opacity: .7; letter-spacing: .08em; }
.rng b { font-size: 22px; font-variant-numeric: tabular-nums; }

.acts { display: grid; gap: 8px; grid-template-columns: repeat(var(--cols, 2), 1fr); }
.acts.n3 { --cols: 3; } .acts.n4 { --cols: 2; } .acts.n5, .acts.n6 { --cols: 3; }
.act {
  position: relative; border: 0; border-radius: 12px; padding: 18px 8px; font-size: 17px; font-weight: 700; color: #fff;
  background: var(--c); transition: transform .06s, opacity .15s; box-shadow: inset 0 -3px 0 #0003;
}
.act:active { transform: scale(.97); }
.act .k { position: absolute; left: 9px; top: 6px; }
.act.dim { opacity: .3; }
.act.chosen.ok { outline: 3px solid var(--good); outline-offset: 2px; }
.act.chosen.bad { outline: 3px solid var(--bad); outline-offset: 2px; opacity: .55; }
.act.right { outline: 3px solid var(--good); outline-offset: 2px; animation: pulse .9s ease 2; }
@keyframes pulse { 50% { transform: scale(1.04); } }

.feedback { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.verdict { font-weight: 700; font-size: 16px; }
.verdict.ok { color: var(--good); } .verdict.bad { color: var(--bad); }
.verdict .muted { font-weight: 400; font-size: 13px; }
.strat { font-size: 14px; }
.sbar { position: relative; height: 10px; border-radius: 5px; background: var(--fold); overflow: visible; }
.sbar i { position: absolute; top: 0; bottom: 0; }
.sbar i:first-child { border-radius: 5px 0 0 5px; }
.sbar .mark { position: absolute; top: -5px; bottom: -5px; width: 3px; margin-left: -1.5px; background: var(--text); border-radius: 2px; }
.mini summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.mini .matrix { margin-top: 8px; }
.next { align-self: stretch; justify-content: center; padding: 12px; font-size: 16px; }

.trainer-foot { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--muted); }
.opts { display: flex; gap: 6px; }
.tog { display: inline-flex; cursor: pointer; }
.tog input { display: none; }
.tog span { padding: 4px 9px; border-radius: 99px; border: 1px solid var(--line); }
.tog input:checked + span { background: var(--panel2); color: var(--text); border-color: var(--muted); }

/* ---------- матрица ---------- */
.matrix { display: grid; grid-template-columns: repeat(13, 1fr); gap: 1px; background: var(--bg); border-radius: 6px; overflow: hidden; user-select: none; }
.cell { position: relative; aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--fold); min-width: 0; }
.cell span { font-size: clamp(7px, 1.9vw, 11px); font-weight: 600; color: #fff; text-shadow: 0 1px 1px #0008; letter-spacing: -.3px; }
.cell em { font-style: normal; font-size: clamp(6px, 1.5vw, 9px); color: #fffc; }
.cell.f span { color: var(--muted); text-shadow: none; font-weight: 500; }
.cell.hl { outline: 2px solid #fff; outline-offset: -2px; z-index: 1; box-shadow: 0 0 0 2px #000; }
.heat .cell { cursor: pointer; }
.heat .cell.none { background: var(--panel2); }
.heat .cell.none span { color: var(--muted); text-shadow: none; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- статистика ---------- */
.stats { max-width: 1100px; margin: 0 auto; }
.stats h3, .editor h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 0 10px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 10px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.tile > span { color: var(--muted); font-size: 12.5px; }
.tile b { font-size: 26px; font-variant-numeric: tabular-nums; }
.tile small { color: var(--muted); }
.kinds { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; font-size: 13px; }
.kinds > div { position: relative; display: flex; justify-content: space-between; padding: 2px 6px; }
.kinds i { position: absolute; left: 0; top: 0; bottom: 0; background: color-mix(in srgb, var(--bad) 18%, transparent); border-radius: 4px; z-index: 0; }
.kinds span, .kinds b { position: relative; z-index: 1; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.spot-table { display: flex; flex-direction: column; gap: 2px; }
.spot-row { display: flex; align-items: center; gap: 10px; border: 0; background: var(--panel); padding: 9px 12px; border-radius: 8px; text-align: left; }
.spot-row:hover { background: var(--panel2); }
.spot-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.k3 { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 60px; text-align: right; }
.hand-detail { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 10px; font-size: 14px; }
.worst { display: flex; flex-wrap: wrap; gap: 6px; }
.worst button { border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 4px 9px; font-size: 13px; }

/* ---------- редактор ---------- */
.editor { max-width: 1100px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.ed-form h3:first-child, .ed-bulk h3 { margin-top: 0; }
.ed-preview { position: sticky; top: 72px; }
.ed-bulk { grid-column: 1 / -1; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.editor label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.editor input:not([type=color]):not([type=file]), .editor textarea {
  width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--text); font-size: 14px;
}
.ed-bulk input:not([type=color]), .ed-bulk textarea { background: var(--bg) !important; }
.editor textarea { font-family: ui-monospace, Menlo, monospace; font-size: 13px; resize: vertical; }
.editor input:focus, .editor textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); border-color: transparent; }
.f2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.f3 { display: grid; grid-template-columns: 2fr 1fr 70px; gap: 10px; }
input[type=color] { width: 34px; height: 34px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; flex: none; }
.f3 input[type=color] { width: 100%; }
.actions-ed { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 12px; }
.act-ed { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.act-head { display: flex; align-items: center; gap: 8px; }
.act-head .act-name { flex: 1; font-weight: 600; }
.add-acts { display: flex; flex-wrap: wrap; gap: 6px; }
.editor details { margin-bottom: 12px; }
.editor summary { cursor: pointer; font-size: 14px; }
.parse-err { color: var(--bad); font-size: 13px; margin-bottom: 10px; }
.ed-btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 4px; }

/* ---------- прочее ---------- */
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty h2 { color: var(--text); }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; opacity: 0; pointer-events: none;
  transition: .2s; font-size: 14px; z-index: 50;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.login { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 100; }
.login form { display: flex; flex-direction: column; gap: 10px; width: 260px; text-align: center; }
.login .logo { font-size: 46px; }
.login input { padding: 11px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); }
.login button { padding: 11px; border-radius: 9px; border: 0; background: var(--accent); color: #fff; font-weight: 600; }
.login .err { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ---------- телефон ---------- */
@media (max-width: 860px) {
  .side {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s;
    width: min(86vw, 340px); box-shadow: 0 0 40px #0008;
  }
  body.side-open .side { transform: none; }
  body.side-open .scrim { display: block; position: fixed; inset: 0; background: #0007; z-index: 20; }
  .menu-btn { display: block; font-size: 20px; color: var(--text); }
  .top { padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top)); gap: 6px; flex-wrap: wrap; }
  .title { font-size: 14px; }
  .tabs { order: 3; width: 100%; }
  .tabs button { flex: 1; padding: 7px 4px; font-size: 14px; }
  .view { padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); }
  .row { min-height: 44px; }
  .felt { min-height: 150px; padding: 22px 12px; }
  .card { width: 66px; height: 92px; }
  .card .r { font-size: 32px; }
  .act { padding: 20px 6px; font-size: 16px; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile.wide { grid-column: 1 / -1; }
  .two, .editor { grid-template-columns: 1fr; }
  .ed-preview { position: static; order: -1; }
  .f2 { grid-template-columns: 1fr; gap: 0; }
  .k3 { display: none; }
  .act .k, .next .k { display: none; }
}
