/* ==========================================================================
 * D&D TOOLS SUITE — Dice Roller (visual rebuild)
 * Уважує BEM-класи плагіна (.dnd-tools__*, .dnd-dice-toast*) і токени теми
 * (--bg-body, --bd-border, --text-main, --accent тощо).
 * ========================================================================== */

.dnd-tools [hidden] { display: none !important; }
body.dnd-tools-open { overflow: hidden; }
.dnd-tools__fab    { display: none; }

/* Іконка кубика в рейлі */
.rail-btn-dnd-tools svg { width: 28px; height: 28px; }
.rail-btn.rail-btn-dnd-tools .i { stroke-width: 1; }

/* ==========================================================================
 * 1. SCRIM
 * ========================================================================== */
.dnd-tools__overlay {
    position: fixed; inset: 0;
    background: var(--scrim, rgba(14, 12, 21, 0.36));
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9998;
    animation: dndt-scrim-in 0.2s ease-out;
}
html[data-theme="dark"] .dnd-tools__overlay { background: oklch(0.15 0.005 70 / 0.75); }

@keyframes dndt-scrim-in { from { opacity: 0; } to { opacity: 1; } }

/* ==========================================================================
 * 2. MAIN MODAL — історія кидків
 * ========================================================================== */
.dnd-tools__modal {
    position: fixed;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 540px;
    max-height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
    border: 1px solid var(--bd-border);
    border-radius: 16px;
    box-shadow: var(--shadow-pop, 0 24px 70px -20px rgba(0,0,0,0.25));
    overflow: hidden;
    z-index: 9999;
    animation: dndt-modal-in 0.28s cubic-bezier(.2,.9,.25,1.05);
}
@keyframes dndt-modal-in {
    from { opacity: 0; transform: translate(-50%, -48%) scale(0.97); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.dnd-tools__modal-handle {
    position: absolute; top: 6px; left: 50%;
    transform: translateX(-50%);
    width: 36px; height: 3px; border-radius: 3px;
    background: var(--bd-border);
    flex: 0 0 auto;
    margin: 0;
}

/* Header */
.dnd-tools__modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 22px 14px;
    border-bottom: 1px solid var(--line-soft);
    flex: 0 0 auto;
}
.dnd-tools__modal-title {
    margin: 0;
    font-family: var(--font-serif, 'Source Serif 4', serif);
    font-size: 19px; font-weight: 500;
    letter-spacing: -0.005em;
    color: var(--text-main);
}
.dnd-tools__modal-actions { display: flex; gap: 4px; }

.dnd-tools__icon-btn {
    width: 30px; height: 30px;
    border: 0; background: transparent;
    border-radius: 7px;
    display: grid; place-items: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.14s, color 0.14s;
    font-size: 14px;
    line-height: 1;
}
.dnd-tools__icon-btn:hover { background: var(--bg-hover); color: var(--text-main); }

/* Body */
.dnd-tools__modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 14px 22px 18px;
}
.dnd-tools__modal-body::-webkit-scrollbar { width: 8px; }
.dnd-tools__modal-body::-webkit-scrollbar-thumb { background: var(--bd-border); border-radius: 8px; }

/* Footer (input row) */
.dnd-tools__modal-footer {
    display: flex; gap: 8px;
    padding: 14px 22px 18px;
    border-top: 1px solid var(--line-soft);
    background: var(--bg-sunken);
    flex: 0 0 auto;
}
html[data-theme="dark"] .dnd-tools__modal-footer { background: var(--bg-body); }

.dnd-tools__input-wrap {
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
    display: flex; align-items: center;
    background: var(--bg-sidebar);
    border: 1px solid var(--bd-border);
    border-radius: 8px;
    overflow: hidden;
    transition: border-color 0.14s;
}
.dnd-tools__input-wrap:focus-within { border-color: var(--accent-soft); }
html[data-theme="dark"] .dnd-tools__input-wrap { background: var(--bg-block); }

.dnd-tools__input {
    flex: 1 1 auto;
    min-width: 0;
    height: 38px;
    border: 0; outline: none; background: transparent;
    padding: 0 14px;
    font-family: var(--font-mono, 'Geist Mono', monospace);
    font-size: 13px;
    color: var(--text-main);
}
.dnd-tools__input::placeholder { color: var(--text-muted); }

.dnd-tools__help-btn {
    flex: 0 0 auto;
    width: 30px; height: 30px;
    margin-right: 4px;
    border: 0; background: transparent;
    border-radius: 6px;
    display: grid; place-items: center;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px; font-weight: 600;
    transition: background 0.14s, color 0.14s;
}
.dnd-tools__help-btn:hover { background: var(--bg-hover); color: var(--text-main); }
.dnd-tools__help-btn[aria-expanded="true"],
.dnd-tools__help-btn.is-on { background: var(--accent-bg); color: var(--accent); }

.dnd-tools__submit {
    flex: 0 0 auto;
    width: 42px; height: 38px;
    border: 0; border-radius: 8px;
    background: var(--accent);
    color: #fff;
    display: grid; place-items: center;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.14s, transform 0.14s;
}
.dnd-tools__submit:hover { background: var(--accent-soft); transform: translateY(-1px); }
.dnd-tools__submit:active { transform: translateY(0); }

/* ==========================================================================
 * 3. HISTORY ROWS
 * Розмітка з JS: .dnd-tools__roll > __roll-total + __roll-expr + __roll-detail
 * Перетворюємо в 2-колонковий grid як у моці (.rh-row).
 * ========================================================================== */
.dnd-tools__empty {
    display: flex; align-items: center; justify-content: center;
    min-height: 220px;
    padding: 32px;
    color: var(--text-muted);
    font-family: var(--font-serif, 'Source Serif 4', serif);
    font-size: 14px;
    text-align: center;
    font-style: italic;
}

.dnd-tools__roll {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    column-gap: 14px;
    padding: 4px 0 16px;
    border-bottom: 1px solid var(--line-soft);
    transition: background 0.14s;
}
.dnd-tools__roll:last-child { border-bottom: 0; }
.dnd-tools__roll:hover { background: transparent; } /* прибираємо стару підсвітку */

.dnd-tools__roll-total {
    grid-row: 1 / 3;
    align-self: start;
    min-width: 44px;
    font-family: var(--font-serif, 'Source Serif 4', serif);
    font-size: 32px; font-weight: 500;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
}
.dnd-tools__roll-expr {
    font-family: var(--font-mono, 'Geist Mono', monospace);
    font-size: 12.5px;
    color: var(--text-main);
    letter-spacing: 0.01em;
    margin: 0 0 4px;
}
.dnd-tools__roll-detail {
    font-family: var(--font-mono, 'Geist Mono', monospace);
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: 0.01em;
    line-height: 1.5;
    margin: 0;
}

/* Crit / fumble варіанти (JS додає клас .dnd-tools__roll--crit / --fumble) */
.dnd-tools__roll--crit .dnd-tools__roll-total { color: oklch(0.50 0.16 150); }
html[data-theme="dark"] .dnd-tools__roll--crit .dnd-tools__roll-total { color: oklch(0.78 0.16 150); }
.dnd-tools__roll--fumble .dnd-tools__roll-total { color: oklch(0.50 0.18 28); }
html[data-theme="dark"] .dnd-tools__roll--fumble .dnd-tools__roll-total { color: oklch(0.78 0.16 28); }

/* ==========================================================================
 * 4. HELP MODAL — пресети формул
 * Розмітка плагіна: .dnd-tools__help > __help-inner > .__help-header + .__help-grid
 * ========================================================================== */
.dnd-tools__help {
    position: fixed;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: 100%; max-width: 540px;
    max-height: calc(100vh - 80px);
    background: var(--bg-sidebar);
    border: 1px solid var(--bd-border);
    border-radius: 16px;
    box-shadow: var(--shadow-pop, 0 24px 70px -20px rgba(0,0,0,0.25));
    overflow-y: auto;
    z-index: 10000;
    animation: dndt-modal-in 0.28s cubic-bezier(.2,.9,.25,1.05);
}

.dnd-tools__help-inner { padding: 22px 22px 20px; }

.dnd-tools__help-header { margin: 0 0 8px; }
.dnd-tools__help-header + .dnd-tools__help-grid + .dnd-tools__help-header { margin-top: 18px; }

.dnd-tools__help-title {
    margin: 0;
    font-family: var(--font-mono, 'Geist Mono', monospace);
    font-size: 9.5px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-weight: 500;
    color: var(--text-muted);
}

.dnd-tools__help-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 0 0 4px;
}

.dnd-tools__preset {
    display: flex; flex-direction: column;
    align-items: flex-start; gap: 2px;
    padding: 10px 12px;
    border: 1px solid var(--bd-border);
    border-radius: 8px;
    background: var(--bg-body);
    color: var(--text-main);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.14s, background 0.14s;
}
.dnd-tools__preset:hover {
    border-color: var(--accent);
    background: var(--accent-bg);
}
.dnd-tools__preset strong {
    font-family: var(--font-mono, 'Geist Mono', monospace);
    font-size: 13px;
    color: var(--text-main);
    font-weight: 500;
}
.dnd-tools__preset:hover strong { color: var(--accent); }
.dnd-tools__preset span {
    font-family: var(--font-main);
    font-size: 11px; line-height: 1.4;
    color: var(--text-muted);
}

.dnd-tools__help-footer {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--line-soft);
    color: var(--text-muted);
    font-family: var(--font-main);
    font-size: 12px; line-height: 1.5;
}

html[data-theme="dark"] .dnd-tools__preset { background: var(--bg-block); }

/* ==========================================================================
 * 5. ROLL TOAST — плавна картка біля рейла
 * Розмітка з JS: .dnd-dice-toast > __result + __expr + __progress > __bar
 * Додатково можемо отримувати модифікатори __crit / __fumble (правки JS).
 * ========================================================================== */
.dnd-dice-toast {
    position: fixed;
    z-index: 10001;
    width: 252px;
    background: var(--bg-sidebar);
    border: 1px solid var(--bd-border);
    border-radius: 14px;
    padding: 16px 18px 0;
    box-shadow:
        0 1px 0 oklch(1 0 0 / 0.04) inset,
        0 22px 48px -22px oklch(0.2 0.05 280 / 0.45),
        0 4px 14px -6px oklch(0.2 0.05 280 / 0.18);
    font-family: var(--font-geist, 'Geist', sans-serif);
    overflow: hidden;
    cursor: default;
    pointer-events: auto;
    opacity: 0;
    scale: 0.96;
    transform-origin: left center;
    transition: opacity 0.18s ease, scale 0.18s ease;
}
.dnd-dice-toast--visible { opacity: 1; scale: 1; }
.dnd-dice-toast--hiding { opacity: 0; scale: 0.96; }

/* Лівий акцентний кант */
.dnd-dice-toast::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: linear-gradient(
        180deg,
        var(--accent) 0%,
        color-mix(in oklab, var(--accent) 60%, transparent) 100%
    );
    z-index: 1;
}

/* Заголовок із міткою «КИДОК» + штампом крит/провал */
.dnd-dice-toast__head {
    display: flex; align-items: center; gap: 6px;
    font-family: var(--font-mono, 'Geist Mono', monospace);
    font-size: 9.5px; letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.dnd-dice-toast__head::before {
    content: '\2B22'; /* шестикутник */
    color: var(--accent);
    font-size: 12px;
    font-family: var(--font-main);
    line-height: 1;
}
.dnd-dice-toast__stamp {
    margin-left: auto;
    padding: 2px 7px;
    border-radius: 4px;
    background: var(--accent);
    color: #fff;
    font-size: 9px; font-weight: 600;
    letter-spacing: 0.1em;
    animation: dndt-stamp-pulse 1.4s ease-in-out infinite;
}
.dnd-dice-toast__stamp--bad { background: oklch(0.55 0.18 28); }
@keyframes dndt-stamp-pulse {
    0%,100% { opacity: 1; }
    50%     { opacity: 0.7; }
}

/* Велике число */
.dnd-dice-toast__result {
    padding: 0;
    font-family: var(--font-serif, 'Source Serif 4', serif);
    font-size: 56px; font-weight: 500;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--text-main);
    text-align: left;
    font-variant-numeric: tabular-nums;
    margin: 4px 0 6px;
}

.dnd-dice-toast__expr {
    padding: 0;
    font-family: var(--font-mono, 'Geist Mono', monospace);
    font-size: 13px;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    text-align: left;
    margin: 0 0 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Footer тоста: підказка ↵ + кнопка історії */
.dnd-dice-toast__foot {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 0 12px;
    border-top: 1px solid var(--line-soft);
}
.dnd-dice-toast__foot-hint {
    font-family: var(--font-mono, 'Geist Mono', monospace);
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    white-space: nowrap;
}
.dnd-dice-toast__foot-history {
    border: 0; background: transparent;
    font-family: var(--font-mono, 'Geist Mono', monospace);
    font-size: 10.5px;
    color: var(--accent);
    letter-spacing: 0.04em;
    padding: 2px 4px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}
.dnd-dice-toast__foot-history:hover { background: var(--accent-bg); }

/* Прогрес-бар (керується JS) — прижатий до низу всередині картки.
   Завдяки overflow: hidden + border-radius батька він автоматично обрізається. */
.dnd-dice-toast__progress {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 3px;
    background: var(--bd-border);
    z-index: 2;
}
.dnd-dice-toast__bar {
    height: 100%;
    background: var(--accent);
    transform-origin: left;
    transform: scaleX(1);
}

/* ----- Crit / Fumble ----- */
/* Крит — зелений, провал — червоний (стандарт D&D-роллерів) */
.dnd-dice-toast--crit {
    border-color: color-mix(in oklab, oklch(0.55 0.16 150) 45%, var(--bd-border));
    box-shadow:
        0 0 0 4px color-mix(in oklab, oklch(0.55 0.16 150) 14%, transparent),
        0 22px 48px -22px oklch(0.2 0.05 280 / 0.5),
        0 4px 14px -6px oklch(0.2 0.05 280 / 0.2);
}
.dnd-dice-toast--crit::before {
    width: 4px;
    background: linear-gradient(180deg, oklch(0.55 0.16 150), oklch(0.65 0.18 130));
}
.dnd-dice-toast--crit .dnd-dice-toast__result { color: oklch(0.50 0.16 150); }
html[data-theme="dark"] .dnd-dice-toast--crit .dnd-dice-toast__result { color: oklch(0.78 0.16 150); }
.dnd-dice-toast--crit .dnd-dice-toast__stamp {
    background: oklch(0.55 0.16 150);
}

.dnd-dice-toast--fumble {
    border-color: color-mix(in oklab, oklch(0.55 0.18 28) 40%, var(--bd-border));
    box-shadow:
        0 0 0 4px color-mix(in oklab, oklch(0.55 0.18 28) 12%, transparent),
        0 22px 48px -22px oklch(0.2 0.05 280 / 0.5),
        0 4px 14px -6px oklch(0.2 0.05 280 / 0.2);
}
.dnd-dice-toast--fumble::before {
    width: 4px;
    background: linear-gradient(180deg, oklch(0.55 0.18 28), oklch(0.45 0.12 28));
}
.dnd-dice-toast--fumble .dnd-dice-toast__result { color: oklch(0.50 0.18 28); }
html[data-theme="dark"] .dnd-dice-toast--fumble .dnd-dice-toast__result { color: oklch(0.78 0.16 28); }

/* ==========================================================================
 * 6. RAIL ICON — анімація під час кидка з тексту
 * ========================================================================== */
@keyframes dnd-dice-shake {
    0%   { transform: translate(0,0) rotate(0)    scale(1);    }
    15%  { transform: translate(-2px,-2px) rotate(-8deg) scale(1.18); }
    30%  { transform: translate(2px,-1px)  rotate(8deg)  scale(1.22); }
    45%  { transform: translate(-2px,1px)  rotate(-6deg) scale(1.18); }
    60%  { transform: translate(2px,2px)   rotate(6deg)  scale(1.14); }
    75%  { transform: translate(-1px,-1px) rotate(-4deg) scale(1.08); }
    100% { transform: translate(0,0) rotate(0)    scale(1);    }
}
.dnd-dice-rolling svg {
    animation: dnd-dice-shake 0.5s ease-in-out;
    transform-origin: center;
}

/* ==========================================================================
 * 7. RESPONSIVE
 * ========================================================================== */
@media (max-width: 640px) {
    .dnd-tools__modal {
        inset: auto 0 0 0;
        transform: none;
        width: 100vw;
        max-width: none;
        max-height: 88vh;
        border-radius: 16px 16px 0 0;
        animation: dndt-modal-in-mobile 0.25s ease-out;
    }
    @keyframes dndt-modal-in-mobile {
        from { transform: translateY(20px); opacity: 0; }
        to   { transform: translateY(0); opacity: 1; }
    }

    .dnd-tools__help {
        width: calc(100vw - 24px);
        max-width: 540px;
    }

    .dnd-tools__modal-header,
    .dnd-tools__modal-footer,
    .dnd-tools__modal-body { padding-left: 16px; padding-right: 16px; }
    .dnd-tools__help-inner { padding-left: 16px; padding-right: 16px; }

    .dnd-tools__roll-total { font-size: 28px; min-width: 38px; }
    .dnd-dice-toast {
        width: 240px;
        max-width: calc(100vw - 24px);
        padding: 14px 16px 0;
    }
    .dnd-dice-toast__result { font-size: 48px; }

    .dnd-tools__help-grid { grid-template-columns: 1fr; }
}/* ==========================================================================
 * RECENT ARTS CAROUSEL — [dnd_recent_arts]
 * ========================================================================== */
.dnd-recent-arts {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1.5rem;
    color: var(--text-main);
}

.dnd-recent-arts__header {
    margin: 0 0 1.25rem;
}

.dnd-recent-arts__title {
    margin: 0;
    font-family: var(--font-serif);
    font-size: 1.75rem;
    line-height: 1.2;
    font-weight: 600;
    color: var(--text-main);
}

.dnd-recent-arts__viewport {
    position: relative;
}

.dnd-recent-arts__track {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: calc((100% - 2rem) / 3);
    gap: 1rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 0.25rem;
}

.dnd-recent-arts__track::-webkit-scrollbar { display: none; }

.dnd-recent-arts__card {
    scroll-snap-align: start;
    background: var(--bg-block);
    border: 1px solid var(--bd-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-card);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.dnd-recent-arts__card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
    border-color: var(--accent-soft);
}

.dnd-recent-arts__link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.dnd-recent-arts__image-wrap {
    aspect-ratio: 4 / 5;
    overflow: hidden;
    background: var(--bg-sunken);
}

.dnd-recent-arts__image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.4s ease;
}

.dnd-recent-arts__card:hover .dnd-recent-arts__image {
    transform: scale(1.05);
}

.dnd-recent-arts__name {
    margin: 0;
    padding: 0.75rem 0.875rem 0.875rem;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-main);
    text-align: center;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Arrows */
.dnd-recent-arts__arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--bd-border);
    background: var(--bg-sidebar);
    color: var(--text-main);
    box-shadow: var(--shadow-card);
    cursor: pointer;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast), opacity var(--transition-fast);
}

.dnd-recent-arts__arrow:hover:not(:disabled) {
    color: var(--accent);
    border-color: var(--accent-soft);
    background: var(--bg-hover);
}

.dnd-recent-arts__arrow:disabled {
    opacity: 0.3;
    cursor: default;
}

.dnd-recent-arts__arrow--prev { left: -20px; }
.dnd-recent-arts__arrow--next { right: -20px; }

/* Tablet */
@media (max-width: 1023px) and (min-width: 769px) {
    .dnd-recent-arts__track {
        grid-auto-columns: calc((100% - 1rem) / 2);
    }
    .dnd-recent-arts__image-wrap {
        max-height: 320px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .dnd-recent-arts {
        padding: 0 1rem;
        margin: 1.5rem auto;
    }
    .dnd-recent-arts__track {
        grid-auto-columns: calc(100% - 1rem);
        gap: 0.75rem;
    }
    .dnd-recent-arts__arrow {
        width: 36px;
        height: 36px;
    }
    .dnd-recent-arts__arrow--prev { left: 0.5rem; }
    .dnd-recent-arts__arrow--next { right: 0.5rem; }
    .dnd-recent-arts__title { font-size: 1.35rem; }
}