:root {
  --bg: #f4efe6;
  --surface: #fffaf1;
  --surface-2: #ece4d6;
  --text: #2a241c;
  --muted: #7a6e5d;
  --line: #d9cdb8;
  --accent: #9a6b1e;
  --accent-soft: #e9d9b6;
  --ok: #4f7a3a;
  --shadow: 0 2px 10px rgba(60, 40, 10, .12);
  --blue: #2f6fd6; --red: #c8382f; --strong-text: #2a241c;
  --nr: #3d6aa8; --nf: #8c7a3a; --st: #4f7a3a; --mo: #9a3b3b; --ne: #7a6e5d; --sk: #6a4f8f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14110d; --surface: #1d1914; --surface-2: #26211a; --text: #ece3d3; --muted: #a39680;
    --line: #3a3227; --accent: #d4a85a; --accent-soft: #3a2e1b; --ok: #8fbf6f; --strong-text: #fff;
    --shadow: 0 2px 14px rgba(0, 0, 0, .5);
    --nr: #6f9be0; --nf: #cbb56a; --st: #8fbf6f; --mo: #df7a7a; --ne: #b3a68f; --sk: #b195dc;
  }
}
:root[data-theme="dark"] {
  --bg: #14110d; --surface: #1d1914; --surface-2: #26211a; --text: #ece3d3; --muted: #a39680;
  --line: #3a3227; --accent: #d4a85a; --accent-soft: #3a2e1b; --ok: #8fbf6f; --strong-text: #fff;
  --shadow: 0 2px 14px rgba(0, 0, 0, .5);
  --nr: #6f9be0; --nf: #cbb56a; --st: #8fbf6f; --mo: #df7a7a; --ne: #b3a68f; --sk: #b195dc;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 Inter, system-ui, sans-serif;
}
a { color: var(--accent); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .92em; word-break: break-all; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }

.top { padding: 28px 0 18px; }
.top-row { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; }
.top-tools { display: flex; gap: 10px; align-items: center; flex: none; padding-top: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--muted); font: 600 13px Inter, sans-serif; padding: 6px 11px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--bg); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--accent); background: var(--accent);
  color: var(--bg); font: 600 14px Inter, sans-serif; padding: 7px 14px; border-radius: 8px; cursor: pointer;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost[aria-pressed="true"] { background: var(--accent); color: var(--bg); }
.btn.small { font-size: 12.5px; padding: 3px 9px; border-radius: 6px; }
.btn.danger { background: transparent; border-color: var(--mo); color: var(--mo); }
h1 {
  font: 700 clamp(32px, 6vw, 48px)/1.05 "Cormorant Garamond", Georgia, serif;
  margin: 0 0 8px; color: var(--accent); letter-spacing: .5px;
}
.lead { margin: 0; color: var(--muted); max-width: 640px; }

.drop {
  border: 2px dashed var(--line); border-radius: 14px; background: var(--surface);
  padding: 32px 20px; text-align: center; transition: border-color .15s, background .15s; outline: none;
}
.drop:focus-visible, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { color: var(--accent); }
.drop-title { font-weight: 600; margin: 8px 0 4px; }
.drop-hint { color: var(--muted); margin: 0; font-size: 14px; }
.status { margin: 10px 0 0; min-height: 1.2em; font-weight: 500; }
.status.error { color: var(--mo); }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

.summary {
  display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr); gap: 16px;
  margin: 8px 0 16px;
}
.total, .factions { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; }
.total-num { font: 700 44px/1 "Cormorant Garamond", Georgia, serif; color: var(--accent); }
.total-num .of { font-size: 24px; color: var(--muted); margin-left: 6px; }
.total-label { margin: 4px 0 2px; }
.save-name { font-size: 13px; margin-bottom: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); width: 0; transition: width .4s; }
.factions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 22px; align-content: center; }
.fac { min-width: 0; }
.fac-name { display: flex; align-items: baseline; gap: 8px; font-size: 14px; }
.fac-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fac-num { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.factions .bar { height: 6px; margin-top: 6px; }

.toolbar { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 0; border-bottom: 1px solid var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 99px; padding: 5px 12px; font: inherit; font-size: 14px; cursor: pointer;
}
.chip[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.chip .n { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }
.toolbar-row { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin-top: 10px; }
#search {
  flex: 1 1 220px; max-width: 320px; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit;
}
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; cursor: pointer; }
.check input { accent-color: var(--accent); }
.list-info { margin: 12px 0; font-size: 14px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; padding-bottom: 32px; }
.tile {
  display: flex; flex-direction: column; text-align: left; padding: 0; border: 0; background: none;
  color: inherit; font: inherit; cursor: pointer;
}
.tile-img {
  position: relative; aspect-ratio: 280 / 516; border-radius: 10px; overflow: hidden;
  background: var(--surface-2); box-shadow: var(--shadow); transition: transform .15s;
}
.tile:hover .tile-img, .tile:focus-visible .tile-img { transform: translateY(-3px); }
.tile:focus-visible { outline: none; }
.tile:focus-visible .tile-img { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.owned .tile-img img { filter: grayscale(.85); opacity: .45; }
.badge {
  position: absolute; left: 6px; top: 6px; font-size: 11px; font-weight: 600; padding: 2px 7px;
  border-radius: 99px; background: rgba(20, 17, 13, .78); color: #f1e6cf;
}
.badge.copies { left: auto; right: 6px; background: var(--accent); color: #fff; }
.badge.shot-badge { top: auto; bottom: 6px; }
.tile-name { margin-top: 8px; font-weight: 600; font-size: 14px; line-height: 1.25; }
.tile-sub { font-size: 12.5px; color: var(--muted); }
.deck-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.empty { grid-column: 1 / -1; text-align: center; padding: 40px 0; color: var(--muted); }

dialog { border: 0; padding: 0; color: var(--text); background: var(--surface); }
dialog::backdrop { background: rgba(10, 8, 5, .7); }
.dialog { width: min(960px, calc(100vw - 24px)); max-height: calc(100vh - 24px); border-radius: 14px; box-shadow: var(--shadow); }
.close {
  position: sticky; top: 8px; float: right; margin: 8px 8px 0 0; z-index: 2;
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 22px; line-height: 1; cursor: pointer;
}
.card-view { display: grid; grid-template-columns: 200px 1fr; gap: 22px; padding: 22px; }
.card-art { width: 100%; border-radius: 10px; box-shadow: var(--shadow); position: sticky; top: 16px; }
.card-view h2 { font: 700 30px/1.1 "Cormorant Garamond", Georgia, serif; margin: 0 0 2px; color: var(--accent); }
.card-view .en { color: var(--muted); margin: 0 0 10px; }
.card-view h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 6px; }
.card-view p { margin: 0 0 6px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { font-size: 12.5px; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); }
.pill.warn { background: var(--accent-soft); }
.how { white-space: pre-line; }
.pill.ok { background: color-mix(in srgb, var(--ok) 22%, transparent); }
.spot-list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 8px; }
.spot-row { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.spot-row .spot-text { flex: 1; min-width: 0; }
.spot-icon { flex: none; width: 13px; height: 17px; border-radius: 3px; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); }
.spot-icon.regular { background: var(--blue); }
.spot-icon.story { background: var(--red); }
.spot-edit { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--bg); display: grid; gap: 6px; }
.spot-edit-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 14px; }
.spot-edit-head b { margin-right: auto; }
.card-view input[type="text"], .card-view input[type="url"], .card-view textarea, .card-view select {
  width: 100%; font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px;
}
.card-view select { width: auto; padding: 3px 6px; }
.card-view textarea { resize: vertical; }
.field { display: grid; gap: 4px; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin-top: 6px; }
.shot-cell { display: grid; gap: 4px; }
.shot-cell > button { padding: 0; border: 0; background: var(--surface-2); cursor: zoom-in; border-radius: 8px; overflow: hidden; aspect-ratio: 16 / 9; }
.shots img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.shot-cell > button:hover img { transform: scale(1.04); }
.shot-tools { display: flex; gap: 6px; justify-content: flex-end; }
.shot-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.shot-add input { flex: 1 1 220px; }
.dlg-save {
  position: sticky; bottom: 0; display: flex; gap: 12px; justify-content: flex-end; align-items: center;
  margin: 16px -22px -22px; padding: 12px 22px; background: var(--surface); border-top: 1px solid var(--line); font-size: 14px;
}

.shot { background: #000; width: auto; max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); border-radius: 10px; }
.shot img { display: block; max-width: calc(100vw - 16px); max-height: calc(100vh - 60px); }
.shot .close { position: absolute; right: 0; top: 0; background: rgba(0, 0, 0, .6); color: #fff; border-color: #555; }
.shot-open { display: block; text-align: center; color: #e8d4a8; padding: 8px; font-size: 14px; }

/* --- переключатель видов и экран выбора --- */
.views { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.view-tab {
  border: 0; background: none; color: var(--muted); font: 600 15px Inter, sans-serif; padding: 10px 14px;
  border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer;
}
.view-tab[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.view-tab.other { margin-left: auto; font-weight: 500; font-size: 14px; }
.chooser { text-align: center; padding: 16px 0 40px; }
.chooser h2 { font: 700 28px/1.2 "Cormorant Garamond", Georgia, serif; margin: 8px 0 18px; }
.choose-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 320px)); gap: 16px; justify-content: center; }
.choose {
  display: grid; justify-items: center; gap: 8px; padding: 28px 20px; border-radius: 14px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); color: var(--text); font: inherit; transition: border-color .15s, transform .15s;
}
.choose:hover, .choose:focus-visible { border-color: var(--accent); transform: translateY(-2px); outline: none; }
.choose svg { color: var(--accent); }
.choose-title { font: 700 24px/1.1 "Cormorant Garamond", Georgia, serif; }
.choose-sub { font-size: 14px; color: var(--muted); }

/* --- карта мира --- */
.map-view { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; padding-bottom: 24px; }
.regions h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 4px 0 8px; }
.region-list { display: grid; gap: 4px; }
.region {
  display: flex; justify-content: space-between; gap: 8px; align-items: center; text-align: left;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px;
  padding: 8px 11px; font: 500 14px Inter, sans-serif; cursor: pointer;
}
.region .left { font-size: 12px; font-weight: 600; color: var(--accent); white-space: nowrap; }
.region.done { color: var(--muted); }
.region.done .left { color: var(--ok); }
.region.active { border-color: var(--accent); background: var(--accent-soft); }
.legend { display: grid; gap: 6px; margin-top: 14px; font-size: 13px; color: var(--muted); }
.legend > div { display: flex; gap: 8px; align-items: center; }
.legend-icon { width: 13px; height: 17px; border-radius: 3px; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); }
.legend-icon.regular { background: var(--blue); }
.legend-icon.story { background: var(--red); }
.map-wrap { position: relative; min-width: 0; }
.map { height: min(72vh, 760px); border-radius: 12px; border: 1px solid var(--line); background: #0d0b08; }
.map.placing { cursor: crosshair; }
.map-hint {
  position: absolute; z-index: 500; top: 10px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 100px);
  background: rgba(20, 17, 13, .9); color: #f1e6cf; padding: 7px 12px; border-radius: 8px; font-size: 13.5px;
  display: flex; gap: 10px; align-items: center;
}
.map-list { display: grid; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.card-marker { background: none; border: 0; }
.cm { position: relative; width: 26px; height: 34px; }
.cm-card {
  position: absolute; inset: 2px 3px 4px; border-radius: 4px; border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .6), inset 0 0 0 3px rgba(255, 255, 255, .18);
}
.cm.regular .cm-card { background: var(--blue); }
.cm.story .cm-card { background: var(--red); }
.cm.owned { opacity: .45; }
.cm-n {
  position: absolute; right: -6px; top: -6px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: #1d1914; color: #f1e6cf; font: 700 11px/17px Inter, sans-serif; text-align: center; border: 1px solid #d4a85a;
}
.leaflet-popup-content { margin: 10px 12px; }
.leaflet-container { font: 14px/1.4 Inter, system-ui, sans-serif; }
.pop { display: grid; gap: 10px; max-height: 320px; overflow: auto; }
.pop-row { display: flex; gap: 10px; align-items: flex-start; }
.pop-row img { width: 46px; border-radius: 4px; flex: none; }
.pop-row.owned img { filter: grayscale(.8); opacity: .6; }
.pop-text { display: grid; gap: 3px; justify-items: start; min-width: 0; }
.pop-name { font-weight: 600; }
.pop-note { font-size: 12.5px; color: #555; }
.map-list .pop-note { color: var(--muted); }

/* --- редактор --- */
.edit-bar {
  position: fixed; z-index: 1000; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; gap: 14px; align-items: center; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--accent); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow);
  font-size: 14px;
}

.foot { padding: 24px 16px 40px; font-size: 13px; border-top: 1px solid var(--line); }

@media (max-width: 860px) {
  .map-view { grid-template-columns: 1fr; }
  .region-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .map { height: 62vh; }
}
@media (max-width: 720px) {
  .summary { grid-template-columns: 1fr; }
  .factions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top-row { flex-direction: column; }
  .choose-grid { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
  .card-view { grid-template-columns: 1fr; padding: 16px; }
  .card-art { width: 150px; position: static; }
  .toolbar { position: static; }
}

/* --- назад, справка по сейвам --- */
.back-btn {
  display: inline-flex; align-items: center; gap: 6px; margin: 0 0 12px; padding: 7px 14px;
  border: 1.5px solid var(--accent); border-radius: 8px; background: transparent;
  color: var(--strong-text); font: 600 14px Inter, sans-serif; cursor: pointer; transition: background .15s;
}
.back-btn:hover, .back-btn:focus-visible { background: var(--accent-soft); outline: none; }
.save-help { margin: 14px 0 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; font-size: 14px; }
.save-help summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.save-help ul { margin: 10px 0 0; padding-left: 18px; display: grid; gap: 6px; }

/* --- цена --- */
.coin { width: 14px; height: 14px; flex: none; }
.price { display: inline-flex; gap: 4px; align-items: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-sub { display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.price-pill { background: color-mix(in srgb, #e2b33c 22%, transparent); }

/* --- игроки в гвинт и панель места на карте --- */
.cm.player .cm-card { background: #8a8f96; }
.legend-icon.player { background: #8a8f96; }
.left-players { color: var(--muted); font-weight: 500; margin-left: 6px; display: inline-flex; gap: 3px; align-items: center; }
.mini-player { width: 7px; height: 10px; border-radius: 2px; background: #8a8f96; border: 1px solid #fff; }
.tags-info { font-size: 12.5px; margin-top: 10px; }
.map-panel {
  position: absolute; z-index: 600; top: 10px; right: 10px; bottom: 10px; width: min(340px, calc(100% - 20px));
  overflow: auto; background: var(--surface); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 14px 14px 16px;
}
.map-panel .close.small { position: sticky; top: 0; float: right; margin: -4px -4px 0 0; width: 30px; height: 30px; font-size: 18px; }
.map-panel .pop { max-height: none; }
.map-panel .pop-note { color: var(--muted); }
.player-pop { display: grid; gap: 8px; }
.pool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
.pool-card { padding: 0; border: 0; background: none; cursor: pointer; border-radius: 4px; overflow: hidden; }
.pool-card img { width: 100%; display: block; }
.player-edit { display: grid; gap: 6px; border-top: 1px solid var(--line); padding-top: 10px; }
.player-edit input, .player-edit select {
  font: inherit; font-size: 14px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px;
}
.small { font-size: 12.5px; }

/* --- вход в редактор --- */
.small-dialog { width: min(380px, calc(100vw - 24px)); }
.token-form { padding: 20px; display: grid; gap: 8px; }
.token-form input { font: inherit; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.token-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* --- подвал --- */
.thanks { margin: 0 0 10px; font-size: 14px; }
.foot-row { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; font-size: 13px; }
.made-by { color: var(--muted); }

@media (max-width: 720px) {
  .map-panel { top: auto; height: 55%; width: auto; left: 10px; }
}

/* --- текстовый блок для поиска --- */
.about { margin-top: 40px; padding-top: 24px; padding-bottom: 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14.5px; max-width: 1180px; }
.about h2 { font: 700 24px/1.2 "Cormorant Garamond", Georgia, serif; color: var(--text); margin: 0 0 10px; }
.about h3 { font-size: 15px; color: var(--text); margin: 18px 0 4px; }
.about p { margin: 0 0 8px; max-width: 820px; }
.about ul { margin: 8px 0 0; padding-left: 20px; max-width: 820px; display: grid; gap: 4px; }
