:root {
  --bg: #0f1115;
  --bg-2: #161922;
  --bg-3: #1e2230;
  --line: #2a3040;
  --fg: #e8ecf4;
  --fg-dim: #97a0b5;
  --accent: #19c37d;
  --accent-2: #3b82f6;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 12px;
  --tap: 44px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}

body { min-height: 100dvh; display: flex; flex-direction: column; overflow-x: hidden; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 650; letter-spacing: .3px; }
.spacer { flex: 1; }
.icon-btn, .back {
  min-width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--line); border-radius: 10px;
  color: var(--fg); font-size: 17px; cursor: pointer;
}
.icon-btn:active, .back:active { background: var(--bg-3); }
[hidden] { display: none !important; }

main {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 24px);
}

/* ---------- generic ---------- */
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 24px 0 10px; color: var(--fg); }
h3 { font-size: 15px; margin: 18px 0 8px; color: var(--fg-dim); font-weight: 600; }
p.sub { color: var(--fg-dim); margin: 0 0 18px; font-size: 14px; }

.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.grid-menu { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }

.menu-item {
  display: block; text-align: left; width: 100%;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; color: var(--fg); cursor: pointer; font: inherit;
  transition: border-color .12s, transform .06s;
}
.menu-item:hover { border-color: #3a4256; }
.menu-item:active { transform: scale(.995); }
.menu-item .t { font-size: 17px; font-weight: 620; margin-bottom: 4px; }
.menu-item .d { font-size: 13px; color: var(--fg-dim); }

button, select, input[type=number], input[type=text] {
  font: inherit; color: var(--fg);
  background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px;
}
button { cursor: pointer; min-height: var(--tap); }
button.primary { background: var(--accent); color: #05120c; border-color: transparent; font-weight: 650; }
button.ghost { background: transparent; }
button:disabled { opacity: .45; cursor: default; }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg-3); font-size: 14px; cursor: pointer; min-height: 36px;
}
.chip[aria-pressed="true"] { background: var(--accent); color: #05120c; border-color: transparent; font-weight: 600; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--fg-dim); }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--fg-dim); }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; z-index: 50; font-size: 14px; max-width: 90vw;
}

.hint { font-size: 13px; color: var(--fg-dim); }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- Schulte ---------- */
.schulte-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.schulte {
  display: grid; gap: 4px;
  width: min(92vw, 520px);
  aspect-ratio: 1;
  touch-action: manipulation;
}
.schulte button, .schulte > div {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
  font-weight: 600; font-variant-numeric: tabular-nums; padding: 0; min-height: 0;
  font-size: clamp(14px, 5.2vw, 30px);
}
.schulte .hit { background: var(--accent); color: #05120c; }
.schulte .miss { background: var(--danger); color: #fff; }
.schulte .red { color: #ff6b6b; }
.schulte .black { color: #e8ecf4; }
.schulte .fixation { color: var(--accent-2); font-size: 20px; }

.big-target { font-size: 20px; color: var(--fg-dim); }
.big-target b { color: var(--fg); font-size: 26px; }

/* ---------- Stroop ---------- */
.stroop-stage {
  display: flex; align-items: center; justify-content: center;
  min-height: 34vh;
  /* «фиолетовый» — 10 букв: на узком экране не должно вылезать за край */
  font-size: clamp(26px, 8.5vw, 64px); font-weight: 800; letter-spacing: .5px;
  user-select: none; text-align: center;
  max-width: 100%; overflow-wrap: anywhere;
}
.stroop-answers { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(140px, 46%), 1fr)); gap: 10px; }
.stroop-answers button { min-height: 58px; font-size: 17px; font-weight: 600; }
.stroop-answers button.swatch { color: transparent; }

/* ---------- Blackjack ---------- */
.bj-stage { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.card-face {
  width: clamp(76px, 24vw, 120px); aspect-ratio: 5/7;
  background: #f7f8fb; color: #10131a; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; box-shadow: 0 6px 18px rgba(0,0,0,.45);
}
.card-face .r { font-size: clamp(26px, 9vw, 44px); line-height: 1; }
.card-face .s { font-size: clamp(18px, 6vw, 28px); line-height: 1; }
.card-face.red { color: #d02030; }
.card-hand { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.card-mini { width: 46px; aspect-ratio: 5/7; font-size: 15px; border-radius: 6px; }
.card-mini .r { font-size: 17px; }
.card-mini .s { font-size: 12px; }
.count-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 320px; margin: 0 auto; }
.count-pad button { min-height: 52px; font-size: 18px; }

/* ---------- Poker ---------- */
.poker-table {
  position: relative;
  width: 100%; aspect-ratio: 16/10;
  max-width: 640px; margin: 0 auto;
  background: radial-gradient(ellipse at center, #1a2130 0%, #11151d 70%);
  border: 1px solid var(--line); border-radius: 50% / 38%;
}
.seat {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: clamp(10px, 2.6vw, 13px);
}
.seat .pos {
  width: clamp(34px, 9vw, 46px); aspect-ratio: 1; border-radius: 50%;
  border: 1.5px solid var(--line); background: var(--bg-2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 650; color: var(--fg-dim);
}
.seat.hero .pos { border-color: var(--accent); color: var(--fg); }
.seat.actor .pos { border-color: var(--warn); color: var(--fg); }
.seat .stack { color: var(--fg-dim); font-variant-numeric: tabular-nums; }
.seat .act { font-size: 11px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line); }
.seat .act.raise { color: #ff8a65; border-color: #5a3326; }
.seat .act.fold { color: #6b7488; }
.seat .act.call { color: #8bc34a; border-color: #35481f; }

.hero-cards { display: flex; gap: 6px; justify-content: center; margin-top: 6px; }

.pot-label {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  text-align: center;
}
.pot-label .v { font-size: clamp(15px, 4vw, 20px); font-weight: 700; }
.pot-label .k { font-size: 11px; color: var(--fg-dim); }

.action-bar { display: grid; gap: 8px; margin-top: 14px; }
.action-bar button {
  min-height: 56px; font-size: 16px; font-weight: 650;
  border: none; color: #07100b; text-align: left; padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between;
}
.action-bar button .pct { font-size: 13px; opacity: .8; font-weight: 600; }

/* 13x13 range grid */
.range-grid {
  display: grid; grid-template-columns: repeat(13, 1fr); gap: 1px;
  width: min(96vw, 560px); margin: 0 auto; aspect-ratio: 1;
}
.range-grid div {
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(6px, 1.7vw, 11px); font-weight: 600;
  background: var(--bg-3); color: #cfd6e4; border-radius: 2px;
  min-width: 0; overflow: hidden;
}
.range-grid div.filled { color: #0d1117; }
.range-grid div.me { outline: 2px solid #fff; outline-offset: -2px; z-index: 2; }

.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; font-size: 13px; }
.legend .li { display: flex; align-items: center; gap: 6px; }
.legend .sw { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(255,255,255,.2); }

.verdict { text-align: center; padding: 10px; border-radius: 10px; font-weight: 650; margin: 12px 0; }
.verdict.ok { background: rgba(25,195,125,.14); color: #5bd6a4; }
.verdict.bad { background: rgba(239,68,68,.14); color: #ff8b8b; }

/* ---------- misc ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-row {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font-size: 14px;
}
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
table.data th { color: var(--fg-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }

.spark { display: block; width: 100%; height: 56px; }

@media (max-width: 420px) {
  main { padding: 12px 12px calc(env(safe-area-inset-bottom) + 20px); }
}
