:root {
  --bg: #0e0c12;
  --panel: #17141d;
  --panel-2: #1f1b27;
  --line: #2e2838;
  --text: #e7e1d6;
  --muted: #9a92a6;
  --gold: #e8b45a;
  --gold-dim: #8a6a34;
  --red: #e0605a;
  --green: #6cc98b;
  --blue: #7aa8ff;
  --radius: 10px;
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  --serif: Georgia, 'Times New Roman', serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(ellipse at top, #1b1624 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font: 14px/1.45 var(--font);
}
.hidden { display: none !important; }

button, input { font: inherit; color: inherit; }
.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover:not(:disabled) { border-color: var(--gold-dim); background: #29222f; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.btn.primary { background: linear-gradient(#c8923d, #9c6c26); border-color: #d9a650; color: #1a1206; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: linear-gradient(#d8a24d, #ac7c36); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.btn kbd { opacity: .55; font-size: 11px; margin-left: 6px; font-family: inherit; }

input {
  background: #0f0d14;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  width: 100%;
}

/* ─────────── Вход ─────────── */
#lobby { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.lobby-card {
  width: min(760px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 30px 80px #0008;
}
h1 { font-family: var(--serif); color: var(--gold); margin: 0; font-size: 38px; letter-spacing: .5px; }
.tagline { color: var(--muted); margin: 6px 0 22px; }
.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }

.classes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 720px) { .classes { grid-template-columns: repeat(2, 1fr); } }
.class-card {
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.class-card:hover { border-color: var(--gold-dim); }
.class-card[aria-checked="true"] { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset, 0 0 24px #e8b45a22; }
.class-card .cname { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.class-card .dot { width: 12px; height: 12px; border-radius: 50%; }
.class-card .stats { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.class-card .cdesc { font-size: 12px; color: #c9c1d4; }

.lobby-actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.lobby-actions .btn.primary { flex: 1 1 200px; padding: 11px; }
.join { display: flex; gap: 8px; flex: 1 1 220px; }
.join input { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; }
.error { color: var(--red); min-height: 1.4em; margin: 12px 0 0; }

/* ─────────── Игра ─────────── */
#game { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: #120f17cc;
}
.room b { color: var(--gold); letter-spacing: .15em; margin: 0 6px; }
.status { flex: 1; text-align: center; color: var(--muted); }
.status b { color: var(--text); }
.status .fight { color: var(--red); font-weight: 700; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 360px; }
.board { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#map { display: block; width: 100%; height: 100%; cursor: pointer; }
#map.targeting { cursor: crosshair; }
.hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  background: #0e0c12e0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100% - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.hint:empty { display: none; }
.hint b { color: var(--gold); }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: #0e0c12f0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 3;
}
.tooltip b { color: var(--gold); }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #0b0a0fd0;
  backdrop-filter: blur(3px);
  z-index: 4;
  padding: 16px;
}
.overlay .box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  width: min(460px, 100%);
  text-align: center;
}
.overlay h2 { font-family: var(--serif); color: var(--gold); margin: 0 0 8px; font-size: 26px; }
.overlay p { color: var(--muted); }
.overlay ul { list-style: none; padding: 0; margin: 16px 0; text-align: left; }
.overlay li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.overlay li:last-child { border: 0; }
.overlay .badge { margin-left: auto; font-size: 11px; color: var(--gold); }
.overlay .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }

.side {
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #120f17;
}
.panel { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }

.order { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 210px; overflow: auto; }
.order li {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid transparent;
  cursor: default;
}
.order li.current { border-color: var(--gold); background: #2a2216; }
.order li.enemy .who { color: #f0a8a0; }
.order li.off { opacity: .45; }
.order .init { font-size: 12px; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.order .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order .hp { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
.hpbar { height: 4px; background: #2a2330; border-radius: 2px; overflow: hidden; grid-column: 2 / 4; }
.hpbar i { display: block; height: 100%; background: var(--green); }

#me .head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
#me .head b { font-size: 16px; }
#me .head span { color: var(--muted); font-size: 12px; }
.stats-row { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 6px 0 8px; font-variant-numeric: tabular-nums; }
.stats-row b { color: var(--text); }
.bigbar { height: 8px; background: #2a2330; border-radius: 4px; overflow: hidden; }
.bigbar i { display: block; height: 100%; background: linear-gradient(90deg, #4fae6e, #7fdc99); transition: width .3s; }
.bigbar.xp { height: 4px; margin-top: 4px; }
.bigbar.xp i { background: var(--gold-dim); }
.turnstate { display: flex; gap: 10px; margin: 8px 0 2px; font-size: 12px; color: var(--muted); }
.pip { display: inline-flex; align-items: center; gap: 5px; }
.pip::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--gold); }
.pip.used::before { background: #3a3242; }
.saves { color: var(--red); font-size: 12px; margin-top: 6px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.badges .badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.badges .badge.rage { color: #ffb09a; border-color: #7a3424; background: #2a1712; }
.badges .badge.hidden { color: #a8e8c0; border-color: #2e5a40; background: #13241a; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.actions .wide { grid-column: 1 / -1; }
.actions .btn { padding: 7px 8px; font-size: 13px; }
.actions .end { background: #2a1d1d; border-color: #5a3434; }

.log-panel { flex: 1; min-height: 160px; display: flex; flex-direction: column; border-bottom: 0; }
.log { list-style: none; margin: 0; padding: 0 2px 0 0; flex: 1; overflow-y: auto; font-size: 13px; display: flex; flex-direction: column; gap: 3px; }
.log li { padding: 2px 0; color: #cfc8d8; overflow-wrap: anywhere; }
.log .k-system { color: var(--muted); font-style: italic; }
.log .k-combat { color: var(--gold); font-weight: 600; }
.log .k-hit { color: #f0c0a0; }
.log .k-crit { color: #ff8a60; font-weight: 700; }
.log .k-miss { color: #8d8599; }
.log .k-kill { color: var(--green); }
.log .k-heal { color: #8fe0a8; }
.log .k-death { color: var(--red); font-weight: 600; }
.log .k-save { color: #e0a0a0; }
.log .k-level { color: var(--gold); font-weight: 700; }
.log .k-loot { color: #d0a0f0; }
.log .k-roll { color: var(--blue); }
.log .k-chat { color: var(--text); }
.log .k-turn { color: #8d8599; font-size: 12px; }
.chat { margin-top: 8px; }

.toast {
  position: fixed;
  left: 50%;
  top: 64px;
  transform: translateX(-50%);
  background: #2a1b1d;
  border: 1px solid #6a3434;
  color: #ffd6d0;
  padding: 8px 16px;
  border-radius: 10px;
  z-index: 10;
  box-shadow: 0 10px 30px #0008;
  max-width: calc(100% - 32px);
}
.toast.ok { background: #1b2a1f; border-color: #346a44; color: #d0ffe0; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.code { color: var(--gold); letter-spacing: .15em; }
.classes.two { grid-template-columns: repeat(2, 1fr); }
.log .k-narration {
  color: #f3e6c8;
  font-family: var(--serif);
  font-size: 14px;
  font-style: italic;
  border-left: 3px solid var(--gold);
  padding: 4px 0 4px 10px;
  margin: 4px 0;
  background: #e8b45a0d;
}

/* Выбор роли в лобби */
.roles { display: flex; gap: 6px; background: #0f0d14; border: 1px solid var(--line); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.role { flex: 1; background: transparent; border: 0; border-radius: 7px; padding: 9px; cursor: pointer; color: var(--muted); font-weight: 600; }
.role.active { background: var(--panel-2); color: var(--gold); box-shadow: 0 0 0 1px var(--gold-dim) inset; }
.dm-note { color: #c9c1d4; background: #e8b45a10; border: 1px solid #e8b45a33; border-radius: 10px; padding: 12px; margin: 0 0 18px; }

/* Шапка */
.help-btn { font-weight: 800; width: 34px; padding-left: 0; padding-right: 0; color: var(--gold); border-color: var(--gold-dim); }

/* Масштаб на карте */
.zoom { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
.zoom .btn { width: 38px; height: 38px; padding: 0; font-size: 20px; font-weight: 700; background: #17141de6; }

/* Подпись к способности */
.ab-note { grid-column: 1 / -1; margin: -2px 0 4px; font-size: 12px; color: var(--muted); }
.actions .btn.primary { grid-column: 1 / -1; }

/* Справка */
.modal { position: fixed; inset: 0; z-index: 20; background: #07060acc; backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { width: min(720px, 100%); max-height: min(88vh, 100%); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 30px 80px #000a; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-family: var(--serif); color: var(--gold); font-size: 22px; }
.modal-body { overflow-y: auto; padding: 8px 18px 18px; -webkit-overflow-scrolling: touch; }
.help-sec { border-bottom: 1px solid var(--line); }
.help-sec summary { cursor: pointer; padding: 12px 0; font-weight: 700; font-size: 15px; list-style: none; display: flex; justify-content: space-between; }
.help-sec summary::-webkit-details-marker { display: none; }
.help-sec summary::after { content: '+'; color: var(--gold); font-weight: 800; }
.help-sec[open] summary::after { content: '−'; }
.help-body { padding: 0 0 12px; color: #d6cfe0; line-height: 1.55; }
.help-body p { margin: 6px 0; }
.help-body ul { margin: 6px 0; padding-left: 20px; }
.help-body li { margin: 4px 0; }
.help-body code { background: #0f0d14; border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }
.help-class { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.help-class-head { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.help-class .dot { width: 12px; height: 12px; border-radius: 50%; }
.help-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.help-table th, .help-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.help-table th { color: var(--muted); font-weight: 600; }

/* Панель мастера */
.dm-panel h2 { color: var(--gold); }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; margin-bottom: 8px; }
.switch input { width: 18px; height: 18px; accent-color: var(--gold); }
.dm-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.dm-card p { margin: 6px 0; font-size: 13px; color: #d6cfe0; }
.dm-card.warn { border-color: #7a3424; background: #24140f; }
.dm-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.dm-block { margin-top: 10px; }
.dm-block summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; cursor: pointer; font-size: 13px; }
.chip span { font-family: var(--serif); font-weight: 800; }
.chip.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
#dm-narrate { display: flex; flex-direction: column; gap: 6px; }
#dm-narrate textarea { background: #0f0d14; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; resize: vertical; font: inherit; color: inherit; }
#dm-narrate .btn { align-self: flex-end; }
body.is-dm .side { width: auto; }

/* Телефон */
@media (max-width: 860px) {
  #game { height: auto; min-height: 100%; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .board { height: 50vh; height: 50svh; }
  /* Свой герой и кнопки — сразу под картой, очередь и журнал ниже */
  #me-panel, #dm-panel { order: -1; }
  .ab-note { font-size: 11px; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .room-label { display: none; }
  .status { order: 3; flex-basis: 100%; font-size: 13px; }
  .panel { padding: 10px 12px; }
  /* Очередь — горизонтальной лентой, чтобы не съедать экран */
  .order { flex-direction: row; overflow-x: auto; max-height: none; padding-bottom: 4px; }
  .order li { min-width: 130px; flex: 0 0 auto; }
  .log-panel { max-height: 45vh; }
  .hint { font-size: 12px; bottom: 8px; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-box { width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; }
}

/* Крупные кнопки для пальцев */
body.touch .btn { min-height: 44px; }
body.touch .btn.small { min-height: 36px; }
body.touch .actions .btn { font-size: 15px; }
body.touch #map { touch-action: none; }

/* Узкие экраны: ничто не должно вылезать по ширине */
.lobby-card, .join input, #chat-input, .layout > *, .side, .panel, .order { min-width: 0; }
@media (max-width: 480px) {
  #lobby { padding: 12px; }
  .lobby-card { padding: 20px 16px; }
  h1 { font-size: 30px; }
  .classes { grid-template-columns: 1fr 1fr; gap: 8px; }
  .class-card { padding: 10px; }
}

/* Портреты из public/art */
.ava { border-radius: 50%; object-fit: cover; border: 2px solid #555; flex: 0 0 auto; background: #0f0d14; vertical-align: middle; }
.ava.sm, .dot.sm { width: 22px; height: 22px; margin-right: 6px; }
.dot.sm { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin: 0 4px; }
.ava.md { width: 34px; height: 34px; }
.ava.lg { width: 44px; height: 44px; }
.ava.tip { width: 40px; height: 40px; float: left; margin: 2px 8px 2px 0; }
.dot.md, .dot.lg { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
#me .head { align-items: center; }
.order .init .ava { margin: 0; }
.order .who { display: flex; align-items: center; gap: 6px; }
.chip .ava.sm { width: 20px; height: 20px; margin-right: 2px; }

.dm-select { flex: 1; min-width: 0; background: #0f0d14; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; color: var(--text); font: inherit; font-size: 13px; }
.dm-block .btn.ghost { margin-top: 6px; display: inline-block; text-decoration: none; }
.lobby-foot { margin: 14px 0 0; text-align: center; font-size: 13px; }
.lobby-foot a { color: var(--muted); }

/* Разметка зон */
.markup-bar { position: absolute; top: 10px; left: 10px; right: 60px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; background: #17141de6; border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; z-index: 2; width: fit-content; max-width: calc(100% - 70px); }
.markup-bar .btn { min-width: 34px; font-size: 16px; }
.mk-color { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.mk-color.active { border-color: #fff; box-shadow: 0 0 0 2px #0008; }
.mk-sep { width: 1px; height: 22px; background: var(--line); }
#markup-btn.active { border-color: var(--gold); color: var(--gold); }

/* Вставка картинок */
.drop-zone { position: relative; border: 2px dashed var(--line); border-radius: 12px; padding: 14px; min-height: 90px; display: flex; align-items: center; gap: 12px; cursor: pointer; color: var(--muted); font-size: 13px; transition: border-color .15s, background .15s; }
.drop-zone:hover, .drop-zone.over { border-color: var(--gold); background: #e8b45a0d; }
.drop-zone.busy { opacity: .6; pointer-events: none; }
.drop-preview { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; flex: 0 0 auto; background: #0f0d14; }

/* Карточка героя */
.sheet-box { width: min(760px, 100%); }
.sheet-btn { margin-left: auto; }
.sh-head { display: flex; align-items: center; gap: 14px; margin: 8px 0 12px; }
.sh-portrait img, .sh-portrait span { width: 76px; height: 76px; border-radius: 50%; object-fit: cover; display: grid; place-items: center; font: 800 30px var(--serif); color: #15121a; border: 2px solid var(--gold-dim); }
.sh-name { font-size: 20px; font-family: var(--serif); }
.sh-note { background: #e8b45a12; border: 1px solid #e8b45a33; border-radius: 8px; padding: 8px 10px; font-size: 13px; color: #d9cfbd; }
.sh-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0; }
.sh-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.sh-field select, .sh-ab select { background: #0f0d14; border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; color: var(--text); font: inherit; font-size: 14px; }
.sh-h { font-size: 14px; margin: 16px 0 6px; display: flex; align-items: center; gap: 10px; }
.sh-abilities { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sh-ab { position: relative; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: grid; grid-template-columns: 1fr auto; gap: 2px 6px; align-items: center; }
.sh-ab-name { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.sh-ab-score { font-size: 22px; font-family: var(--serif); }
.sh-ab-mod { font-size: 13px; color: var(--gold); font-weight: 700; }
.sh-ab select { grid-column: 1 / -1; padding: 4px 6px; }
.sh-bonus { position: absolute; top: 6px; right: 8px; font-size: 11px; color: var(--green); font-weight: 700; }
.sh-ab .sh-roll { grid-column: 1 / -1; }
.sh-skills { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.sh-skill { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 8px; font-size: 13px; }
.sh-skill.on { background: #e8b45a10; }
.sh-skill input { accent-color: var(--gold); width: 16px; height: 16px; }
.sh-skill b { font-variant-numeric: tabular-nums; }
.sh-roll { padding: 2px 8px; }
.sh-text { width: 100%; background: #0f0d14; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--text); font: inherit; font-size: 14px; resize: vertical; margin-bottom: 8px; }
.sh-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.sh-actions { justify-content: flex-end; margin-top: 14px; }
@media (max-width: 600px) {
  .sh-grid, .sh-skills { grid-template-columns: 1fr; }
  .sh-abilities { grid-template-columns: repeat(2, 1fr); }
}

/* Новый монстр мастера */
.nm-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.nm-form input, .nm-form textarea, .nm-form select { background: #0f0d14; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; color: var(--text); font: inherit; font-size: 13px; width: 100%; }
.nm-form textarea { resize: vertical; }
.nm-tier { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.nm-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.nm-stats label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); }
.nm-stats input { padding: 5px 6px; }
.nm-list { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.nm-list li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.nm-list li span { flex: 1; }

/* ───────── Иконки (game-icons.net, CC BY 3.0) ───────── */
.ic { display: inline-block; width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; background: currentColor;
  -webkit-mask: var(--i) center / contain no-repeat; mask: var(--i) center / contain no-repeat; }
.btn .ic { margin-right: 6px; }
.btn.ic-btn { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; }
.btn.ic-btn .ic { margin: 0; width: 18px; height: 18px; }
.btn.ic-btn.active { color: var(--gold); }
.sh-roll .ic { margin: 0; color: var(--gold); }
.stats-row .ic { color: var(--gold-dim); margin-right: 2px; }
.stats-row span:first-child .ic { color: #e0605a; }
.crown .ic { color: var(--gold); width: 1em; height: 1em; }
.order .init .ic { color: var(--gold); }

/* ───────── Живость интерфейса ───────── */
.btn { transition: transform .12s ease, border-color .15s, background .15s, box-shadow .2s; }
.btn:hover:not(:disabled) { box-shadow: 0 0 14px -4px #e8b45a66; }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.97); }
.btn.primary:not(:disabled) { animation: glow 2.4s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 18px -2px #e8b45a88; } }

.order li { transition: border-color .25s, background .25s, opacity .25s; }
.order li.current { animation: current 1.6s ease-in-out infinite; }
@keyframes current { 50% { box-shadow: 0 0 0 1px #e8b45a55, 0 0 16px -4px #e8b45a99; } }

.log li.new { animation: log-in .35s ease-out both; }
@keyframes log-in { from { opacity: 0; transform: translateX(-10px); } }
.log li.new.k-crit { animation: log-in .35s ease-out both, crit-flash .9s ease-out; }
@keyframes crit-flash { 0%, 30% { text-shadow: 0 0 10px #ff8a60; } }

.toast { animation: toast-in .28s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 14px) scale(.96); } }

.modal:not(.hidden) { animation: fade-in .2s ease-out both; }
.modal:not(.hidden) .modal-box { animation: box-in .28s cubic-bezier(.2, 1.2, .4, 1) both; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes box-in { from { opacity: 0; transform: translateY(18px) scale(.97); } }

/* Хиты: заливка съезжает быстро, светлый «след» потерянного — с задержкой. */
.hpbar { position: relative; height: 10px; }
.hpbar i { position: absolute; left: 0; top: 0; bottom: 0; display: block; }
.hpbar .ghost { background: #f0d8a0; transition: width .6s ease .45s; }
.hpbar .fill { background: linear-gradient(90deg, #4fae6e, #7fdc99); transition: width .3s ease-out; }
.hpbar.low .fill { background: linear-gradient(90deg, #b8403a, #e0605a); animation: low-hp 1s ease-in-out infinite; }
@keyframes low-hp { 50% { filter: brightness(1.5); } }

/* Попали по тебе — экран вздрагивает, края краснеют. */
.board::after { content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0;
  box-shadow: inset 0 0 90px 10px #c01818; }
.board.hurt { animation: shake .32s linear; }
.board.hurt::after { animation: vignette .6s ease-out; }
.board.hurt-crit { animation: shake-hard .5s linear; }
.board.hurt-crit::after { animation: vignette 1s ease-out; }
@keyframes shake { 20% { transform: translate(-5px, 2px); } 40% { transform: translate(4px, -3px); } 60% { transform: translate(-3px, 1px); } 80% { transform: translate(2px, 0); } }
@keyframes shake-hard { 10% { transform: translate(-9px, 4px) rotate(-.4deg); } 25% { transform: translate(8px, -5px) rotate(.4deg); }
  40% { transform: translate(-6px, 3px); } 55% { transform: translate(5px, -2px); } 70% { transform: translate(-3px, 1px); } 85% { transform: translate(2px, 0); } }
@keyframes vignette { 0% { opacity: .75; } 100% { opacity: 0; } }
/* Выбитая дверь: доску встряхивает, но без красной засветки — это не урон по герою. */
.board.jolt { animation: shake .26s linear; }

/* Баннеры «Ваш ход», «Бой!». */
.banner { position: absolute; left: 0; right: 0; top: 38%; z-index: 6; pointer-events: none; display: grid; place-items: center; }
.banner span { font-family: var(--serif); font-weight: 700; font-size: clamp(34px, 7vw, 64px); letter-spacing: .06em; color: var(--gold);
  padding: 6px 60px; background: linear-gradient(90deg, transparent, #0e0c12e6 20%, #0e0c12e6 80%, transparent);
  text-shadow: 0 0 24px #e8b45a88, 0 3px 0 #000; animation: banner 1.9s cubic-bezier(.2, .9, .3, 1) both; }
.banner.fight span { color: #ff7a60; text-shadow: 0 0 26px #ff403088, 0 3px 0 #000; }
.banner.win span { color: #ffe08a; }
@keyframes banner {
  0% { opacity: 0; transform: scale(1.6); letter-spacing: .4em; }
  18% { opacity: 1; transform: scale(1); letter-spacing: .06em; }
  75% { opacity: 1; transform: scale(1.02); }
  100% { opacity: 0; transform: scale(.96) translateY(-8px); }
}

/* ───────── Выбор кубиков в карточке ───────── */
.sh-dice { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 6px; }
.sh-dice button { display: flex; align-items: center; gap: 7px; padding: 6px 8px; border-radius: 10px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text); font: inherit; font-size: 13px; text-align: left; }
.sh-dice button:hover { border-color: var(--gold-dim); }
.sh-dice button.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.sh-dice .pip { width: 20px; height: 20px; flex: none; border-radius: 5px; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; border: 1px solid #0006; }

/* ───────── 3D-кубики ───────── */
/* Вуаль под кубиком лёгкая: раньше края экрана глохли на 72%, и враги по периметру
   пропадали на время броска, а потом все разом «появлялись». */
#dice-layer { position: fixed; inset: 0; z-index: 40; pointer-events: none; opacity: 0; transition: opacity .3s;
  background: radial-gradient(70% 70% at 50% 45%, #0a081026, #07060a59); }
#dice-layer.light-scene { background: radial-gradient(70% 70% at 50% 45%, #f6f1e626, #e9e0cf59); }
#dice-layer.light-scene .dice-caption { background: #fbf7efe8; border-color: #cbbfa8; color: #2a2118; }
#dice-layer.light-scene .dc-total { color: #2a2118; }
#dice-layer.light-scene .dc-label { color: #4a4038; }
#dice-layer.show { opacity: 1; }
#dice-scene { position: absolute; inset: 0; }
#dice-scene canvas { width: 100% !important; height: 100% !important; }
.dice-caption { position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 10px 26px 12px; border-radius: 14px; background: #0e0c12e0; border: 1px solid var(--line); box-shadow: 0 16px 50px #000c;
  opacity: 0; min-width: 180px; text-align: center; }
.dice-caption.show { animation: caption-in .35s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes caption-in { from { opacity: 0; transform: translateX(-50%) translateY(14px) scale(.8); } to { opacity: 1; transform: translateX(-50%); } }
.dc-total { font-family: var(--serif); font-size: 44px; line-height: 1; color: var(--text); }
.dc-math { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.dc-label { font-size: 13px; color: #cfc8d8; }
.dc-verdict { font-style: normal; font-weight: 700; font-size: 15px; margin-top: 2px; }
.dice-caption.hit .dc-verdict { color: var(--green); }
.dice-caption.miss .dc-verdict, .dice-caption.fumble .dc-verdict { color: #b0a8bc; }
.dice-caption.crit { border-color: #e8b45a; box-shadow: 0 0 40px -6px #e8b45a, 0 16px 50px #000c; }
.dice-caption.crit .dc-total, .dice-caption.crit .dc-verdict { color: #ffcf6a; text-shadow: 0 0 18px #ff9a3a; }
.dice-caption.fumble .dc-total { color: #8d8599; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ───────── Полное управление мастера ───────── */
.badges .badge.insp { color: #ffe08a; border-color: #6a5320; background: #2a2212; }
.badges .badge.dis { color: #cfc4d8; border-color: #4a4156; background: #221d2a; }
.dm-gift { margin-top: 6px; }
.dm-gift .btn { font-size: 12px; }
.pause-note { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 5; pointer-events: none;
  padding: 7px 18px; border-radius: 999px; background: #1a1526e6; border: 1px solid var(--gold-dim); color: var(--gold);
  font-family: var(--serif); font-size: 15px; box-shadow: 0 10px 30px #0008; animation: pause-in .3s ease-out both; }
.pause-note::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%;
  background: var(--gold); animation: pause-pulse 1.4s ease-in-out infinite; vertical-align: 1px; }
@keyframes pause-in { from { opacity: 0; transform: translate(-50%, -10px); } }
@keyframes pause-pulse { 50% { opacity: .25; } }
.dm-bonus { display: flex; flex-direction: column; gap: 6px; padding: 8px; margin: 6px 0; border: 1px solid var(--gold-dim); border-radius: 10px; background: #1d1726; }
.dm-bonus input[type="number"] { width: 64px; text-align: center; }
.dm-bonus input[type="text"] { flex: 1; min-width: 0; }

/* ───────── Громкость ───────── */
.sound-vol { width: 34px; height: 90px; writing-mode: vertical-lr; direction: rtl; accent-color: var(--gold);
  background: #17141de6; border: 1px solid var(--line); border-radius: 10px; padding: 6px 0; cursor: pointer; }
#sound-btn { font-size: 15px; line-height: 1; }

/* ───────── Телефон: карта во весь экран, панели — вкладками снизу ───────── */
.tabs { display: none; }
@media (max-width: 860px) {
  #game { height: 100dvh; overflow: hidden; }
  .layout { grid-template-rows: minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); }
  .board { height: auto; min-height: 0; }
  .side { border-top: 1px solid var(--line); background: var(--panel); max-height: 42dvh; display: flex; flex-direction: column; }
  .tabs { display: flex; order: -2; gap: 4px; padding: 6px 8px 0; flex: none; }
  .tabs .tab { position: relative; flex: 1; padding: 9px 6px; min-height: 42px; font: inherit; font-size: 13px; cursor: pointer;
    color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); border-bottom: 0; border-radius: 10px 10px 0 0; }
  .tabs .tab[aria-pressed="true"] { color: var(--gold); background: #241d2e; border-color: var(--gold-dim); }
  .tabs .dot-new { position: absolute; top: 6px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--gold); }
  /* Видна только выбранная панель, остальное не занимает место. */
  .side .panel { display: none; overflow-y: auto; }
  body.sheet-open[data-tab="me"] #me-panel:not(.hidden),
  body.sheet-open[data-tab="me"] #dm-panel:not(.hidden),
  body.sheet-open[data-tab="order"] #order-panel,
  body.sheet-open[data-tab="log"] .log-panel { display: flex; flex-direction: column; }
  body:not(.sheet-open) .side { max-height: none; }
  .log-panel { max-height: none; min-height: 0; }
  .log { max-height: 34dvh; }
  .order { flex-direction: column; max-height: 34dvh; }
  .order li { min-width: 0; }
  /* Кнопки на карте — компактнее, чтобы не съедали поле */
  .zoom { gap: 6px; }
  .zoom .btn { min-height: 38px; width: 38px; padding: 0; }
  .zoom .btn.ic-btn { width: 38px; height: 38px; }
  .sound-vol { height: 70px; }
  .actions { gap: 6px; }
  /* Вырез и «домашняя полоска» на iPhone не должны перекрывать кнопки */
  .side { padding-bottom: env(safe-area-inset-bottom); }
  .topbar { padding-top: max(8px, env(safe-area-inset-top)); }
  .ab-note { margin: 2px 0 4px; }
}

/* ───────── Свободные действия и снаряжение ───────── */
.att .att-text { margin: 4px 0 8px; font-style: italic; color: #ded6e8; }
.att select { max-width: 48%; }
.ab-note.wait { color: var(--gold); }
.gear { display: flex; flex-direction: column; gap: 6px; margin: 6px 0; }
.gear-item { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; }
.gear-item.on { border-color: var(--gold); }
.gear-item > div { flex: 1; min-width: 0; }
.log .k-attempt { color: #d0a0f0; font-style: italic; }
.actions .gear, .actions .ab-note { grid-column: 1 / -1; }

/* ───────── NPC мастера ───────── */
.npc-row { display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; flex-wrap: wrap; }
.npc-row > span { font-weight: 600; }
.npc-row input { flex: 1 1 140px; min-width: 0; }
.log .k-speech { color: #ffe0a8; }
.log .k-speech::before { content: '💬 '; }

.scene-row { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; }
.scene-row b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

.intro-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; color: #ded6e8; }
.intro-list b { color: var(--gold); }

/* ───────── Рисованное оформление: рамки из Gemini ─────────
   Панели берут рамку картинкой (border-image), фон остаётся нашим — так текст
   читается, а рамка выглядит нарисованной. Нет файла — останется обычная рамка. */
body.skin-art .panel,
body.skin-art .modal-box,
body.skin-art .dm-card {
  border: var(--ui-frame-w, 18px) solid transparent;
  /* round, а не stretch: середина сторон повторяется кусочками и не размазывается на длинных панелях */
  border-image: var(--ui-frame, url(/art/ui3/panel.png)) var(--ui-frame-slice, 118) / var(--ui-frame-w, 18px) / 0 round;
  border-radius: 0;
  background-color: var(--ui-panel-bg, #16120f);
  background-clip: padding-box;
}
body.skin-art .panel { padding: 12px 14px; }
body.skin-art .side { background: #100d0b; }
body.skin-art .topbar { background: #14100d; border-bottom-color: #4a3a22; }

/* ───────── Окно ожидания на телефоне ─────────
   Раньше список классов упирался в нижнюю панель и не прокручивался. */
.overlay { overflow-y: auto; -webkit-overflow-scrolling: touch; align-items: start; padding: 12px 0; }
.overlay .box { margin: auto; max-height: none; }
@media (max-width: 860px) {
  .overlay { padding: 10px 0 16px; }
  .overlay .box { width: calc(100% - 20px); padding: 14px; }
  .overlay .classes { grid-template-columns: 1fr 1fr; }
  .overlay .class-card { padding: 8px; font-size: 12px; }
}

/* ───────── Поведение касаний ─────────
   Android подсвечивал нажатие голубым и выделял текст при перетаскивании карты. */
* { -webkit-tap-highlight-color: transparent; }
body.touch { -webkit-user-select: none; user-select: none; }
body.touch input, body.touch textarea, body.touch .log { -webkit-user-select: text; user-select: text; }
.btn, .tab, .chip, #map { touch-action: manipulation; }
body.touch #map { touch-action: none; }
.prompt-text { width: 100%; background: #0f0d14; border: 1px solid var(--line); border-radius: 10px; padding: 10px;
  color: var(--text); font: inherit; font-size: 13px; resize: vertical; }

/* ───────── Кнопки в стиле темы ─────────
   .skinned вешается и на игру, и на тест-комнату: правила одни и те же.
   Табличка рисуется картинкой: края — украшения, середина растягивается под текст. */
body.skin-art .skinned .btn:not(.ic-btn):not(.ghost) {
  /* fill — рисуем и середину таблички, иначе кнопка получается пустой и высокой */
  border: 9px solid transparent;
  border-image: var(--ui-btn, none) 66 150 fill / 9px 22px / 0 stretch;
  background-color: transparent;
  color: var(--ui-btn-fg, var(--text));
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  border-radius: 0;
  padding: 4px 8px;
  min-height: 0;
  box-shadow: none;
}
body.skin-art .skinned .btn:not(.ic-btn):not(.ghost):hover:not(:disabled) { filter: brightness(1.12); box-shadow: none; }
body.skin-art .skinned .btn:not(.ic-btn):not(.ghost):disabled { filter: grayscale(0.5) brightness(0.7); }
body.skin-art .skinned .btn.primary:not(.ic-btn) { filter: saturate(1.35) brightness(1.1); font-weight: 700; }
body.skin-art .skinned .btn kbd { opacity: .7; }
/* Кнопки масштаба и значков остаются компактными — табличка им не нужна. */
body.skin-art .skinned .zoom .btn {
  border: 1px solid var(--line);
  border-image: none;
  background-color: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  text-shadow: none;
  padding: 4px 10px;
}

/* ───────── Полоска хитов в оправе ─────────
   Рамка лежит поверх заливки: середина картинки прозрачная, сквозь неё видно полоску. */
body.skin-art .skinned .bigbar.hpbar {
  position: relative;
  height: 16px;
  margin: 10px 12px 12px;
  background: #16110d;
  border-radius: 2px;
  overflow: visible;
}
body.skin-art .skinned .bigbar.hpbar::after {
  content: '';
  position: absolute;
  inset: -7px -12px;
  background: var(--ui-bar, none) center / 100% 100% no-repeat;
  pointer-events: none;
}
body.skin-art .skinned .bigbar.hpbar .ghost,
body.skin-art .skinned .bigbar.hpbar .fill { border-radius: 0; }

/* ───────── Вкладки и разделители в стиле темы ─────────
   Вкладка — нарисованная табличка (border-image), выбранная ярче, остальные приглушены.
   Разделитель — тонкая планка под заголовком панели, своя для каждой темы. */
body.skin-art .tabs .tab {
  border: 0 solid transparent;
  border-width: 12px 14px 4px;
  border-image: var(--ui-tab, none) 42 48 12 48 fill / 12px 14px 4px / 0 stretch;
  border-radius: 0;
  background-color: transparent;
  color: var(--ui-tab-fg, var(--text));
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
  padding: 2px 4px;
  min-height: 40px;
  filter: brightness(0.72) saturate(0.7);
}
body.skin-art .tabs .tab[aria-pressed="true"] {
  color: var(--ui-tab-fg, var(--text));
  background-color: transparent;
  filter: none;
}
body.skin-art .tabs .dot-new { background: #e04a3a; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35); }

body.skin-art .panel h2 {
  position: relative;
  padding-bottom: 10px;
  margin-bottom: 8px;
}
body.skin-art .panel h2::after {
  content: '';
  position: absolute;
  left: -2px;
  right: -2px;
  bottom: 0;
  height: 9px;
  background: var(--ui-div, none) center / 100% 100% no-repeat;
  pointer-events: none;
}
