:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #15181c);
  --hint: var(--tg-theme-hint-color, #6b7380);
  --link: var(--tg-theme-link-color, #2a7bd6);
  --btn: var(--tg-theme-button-color, #2a7bd6);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --good: #1f9d55;
  --bad: #d64545;
  --warn: #c98a00;
  --felt: #17603f;
  --felt-edge: #0f4a30;
  --rail: #5a3b22;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17191d; --bg2: #0f1114; --card: #1f2227; --text: #eef0f3; --hint: #9aa3ae;
    --link: #5aa6ff; --btn: #3d8ef0;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg2); color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif; }
body { min-height: 100vh; overscroll-behavior-y: none; }
main { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
h1 { font-size: 24px; margin: 4px 0 12px; line-height: 1.2; }
h2 { font-size: 19px; margin: 20px 0 10px; }
p { margin: 0 0 10px; }
.muted { color: var(--hint); font-size: 15px; }
.small { font-size: 14px; }
.loading { padding: 60px 0; text-align: center; color: var(--hint); }
.pre { white-space: pre-line; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.icon-btn { border: 0; background: var(--card); color: var(--text); width: 44px; height: 44px; border-radius: 50%;
  font-size: 20px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.qmark { border: 0; background: color-mix(in srgb, var(--btn) 15%, transparent); color: var(--btn); width: 26px; height: 26px;
  border-radius: 50%; font-weight: 700; font-size: 15px; cursor: pointer; vertical-align: middle; margin-left: 6px; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin: 0 0 12px; }
.btn { display: block; width: 100%; border: 0; border-radius: 14px; padding: 15px 16px; font-size: 17px; font-weight: 600;
  background: var(--btn); color: var(--btn-text); cursor: pointer; text-align: center; }
.btn + .btn { margin-top: 10px; }
.btn.sec { background: color-mix(in srgb, var(--btn) 13%, var(--card)); color: var(--btn); }
.btn.ghost { background: transparent; color: var(--link); padding: 10px; font-weight: 500; }
.btn:disabled { opacity: .45; }
.btn.good { background: var(--good); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; margin: 0 !important; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.choices.one { grid-template-columns: 1fr; }
.choices .btn { margin: 0; padding: 16px 10px; font-size: 18px; }
.choices .btn.picked-bad { background: var(--bad); }
.choices .btn.picked-good, .choices .btn.right { background: var(--good); }

.hero-btn { display: block; width: 100%; border: 0; text-align: left; background: var(--btn); color: var(--btn-text);
  border-radius: 20px; padding: 20px; cursor: pointer; margin-bottom: 12px; }
.hero-btn .t { font-size: 21px; font-weight: 700; display: block; }
.hero-btn .s { opacity: .85; font-size: 15px; display: block; margin-top: 4px; }

.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; border: 0; background: transparent;
  color: var(--text); font-size: 17px; text-align: left; cursor: pointer; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .ic { font-size: 22px; width: 28px; text-align: center; flex: none; }
.item .tx { flex: 1; min-width: 0; }
.item .tx small { display: block; color: var(--hint); font-size: 14px; margin-top: 2px; }
.item .ar { color: var(--hint); flex: none; }
.item.off { opacity: .55; }

.stat-tile { display: flex; gap: 14px; align-items: center; }
.big-num { font-size: 34px; font-weight: 800; line-height: 1; }
.tiles { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.tile { background: var(--card); border-radius: 14px; padding: 12px; text-align: center; }
.tile b { display: block; font-size: 24px; }
.tile span { color: var(--hint); font-size: 13px; }

.bar-row { display: block; width: 100%; border: 0; background: transparent; color: var(--text); text-align: left; padding: 10px 0;
  border-bottom: 1px solid var(--line); cursor: pointer; font-size: 16px; }
.bar-row:last-child { border-bottom: 0; }
.bar-row .lbl { display: flex; justify-content: space-between; gap: 8px; }
.bar-row .lbl b { white-space: nowrap; }
.meter { height: 8px; border-radius: 4px; background: var(--line); margin-top: 6px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 4px; background: var(--btn); }
.meter i.low { background: var(--bad); } .meter i.mid { background: var(--warn); } .meter i.hi { background: var(--good); }

.chart svg { width: 100%; height: auto; display: block; }
.chart .cap { font-size: 14px; color: var(--hint); min-height: 20px; margin-top: 4px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; border-radius: 20px; padding: 9px 14px; font-size: 15px; background: var(--card); color: var(--text); cursor: pointer; }
.chip.on { background: var(--btn); color: var(--btn-text); }

.tip { background: color-mix(in srgb, var(--btn) 12%, var(--card)); border-radius: 14px; padding: 12px 40px 12px 14px;
  position: relative; margin-bottom: 12px; font-size: 15px; }
.tip button { position: absolute; top: 6px; right: 6px; border: 0; background: transparent; color: var(--hint); font-size: 20px; width: 32px; height: 32px; cursor: pointer; }

.terms { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.term { border: 0; border-radius: 14px; padding: 6px 10px; font-size: 14px; background: var(--bg2); color: var(--link); cursor: pointer; }

.verdict { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.verdict.good { color: var(--good); } .verdict.bad { color: var(--bad); }
.explain { font-size: 15px; white-space: pre-line; }
.pic { width: 100%; border-radius: 12px; display: block; background: #20242a; min-height: 120px; }
.progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin-bottom: 12px; }
.progress i { display: block; height: 100%; background: var(--btn); }

/* стол */
.table-wrap { position: relative; width: 100%; aspect-ratio: 1 / .78; margin: 6px 0 4px; }
.felt { position: absolute; inset: 9% 9%; border-radius: 50%; background: radial-gradient(ellipse at 50% 40%, #1f7a51, var(--felt) 70%);
  border: 7px solid var(--rail); box-shadow: inset 0 0 0 3px var(--felt-edge); }
.felt-center { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; color: #e9f5ee; width: 76%; }
.felt-center .pot { font-size: 14px; opacity: .9; margin-top: 4px; }
.felt-center .line { font-size: 13px; opacity: .8; margin-top: 2px; }
.board { display: flex; gap: 4px; justify-content: center; }
.seat { position: absolute; transform: translate(-50%, -50%); text-align: center; min-width: 54px; }
.seat .nm { display: inline-block; background: #2d333b; color: #fff; border-radius: 10px; padding: 3px 7px; font-size: 13px; font-weight: 700; border: 2px solid transparent; }
.seat.fold .nm { opacity: .38; }
.seat.hero .nm { background: #f2c14e; color: #1b1b1b; font-size: 14px; }
.seat.raise .nm, .seat.jam .nm { border-color: #f2c14e; }
.seat .bt { display: block; font-size: 12px; color: #fff; background: rgba(0,0,0,.45); border-radius: 8px; padding: 1px 6px; margin-top: 3px; white-space: nowrap; }
.seat.raise .bt, .seat.jam .bt { background: #f2c14e; color: #1b1b1b; font-weight: 700; }
.seat .st { display: block; font-size: 11px; color: var(--hint); margin-top: 1px; }
.dealer { position: absolute; width: 20px; height: 20px; border-radius: 50%; background: #fff; color: #111; font-size: 11px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; transform: translate(-50%, -50%); box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.hand { display: flex; gap: 8px; justify-content: center; margin: 4px 0 6px; }
.pcard { width: 44px; height: 62px; border-radius: 7px; background: #fff; color: #111; display: inline-flex; flex-direction: column;
  align-items: center; justify-content: center; font-weight: 800; box-shadow: 0 1px 4px rgba(0,0,0,.35); line-height: 1; }
.pcard .r { font-size: 22px; } .pcard .s { font-size: 20px; margin-top: 2px; }
.pcard.big { width: 62px; height: 86px; } .pcard.big .r { font-size: 30px; } .pcard.big .s { font-size: 28px; }
.pcard.sm { width: 34px; height: 48px; } .pcard.sm .r { font-size: 17px; } .pcard.sm .s { font-size: 15px; }
.su-s { color: #111; } .su-h { color: #d23030; } .su-d { color: #2563d8; } .su-c { color: #198a3c; }
.situation { text-align: center; font-size: 15px; color: var(--hint); margin-bottom: 4px; }
.qtext { font-size: 17px; white-space: pre-line; }
.numrow { display: flex; gap: 10px; margin-top: 12px; }
.numrow input { flex: 1; font-size: 22px; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--bg); color: var(--text); min-width: 0; }
.numrow .btn { width: auto; flex: none; padding: 0 22px; }

/* сетка 13x13 */
.grid { display: grid; grid-template-columns: repeat(13, 1fr); gap: 2px; user-select: none; touch-action: none; margin: 8px 0; }
.cell { aspect-ratio: 1; border: 0; border-radius: 4px; padding: 0; font-size: 10px; font-weight: 700; color: var(--text);
  background: var(--bg2); display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; letter-spacing: -.3px; }
.cell.pair { background: color-mix(in srgb, var(--hint) 22%, var(--bg2)); }
.cell.on { background: var(--btn); color: var(--btn-text); }
.cell .fill { position: absolute; left: 0; bottom: 0; right: 0; z-index: 0; }
.cell span { position: relative; z-index: 1; }
.cell.ok-in { background: var(--good); color: #fff; }
.cell.extra { background: var(--bad); color: #fff; }
.cell.miss { box-shadow: inset 0 0 0 2px var(--bad); color: var(--bad); }
.cell.edge { box-shadow: inset 0 0 0 2px var(--warn); }
.cell.edge.on, .cell.edge.ok-in { background: color-mix(in srgb, var(--warn) 70%, var(--bg2)); color: #fff; }
.cell.hl { box-shadow: inset 0 0 0 3px #f2c14e; }
.cell.mark-ok { box-shadow: inset 0 0 0 2px var(--text); }
.cell.mark-bad { box-shadow: inset 0 0 0 3px var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 13px; color: var(--hint); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }
@media (min-width: 420px) { .cell { font-size: 11px; } }

/* уроки и онбординг */
.slides { overflow: hidden; touch-action: pan-y; }
.dots { display: flex; gap: 6px; justify-content: center; margin: 12px 0; }
.dots i { width: 8px; height: 8px; border-radius: 4px; background: var(--line); }
.dots i.on { background: var(--btn); width: 22px; }
.onb { min-height: 70vh; display: flex; flex-direction: column; justify-content: center; }
.onb .emoji { font-size: 64px; text-align: center; margin-bottom: 12px; }
.onb h1 { text-align: center; }
.onb p { text-align: center; font-size: 18px; }
.swipe-in { animation: sw .22s ease-out; }
@keyframes sw { from { opacity: .2; transform: translateX(24px); } to { opacity: 1; transform: none; } }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; z-index: 20; }
.sheet[hidden] { display: none; }
.sheet-box { background: var(--card); width: 100%; max-width: 560px; margin: 0 auto; border-radius: 20px 20px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 80vh; overflow: auto; }
.sheet-box h3 { margin: 0 0 8px; font-size: 19px; }
.sheet-box .txt { white-space: pre-line; margin-bottom: 14px; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: rgba(20,20,20,.9); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; z-index: 30; max-width: 90vw; }
.search { width: 100%; font-size: 17px; padding: 12px 14px; border-radius: 14px; border: 0; background: var(--card); color: var(--text); margin-bottom: 12px; }
.seg { display: flex; background: var(--bg2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--text); padding: 10px 6px; border-radius: 10px; font-size: 16px; cursor: pointer; }
.seg button.on { background: var(--card); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.15); }

.back-link{background:none;border:0;color:var(--link,var(--btn));font:inherit;font-size:16px;padding:4px 0 10px;cursor:pointer}
#nav{max-width:560px;margin:0 auto;padding:8px 16px 0}

/* термин в тексте: пунктир в цвет ссылки темы Telegram, нажимается */
.tw { text-decoration: underline dotted var(--link); text-decoration-thickness: 1.5px; text-underline-offset: 3px;
  cursor: pointer; border-radius: 4px; }
.tw:active, .tw:focus-visible { background: color-mix(in srgb, var(--link) 16%, transparent); outline: none; }
.sheet-box .txt.muted { font-size: 15px; }
