/* ========================================
   Лист персонажа — три страницы официального листа D&D 5e
   в оформлении «тёмная рамка, пергамент, золотые щиты».
   Разметка и логика — js/character-sheet.js.
   ======================================== */

:root {
    --cs-paper: #ebe1c6;
    --cs-paper-light: #f5edd9;
    --cs-paper-dark: #ddd0ae;
    --cs-ink: #2a2119;
    --cs-ink-soft: #5a4a36;
    --cs-line: #b9a985;
    --cs-gold: #c9a227;
    --cs-gold-dark: #8d6a1a;
    --cs-gold-light: #efd77a;
    --cs-silver: #d6d8dd;
    --cs-frame: #1b1a1f;
    --cs-frame-light: #34323a;
    --cs-box-border: #3b3128;
    --cs-font-title: 'Cinzel', 'Georgia', serif;
    --cs-font-body: 'Crimson Text', 'Georgia', serif;
}

/* --- Модалка под лист --- */
.modal.cs-modal {
    width: 98%;
    max-height: 98vh;
    background: #0f0e12;
}
.modal.cs-modal .modal-header { padding: 8px 16px; }
.modal.cs-modal .modal-title { font-size: var(--font-size-lg); }
.modal.cs-modal .modal-footer { padding: 8px 16px; }
.modal.cs-modal .modal-body {
    padding: 6px 12px;
    height: calc(98vh - 112px);
    max-height: calc(98vh - 112px);
}

.cs-sheet {
    color: var(--cs-ink);
    font-family: var(--cs-font-body);
    font-size: 15px;
    line-height: 1.3;
}

/* --- Панель над листом: вкладки, режим броска, замки, результат --- */
.cs-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm) var(--space-md);
    margin-bottom: var(--space-sm);
    color: var(--text-primary);
    font-family: var(--font-ui);
}
.cs-tabs {
    display: flex;
    gap: 4px;
}
.cs-tab {
    font-family: var(--cs-font-title);
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 8px 16px;
    border: 1px solid var(--border-medium);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    background: var(--bg-dark);
    color: var(--text-secondary);
    cursor: pointer;
}
.cs-tab:hover { color: var(--text-primary); }
.cs-tab.is-active {
    background: linear-gradient(180deg, var(--cs-gold-light), var(--cs-gold));
    color: #1b1408;
    border-color: var(--cs-gold);
}
.cs-toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-left: auto;
    order: 2;
}
.cs-roll-mode {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}
.cs-roll-mode .form-select { padding: 4px 28px 4px 8px; font-size: 13px; min-width: 150px; }
.cs-zoom {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    background: var(--bg-dark);
}
.cs-zoom-btn {
    min-width: 28px;
    height: 26px;
    padding: 0 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
}
.cs-zoom-btn:hover { color: var(--text-primary); background: var(--bg-light); }
.cs-zoom-fit { font-size: 12px; }
.cs-zoom-fit.is-active { background: var(--cs-gold); color: #1b1408; }
.cs-zoom-value {
    min-width: 42px;
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
}
.cs-roll-result {
    order: 1;
    flex: 1 1 240px;
    min-width: 0;
    min-height: 20px;
    font-size: 14px;
    color: var(--cs-gold-light);
}
.cs-roll-result.is-flash { animation: cs-flash 0.6s ease; }
@keyframes cs-flash {
    0% { color: #fff; text-shadow: 0 0 8px var(--cs-gold-light); }
    100% { color: var(--cs-gold-light); text-shadow: none; }
}

/* --- Рамка и пергамент ---
   Рамка — картинка assets/sheet/frame.png, растягивается «девятью кусками» (border-image):
   углы остаются как нарисованы, стороны повторяются при удлинении листа.
   Масштаб рамки: 0,55 от исходника (толщина 180 px исходника → 99 px на экране).
   Звёзды посередине сторон — отдельные картинки того же масштаба. */
.cs-frame {
    position: relative;
    box-sizing: border-box;
    /* Постоянная ширина страницы: при уменьшении («Весь лист») пропорции листа не меняются. */
    width: 1240px;
    margin: 0 auto;
    padding: 58px 56px;
}
.cs-frame::before {
    content: '';
    position: absolute;
    inset: 22px;
    border-radius: 6px;
    background:
        radial-gradient(ellipse at 20% 10%, rgba(255, 255, 255, 0.35), transparent 50%),
        radial-gradient(ellipse at 80% 90%, rgba(120, 90, 40, 0.18), transparent 55%),
        radial-gradient(ellipse at 50% 50%, var(--cs-paper-light), var(--cs-paper) 70%, var(--cs-paper-dark));
    box-shadow: inset 0 0 50px rgba(90, 60, 20, 0.3);
    z-index: 0;
}
.cs-frame::after {
    content: '';
    position: absolute;
    inset: 0;
    border: 99px solid transparent;
    border-image: url('../assets/sheet/frame.png') 180 round;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.55));
    pointer-events: none;
    z-index: 3;
}
.cs-star {
    position: absolute;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    z-index: 4;
    pointer-events: none;
}
.cs-star-t { top: 0; left: calc(50% - 41px); width: 83px; height: 69px; background-image: url('../assets/sheet/frame-star-top.png'); }
.cs-star-b { bottom: 0; left: calc(50% - 41px); width: 83px; height: 69px; background-image: url('../assets/sheet/frame-star-bottom.png'); }
.cs-star-l { left: 0; top: calc(50% - 41px); width: 55px; height: 83px; background-image: url('../assets/sheet/frame-star-left.png'); }
.cs-star-r { right: 0; top: calc(50% - 41px); width: 55px; height: 83px; background-image: url('../assets/sheet/frame-star-right.png'); }

.cs-paper {
    position: relative;
    z-index: 1;
}

.cs-page[hidden] { display: none; }

/* --- Блоки --- */
.cs-box {
    position: relative;
    padding: 26px 10px 10px;
    border: 2px solid var(--cs-box-border);
    border-radius: 9px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 30%), var(--cs-paper);
    box-shadow:
        inset 0 0 0 1px var(--cs-gold),
        inset 0 0 18px rgba(90, 60, 20, 0.12),
        0 1px 3px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.cs-box::before,
.cs-box::after {
    content: '';
    position: absolute;
    width: 9px;
    height: 9px;
    background: linear-gradient(135deg, var(--cs-gold-light), var(--cs-gold-dark));
    transform: rotate(45deg);
    box-shadow: 0 0 0 1px #2b2420;
    pointer-events: none;
}
.cs-box::before { top: -6px; left: -6px; }
.cs-box::after { bottom: -6px; right: -6px; }
.cs-box-plain { padding-top: 10px; }
.cs-box-grow { flex: 1 1 auto; }

/* Плашка заголовка */
.cs-title {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100% - 36px);
    padding: 2px 14px;
    border: 1.5px solid var(--cs-ink-soft);
    border-radius: 4px;
    background: linear-gradient(180deg, #f8f1de, #e8dcc0);
    box-shadow: inset 0 0 0 1px var(--cs-gold), 0 1px 2px rgba(0, 0, 0, 0.35);
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-align: center;
    color: var(--cs-ink);
    white-space: normal;
    line-height: 1.15;
    z-index: 1;
}
.cs-title::before,
.cs-title::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 7px;
    height: 7px;
    margin-top: -3.5px;
    background: linear-gradient(135deg, var(--cs-gold-light), var(--cs-gold-dark));
    transform: rotate(45deg);
}
.cs-title::before { left: 3px; }
.cs-title::after { right: 3px; }
.cs-title-sm { font-size: 10px; padding: 1px 10px; max-width: calc(100% - 12px); }
.cs-title-sm::before { left: 2px; width: 5px; height: 5px; margin-top: -2.5px; }
.cs-title-sm::after { right: 2px; width: 5px; height: 5px; margin-top: -2.5px; }
.cs-title-btn {
    all: unset;
    cursor: pointer;
    text-decoration: underline dotted transparent;
    transition: color 0.15s, text-decoration-color 0.15s;
}
.cs-title-btn:hover { color: var(--cs-gold-dark); text-decoration-color: var(--cs-gold-dark); }

/* Замок блока */
.cs-lock {
    position: absolute;
    top: -11px;
    right: 6px;
    z-index: 2;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1.5px solid var(--cs-ink-soft);
    border-radius: 50%;
    background: linear-gradient(180deg, #f8f1de, #e8dcc0);
    box-shadow: inset 0 0 0 1px var(--cs-gold);
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.55;
    transition: opacity 0.15s, transform 0.15s;
}
.cs-lock:hover { opacity: 1; transform: scale(1.1); }
.cs-box.is-locked .cs-lock { opacity: 0.85; }
.cs-box.is-locked .cs-x,
.cs-box.is-locked .cs-add,
.cs-box.is-locked .cs-portrait-actions,
.cs-box.is-locked .cs-mini[data-weapon-gear] { display: none; }
.cs-ro { pointer-events: none; }
.cs-box.is-locked .cs-input[readonly],
.cs-box.is-locked .cs-lined[readonly],
.cs-box.is-locked .cs-num[readonly],
.cs-box.is-locked .cs-score[readonly] { cursor: default; }

/* --- Поля --- */
.cs-input,
.cs-lined,
.cs-num,
.cs-score,
.cs-coin-input {
    font-family: var(--cs-font-body);
    color: var(--cs-ink);
    background: transparent;
    border: 0;
    outline: none;
}
.cs-input {
    width: 100%;
    padding: 2px 4px;
    border-bottom: 1px solid var(--cs-ink-soft);
    font-size: 16px;
    border-radius: 0;
    transition: background 0.15s, border-color 0.15s;
}
.cs-input:focus:not([readonly]) {
    background: rgba(255, 255, 255, 0.45);
    border-bottom-color: var(--cs-gold-dark);
}
.cs-input-lg { font-size: 22px; font-family: var(--cs-font-title); font-weight: 600; }
.cs-input-center { text-align: center; }
.cs-input-level { width: 56px; flex: 0 0 56px; text-align: center; font-weight: 600; }
.cs-select {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    background-image: linear-gradient(45deg, transparent 50%, var(--cs-ink-soft) 50%), linear-gradient(135deg, var(--cs-ink-soft) 50%, transparent 50%);
    background-position: calc(100% - 12px) 55%, calc(100% - 7px) 55%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
    padding-right: 20px;
}
.cs-select-sm { width: auto; font-size: 14px; padding: 0 18px 0 4px; }
.cs-select.cs-ro { background-image: none; }
.cs-label {
    display: block;
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--cs-ink);
}
.cs-label-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}
.cs-field { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.cs-inline { display: flex; gap: 8px; align-items: flex-end; }
.cs-wiki-link {
    font-size: 10px;
    padding: 0 4px;
    border: none;
    border-radius: 0;
    background: none;
    color: var(--cs-gold-dark);
    text-decoration: underline dotted;
    cursor: pointer;
    min-width: 0;
}
.cs-wiki-link:hover { color: var(--cs-ink); }
.cs-hint { font-size: 12px; color: var(--cs-ink-soft); }

/* Линованные текстовые поля — растут вместе с содержимым */
.cs-lined {
    width: 100%;
    resize: none;
    overflow: hidden;
    padding: 0 4px;
    font-size: 16px;
    line-height: 27px;
    background-image: repeating-linear-gradient(transparent 0, transparent 26px, var(--cs-line) 26px, var(--cs-line) 27px);
    background-attachment: local;
    border-radius: 0;
}
.cs-lined:focus:not([readonly]) { background-color: rgba(255, 255, 255, 0.3); }

/* Числа в рамочках */
.cs-num {
    display: inline-block;
    box-sizing: border-box;
    width: 64px;
    padding: 2px 4px;
    border: 1.5px solid var(--cs-ink-soft);
    border-radius: 7px;
    background: var(--cs-paper-light);
    box-shadow: inset 0 0 0 1px var(--cs-gold), inset 0 1px 3px rgba(0, 0, 0, 0.15);
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 20px;
    text-align: center;
    line-height: 1.2;
}
.cs-num:focus:not([readonly]) { border-color: var(--cs-gold-dark); background: #fff; }
.cs-num-sm { width: 52px; font-size: 17px; }
.cs-num-xs { width: 44px; font-size: 15px; padding: 1px 2px; }
.cs-num-wide { width: 100%; font-size: 26px; }
.cs-num-xl { font-size: 32px; }
.cs-num-static { cursor: default; }

/* Кружки владения */
.cs-circle {
    appearance: none;
    -webkit-appearance: none;
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
    margin: 0;
    border: 1.5px solid var(--cs-ink-soft);
    border-radius: 50%;
    background: var(--cs-paper-light);
    box-shadow: inset 0 0 0 1px var(--cs-gold);
    cursor: pointer;
    vertical-align: middle;
    transition: background 0.15s;
}
.cs-circle:checked { background: radial-gradient(circle, var(--cs-ink) 55%, var(--cs-gold-dark) 60%, var(--cs-ink) 70%); }
.cs-circle-lg { width: 22px; height: 22px; }

/* Строки спасбросков и навыков */
.cs-rows { display: flex; flex-direction: column; gap: 2px; }
.cs-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 22px;
    border-bottom: 1px dotted var(--cs-line);
}
.cs-row-val {
    flex: 0 0 34px;
    text-align: center;
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 13px;
}
.cs-rollable {
    all: unset;
    cursor: pointer;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}
.cs-rollable:hover { color: var(--cs-gold-dark); background: rgba(201, 162, 39, 0.14); }
.cs-rollable:active { background: rgba(201, 162, 39, 0.3); }
.cs-row-name { flex: 1 1 auto; padding: 1px 4px; font-size: 15px; }
.cs-row-name small { font-size: 11px; color: var(--cs-ink-soft); }

/* Пилюли: вдохновение, бонус мастерства, пассивное восприятие */
.cs-pill-box { padding: 8px 10px; }
.cs-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: default;
}
.cs-pill-text {
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    line-height: 1.2;
}

/* --- Щиты --- */
.cs-shield {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 108px;
}
.cs-shield-label {
    all: unset;
    display: block;
    box-sizing: border-box;
    width: 100%;
    padding: 2px 3px;
    border: 1.5px solid var(--cs-ink-soft);
    border-radius: 4px;
    background: linear-gradient(180deg, #f8f1de, #e8dcc0);
    box-shadow: inset 0 0 0 1px var(--cs-gold);
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 9px;
    letter-spacing: 0;
    text-transform: uppercase;
    text-align: center;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
    z-index: 1;
}
button.cs-shield-label { cursor: pointer; transition: color 0.15s, background 0.15s; }
button.cs-shield-label:hover { color: var(--cs-gold-dark); background: #fff7df; }
.cs-shield-shape {
    display: block;
    position: relative;
    width: 100px;
    height: 138px;
    margin-top: -2px;
    background: url('../assets/sheet/shield-ability.png') center / contain no-repeat;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
}
.cs-shield-inner {
    position: absolute;
    left: 16%;
    right: 16%;
    top: 14%;
    height: 48%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cs-score {
    position: relative;
    width: 56px;
    text-align: center;
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 30px;
    line-height: 1;
    -moz-appearance: textfield;
}
.cs-score::-webkit-inner-spin-button,
.cs-score::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.cs-score:focus:not([readonly]) { color: var(--cs-gold-dark); }
.cs-mod {
    position: absolute;
    left: 50%;
    top: 78.5%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 14px;
    z-index: 1;
}
.cs-shield-sm { width: 96px; }
.cs-shield-sm .cs-shield-shape {
    width: 82px;
    height: 108px;
    background-image: url('../assets/sheet/shield-combat.png');
}
.cs-shield-sm .cs-shield-inner { left: 14%; right: 14%; top: 16%; height: 58%; }
.cs-shield-sm .cs-score { font-size: 26px; width: 50px; }

/* --- Страница 1: сетка --- */
.cs-head { margin-bottom: 14px; padding-top: 12px; }
.cs-head-grid {
    display: grid;
    grid-template-columns: minmax(260px, 1.1fr) 2fr;
    gap: 10px 22px;
}
.cs-head-left { display: flex; flex-direction: column; gap: 8px; }
.cs-head-right {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px 16px;
}
.cs-field-class { grid-column: span 2; }

.cs-grid {
    display: grid;
    grid-template-columns: minmax(320px, 350px) minmax(300px, 1fr) minmax(260px, 1fr);
    gap: 14px;
    align-items: stretch;
}
.cs-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}
.cs-abil-row {
    display: grid;
    grid-template-columns: 118px 1fr;
    gap: 10px;
    align-items: start;
}
.cs-abil-stack {
    align-items: center;
    gap: 14px;
    padding: 14px 4px 10px;
}
.cs-abil-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.cs-passive .cs-pill-text { font-size: 10px; }

.cs-combat {
    flex-direction: row;
    justify-content: space-around;
    padding: 12px 6px 8px;
}
.cs-hp-box { padding-top: 18px; }
.cs-two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.cs-two .cs-box { padding-top: 32px; }
.cs-two .cs-title { font-size: 10px; }
/* Кости хитов — как в официальном листе: «Всего» сверху, крупно — сколько осталось,
   подпись «Кости хитов (D6)» снизу (клик по подписи — бросок, D6 — выбор кости). */
.cs-two .cs-hd-box {
    padding: 10px 10px 8px;
    align-items: stretch;
    justify-content: space-between;
    gap: 4px;
}
.cs-hd-top {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-right: 20px; /* место под замок */
}
.cs-hd-top-label {
    font-family: var(--cs-font-body);
    font-size: 14px;
    color: var(--cs-ink-soft);
}
.cs-hd-total {
    flex: 1 1 auto;
    min-width: 0;
    padding: 1px 4px;
    border: 1.5px solid var(--cs-ink-soft);
    border-radius: 5px;
    background: var(--cs-paper-light);
    box-shadow: inset 0 0 0 1px var(--cs-gold);
    text-align: center;
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 16px;
    line-height: 1.3;
}
.cs-hd-left {
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--cs-ink);
    text-align: center;
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 34px;
    line-height: 1.1;
    outline: none;
    -moz-appearance: textfield;
}
.cs-hd-left::-webkit-inner-spin-button,
.cs-hd-left::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.cs-hd-left:focus { background: rgba(255, 255, 255, 0.45); border-radius: 4px; }
.cs-hd-caption {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 2px;
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--cs-ink);
}
.cs-hd-caption-btn { padding: 0 3px; text-transform: uppercase; }
.cs-hd-select {
    appearance: none;
    -webkit-appearance: none;
    padding: 0 1px;
    border: 0;
    border-bottom: 1px dotted var(--cs-ink-soft);
    background: transparent;
    color: var(--cs-ink);
    font: inherit;
    letter-spacing: 0;
    cursor: pointer;
}
.cs-hd-select:hover { color: var(--cs-gold-dark); }
.cs-hd-select.cs-ro { border-bottom-color: transparent; }

/* Спасброски от смерти: провалы — красным, подпись итога, «Сбросить». */
.cs-death { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.cs-death-row { display: flex; align-items: center; gap: 6px; }
.cs-death-row .cs-label { min-width: 54px; }
.cs-circle-fail:checked {
    background: radial-gradient(circle, #8f1d17 55%, var(--cs-gold-dark) 60%, #5b120e 70%);
}
.cs-death-status {
    max-width: 100%;
    font-size: 12px;
    line-height: 1.2;
    text-align: center;
    color: var(--cs-ink-soft);
}
.cs-death-status:empty { display: none; }
.cs-death-status[data-kind='stable'] { color: #2d6a3e; font-weight: 600; }
.cs-death-status[data-kind='dead'] { color: #8f1d17; font-weight: 600; }
.cs-death-reset {
    all: unset;
    padding: 0 6px;
    border-radius: 4px;
    font-family: var(--cs-font-title);
    font-size: 10px;
    font-weight: 600;
    color: var(--cs-gold-dark);
    cursor: pointer;
}
.cs-death-reset:hover { background: rgba(201, 162, 39, 0.18); color: var(--cs-ink); }
.cs-death-reset[hidden] { display: none; }

/* Таблица атак */
.cs-attacks { width: 100%; border-collapse: collapse; font-size: 14px; }
.cs-attacks th {
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 9.5px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-align: center;
    padding: 0 2px 2px;
    color: var(--cs-ink-soft);
}
.cs-attacks td { padding: 2px; border-bottom: 1px dotted var(--cs-line); vertical-align: middle; }
.cs-attacks td:first-child { width: 42%; }
.cs-cell { font-size: 14px; padding: 1px 3px; border-bottom-color: transparent; }
.cs-cell-center { text-align: center; }
.cs-cell-roll { white-space: nowrap; }
.cs-cell-roll .cs-cell { display: inline-block; width: calc(100% - 26px); vertical-align: middle; }
.cs-cell-text { display: block; font-size: 14px; padding: 1px 3px; }
.cs-cell-note { display: block; font-size: 11px; color: var(--cs-ink-soft); padding: 0 3px; line-height: 1.2; }
.cs-cell-btn {
    display: block;
    width: 100%;
    padding: 2px 4px;
    text-align: center;
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 13px;
    box-sizing: border-box;
}
.cs-cell-btn-sm { font-size: 11px; font-weight: 600; }
.cs-cell-x { width: 24px; text-align: center; }
.cs-mini {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--cs-ink-soft);
    border-radius: 4px;
    background: var(--cs-paper-light);
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    vertical-align: middle;
}
.cs-mini:hover { background: #fff7df; border-color: var(--cs-gold-dark); }
.cs-attack-settings td { padding: 6px 2px 8px; }
.cs-settings { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; }
.cs-settings .cs-hint { flex-basis: 100%; }
.cs-settings-field { display: flex; flex-direction: column; gap: 2px; flex: 1 1 140px; font-size: 12px; }
.cs-settings-buttons { display: flex; gap: 6px; }

/* Списки с крестиками */
.cs-list { display: flex; flex-direction: column; gap: 2px; }
.cs-list-row,
.cs-spell-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.cs-sheet .character-sheet-list-row { margin: 0; }
.cs-line-input { border-bottom: 1px solid var(--cs-line); }
.cs-x {
    all: unset;
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    text-align: center;
    line-height: 18px;
    border-radius: 50%;
    color: var(--cs-ink-soft);
    cursor: pointer;
    font-size: 15px;
    opacity: 0.45;
}
.cs-x:hover { opacity: 1; background: rgba(199, 62, 58, 0.15); color: var(--color-accent-red); }
.cs-add {
    all: unset;
    align-self: flex-start;
    margin-top: 2px;
    padding: 1px 6px;
    border-radius: 4px;
    font-family: var(--cs-font-title);
    font-size: 11px;
    font-weight: 600;
    color: var(--cs-gold-dark);
    cursor: pointer;
}
.cs-add:hover { background: rgba(201, 162, 39, 0.18); color: var(--cs-ink); }

/* Кошелёк */
.cs-coins {
    display: flex;
    justify-content: space-around;
    gap: 4px;
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--cs-line);
}
.cs-coin { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.cs-coin-label {
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 10px;
    letter-spacing: 0.05em;
}
.cs-coin-input {
    box-sizing: border-box;
    width: 46px;
    height: 46px;
    border: 2px solid var(--cs-gold-dark);
    border-radius: 50%;
    background: radial-gradient(circle, #fff8e6, var(--cs-paper-light));
    box-shadow: 0 0 0 1.5px var(--cs-ink-soft);
    text-align: center;
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 13px;
}
.cs-coin-input:focus:not([readonly]) { background: #fff; }

/* --- Страница 2 --- */
.cs-bio-head {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(300px, 1.2fr);
    gap: 14px;
    margin-bottom: 18px;
}
.cs-box-name { justify-content: center; }
.cs-bio-name {
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 24px;
    text-align: center;
    min-height: 32px;
    padding: 4px;
}
.cs-bio-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px 10px;
    padding: 18px 10px 10px;
    box-shadow: none;
    border: none;
    background: none;
}
.cs-bio-stats::before,
.cs-bio-stats::after { display: none; }
.cs-bio-stats .cs-lock { top: -6px; right: 0; }
.cs-stat {
    position: relative;
    padding: 14px 8px 6px;
    border: 2px solid var(--cs-box-border);
    border-radius: 8px;
    background: var(--cs-paper);
    box-shadow: inset 0 0 0 1px var(--cs-gold), 0 1px 3px rgba(0, 0, 0, 0.3);
}
.cs-bio-grid {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(300px, 1.4fr);
    gap: 14px;
    align-items: stretch;
}
.cs-portrait-box { align-items: center; }
.cs-portrait {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    aspect-ratio: 1 / 1;
    max-height: 420px;
    border: 1.5px solid var(--cs-ink-soft);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.25);
    box-shadow: inset 0 0 0 1px var(--cs-gold), inset 0 0 30px rgba(90, 60, 20, 0.2);
    overflow: hidden;
    cursor: pointer;
}
/* Старое правило формы (.character-sheet-portrait-preview, pages.css) задаёт 112×112 —
   здесь поле на всю ширину блока, а картинка вписывается целиком, без обрезки. */
.cs-sheet .cs-portrait {
    height: auto;
    min-height: 220px;
    border-radius: 6px;
}
.cs-sheet .cs-portrait img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
}
.cs-portrait-empty { font-family: var(--cs-font-title); font-size: 12px; color: var(--cs-ink-soft); text-transform: uppercase; letter-spacing: 0.05em; }
.cs-portrait-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; width: 100%; }
.cs-check-inline { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.cs-allies { display: grid; grid-template-columns: 1fr 120px; gap: 10px; align-items: end; }
.cs-allies-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.cs-symbol {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 120px;
    height: 120px;
    padding: 14px 6px 6px;
    border: 2px solid var(--cs-box-border);
    border-radius: 8px;
    background: var(--cs-paper-light);
    box-shadow: inset 0 0 0 1px var(--cs-gold);
}
.cs-symbol-input { font-size: 26px; border-bottom: none; }

/* --- Страница 3 --- */
.cs-cast-head {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    padding: 14px 12px 12px;
    margin-bottom: 18px;
}
.cs-cast-cell {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 18px 8px 8px;
    border: 2px solid var(--cs-box-border);
    border-radius: 8px;
    background: var(--cs-paper);
    box-shadow: inset 0 0 0 1px var(--cs-gold), 0 1px 3px rgba(0, 0, 0, 0.3);
    min-height: 74px;
}
.cs-cast-cell .cs-title { white-space: normal; line-height: 1.15; }
.cs-cast-class .cs-input { font-family: var(--cs-font-title); font-weight: 600; font-size: 17px; }
.cs-spells-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    align-items: stretch;
}
.cs-spell-box { padding-top: 30px; }
.cs-level-head {
    position: absolute;
    top: -24px;
    left: 4px;
    right: 34px;
    display: flex;
    align-items: center;
    gap: 2px;
    z-index: 1;
}
.cs-level-badge {
    position: relative;
    flex: 0 0 auto;
    width: 38px;
    height: 51px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: url('../assets/sheet/level-badge.png') center / contain no-repeat;
    color: #fff3c4;
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 17px;
    text-shadow: 0 0 4px rgba(239, 215, 122, 0.8);
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
    isolation: isolate;
}
.cs-level-badge::before {
    content: '';
    position: absolute;
    inset: 23% 27% 23% 28%;
    background: linear-gradient(160deg, #3b3a40, #141317);
    clip-path: polygon(50% 0, 100% 16%, 100% 84%, 50% 100%, 0 84%, 0 16%);
    z-index: -1;
}
.cs-title-level {
    position: static;
    transform: none;
    flex: 1 1 auto;
    max-width: none;
    text-align: left;
    padding-left: 18px;
}
.cs-slots {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 2px 6px;
    border-bottom: 1px solid var(--cs-line);
}
.cs-slot { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1 1 0; text-align: center; }
.cs-slot .cs-label { font-size: 9px; }
.cs-spell-col-head {
    margin-top: 6px;
    font-family: var(--cs-font-title);
    font-weight: 700;
    font-size: 9.5px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-align: center;
    color: var(--cs-ink-soft);
}
.cs-spell-name { flex: 1 1 auto; min-width: 0; }
.cs-sheet .character-spell-name-controls { display: flex; align-items: center; gap: 4px; }
.cs-sheet .character-spell-info-btn {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    border: 1px solid var(--cs-ink-soft);
    border-radius: 50%;
    background: var(--cs-paper-light);
    color: var(--cs-ink);
    font-family: var(--cs-font-title);
    font-size: 11px;
    line-height: 1;
}
.cs-sheet .character-spell-info-btn:disabled { opacity: 0.3; }
.cs-sheet .character-spell-cast-btn { padding: 2px 8px; font-size: 11px; }
.cs-sheet .character-spell-cast-panel {
    margin: 4px 0 8px;
    padding: 8px;
    border: 1px solid var(--cs-ink-soft);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.35);
}
.cs-sheet .character-spell-cast-panel .form-label { color: var(--cs-ink); }
.cs-sheet .character-spell-cast-panel .form-input,
.cs-sheet .character-spell-cast-panel .form-select {
    background: #fff;
    color: var(--cs-ink);
    border-color: var(--cs-ink-soft);
}
.cs-sheet .character-spell-popover {
    background: #fffaf0;
    color: var(--cs-ink);
    border: 1px solid var(--cs-ink-soft);
}
.cs-sheet .character-search-results { background: #fffaf0; border: 1px solid var(--cs-ink-soft); color: var(--cs-ink); }
.cs-sheet .character-search-results-item { color: var(--cs-ink); }
.cs-sheet .character-search-results-item:hover { background: rgba(201, 162, 39, 0.2); }
.cs-legend {
    margin: 14px 0 0;
    text-align: center;
    font-family: var(--cs-font-title);
    font-size: 12px;
    color: var(--cs-ink-soft);
}

/* --- Узкие экраны --- */
/* На компьютере лист всегда в три колонки и уменьшается масштабом; в колонку — только на телефоне. */
@media (max-width: 699px) {
    .cs-frame { width: auto; }
    .cs-grid,
    .cs-bio-grid,
    .cs-bio-head,
    .cs-spells-grid { grid-template-columns: 1fr; }
    .cs-head-grid { grid-template-columns: 1fr; }
    .cs-cast-head { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
    .modal.cs-modal .modal-body { padding: var(--space-xs); }
    .cs-frame { padding: 40px 30px; }
    .cs-frame::before { inset: 14px; }
    .cs-frame::after { border-width: 63px; }
    .cs-head-right { grid-template-columns: 1fr 1fr; }
    .cs-abil-row { grid-template-columns: 1fr; }
    .cs-abil-stack { flex-direction: row; flex-wrap: wrap; justify-content: center; }
    .cs-two,
    .cs-allies,
    .cs-cast-head { grid-template-columns: 1fr; }
    .cs-star { display: none; }
}

/* --- Кнопка «В отдельном окне» рядом с крестиком --- */
.cs-modal-header .modal-title { flex: 1 1 auto; }
.modal-header .cs-popout-btn { margin-right: 4px; }

/* --- Отдельное окно листа (#sheet): без шапки и подвала сайта --- */
body.page-sheet .main-nav,
body.page-sheet .main-footer { display: none; }
body.page-sheet .page-content { margin-top: 0; }
.cs-popout-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #0f0e12;
}
.cs-popout-loading {
    margin: auto;
    color: var(--text-secondary);
    font-family: var(--font-ui);
}
.cs-popout-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 10px 14px;
}
.cs-popout-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-md);
    padding: 8px 16px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-darker);
}
.cs-popout-title {
    margin-right: auto;
    font-family: var(--font-display);
    font-size: var(--font-size-lg);
    color: var(--text-primary);
}

/* --- Ячейки по таблице класса: подсказка и поля «только для чтения» --- */
.cs-slots-hint {
    margin: -8px 0 14px;
    min-height: 1em;
    text-align: center;
    font-size: 13px;
    color: var(--cs-ink-soft);
}
.cs-num[data-auto] {
    background: #ede3c8;
    cursor: default;
}

/* Коробка, куда перенесли заклинание, коротко подсвечивается. */
.cs-spell-box.is-flash { animation: cs-box-flash 1.2s ease; }
@keyframes cs-box-flash {
    0%, 40% { box-shadow: inset 0 0 0 1px var(--cs-gold), 0 0 0 3px var(--cs-gold-light), 0 0 18px var(--cs-gold); }
    100% { box-shadow: inset 0 0 0 1px var(--cs-gold), inset 0 0 18px rgba(90, 60, 20, 0.12), 0 1px 3px rgba(0, 0, 0, 0.35); }
}
