:root {
  --bg: #1C130D; --card: #2A1D14; --line: #3A2A1C; --edge: #6B4A2E; --wood: #2E2016;
  --ink: #F3E6C8; --muted: #CDB894; --dim: #8A7458; --accent: #E8A33D; --hi: #FFE2AE;
  --parch: #F3E6C8; --parch-ink: #2B1D12; --parch-muted: #5C4733; --good: #8FBF6A; --bad: #E58A6E;
  --top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --bottom: var(--tg-safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; color: var(--ink); font-family: "Alegreya Sans", system-ui, sans-serif;
  font-size: 16px; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
body { background: radial-gradient(90% 40% at 0% 0%, rgba(232,163,61,.10), transparent 70%),
  radial-gradient(90% 40% at 100% 0%, rgba(232,163,61,.07), transparent 70%), var(--bg); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, .serif { font-family: "Alegreya", Georgia, serif; }
.muted { color: var(--muted); } .small { font-size: 13px; } .hidden { display: none !important; }

.screen { display: none; height: 100%; flex-direction: column; padding-top: var(--top); }
.screen.on { display: flex; }
.scroll { flex: 1; overflow-y: auto; padding: 0 16px 16px; }
.head { padding: 14px 16px 8px; display: flex; align-items: center; gap: 10px; }
.head h1 { margin: 0; font-size: 26px; font-weight: 800; color: var(--hi); flex: 1; min-width: 0; }
.head .sub { font-size: 14px; color: var(--muted); }
.back { min-width: 44px; height: 44px; border: 0; background: transparent; color: var(--hi); font-size: 22px; margin-left: -10px; }
.section-title { margin: 18px 0 8px; font-size: 19px; font-weight: 800; color: var(--hi); display: flex; align-items: baseline; gap: 8px; }
.section-title .small { margin-left: auto; font-family: "Alegreya Sans", sans-serif; font-weight: 400; }

/* Кнопки */
.main-btn { width: 100%; min-height: 52px; border: 0; border-radius: 12px; background: var(--accent); color: var(--parch-ink);
  font-weight: 700; font-size: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.main-btn small { font-weight: 500; font-size: 13px; }
.main-btn:disabled { opacity: .5; }
.ghost-btn { width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--edge); background: transparent; font-weight: 700; font-size: 15px; }
.row-btns { display: flex; gap: 8px; } .row-btns > * { flex: 1; }
footer.actions { padding: 12px 16px calc(12px + var(--bottom)); display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }

/* Карточки */
.parch { background: var(--parch); color: var(--parch-ink); border-radius: 14px; padding: 12px 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.kicker { font-size: 13px; font-weight: 700; letter-spacing: .06em; color: #7A3B22; }
.badge { font-size: 13px; font-weight: 700; padding: 3px 9px; border-radius: 10px; white-space: nowrap; }
.badge.free { background: #4E7A3A; color: var(--ink); } .badge.soon { border: 1px solid var(--edge); color: var(--muted); }
.badge.stars { background: var(--accent); color: var(--parch-ink); }
.adv { width: 100%; display: flex; gap: 12px; align-items: center; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px; margin-bottom: 8px; min-height: 76px; }
.adv.soon { opacity: .6; border-style: dashed; }
.adv .ic { width: 52px; height: 52px; border-radius: 12px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 26px; }
.adv .t { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.adv .t b { font-family: "Alegreya", serif; font-size: 18px; color: var(--hi); }
.adv .t span { font-size: 13px; color: var(--muted); }

/* Нижние вкладки */
.tabs { flex-shrink: 0; display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line);
  padding-bottom: var(--bottom); background: var(--bg); }
.tabs button { min-height: 60px; border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px; font-size: 13px; }
.tabs button.on { color: var(--accent); font-weight: 700; }
.tabs svg { width: 22px; height: 22px; }

/* Выбор */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 44px; padding: 0 16px; border-radius: 22px; border: 1px solid var(--edge); background: transparent; font-weight: 700; font-size: 15px; }
.chip.on { background: var(--accent); color: var(--parch-ink); border-color: var(--accent); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.tile { min-height: 64px; border-radius: 12px; border: 1px solid var(--edge); background: var(--card); text-align: left; padding: 8px 12px;
  display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.tile b { font-size: 16px; } .tile span { font-size: 13px; color: var(--muted); }
.tile.on { background: var(--parch); color: var(--parch-ink); border: 2px solid var(--accent); } .tile.on span { color: var(--parch-muted); }
.name-row { display: flex; gap: 8px; }
.field { flex: 1; min-width: 0; height: 48px; border-radius: 12px; border: 1px solid var(--edge); background: var(--card); padding: 0 14px;
  font-size: 18px; font-family: "Alegreya", serif; font-weight: 700; }
.square { width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--edge); background: var(--card); color: var(--accent); font-size: 20px; }
.sheet-sum { margin-top: 14px; }
.sheet-sum b.serif { font-size: 18px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0; }
.stat { background: #EADBB8; border-radius: 10px; padding: 6px 4px; text-align: center; }
.stat b { display: block; font-family: "Alegreya", serif; font-size: 20px; } .stat span { font-size: 13px; color: var(--parch-muted); }
.sheet-sum ul { margin: 6px 0 0; padding-left: 18px; font-size: 14px; line-height: 1.35; }

/* Герои */
.hero-card { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; margin-bottom: 8px; }
.ava { width: 44px; height: 44px; border-radius: 22px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ava i { width: 30px; height: 30px; background: var(--hi); -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat; }
.hero-card .t { flex: 1; min-width: 0; }
.hero-card .t b { font-family: "Alegreya", serif; font-size: 18px; display: block; }
.hero-card .t span { font-size: 13px; color: var(--parch-muted); }

/* Профиль */
.list { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.list > * { display: flex; align-items: center; gap: 10px; min-height: 50px; padding: 10px 14px; border-bottom: 1px solid var(--line);
  width: 100%; background: transparent; border-left: 0; border-right: 0; border-top: 0; text-align: left; font-size: 15px; }
.list > *:last-child { border-bottom: 0; }
.list .v { margin-left: auto; color: var(--muted); }
.legal { font-size: 13px; color: var(--muted); line-height: 1.45; }
.legal a { color: #F0C27A; }

/* Обучение */
.progress { display: flex; gap: 4px; flex: 1; } .progress span { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.progress span.on { background: var(--accent); }
.skip { border: 0; background: transparent; color: #F0C27A; font-weight: 700; font-size: 14px; min-height: 44px; }
.scene { flex-shrink: 0; height: 150px; overflow: hidden; }
.scene svg { display: block; width: 100%; height: 150px; }
.hint { background: #1F3A3E; border: 1px solid #3E7C8A; border-radius: 12px; padding: 12px 14px; color: #DFF1F5; font-size: 14.5px; line-height: 1.4; margin-top: 10px; }
.hint b { display: block; margin-bottom: 4px; font-size: 15px; }
.formula { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 10px; }
.formula span { min-height: 44px; padding: 0 12px; border-radius: 10px; background: var(--parch); color: var(--parch-ink); display: flex; flex-direction: column;
  align-items: center; justify-content: center; line-height: 1.05; font-weight: 800; font-size: 16px; }
.formula span small { font-size: 13px; font-weight: 500; } .formula span.dc { background: var(--accent); } .formula i { font-style: normal; font-weight: 700; font-size: 18px; }
.big-die { width: 128px; height: 128px; border-radius: 64px; border: 0; background: var(--card); box-shadow: 0 0 0 6px var(--line), 0 0 0 10px var(--accent);
  margin: 22px auto 14px; display: flex; align-items: center; justify-content: center; }
.big-die.rolling svg { animation: spin .9s ease-out; }
@keyframes spin { from { transform: rotate(0) scale(.8); } to { transform: rotate(720deg) scale(1); } }
.center { text-align: center; }
.result { margin-top: 10px; }
.enemies { display: flex; gap: 8px; margin-top: 10px; }
.enemy { flex: 1; min-height: 64px; border-radius: 12px; border: 1px solid #8A3A24; background: var(--card); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; font-weight: 700; }
.enemy.sel { border: 2px solid var(--accent); box-shadow: 0 0 12px rgba(232,163,61,.4); }
.enemy.down { opacity: .45; border-style: dashed; }
.hpbar { width: 70%; height: 5px; border-radius: 3px; background: #4A3524; overflow: hidden; } .hpbar span { display: block; height: 100%; }
.log { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }

/* Игровой стол */
.bar { padding: 8px 16px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.bar .serif { font-size: 19px; font-weight: 800; color: var(--hi); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed { flex: 1; overflow-y: auto; padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 8px; }
.msg-master { background: var(--parch); color: var(--parch-ink); border: 2px solid var(--edge); box-shadow: inset 0 0 0 1px #B79C74, 0 6px 18px rgba(0,0,0,.4);
  border-radius: 6px; padding: 12px 14px; }
.msg-master .who { font-family: "Alegreya", serif; font-weight: 800; font-size: 14px; color: #7A3B22; margin-bottom: 4px; }
.msg-master .text { font-family: "Alegreya", serif; font-size: 17px; line-height: 1.42; white-space: pre-wrap; }
.msg-master.old .text { font-size: 15px; color: #4A3524; }
.howto { background: #1F3A3E; border: 1px solid #3E7C8A; border-radius: 12px; padding: 10px 14px; color: #DFF1F5; font-size: 14px; line-height: 1.4; }
.howto b { display: block; margin-bottom: 4px; }
.roll { display: flex; gap: 8px; align-items: flex-start; background: rgba(42,29,20,.85); color: #E9D7B4; border-radius: 10px; padding: 8px 10px; font-size: 14px; line-height: 1.3; }
.roll::before { content: "⬢"; color: var(--muted); }
.msg-player { align-self: flex-end; max-width: 85%; background: #3A2A1C; border: 1px solid var(--edge); border-radius: 14px 14px 4px 14px; padding: 8px 12px; font-size: 15px; }
.msg-player .who { font-size: 13px; color: var(--accent); font-weight: 700; }
.thinking { align-self: flex-start; color: var(--muted); font-style: italic; padding: 4px 6px; }
.table { display: flex; gap: 6px; padding: 8px 12px; border-top: 2px solid var(--edge); background: var(--wood); flex-shrink: 0; }
.seat { flex: 0 1 76px; min-width: 0; height: 56px; border-radius: 12px; border: 1px solid var(--edge); background: #241910; display: flex; flex-direction: column;
  align-items: center; justify-content: space-between; padding: 4px 2px 5px; }
.seat.me { box-shadow: 0 0 0 2px var(--accent), 0 0 14px rgba(232,163,61,.5); }
.seat .ava { width: 28px; height: 28px; } .seat .ava i { width: 20px; height: 20px; }
.seat .hp { font-size: 13px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.seat .hpbar { width: 34px; height: 4px; }
.ideas { display: flex; gap: 6px; overflow-x: auto; padding: 0 12px 8px; background: var(--wood); scrollbar-width: none; flex-shrink: 0; }
.ideas::-webkit-scrollbar { display: none; }
.idea { flex-shrink: 0; min-height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--edge); background: var(--card); font-weight: 700; font-size: 15px; white-space: nowrap; }
.composer { display: flex; gap: 8px; padding: 0 12px calc(10px + var(--bottom)); background: var(--wood); flex-shrink: 0; }
.composer input { flex: 1; min-width: 0; height: 44px; border-radius: 22px; border: 1px solid var(--edge); background: var(--bg); padding: 0 16px; font-size: 16px; }
.send { width: 48px; height: 48px; border-radius: 24px; border: 2px solid var(--edge); background: radial-gradient(circle at 35% 30%, #FFD089, #E8A33D 55%, #B0721E);
  color: var(--parch-ink); font-size: 20px; font-weight: 800; flex-shrink: 0; }
.send:disabled { opacity: .5; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(90px + var(--bottom)); background: #8A3A24; color: var(--ink); border-radius: 12px;
  padding: 10px 14px; font-size: 14px; display: none; z-index: 5; }
.pillar { display: flex; gap: 12px; align-items: center; }
.pillar > span { width: 40px; height: 40px; border-radius: 20px; background: var(--line); border: 1px solid var(--edge); display: flex;
  align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
