/* Кодекс: список (/codex), запись (/codex/{slug}), мини-карта и теги.
   Мини-карта и теги нужны и в редакторе /admin/codex, поэтому файл
   подключается и там. Карточки повторяют розыгрыши (giveaways.css). */

.codex-page,
.codex-view-page {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 20px 0 40px;
    box-sizing: border-box;
    color: var(--text-primary);
}
@media (max-width: 700px) {
    .codex-page,
    .codex-view-page { padding: 18px 16px 24px; }
}

.cx-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.cx-page-title {
    color: var(--text-bright);
    font-size: 22px;
    font-weight: 600;
    margin: 0;
}
.cx-admin-link { font-size: 13px; }

.cx-empty {
    color: var(--text-muted);
    padding: 12px 0;
}
.cx-error { color: var(--color-danger); }

/* ---------- теги ---------- */

/* Палитра совпадает с метками /admin/todo. */
.c-gray   { --lc: #8b949e; }
.c-red    { --lc: #e5736f; }
.c-orange { --lc: #e39556; }
.c-yellow { --lc: #d9b955; }
.c-green  { --lc: #6dd6a4; }
.c-teal   { --lc: #4fbfc4; }
.c-blue   { --lc: #7ea8e0; }
.c-purple { --lc: #a887e0; }

.cx-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.cx-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.5;
    color: var(--text-bright);
    background: color-mix(in srgb, var(--lc, #8b949e) 22%, rgba(20, 24, 31, .6));
    border: 1px solid color-mix(in srgb, var(--lc, #8b949e) 60%, transparent);
    text-decoration: none;
    white-space: nowrap;
}
a.cx-tag:hover { background: color-mix(in srgb, var(--lc, #8b949e) 38%, rgba(20, 24, 31, .6)); color: #fff; }

/* Кнопка-тег в фильтре. */
.cx-chip {
    font: inherit;
    font-size: 12.5px;
    padding: 5px 12px;
    cursor: pointer;
    color: var(--text-secondary);
    background: color-mix(in srgb, var(--lc, #8b949e) 8%, transparent);
    border-color: color-mix(in srgb, var(--lc, #8b949e) 40%, transparent);
}
.cx-chip:hover { color: var(--text-bright); }
.cx-chip[aria-pressed="true"] {
    color: #fff;
    background: color-mix(in srgb, var(--lc, #8b949e) 34%, transparent);
    border-color: var(--lc, #8b949e);
}
.cx-chip:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.cx-chip:disabled { cursor: default; }
.cx-chip-n {
    font-weight: 400;
    font-size: 11px;
    opacity: .7;
    font-variant-numeric: tabular-nums;
}

/* ---------- фильтр ---------- */

.cx-filter {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
}
.cx-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.cx-filter-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    font-size: 12.5px;
    color: var(--text-muted);
}
.cx-mode {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.cx-mode[hidden],
.cx-filter-meta[hidden] { display: none; }
.cx-mode button {
    font: inherit;
    background: transparent;
    color: var(--text-secondary);
    border: 0;
    padding: 4px 10px;
    cursor: pointer;
}
.cx-mode button[aria-pressed="true"] { background: var(--bg-card); color: var(--text-bright); }
.cx-linkbtn {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    color: var(--link);
    cursor: pointer;
}
.cx-linkbtn:hover { color: var(--link-hover); }

/* ---------- серверы: переключатель, заголовки групп, плашка записи ---------- */

.cx-servers {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}
.cx-servers[hidden] { display: none; }
.cx-server-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font: inherit;
    font-size: 13px;
    padding: 6px 13px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}
.cx-server-btn:hover { color: var(--text-bright); border-color: var(--border-hover); }
.cx-server-btn[aria-pressed="true"] {
    color: var(--text-bright);
    background: var(--bg-card);
    border-color: var(--link);
}
.cx-server-btn:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.cx-server-btn img,
.cx-group img,
.cx-server-badge img {
    width: 18px;
    height: 18px;
    object-fit: contain;
    border-radius: 4px;
    flex: none;
}

.cx-group {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 14px 0 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    color: var(--text-bright);
    font-size: 16px;
    font-weight: 600;
}
.cx-group img { width: 22px; height: 22px; }
.cx-group:first-child { margin-top: 0; }

.cx-server-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px 2px 4px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.6;
    color: #fff;
    background: rgba(20, 24, 31, .72);
    border: 1px solid rgba(255, 255, 255, .25);
    text-decoration: none;
    white-space: nowrap;
}
.cx-server-badge:hover { border-color: rgba(255, 255, 255, .5); color: #fff; }

/* ---------- карточки ---------- */

.cx-cards {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.cx-card {
    position: relative;
    display: block;
    min-height: 190px;
    background-color: var(--bg-card);
    background-size: cover;
    background-position: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s;
}
.cx-card:hover { border-color: var(--border-hover); }
.cx-card:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.cx-card-overlay {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(90deg, rgba(20,24,31,.92) 0%, rgba(20,24,31,.76) 55%, rgba(20,24,31,.28) 100%),
        linear-gradient(180deg, rgba(20,24,31,.1) 0%, rgba(20,24,31,.1) 60%, rgba(20,24,31,.6) 100%);
    pointer-events: none;
}
.cx-card-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 190px;
    padding: 16px 20px 14px;
    box-sizing: border-box;
}
.cx-card-title {
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    line-height: 1.2;
    max-width: 34ch;
    overflow-wrap: anywhere;
    text-shadow: 0 1px 4px rgba(0,0,0,.6);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.cx-card-summary {
    /* Во всю ширину карточки. flex:1 тут нельзя: растянутый по высоте блок
       показывал строки сверх line-clamp, многоточие оказывалось посреди текста. */
    color: rgba(230,233,238,.9);
    font-size: 13.5px;
    line-height: 1.45;
    white-space: pre-line;
    text-shadow: 0 1px 3px rgba(0,0,0,.8);
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.cx-card-footer {
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: 12px;
    color: rgba(230,233,238,.72);
}
.cx-more-wrap {
    display: flex;
    justify-content: center;
    margin-top: 16px;
}

/* ---------- запись ---------- */

.cx-back {
    display: inline-block;
    margin-bottom: 12px;
    font-size: 13px;
}
.cx-hero {
    position: relative;
    display: flex;
    align-items: flex-end;
    min-height: 240px;
    background-color: var(--bg-card);
    background-size: cover;
    background-position: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.cx-hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(20,24,31,.1) 15%, rgba(20,24,31,.94) 100%);
}
.cx-hero-in {
    position: relative;
    display: grid;
    gap: 8px;
    padding: 18px 22px;
}
.cx-hero-title {
    margin: 0;
    color: #fff;
    font-size: 30px;
    line-height: 1.15;
    text-wrap: balance;
    overflow-wrap: anywhere;
    text-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.cx-hero-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 12.5px;
    color: rgba(230,233,238,.75);
}
.cx-hero-meta a { color: inherit; text-decoration: underline; }
@media (max-width: 600px) {
    .cx-hero { min-height: 200px; }
    .cx-hero-title { font-size: 23px; }
    .cx-hero-in { padding: 14px 16px; }
}

.cx-article {
    cursor: default;
    margin-top: 18px;
    padding: 22px 26px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
}
@media (max-width: 600px) {
    .cx-article { padding: 16px; }
}

/* ---------- метка на карте в тексте ---------- */

.cx-content .cx-map {
    display: grid;
    grid-template-columns: minmax(0, 240px) minmax(0, 1fr);
    margin: 14px 0;
    background: var(--bg-inner);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.cx-content .cx-map.cx-map--nobox { grid-template-columns: minmax(0, 1fr); }
/* В записи карта занимает всю высоту блока: при длинном описании видно
   больше карты вместо пустого места под квадратом. */
.cx-content .cx-map > .cx-map-box {
    aspect-ratio: auto;
    align-self: stretch;
    min-height: 240px;
}
.cx-map-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px 16px;
    min-width: 0;
}
.cx-map-text { display: grid; gap: 4px; align-content: start; }
.cx-map-label { color: var(--text-bright); font-size: 15px; }
.cx-map-server {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-muted);
}
.cx-content .cx-map-desc {
    margin: 4px 0 0;
    white-space: pre-line;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}
/* Кнопка прижата к низу блока, под описанием. */
.cx-map-btns {
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.cx-map-btns .btn-secondary { font-size: 12.5px; padding: 6px 12px; text-decoration: none; }
@media (max-width: 560px) {
    .cx-content .cx-map { grid-template-columns: minmax(0, 1fr); }
}

/* Сама мини-карта (codex_minimap.js). Квадрат, тайлы абсолютно внутри. */
.cx-map-box {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    max-width: 100%;
}
.cxm {
    overflow: hidden;
    background: #0e1116;
}
.cxm-layer { position: absolute; inset: 0; }
.cxm .cxm-layer img {
    position: absolute;
    max-width: none;
    margin: 0;
    border-radius: 0;
    user-select: none;
    pointer-events: none;
}
.cxm-pin {
    position: absolute;
    width: 26px;
    height: 26px;
    transform: translate(-50%, -100%);
    pointer-events: none;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,.6));
}
.cxm-pin svg { display: block; width: 100%; height: 100%; }
.cxm-ring {
    position: absolute;
    width: 36px;
    height: 36px;
    margin: -18px 0 0 -18px;
    border: 2px solid #f0b45a;
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
    .cxm-ring { animation: cxm-ping 2s ease-out infinite; }
}
@keyframes cxm-ping { from { transform: scale(.3); opacity: .9; } to { transform: scale(1.6); opacity: 0; } }
.cxm-zoom {
    position: absolute;
    right: 6px;
    bottom: 6px;
    display: grid;
    gap: 4px;
}
.cxm-zoom button {
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 4px;
    border: 1px solid var(--border-hover);
    background: rgba(20,24,31,.85);
    color: var(--text-bright);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}
.cxm-zoom button:disabled { opacity: .4; cursor: default; }
.cxm-zoom button:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }

/* ---------- комментарии ---------- */

.cx-comments {
    margin-top: 18px;
    padding: 20px 26px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: grid;
    gap: 14px;
}
@media (max-width: 600px) {
    .cx-comments { padding: 16px; }
}
.cx-comments-title {
    margin: 0;
    color: var(--text-bright);
    font-size: 17px;
}
.cx-comments-title span { color: var(--text-muted); font-weight: 400; }
#cx-comments-list { display: grid; gap: 14px; }
.cx-c {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 10px;
}
.cx-c-ava {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    background: var(--bg-inner);
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    font-weight: 600;
    color: var(--text-secondary);
    object-fit: cover;
    box-sizing: border-box;
}
.cx-c-main { min-width: 0; display: grid; gap: 3px; }
.cx-c-head {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    font-size: 12.5px;
    color: var(--text-muted);
}
.cx-c-head b { color: var(--text-bright); }
.cx-c-body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: 14px;
    line-height: 1.5;
}
.cx-c--deleted .cx-c-body { color: var(--text-muted); font-style: italic; }
.cx-c--deleted .cx-c-ava { visibility: hidden; }
.cx-c-actions {
    display: flex;
    gap: 12px;
}
.cx-c-actions button {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
}
.cx-c-actions button:hover { color: var(--text-bright); }
.cx-c-actions button.danger:hover { color: var(--color-danger); }
.cx-c-empty,
.cx-c-note { color: var(--text-muted); font-size: 13.5px; }
.cx-c-form { display: grid; gap: 8px; }
.cx-c-form textarea,
.cx-c-edit {
    width: 100%;
    box-sizing: border-box;
    min-height: 70px;
    resize: vertical;
    padding: 10px 12px;
    background: var(--bg-inner);
    border: 1px solid var(--border-hover);
    border-radius: 6px;
    color: var(--text-primary);
    font: inherit;
    font-size: 14px;
}
.cx-c-form textarea:focus,
.cx-c-edit:focus { outline: none; border-color: var(--link); }
.cx-c-form-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}
.cx-c-err { color: var(--color-danger); font-size: 13px; margin-right: auto; }

/* ---------- предметы в тексте (<itemid:N>, src/CodexItems.php) ---------- */

.cx-content .cx-item {
    color: #e3c27a;
    font-weight: 600;
    border-bottom: 1px dotted rgba(227, 194, 122, .6);
    cursor: help;
}
.cx-content .cx-item:hover,
.cx-content .cx-item:focus-visible { color: #f3d996; outline: none; border-bottom-style: solid; }
.cx-content .cx-item--missing {
    color: var(--text-muted);
    font-weight: 400;
    border-bottom-color: var(--border-hover);
}
.cx-item-tip {
    position: absolute;
    z-index: 1300;
    display: flex;
    gap: 10px;
    width: max-content;
    max-width: min(320px, calc(100vw - 16px));
    padding: 10px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-hover);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
    pointer-events: none;
    box-sizing: border-box;
    /* Высоту урезает codex_view.js, когда подсказка не влезает ни над словом, ни под ним. */
    overflow-y: auto;
}
.cx-item-tip[hidden] { display: none; }
.cx-item-tip-icon {
    flex: none;
    width: 48px;
    height: 48px;
    border-radius: 6px;
    background: var(--bg-inner);
    border: 1px solid var(--border);
    object-fit: contain;
}
.cx-item-tip-text {
    display: grid;
    gap: 3px;
    align-content: start;
    min-width: 0;
    font-size: 13px;
    line-height: 1.4;
    color: var(--text-secondary);
    white-space: pre-line;
    overflow-wrap: anywhere;
}
.cx-item-tip-text b { color: #e3c27a; font-size: 14px; white-space: normal; }
.cx-item-tip-empty { color: var(--text-muted); font-style: italic; }
.cx-item-tip-type { margin-top: -2px; font-size: 11px; color: var(--text-muted); }
.cx-item-tip-stats { font-size: 12px; color: var(--text-muted); }
.cx-item-tip-stats b { font-size: 12px; color: var(--text-bright); }
/* Полное описание длиннее короткого: подсказка шире, текст под чертой. */
.cx-item-tip.has-long { max-width: min(400px, calc(100vw - 16px)); }
.cx-item-tip-long {
    margin-top: 4px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

/* ---------- рецепты и таланты в тексте (<recipeid:N>, <featid:N>) ---------- */

.cx-content .cx-item--recipe::before,
.cx-content .cx-item--feat::before {
    margin-right: 3px;
    font-weight: 400;
    opacity: .75;
}
.cx-content .cx-item--recipe::before { content: "⚒"; }
.cx-content .cx-item--feat::before { content: "✦"; }

/* Подсказку рецепта и таланта можно прокрутить, поэтому она ловит мышь. */
.cx-item-tip.is-craft {
    display: block;
    width: min(340px, calc(100vw - 16px));
    max-height: calc(100vh - 16px);
    overflow-y: auto;
    pointer-events: auto;
    cursor: default;
}
.cx-item-tip.is-craft[hidden] { display: none; }
.cx-tip-head { display: flex; gap: 10px; align-items: center; }
.cx-tip-head .cx-item-tip-icon { width: 40px; height: 40px; }
.cx-tip-sect {
    margin: 10px 0 4px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.cx-tip-row {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) auto auto;
    gap: 8px;
    align-items: center;
    padding: 2px 0;
    font-size: 13px;
    color: var(--text-secondary);
}
.cx-tip-row img,
.cx-tip-noicon {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    background: var(--bg-inner);
    object-fit: contain;
}
.cx-tip-row-name { overflow-wrap: anywhere; }
.cx-tip-row-qty { color: var(--text-bright); font-variant-numeric: tabular-nums; }
.cx-tip-row-chance {
    min-width: 42px;
    text-align: right;
    color: #e3c27a;
    font-variant-numeric: tabular-nums;
}
.cx-tip-list { max-height: 260px; overflow-y: auto; padding-right: 4px; }

/* В записи - обычная стрелка вместо текстовой каретки, на ссылках - палец. */
.codex-view-page { cursor: default; }
.codex-view-page a[href],
.codex-view-page button:not(:disabled) { cursor: pointer; }
.codex-view-page textarea { cursor: text; }

/* Посещённые ссылки в тексте записи - тем же цветом, без браузерного фиолетового. */
.cx-content a:visited { color: var(--link); }
.cx-content a:visited:hover { color: var(--link-hover); }

/* Мини-карту можно двигать: курсор-рука, на тач-экране вертикальный жест
   остаётся прокруткой страницы. */
.cxm { cursor: grab; touch-action: pan-y; user-select: none; }
.cxm.cxm-dragging { cursor: grabbing; }
/* Иконка существующей метки карты (вместо жёлтой булавки), по центру точки. */
.cxm-icon {
    position: absolute;
    width: 30px;
    height: 30px;
    transform: translate(-50%, -50%);
    pointer-events: none;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,.7));
}
.cxm .cxm-icon img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    margin: 0;
    object-fit: contain;
    border-radius: 50%;
}
.cxm-zoom button[hidden] { display: none; }
