:root {
  --bg: #1a0f1e;
  --bg2: #2a1a30;
  --panel: #34213b;
  --panel2: #43294b;
  --text: #f4e9f7;
  --muted: #b79cc0;
  --accent: #ff8a1f;
  --accent2: #ffd23f;
  --danger: #ff4d5e;
  --ok: #5fd68a;
  --blue: #4fb3ff;
  --purple: #c96bff;
  --radius: 12px;
  font-size: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; height: 100%; }
body { overscroll-behavior: none; }
#app { min-height: 100dvh; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; background: var(--panel2); border: 1px solid #5c3a66; border-radius: 10px; padding: 10px 14px; cursor: pointer; }
button:active { transform: translateY(1px); filter: brightness(1.15); }
button.primary { background: var(--accent); color: #1a0f1e; border-color: #ff9f47; font-weight: 700; }
button.danger { background: var(--danger); color: #fff; border-color: #ff6c7a; }
button.ghost { background: transparent; border-color: #5c3a66; }
button:disabled { opacity: .45; cursor: default; }
input[type=text] { font: inherit; background: var(--bg2); color: var(--text); border: 1px solid #5c3a66; border-radius: 8px; padding: 8px 10px; width: 100%; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.screen { padding: 14px; max-width: 720px; margin: 0 auto; width: 100%; }
h1 { font-size: 1.6rem; margin: 8px 0 4px; color: var(--accent2); text-shadow: 0 2px 0 #000; }
h2 { font-size: 1.15rem; margin: 14px 0 8px; color: var(--accent); }
h3 { font-size: 1rem; margin: 10px 0 6px; color: var(--muted); font-weight: 600; }
.sub { color: var(--muted); font-size: .9rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.card-panel { background: var(--panel); border-radius: var(--radius); padding: 12px; }

/* ---------- пасс экран ---------- */
.pass { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 18px; }
.pass .big { font-size: 2rem; font-weight: 800; color: var(--accent2); }
.pass button { font-size: 1.2rem; padding: 16px 26px; }

/* ---------- верхняя панель игроков ---------- */
.players { display: flex; gap: 6px; overflow-x: auto; padding: 8px; background: var(--bg2); position: sticky; top: 0; z-index: 5; }
.pl { flex: 0 0 auto; min-width: 112px; background: var(--panel); border-radius: 10px; padding: 6px 8px; border: 2px solid transparent; font-size: .8rem; line-height: 1.3; }
.pl.active { border-color: var(--accent); }
.pl.viewer { background: var(--panel2); }
.pl .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.pl .st { display: flex; gap: 6px; flex-wrap: wrap; color: var(--muted); }
.pl .st b { color: var(--text); }
.badge { display: inline-block; padding: 1px 6px; border-radius: 8px; font-size: .75rem; background: var(--panel2); }
.badge.loser { background: #6b4aa0; }
.badge.prize { background: #a35c00; }

/* ---------- карты ---------- */
.cards { display: flex; gap: 8px; overflow-x: auto; padding: 6px 2px 10px; scroll-snap-type: x proximity; align-items: stretch; }
.cards.wrap { flex-wrap: wrap; overflow: visible; }
.card { flex: 0 0 auto; width: 170px; border-radius: 10px; overflow: hidden; position: relative;
  background: color-mix(in srgb, var(--tc, #5c3a66) 20%, #241329);
  border: 1px solid color-mix(in srgb, var(--tc, #5c3a66) 55%, #241329);
  border-top: 3px solid var(--tc, #5c3a66); scroll-snap-align: start; cursor: pointer;
  display: flex; flex-direction: column; }
.card.sm { width: 152px; }
.card.hand { width: 180px; }
.card.legend { box-shadow: 0 0 0 1px #d4a017; border-color: #d4a017; background: color-mix(in srgb, #d4a017 16%, #241329); }
.card .art { position: relative; aspect-ratio: 13/9; background: #221; flex: 0 0 auto; }
.card .art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card .nm { font-size: .88rem; font-weight: 700; padding: 4px 6px 1px; line-height: 1.15; }
.card.sm .nm { font-size: .82rem; }
.card .meta { display: flex; align-items: center; gap: 4px; padding: 0 6px 3px; font-size: .72rem; color: var(--muted); }
.card .meta .ty { color: color-mix(in srgb, var(--tc, var(--muted)) 70%, #fff); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta .icons { display: flex; gap: 1px; margin-left: auto; }
.card .meta .ic { font-size: .74rem; }
.card .meta .vp { color: var(--accent2); font-weight: 700; white-space: nowrap; }
.card .txt { font-size: .76rem; line-height: 1.3; padding: 3px 6px 6px; color: #f0e8f5; border-top: 1px solid #ffffff1a; flex: 1; }
.card .txt.long { font-size: .68rem; }
.card.sm .txt { font-size: .72rem; }
.card.sm .txt.long { font-size: .65rem; }
/* доступность покупки */
.card.buyable { outline: 2px solid var(--ok); outline-offset: 1px; }
.card.buyable .cost { background: #145c32; border-color: var(--ok); }
.card.noafford { opacity: .55; filter: saturate(.6); }
.card.noafford .cost { background: #5c1420; border-color: #a04552; }
/* кнопка под картой */
.cardbtn { padding: 4px 6px 6px; }
.cardbtn .qp { width: 100%; padding: 7px 6px; font-size: .82rem; border-radius: 8px; }
.cardbtn .qp.primary { background: var(--accent); color: #1a0f1e; border-color: #ff9f47; font-weight: 700; }
.card .txt b { color: var(--accent2); }
.card .cost { position: absolute; top: 4px; right: 4px; background: #111; color: #fff; border-radius: 50%; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; font-size: .78rem; font-weight: 700; border: 2px solid #ccc; }
.card .chips { position: absolute; top: 4px; left: 4px; background: var(--accent); color: #000; border-radius: 6px; padding: 0 5px; font-size: .72rem; font-weight: 700; }
.card .actdot { position: absolute; bottom: 4px; right: 4px; background: var(--accent2); color: #000; border-radius: 50%; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; font-size: .8rem; }
.card.selected { border-color: var(--accent2); box-shadow: 0 0 0 2px var(--accent2); }
.card.dim { opacity: .5; }
.card.pile { align-items: center; justify-content: center; text-align: center; font-size: .72rem; padding: 6px; min-height: 120px; }
.card.pile b { font-size: 1.3rem; color: var(--accent2); }
/* цвета типов */
.t-beast { --tc: #e05252; }
.t-wizard { --tc: #5b9bef; }
.t-spell { --tc: #f0913d; }
.t-treasure { --tc: #d4b13d; }
.t-place { --tc: #9aa5b1; }
.t-familiar { --tc: #45c4a0; }
.t-starter { --tc: #8f8f8f; }
.t-chaos { --tc: #c07ff5; }
.t-limp { --tc: #6b7b6e; }
.t-bespredel { --tc: #ff4d5e; }
.cardtext { white-space: pre-wrap; font-size: .92rem; line-height: 1.35; }
.cardtext b { color: var(--accent2); }
/* десктоп: карты крупнее, ряды переносятся */
@media (min-width: 760px) {
  .cards { flex-wrap: wrap; overflow: visible; }
  .card { width: 200px; }
  .card.sm { width: 180px; }
  .card.hand { width: 210px; }
  .card .txt { font-size: .82rem; }
  .card .txt.long { font-size: .74rem; }
  .card.sm .txt { font-size: .78rem; }
  .card .nm { font-size: .95rem; }
  .section { max-width: 1180px; margin: 0 auto; width: 100%; }
}
/* строка запасов (вялые палочки, чипсины) */
.supply { font-size: .85rem; color: var(--muted); padding: 2px 2px 6px; }
.supply b { color: var(--text); }
/* всегда видимое свойство игрока */
.traitbox { margin-top: 8px; background: var(--panel); border-left: 3px solid var(--accent2); border-radius: 8px; padding: 8px 10px; font-size: .88rem; line-height: 1.35; cursor: pointer; }
.traitbox b { color: var(--accent2); }

/* ---------- секции ---------- */
.section { padding: 4px 10px; }
.section h3 { display: flex; justify-content: space-between; align-items: center; margin: 8px 0 2px; }
.section h3 .sub { font-weight: 400; }

/* ---------- нижняя панель ---------- */
.bottom { position: sticky; bottom: 0; background: var(--bg2); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: center; border-top: 1px solid #5c3a66; z-index: 5; }
.bottom .power { font-size: 1.1rem; font-weight: 800; color: var(--accent2); }
.bottom .spacer { flex: 1; }

/* ---------- модалки ---------- */
#modal:empty { display: none; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
@media (min-width: 600px) { .overlay { align-items: center; } }
.dialog { background: var(--panel); width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 30px #000; }
@media (min-width: 600px) { .dialog { border-radius: 16px; } }
.dialog h2 { margin-top: 0; }
.dialog .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; position: sticky; bottom: 0; background: var(--panel); padding-top: 8px; }
.dialog .actions button { flex: 1 1 auto; min-width: 120px; }
.detail { display: flex; gap: 12px; }
.detail.vert { flex-direction: column; }
.detail.vert img { align-self: center; }
.detail img { width: 46%; max-width: 260px; border-radius: 10px; align-self: flex-start; }
.detail .info { flex: 1; }
.opt { display: block; width: 100%; text-align: left; margin-bottom: 8px; padding: 12px; }
.opt.sel { border-color: var(--accent2); background: #5a3f1c; }
.log { font-size: .82rem; line-height: 1.35; color: var(--muted); max-height: 60dvh; overflow-y: auto; white-space: pre-wrap; }
.log div:nth-child(odd) { background: rgba(255,255,255,.03); }
.log .hl { color: var(--accent2); }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #000c; color: #fff; padding: 8px 14px; border-radius: 20px; font-size: .9rem; z-index: 60; pointer-events: none; animation: fade 2.4s forwards; }
@keyframes fade { 0%,70% { opacity: 1; } 100% { opacity: 0; } }
.stepper { display: flex; align-items: center; gap: 12px; justify-content: center; font-size: 1.5rem; }
.stepper button { width: 52px; height: 52px; font-size: 1.5rem; }
table.score { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.score td, table.score th { padding: 6px 8px; border-bottom: 1px solid #5c3a66; text-align: left; }
table.score td.num { text-align: right; font-variant-numeric: tabular-nums; }
.winner { color: var(--accent2); font-weight: 800; }
.token { background: var(--panel2); border-radius: 10px; padding: 10px; font-size: .9rem; margin-bottom: 8px; }
.token img { width: 100%; max-width: 320px; border-radius: 8px; display: block; margin: 0 auto 6px; }
.hint { font-size: .85rem; color: var(--muted); margin: 4px 0; }
.setup-card { background: var(--panel); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; border: 2px solid transparent; cursor: pointer; }
.setup-card.sel { border-color: var(--accent2); }
.setup-card img { width: 100%; max-width: 300px; border-radius: 8px; display: block; margin: 0 auto 8px; }
.menu button { display: block; width: 100%; text-align: left; margin-bottom: 8px; }
.banner { margin: 6px 10px 0; padding: 8px 12px; border-radius: 10px; background: var(--panel); color: var(--muted); font-size: .9rem; text-align: center; }
.banner.mine { background: #5a3f1c; color: var(--accent2); font-weight: 700; }
