/* ───────── Sidebar Container ───────── */
#sidebar {
    position: fixed;
    top: 0;
    left: -100vw;
    width: 50vw;
    height: 100%;
    background: var(--dark-1);
    color: var(--white);
    padding: var(--padding);
    box-shadow: var(--box-shadow);
    border-radius: var(--border-radius);
    transition: left 0.3s ease;
    z-index: 1000;
}

#sidebar.open {
    left: 0;
}

:root {
    --sidebar-shift: 50vw;
}

/* Button positions */
#toggle-top {
    top: 0;
}

#toggle-sidebar {
    top: 50px;
}

#toggle-spellbook {
    top: 100px;
}

#toggle-monsters {
    top: 150px;
}

#floating-search {
    top: 200px;
}

#toggle-sidebar,
#toggle-spellbook,
#toggle-monsters,
#toggle-top,
#floating-search {
    position: fixed;
    left: 0;
    width: 40px;
    height: 40px;
    background: var(--dark-2);
    color: var(--white);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    box-shadow: var(--box-shadow);
    z-index: 1001;
    transition: background .2s ease, transform .3s ease;
    font-size: 0;
    display: inline-block;
    text-decoration: none;
}

/* Use PNG icons instead of emoji for sidebar buttons */
#toggle-sidebar,
#toggle-spellbook,
#toggle-monsters,
#toggle-top {
    background-size: 100%;
    background-repeat: no-repeat;
    background-position: center;
}

/* Individual icons (adjust path if your CSS is in a /css folder) */
#toggle-sidebar {
    /* open/close sidebar – dice icon */
background-image: url('../assets/icons/dice.png');
}

#toggle-spellbook {
    /* spellbook tab */
    background-image: url('../assets/icons/spellbook.png');
}

#toggle-monsters {
    /* monsters / NPC generator link */
    background-image: url('../assets/icons/monster.png');
}

#toggle-top {
    /* scroll to top */
    background-image: url('../assets/icons/top.png');
}

#toggle-sidebar:hover,
#toggle-spellbook:hover,
#toggle-monsters:hover,
#toggle-top:hover {
    filter: invert(1);
}

/* Shift buttons when sidebar opens */
#sidebar.open #toggle-sidebar,
#sidebar.open #toggle-spellbook,
#sidebar.open #toggle-monsters,
#sidebar.open #toggle-top,
#sidebar.open #floating-search {
    transform: translateX(var(--sidebar-shift));
}

/* ───────── Floating Search ───────── */
#floating-search.collapsed input {
    display: none;
}

#floating-search.expanded {
    width: 250px;
}

#floating-search input,
#floating-search button {
    border-radius: var(--border-radius);
    background: var(--dark-1);
    color: var(--text-cream);
    border-color: var(--green-1);
}

#floating-search input {
    font-size: 1rem;
    padding: .3rem .5rem;
    width: 260px;
}

#floating-search button {
    background: var(--dark-3);
    font-size: 1.1rem;
    cursor: pointer;
    width: 100%;
}

/* ───────── Roller Switch Tabs ───────── */
.roller-switch {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.roller-switch input[type="radio"] {
    display: none;
}

.roller-switch label {
    flex: 1;
    padding: .5rem;
    background: var(--medium);
    color: var(--white);
    text-align: center;
    cursor: pointer;
    border-radius: var(--border-radius);
    transition: background .3s ease;
    width: 80%;
}

.roller-switch input[type="radio"]:checked+label {
    background: var(--theme);
    font-weight: bold;
}

.roller-switch label[for="check-mode"]+label[for="standard-mode"] {
    margin-left: -4px;
}

/* Roller visibility */
.roller-block {
    display: none;
}

.roller-block.active {
    display: block;
}


/* Make the visible block scroll to fit the screen */
.roller-content {
    max-height: calc(100vh - 220px);
    overflow: auto;
}

#condition-block {
    max-height: calc(100vh - 220px);
    overflow-y: auto;
    overflow-x: hidden;
}

@supports (height: 100dvh) {

    .roller-content,
    #condition-block {
        max-height: calc(100dvh - 220px);
    }
}

/* Keep table header visible while scrolling */
#condition-block table.condition thead th {
    position: sticky;
    top: 0;
    background: var(--dark-1);
    z-index: 1;
}

/* Prevent horizontal overflow on small screens */
#condition-block table.condition {
    table-layout: fixed;
    width: 100%;
}

#condition-block table.condition td,
#condition-block table.condition th {
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

/* ───────── D20 Roller ───────── */
#d20-check-roller {
    background: var(--dark);
    color: var(--white);
    padding: var(--padding);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    margin-bottom: 20px;
}

#d20-check-roller h3 {
    color: var(--theme);
}

#d20-check-roller-form {
    display: flex;
    flex-direction: column;
    gap: var(--padding);
}

#roll-d20-check {
    background: var(--theme);
    border: none;
    padding: 10px;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: box-shadow .3s ease;
}

#roll-d20-check:hover {
    background: var(--theme-hover);
    box-shadow: var(--box-hover);
}

/* ───────── Roll History ───────── */
.roll-history,
#check-history,
#roll-history {
    list-style: none;
    padding: var(--padding);
    overflow-y: hidden;
    background: var(--dark-3);
    border-radius: var(--border-radius);
}

#clear-history {
    background: var(--medium);
    color: var(--white);
    border: none;
    padding: var(--padding);
    margin-top: 10px;
    cursor: pointer;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    transition: background .3s, box-shadow .3s;
}

#clear-history:hover {
    background: var(--theme-hover);
    box-shadow: var(--box-hover);
}

/* Roll results */
.styled-roll {
    padding: var(--padding);
    margin-bottom: var(--padding);
    background: var(--dark);
    border-left: 4px solid var(--theme);
    border-radius: var(--border-radius);
}

.roll-label {
    color: var(--rust);
    font-weight: bold;
    margin-right: 4px;
}

.roll-val {
    font-weight: bold;
}

.roll-mod {
    color: var(--gold);
}

.roll-total {
    color: var(--white);
    font-size: 1.1rem;
}

.roll-chosen {
    color: var(--cream);
    font-weight: bold;
}

.roll-max,
.roll-min {
    font-weight: bold;
    font-size: 2rem;
    text-shadow: 0 0 6px;
}

.roll-max {
    color: var(--gold);
}

.roll-min {
    color: red;
}

.roll-success {
    background-color: var(--theme-dark);
    border-left-color: var(--gold);
}

.success-count {
    margin-left: 10px;
    color: var(--gold);
    font-weight: bold;
    font-size: .9rem;
}

/* Dividers */
.roll-line hr,
.total-line hr {
    border: none;
    border-top: 1px solid var(--medium);
    margin: 4px 0;
}

/* ───────── Dice & Mod Adjustments ───────── */
.dice-adjust,
.mod-adjust {
    display: flex;
    flex-direction: column;
    gap: .25rem;
}

.dice-input-group,
.mod-input-group {
    display: flex;
    align-items: center;
}

.dice-input-group input[type="number"],
.mod-input-group input[type="number"] {
    width: 50px;
    text-align: center;
    font-size: 1.2rem;
    padding: .25rem;
    margin: 0 .5rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--medium);
    background: var(--dark);
    color: var(--white);
}

.dice-button,
.mod-button {
    font-size: 1.5rem;
    padding: .25rem .75rem;
    background: var(--theme);
    color: var(--white);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background .3s;
}

.dice-button:hover,
.mod-button:hover {
    background: var(--theme-hover);
}

/* ───────── References ───────── */
.references,
#condition-block {
    overflow-y: auto;
    scroll-behavior: smooth;
    padding-right: 8px;
}

.references {
    max-height: 500px;
}

#condition-block {
    max-height: 1000px;
    padding: 1rem;
}

.references:hover,
#condition-block:hover {
    scrollbar-width: thin;
    filter: brightness(1.05);
}

.references::-webkit-scrollbar,
#condition-block::-webkit-scrollbar {
    width: 6px;
}

.references::-webkit-scrollbar-thumb,
#condition-block::-webkit-scrollbar-thumb {
    background-color: rgba(100, 100, 100, 0.5);
    border-radius: 4px;
}

/* ───────── Conditions & Lists ───────── */
.condition {
    font-size: .8rem;
}

table.condition {
    width: 100%;
    background-color: var(--dark-1);
}

table.condition td {
    padding: .6rem;
}

table.condition .category-row {
    background: var(--dark-1);
    font-weight: bold;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 5px;
    padding: .5rem;
}

.dragon-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    list-style: decimal inside;
    padding: 0;
    margin: 0;
}

.dragon-list li {
    flex: 1 1 30%;
    padding: 4px;
    font-size: .9rem;
    background: var(--dark-2);
    border-radius: var(--border-radius);
    box-sizing: border-box;
}

/* ───────── Compatibility ───────── */
.compatibility-group {
    margin-bottom: 1rem;
    padding: .5rem;
    background: var(--dark-2);
    border-left: 4px solid var(--theme);
    border-radius: var(--border-radius);
}

.compatibility-group h4 {
    margin: 0 0 .25rem 0;
    color: var(--gold);
    font-size: 1.1rem;
}

.compatibility-group ul {
    margin: 0;
    padding-left: 1.25rem;
    list-style: disc;
}

.compatibility-group p,
.compatibility-group li {
    font-size: .95rem;
    color: var(--text-cream);
}

/* ───────── Responsive ───────── */
@media (max-width: 700px) {
    :root {
        --sidebar-shift: 80vw;
    }

    #sidebar {
        width: 80vw;
    }

    #toggle-sidebar,
    #toggle-spellbook,
    #toggle-monsters,
    #toggle-top {
        border-radius: 0 6px 6px 0;
        line-height: 48px;
        padding: 0;
    }

    .dragon-list li {
        flex: 1 1 100%;
    }

    #roll-d20-check {
        margin: 5px;
        width: 97%;
    }
}