.control_panel {
    position: fixed;
    top: 1rem;
    left: 1rem;
    right: auto;
    z-index: 20;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    width: min(30rem, calc(100vw - 2rem));
    padding: 1rem 1.1rem;
}

.brand_block {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    min-width: 0;
}

.brand_icon {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.85rem;
    flex: 0 0 auto;
}

.brand_copy {
    display: grid;
    gap: 0.22rem;
    min-width: 0;
}

.brand_title {
    font-size: 1.05rem;
    line-height: 1.2;
    font-weight: 700;
}

.status_text,
.repo_link,
.history_subtitle,
.modal_subtitle,
.helper_text,
#sethelp,
#labelhelp {
    color: var(--muted);
    line-height: 1.45;
}

.status_text,
.repo_link,
.history_subtitle,
.modal_subtitle,
.helper_text {
    font-size: 0.9rem;
}

.repo_link a {
    text-decoration: none;
}

.repo_link a:hover {
    text-decoration: underline;
}

.control_actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.control_btn {
    white-space: nowrap;
}

.overlay_ui {
    position: fixed;
    inset: 0;
    z-index: 10;
    pointer-events: none;
}

.overlay_panel {
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    padding: 7rem 1rem 5rem;
    pointer-events: none;
}

.panel_card {
    width: min(32rem, calc(100vw - 2rem));
    padding: 1.4rem;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.7);
    background: var(--surface-strong);
    box-shadow: var(--shadow);
    pointer-events: none;
}

.overlay_panel .panel_card button,
.overlay_panel .panel_card input,
.overlay_panel .panel_card label {
    pointer-events: auto;
}

.panel_kicker {
    margin-bottom: 0.75rem;
    font-size: 0.78rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.result_card {
    text-align: center;
}

.result_breakdown {
    font-size: clamp(1.45rem, 4vw, 2.4rem);
    font-weight: 700;
    line-height: 1.2;
    color: var(--text);
    word-break: break-word;
}

.result_total {
    margin-top: 0.85rem;
    font-size: clamp(2.2rem, 10vw, 4rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    color: var(--accent);
}

.bottom_field {
    display: grid;
    justify-items: center;
    gap: 1rem;
    margin-top: 1.2rem;
}

#labelhelp {
    font-size: 0.95rem;
}

.selector_card {
    display: grid;
    gap: 1rem;
}

.input_label {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text);
}

#set {
    width: 100%;
    min-height: 3.9rem;
    padding: 0.9rem 1.1rem;
    border: 1px solid rgba(32, 32, 32, 0.12);
    border-radius: var(--radius-md);
    font-size: clamp(1.25rem, 3vw, 1.8rem);
    text-align: center;
    color: var(--text);
    background: rgba(255, 255, 255, 0.85);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

#sethelp {
    font-size: 0.95rem;
}

.selector_actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
}

.helper_text {
    font-size: 0.85rem;
}

.dice_place {
    position: absolute;
    border: solid black 1px;
}

.roll_history_container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 20;
    width: min(22rem, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    padding: 1rem;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 0.9rem;
}

.roll_history_container.collapsed {
    max-height: none;
    gap: 0;
}

.roll_history_container.collapsed .history_subtitle,
.roll_history_container.collapsed #roll_history_empty,
.roll_history_container.collapsed .roll_history_content,
.roll_history_container.collapsed .history_actions {
    display: none;
}

.history_header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.history_header h2,
.modal_header h2 {
    font-size: 1.05rem;
}

.history_empty {
    padding: 0.9rem 1rem;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.58);
    color: var(--muted);
    text-align: center;
}

.roll_history_content {
    display: grid;
    gap: 0.7rem;
    overflow-y: auto;
    padding-right: 0.2rem;
}

.history_entry {
    display: grid;
    gap: 0.38rem;
    width: 100%;
    padding: 0.85rem 0.95rem;
    border: 1px solid rgba(32, 32, 32, 0.08);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.72);
    text-align: left;
}

.history_entry:hover {
    background: rgba(255, 255, 255, 0.95);
}

.history_formula {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.history_value {
    font-size: 0.98rem;
    line-height: 1.45;
    color: var(--text);
}

.history_time {
    font-size: 0.8rem;
    color: var(--muted);
}

.history_actions {
    display: flex;
}

.history_actions .secondary_btn {
    width: 100%;
}

.modal_backdrop {
    position: fixed;
    inset: 0;
    z-index: 29;
    background: rgba(15, 18, 24, 0.4);
    backdrop-filter: blur(4px);
}

.settings_modal {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 30;
    width: min(30rem, calc(100vw - 2rem));
    transform: translate(-50%, -50%);
    padding: 1.25rem;
    background: var(--surface-strong);
}

.modal_header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-top: 0.95rem;
}

.setting-item label {
    font-size: 0.95rem;
    font-weight: 600;
}

.setting-item input[type="color"] {
    width: 3rem;
    height: 3rem;
    padding: 0;
    border: none;
    background: transparent;
}

.setting-stack {
    display: grid;
    gap: 0.6rem;
    margin-top: 0;
}

.setting-stack select {
    width: 100%;
}

select {
    min-height: 2.85rem;
    padding: 0.75rem 0.9rem;
    border: 1px solid rgba(32, 32, 32, 0.12);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.9);
}

.theme_preview {
    margin: 1rem 0 0.4rem;
    padding: 1rem;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.62);
}

.preview_desk {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 8rem;
    border-radius: var(--radius-md);
    background: #dfdfdf;
    overflow: hidden;
}

.preview_desk::after {
    content: "";
    position: absolute;
    inset: auto 10% 12% 10%;
    height: 1rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.08);
    filter: blur(10px);
}

.preview_dice {
    position: relative;
    width: 4.2rem;
    height: 4.2rem;
    border-radius: 1rem;
    background: #202020;
    transform: rotate(12deg);
    box-shadow: 0 12px 18px rgba(0, 0, 0, 0.18);
}

.preview_label {
    position: absolute;
    font-size: 1.6rem;
    font-weight: 800;
    color: #aaaaaa;
}

@media (max-width: 900px) {
    .control_panel {
        width: calc(100vw - 2rem);
    }

    .roll_history_container {
        top: auto;
        bottom: 1rem;
        right: 1rem;
        max-height: min(20rem, 45vh);
    }

    .overlay_panel {
        padding-top: 8rem;
        padding-bottom: 12rem;
    }
}

@media (max-width: 640px) {
    .control_panel {
        flex-direction: column;
        gap: 0.9rem;
        padding: 0.95rem;
    }

    .control_actions {
        width: 100%;
    }

    .control_btn {
        width: 100%;
    }

    .panel_card,
    .settings_modal,
    .roll_history_container {
        width: calc(100vw - 1rem);
    }

    .overlay_panel {
        padding: 7.5rem 0.5rem 11rem;
    }

    .selector_actions {
        grid-template-columns: 1fr;
    }

    .roll_history_container {
        left: 0.5rem;
        right: 0.5rem;
        bottom: 0.5rem;
        padding: 0.9rem;
    }

    .settings_modal {
        top: auto;
        bottom: 0.5rem;
        left: 50%;
        transform: translateX(-50%);
        max-height: calc(100vh - 1rem);
        overflow-y: auto;
    }

    .setting-item {
        align-items: center;
    }
}
