:root {
  --bg: var(--tg-theme-bg-color, #10151c);
  --bg2: var(--tg-theme-secondary-bg-color, #182028);
  --fg: var(--tg-theme-text-color, #eef3f8);
  --muted: var(--tg-theme-hint-color, #8b98a8);
  --accent: var(--tg-theme-button-color, #3d8bfd);
  --accent-fg: var(--tg-theme-button-text-color, #fff);
  --card-bg: #f7f8fa;
  --card-red: #d92d3c;
  --card-black: #1c232b;
  --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
}

#app { height: 100%; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

button {
  font: inherit; border: 0; border-radius: var(--radius);
  padding: 12px 16px; cursor: pointer; transition: transform .08s, opacity .15s;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .4; }
.primary { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.secondary { background: var(--bg2); color: var(--fg); }
.ghost { background: transparent; color: var(--muted); }
.small { padding: 8px 12px; font-size: 13px; }
.big { padding: 18px; font-size: 18px; width: 100%; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 8px;
}
.logo { font-size: 20px; font-weight: 700; letter-spacing: .3px; }

/* ---------- лобби ---------- */
.lobby-body { padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--bg2); }
.row { display: flex; gap: 10px; }
.row button { flex: 1; }
.join { display: flex; gap: 8px; flex: 1; }
.join input {
  flex: 1; min-width: 0; padding: 12px; border-radius: var(--radius);
  background: var(--bg2); color: var(--fg); border: 1px solid transparent;
  text-transform: uppercase; letter-spacing: 2px; text-align: center; font-weight: 600;
}
.join input:focus { outline: none; border-color: var(--accent); }
.players { display: flex; flex-direction: column; gap: 6px; }
.players .p { background: var(--bg2); border-radius: var(--radius); padding: 10px 12px; font-size: 14px; }
.rules { line-height: 1.6; margin-top: 8px; }

/* ---------- игра ---------- */
.game-top { padding: 10px 14px 0; }
.trump-box { display: flex; align-items: center; gap: 12px; }
.trump {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg2); border-radius: 12px; padding: 6px 12px 6px 10px;
  transition: box-shadow .3s;
}
.trump .glyph { font-size: 26px; line-height: 1; font-weight: 700; }
.trump .glyph.red { color: #ff6b6b; }
.trump-meta { display: flex; flex-direction: column; line-height: 1.15; }
.trump .cap { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.trump .was { font-size: 11px; color: #ffce4d; white-space: nowrap; }
.trump.changed { box-shadow: 0 0 0 2px #ffce4d; }
.stat { display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--muted); }
.stat b { font-size: 15px; color: var(--fg); }

.timer { width: 40px; height: 40px; position: relative; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--bg2); stroke-width: 3; }
.ring { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 97.4; transition: stroke-dashoffset .9s linear, stroke .3s; }
.timer span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.timer.low .ring { stroke: #ff5c5c; }
.timer.low span { color: #ff5c5c; }

.opponents { display: flex; justify-content: space-around; gap: 8px; padding: 8px 10px; }
.opp {
  flex: 1; max-width: 110px; background: var(--bg2); border-radius: var(--radius);
  padding: 8px; text-align: center; position: relative; transition: box-shadow .2s;
}
.opp.active { box-shadow: 0 0 0 2px var(--accent); }
.opp.out { opacity: .35; }
.opp .nm { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opp .cards { font-size: 11px; color: var(--muted); margin-top: 2px; }
.opp .turn { position: absolute; top: -6px; left: 50%; transform: translateX(-50%); font-size: 9px; background: var(--accent); color: var(--accent-fg); border-radius: 6px; padding: 1px 6px; }

.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; position: relative; }
.table { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; max-width: 340px; }
.pair { display: flex; gap: 4px; }

.banner {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  background: #ffce4d; color: #2a1c00; font-size: 13px; font-weight: 600;
  padding: 6px 12px; border-radius: 999px; white-space: nowrap;
}
.toast {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  background: #ff5c5c; color: #fff; font-size: 13px; padding: 8px 14px; border-radius: 999px;
  max-width: 90%; text-align: center;
}

.me-area { padding: 4px 10px 14px; }
.me-info { display: flex; gap: 8px; align-items: center; padding: 0 6px 6px; font-size: 12px; }
.me-info .role { color: var(--accent); font-weight: 600; }
.reserve { background: var(--bg2); border-radius: 8px; padding: 2px 8px; color: var(--muted); }

.hand {
  display: flex; justify-content: center; align-items: flex-end;
  min-height: 124px; padding-top: 24px; gap: 0;
}
.hand .card { margin-left: -18px; transition: transform .12s, margin .12s; }
.hand .card:first-child { margin-left: 0; }
.hand .card.playable:active { transform: translateY(-10px); }

.actions { display: flex; gap: 8px; margin-top: 8px; }
.action { flex: 1; background: var(--bg2); color: var(--fg); font-size: 14px; }
.action.warn { background: #b93a3a; color: #fff; }

/* ---------- карты ---------- */
.card {
  width: 56px; height: 82px; border-radius: 8px; background: var(--card-bg);
  color: var(--card-black); position: relative; flex: 0 0 auto;
  box-shadow: 0 2px 6px rgba(0,0,0,.35);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 5px 6px; font-weight: 700; border: 1px solid rgba(0,0,0,.08);
}
.card.red { color: var(--card-red); }
.card .r { font-size: 15px; line-height: 1; }
.card .s { font-size: 17px; line-height: 1; align-self: flex-end; }
.card .big-suit { position: absolute; inset: 0; display: grid; place-items: center; font-size: 30px; opacity: .22; }
.card.small { width: 34px; height: 50px; padding: 3px 4px; border-radius: 6px; }
.card.small .r { font-size: 10px; }
.card.small .s { font-size: 11px; }
.card.small .big-suit { font-size: 18px; }
.card.playable {
  transform: translateY(-16px);
  box-shadow: 0 0 0 2px var(--accent), 0 8px 14px rgba(0,0,0,.45);
}
.card.back {
  background: repeating-linear-gradient(45deg, #2a4a7a, #2a4a7a 6px, #24406a 6px, #24406a 12px);
  border: 1px solid #35598d;
}
.card.back::after { content: ""; position: absolute; inset: 6px; border: 1px solid rgba(255,255,255,.18); border-radius: 4px; }
.known-badge {
  position: absolute; top: -6px; right: -6px; background: var(--accent); color: #fff;
  font-size: 9px; border-radius: 999px; padding: 1px 5px; font-weight: 600;
}

/* ---------- финал / рейтинг ---------- */
.over-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; padding: 24px; text-align: center; }
.over-body h1 { margin: 0; font-size: 26px; }
.board { padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 6px; }.board .b { display: flex; justify-content: space-between; background: var(--bg2); border-radius: var(--radius); padding: 10px 12px; font-size: 14px; }
.board .rating { font-weight: 700; color: var(--accent); }

/* ---------- лог ---------- */
.logticker {
  margin-top: 10px; max-width: 96%; text-align: center;
  font-size: 11px; line-height: 1.45; color: var(--muted);
}
.logticker div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logticker div:last-child { color: var(--fg); }

.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--bg2);
}
.sheet-body { flex: 1; overflow-y: auto; padding: 12px 16px 32px; display: flex; flex-direction: column; gap: 6px; }
.sheet-body .l { background: var(--bg2); border-radius: 8px; padding: 7px 10px; font-size: 13px; }
.sheet-body .l:last-child { box-shadow: inset 2px 0 0 var(--accent); }
.sheet-body .g {
  background: var(--bg2); border-radius: 10px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 3px; font-size: 14px;
}
.sheet-body .g .meta { font-size: 12px; color: var(--muted); }
