/* ===== Правила настольных игр — общий стиль ===== */
:root {
  --bg: #f4ecdd;
  --paper: #fffaf1;
  --text: #2a2118;
  --muted: #74624f;
  --line: #e3d5bd;
  --accent: #8a5a12;
  --accent-soft: #f6e6c6;
  --note: #2c5d8f;
  --note-bg: #eaf2fb;
  --warn: #a8321f;
  --warn-bg: #fbe9e4;
  --example-bg: #f3efe7;
  --mark: #ffe066;
  --shadow: 0 1px 2px rgba(60, 40, 10, .08), 0 4px 16px rgba(60, 40, 10, .08);
  --header-h: 108px;
  --brown: #8b5a2b; --grey: #808080; --blue: #2a6fb0; --green: #2e8b57;
  --yellow: #d4a017; --red: #c0392b; --purple: #7b4fa0;
}
body.game-cob {
  --accent: #7d1f2c;
  --accent-soft: #f5e1e1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16120e;
    --paper: #211b15;
    --text: #efe5d6;
    --muted: #b3a38e;
    --line: #3a3027;
    --accent: #e0b060;
    --accent-soft: #3a2d18;
    --note: #8dbdf0;
    --note-bg: #1b2735;
    --warn: #f0917c;
    --warn-bg: #3a1f19;
    --example-bg: #2a231c;
    --mark: #806a00;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  }
  body.game-cob { --accent: #f08a96; --accent-soft: #3b1e22; }
  figure img, .pages img { filter: brightness(.92); }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
img { max-width: 100%; height: auto; }
a { color: var(--accent); }
body.lb-open { overflow: hidden; }

/* ----- Шапка ----- */
.top {
  position: sticky; top: 0; z-index: 30;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.top-row {
  display: flex; align-items: center; gap: 8px;
  max-width: 900px; margin: 0 auto; padding: 8px 10px 4px;
}
.top-title {
  flex: 1; font-weight: 700; font-size: 1.05rem; color: var(--accent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 44px; height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text);
  font: inherit; font-size: .95rem; text-decoration: none; cursor: pointer;
}
.icon-btn:active { transform: scale(.97); }
.search-row { max-width: 900px; margin: 0 auto; padding: 4px 10px 10px; position: relative; }
#q {
  width: 100%; height: 46px; padding: 0 44px 0 42px;
  border: 2px solid var(--line); border-radius: 14px;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%23998877' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='8.5' cy='8.5' r='6'/%3E%3Cpath d='M13 13l5 5'/%3E%3C/svg%3E") 13px 50% no-repeat;
  color: var(--text); font: inherit; font-size: 16px; outline: none;
  -webkit-appearance: none; appearance: none;
}
#q:focus { border-color: var(--accent); }
#q::-webkit-search-cancel-button { display: none; }
#q-clear {
  position: absolute; right: 16px; top: 50%; transform: translateY(-58%);
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 18px; cursor: pointer;
}

/* ----- Результаты поиска ----- */
#results {
  position: fixed; z-index: 40; left: 0; right: 0; top: var(--header-h);
  max-width: 900px; margin: 0 auto;
  max-height: calc(100dvh - var(--header-h) - 8px); overflow-y: auto;
  background: var(--paper); border: 1px solid var(--line); border-top: 0;
  border-radius: 0 0 16px 16px; box-shadow: var(--shadow);
  overscroll-behavior: contain;
}
.r-count, .r-empty { padding: 10px 16px; color: var(--muted); font-size: .9rem; }
.r {
  display: block; padding: 10px 16px; border-top: 1px solid var(--line);
  color: var(--text); text-decoration: none;
}
.r:focus { outline: none; }
.r.active { background: var(--accent-soft); box-shadow: inset 4px 0 0 var(--accent); }
.r-crumb { display: block; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.r-title { display: block; font-weight: 700; color: var(--accent); }
.r-snip { display: block; font-size: .92rem; line-height: 1.45; color: var(--text); }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
mark.hit { animation: hitpulse 1.6s ease-out 1; }
@keyframes hitpulse { 0% { box-shadow: 0 0 0 6px var(--mark); } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ----- Оглавление ----- */
#toc {
  position: fixed; z-index: 50; top: 0; right: 0; bottom: 0;
  width: min(86vw, 360px); overflow-y: auto;
  background: var(--paper); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform .22s ease;
  padding: 12px 0 40px; overscroll-behavior: contain;
}
body.toc-open #toc { transform: none; box-shadow: var(--shadow); }
#scrim { position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.35); display: none; }
body.toc-open #scrim { display: block; }
.toc-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 12px 8px 18px; font-weight: 700; color: var(--accent); }
#toc ol { list-style: none; margin: 0; padding: 0; }
#toc li a { display: block; padding: 9px 18px; color: var(--text); text-decoration: none; border-left: 3px solid transparent; }
#toc li:not(.sub) > a { font-weight: 650; margin-top: 4px; }
#toc li.sub a { padding: 6px 18px 6px 34px; font-size: .93rem; color: var(--muted); }
#toc li a.active { border-left-color: var(--accent); background: var(--accent-soft); color: var(--text); }

@media (min-width: 1180px) {
  #toc { left: 0; right: auto; top: var(--header-h); width: 300px; transform: none; border-left: 0; border-right: 1px solid var(--line); }
  #toc-btn, #scrim, .toc-close { display: none !important; }
  main, .top-row, .search-row { margin-left: max(320px, calc(50vw - 450px + 150px)) !important; }
  #results { margin-left: max(320px, calc(50vw - 450px + 150px)); }
}

/* ----- Контент ----- */
main { max-width: 900px; margin: 0 auto; padding: 8px 14px 80px; }
section[id] { scroll-margin-top: calc(var(--header-h) + 8px); }
main > section {
  background: var(--paper); border-radius: 18px; box-shadow: var(--shadow);
  padding: 4px 16px 16px; margin: 16px 0;
}
h1 { font-size: 1.7rem; line-height: 1.2; margin: 18px 0 6px; }
h2 {
  font-size: 1.45rem; line-height: 1.25; color: var(--accent);
  margin: 14px 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--accent-soft);
}
h3 { font-size: 1.18rem; line-height: 1.3; margin: 22px 0 8px; }
h4 { font-size: 1.02rem; margin: 16px 0 6px; }
p { margin: 8px 0; }
ul, ol { padding-left: 1.3em; margin: 8px 0; }
li { margin: 4px 0; }
.src {
  float: right; margin: 2px 0 6px 10px; padding: 2px 10px;
  font-size: .78rem; font-weight: 600; text-decoration: none;
  color: var(--muted); border: 1px solid var(--line); border-radius: 999px; background: var(--bg);
}
h2 .src, h3 .src { margin-top: 6px; }
.lead { color: var(--muted); margin-top: 0; }

.brief, .note, .warn, .example {
  border-radius: 12px; padding: 10px 14px; margin: 12px 0;
}
.brief { background: var(--accent-soft); border-left: 4px solid var(--accent); }
.brief > b:first-child { display: block; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); }
.note { background: var(--note-bg); border-left: 4px solid var(--note); }
.warn { background: var(--warn-bg); border-left: 4px solid var(--warn); }
.example { background: var(--example-bg); border-left: 4px solid var(--line); font-style: italic; }
.note > b:first-child, .warn > b:first-child, .example > b:first-child { font-style: normal; }
.formula {
  font-size: 1.12rem; font-weight: 700; text-align: center;
  padding: 12px; border: 2px solid var(--warn); border-radius: 14px; color: var(--warn); margin: 12px 0;
}

figure { margin: 14px 0; text-align: center; }
figure img {
  border-radius: 10px; cursor: zoom-in; background: #efe3cc;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
figure.narrow img { max-width: min(100%, 420px); }
@media (max-width: 640px) {
  figure.bleed { margin-left: -12px; margin-right: -12px; }
  figure.bleed img { border-radius: 6px; }
}
figure.tiny img { max-width: min(100%, 260px); }
figcaption { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.fig-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: flex-start; }
.fig-row figure { flex: 1 1 200px; margin: 8px 0; }

.item { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px dashed var(--line); }
.item:first-of-type { border-top: 0; }
.item > img { flex: 0 0 auto; width: 64px; border-radius: 8px; }
.item > img.tall { width: 44px; }
.item > div { flex: 1; min-width: 0; }
.item h4 { margin: 0 0 2px; }
.item p { margin: 2px 0; }

/* Тайлы-шестиугольники: текст слева, тайл справа */
.item.right { flex-direction: row-reverse; }
.item > img.hex { width: 78px; border-radius: 0; background: none; filter: drop-shadow(0 2px 3px rgba(0,0,0,.3)); }
.has-hex { display: flow-root; }
.has-hex > h3, .has-hex > h4, .has-hex > .example, .has-hex > .note, .has-hex > .warn { clear: both; }
.hex-float { float: right; width: 104px; margin: 2px 0 8px 14px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.3)); }
.hex-float.pile { width: 160px; }
@media (min-width: 640px) {
  .hex-float { width: 130px; }
  .hex-float.pile { width: 210px; }
  .item > img.hex { width: 92px; }
}

/* Значки ресурсов в тексте */
.ic { display: inline-block; height: 1.55em; width: auto; vertical-align: -0.42em; margin: 0 1px; }
.ic.hexic { height: 1.9em; vertical-align: -0.6em; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }
.ic.act { height: 2em; vertical-align: -0.6em; }
.cheat ul.ic-list { list-style: none; padding-left: 0; }
.ic-list li { display: flex; gap: 8px; align-items: flex-start; }
.ic-list li > .ic { flex: 0 0 2.2em; height: auto; max-height: 2.1em; object-fit: contain; margin-top: 1px; vertical-align: 0; }
.ic-list li > span { flex: 1; min-width: 0; }

.num { display: inline-block; min-width: 2em; padding: 0 6px; margin-right: 4px; border-radius: 8px; background: var(--accent); color: var(--paper); font-weight: 700; text-align: center; font-size: .9rem; }

.dot { display: inline-block; width: .8em; height: .8em; border-radius: 3px; vertical-align: -1px; margin-right: 6px; }
.dot.brown { background: var(--brown); } .dot.grey { background: var(--grey); } .dot.blue { background: var(--blue); }
.dot.green { background: var(--green); } .dot.yellow { background: var(--yellow); } .dot.red { background: var(--red); } .dot.purple { background: var(--purple); }

.table-wrap { overflow-x: auto; margin: 10px 0; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { border: 1px solid var(--line); padding: 6px 8px; text-align: center; }
th { background: var(--accent-soft); }
td:first-child, th:first-child { text-align: left; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.chips a {
  padding: 7px 12px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line);
  text-decoration: none; color: var(--text); font-size: .92rem; box-shadow: var(--shadow);
}

.cheat { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.cheat > div { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.cheat h4 { margin: 0 0 4px; color: var(--accent); }
.cheat ul { margin: 0; padding-left: 1.1em; }

.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.pages a { display: block; text-align: center; text-decoration: none; color: var(--muted); font-size: .85rem; }
.pages img { display: block; width: 100%; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.2); }

/* ----- Кнопка «наверх» ----- */
#to-top {
  position: fixed; right: 14px; bottom: 16px; z-index: 25;
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--paper); color: var(--accent); font-size: 22px; box-shadow: var(--shadow); cursor: pointer;
}

/* ----- Просмотр картинок ----- */
#lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(10, 8, 6, .94); display: flex; flex-direction: column; }
#lightbox .lb-scroll { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 8px; touch-action: pan-x pan-y pinch-zoom; }
#lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; border-radius: 4px; }
#lightbox.zoomed .lb-scroll { display: block; }
#lightbox.zoomed img { max-width: none; max-height: none; width: 230%; cursor: zoom-out; }
#lightbox .lb-cap { color: #ddd; text-align: center; font-size: .9rem; padding: 6px 50px 12px; }
#lightbox .lb-close {
  position: absolute; top: 10px; right: 10px; z-index: 2; width: 46px; height: 46px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.18); color: #fff; font-size: 22px; cursor: pointer;
}
#lightbox .lb-hint { position: absolute; left: 12px; top: 18px; color: #aaa; font-size: .8rem; }

/* ----- Карточки щитов ----- */
.sh-grid { display: grid; gap: 10px; grid-template-columns: 1fr; margin: 12px 0; }
@media (min-width: 700px) { .sh-grid { grid-template-columns: 1fr 1fr; } }
.sh-card {
  display: flex; align-items: center; gap: 12px; margin: 0; padding: 10px 10px 10px 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); cursor: pointer; transition: transform .12s, border-color .12s;
  -webkit-tap-highlight-color: transparent;
}
.sh-card:hover { border-color: var(--accent); }
.sh-card:active { transform: scale(.98); }
.sh-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sh-body { flex: 1; min-width: 0; }
.sh-label { display: block; font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.sh-card h4 { margin: 0 0 3px; font-size: 1.02rem; line-height: 1.25; }
.sh-card p { margin: 0; font-size: .92rem; line-height: 1.4; }
.sh-img { flex: 0 0 auto; width: 60px; height: auto; filter: drop-shadow(0 2px 3px rgba(0,0,0,.3)); }
.sh-side { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.sh-vp {
  display: inline-block; padding: 1px 8px; border-radius: 999px; white-space: nowrap;
  background: var(--accent); color: var(--paper); font-weight: 700; font-size: .78rem;
}
.sh-more { color: var(--muted); font-size: .72rem; }

/* ----- Всплывающее окно ----- */
#popup {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(20, 12, 6, .55);
}
.pop-panel {
  position: relative; display: flex; flex-direction: column; width: min(100%, 520px); max-height: calc(100dvh - 32px);
  background: var(--paper); color: var(--text); border-radius: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.45);
  animation: pop-in .18s ease-out;
}
.pop-body { overflow-y: auto; overscroll-behavior: contain; padding: 22px 20px 10px; }
.pop-head { text-align: center; }
.pop-img { width: 132px; height: auto; filter: drop-shadow(0 4px 8px rgba(0,0,0,.35)); }
.pop-head .sh-label { margin-top: 6px; }
.pop-head h3 { margin: 2px 0 6px; font-size: 1.3rem; color: var(--accent); }
.pop-text { margin-top: 12px; }
.pop-text p { margin: 8px 0; }
.pop-text .src { float: none; display: inline-block; margin: 6px 0 0; }
.pop-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px 14px; border-top: 1px solid var(--line); }
.pop-count { font-weight: 700; color: var(--muted); }
.pop-close {
  position: absolute; top: 10px; right: 10px; z-index: 1; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 18px; cursor: pointer;
}
body.pop-open { overflow: hidden; }
body.pop-open #fastscroll { display: none; }
@keyframes pop-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes pop-up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (max-width: 640px) {
  #popup { align-items: flex-end; padding: 0; }
  .pop-panel { width: 100%; max-height: 88dvh; border-radius: 20px 20px 0 0; animation: pop-up .22s ease-out; }
  .pop-nav { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
}

/* ----- Галерея в просмотре ----- */
#lightbox .lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; display: none;
  width: 46px; height: 66px; border: 0; border-radius: 12px;
  background: rgba(255,255,255,.16); color: #fff; font-size: 34px; line-height: 1; cursor: pointer;
}
#lightbox.has-gallery .lb-nav { display: block; }
#lightbox .lb-prev { left: 8px; }
#lightbox .lb-next { right: 8px; }
#lightbox .lb-count { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); color: #eee; font-weight: 700; }
#lightbox.has-gallery .lb-hint { display: none; }
@media (pointer: coarse) { #lightbox .lb-nav { width: 38px; background: rgba(255,255,255,.1); } }

/* ----- Лента страниц буклета ----- */
.pages-carousel {
  position: relative; display: flex; gap: 12px; overflow-x: auto;
  scroll-snap-type: x mandatory; overscroll-behavior-x: contain;
  padding: 4px 2px 10px; scrollbar-width: thin;
}
.pages-carousel .pg {
  flex: 0 0 min(88%, 460px); scroll-snap-align: center;
  text-align: center; text-decoration: none; color: var(--muted); font-size: .85rem;
}
.pages-carousel img { display: block; width: 100%; height: auto; border-radius: 8px; background: #efe3cc; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.pc-bar { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 6px; }
.pc-count { min-width: 5em; text-align: center; font-weight: 700; color: var(--muted); }

/* ----- Ползунок быстрой прокрутки (телефон) ----- */
#fastscroll .fs-thumb {
  position: fixed; top: 0; right: 3px; z-index: 35; width: 30px; height: 58px; border-radius: 15px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .25s; touch-action: none;
}
#fastscroll.show .fs-thumb { opacity: .85; pointer-events: auto; }
#fastscroll.drag .fs-thumb { opacity: 1; }
#fastscroll .fs-thumb span { width: 10px; height: 20px; border-left: 2px solid var(--paper); border-right: 2px solid var(--paper); }
#fastscroll .fs-label {
  position: fixed; right: 44px; z-index: 35; transform: translateY(-50%);
  max-width: 70vw; padding: 7px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--paper); color: var(--text); font-weight: 700; box-shadow: var(--shadow);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.lb-open #fastscroll { display: none; }

/* ----- Главная ----- */
.home-wrap { max-width: 900px; margin: 0 auto; padding: 20px 16px 60px; }
.home-wrap h1 { text-align: center; }
.home-wrap .lead { text-align: center; }
.games { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-top: 20px; }
.game-card {
  display: block; background: var(--paper); border-radius: 18px; overflow: hidden;
  box-shadow: var(--shadow); text-decoration: none; color: var(--text);
}
.game-card img { display: block; width: 100%; aspect-ratio: 16/10; object-fit: cover; }
.game-card:not(.cob) img { object-position: 50% 14%; }
.game-card.cob img { object-fit: contain; background: #5a111c; padding: 12px; }
.game-card div { padding: 12px 16px 16px; }
.game-card b { display: block; font-size: 1.2rem; color: var(--accent); }
.game-card span { color: var(--muted); font-size: .92rem; }
footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 20px; }
