/* --- Settings Specific Layout --- */

/* --- Settings Modal Layout --- */
.settings-rounds-container {
    display: flex;
    min-width: 0;
    max-width: 100%;
    flex-direction: column;
    gap: 0.8rem;
    max-height: 100%;
    overflow-y: auto;
    padding-left: 1rem;
    padding-top: 0.5rem;
    padding-bottom: 80px;
    padding-right: 1rem;
    /* Space for scrollbar */
    /* Leave space for the floating HOST action button */
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-accent) rgba(255, 255, 255, 0.05);
}

/* Scrollbar for settings */
.settings-rounds-container::-webkit-scrollbar {
    width: 8px;
}

.settings-rounds-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
}

.settings-rounds-container::-webkit-scrollbar-thumb {
    background: var(--primary-accent);
    border-radius: 6px;
}

.settings-round-box {
    border-radius: 12px;
    padding: 1.2rem;
    position: relative;
    z-index: 1;
    /* Stacking context */
    /* Hardware acceleration to fix WebKit composite bugs */
    transform: translateZ(0);
    will-change: transform;
    isolation: isolate;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Isolate glass effect to completely fix WebKit background bleed on hover */
.settings-round-box::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid rgba(255, 255, 255, 0.06);
    /* Removed drop shadow; external shadows overlapping blurred layers trigger WebKit compositing bugs */
    border-radius: inherit;
    pointer-events: none;
}

.round-header {
    font-family: var(--font-head);
    font-size: 1.2rem;
    color: var(--primary-accent);
    margin-bottom: 0.2rem;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.accordion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    text-transform: uppercase;
}

/* Layout overrides previously set via HTML inline styles */
.settings-global-box-flex { display: flex; flex-direction: column; gap: 1rem; }
.settings-input-w100 { width: 100%; max-width: 100%; }
.settings-room-input { width: 100%; text-transform: uppercase; }
.settings-row-w100-sb { justify-content: space-between; width: 100%; }

.accordion-icon {
    width: 20px;
    height: 20px;
    stroke: var(--primary-accent);
    opacity: 0.7;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.accordion-header.header-open .accordion-icon {
    transform: rotate(180deg);
}

.accordion-content {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.accordion-content.open {
    grid-template-rows: 1fr;
}

.accordion-inner {
    overflow: hidden;
    padding-top: 0.5rem;
}

.round-header::after {
    content: '';
    flex-grow: 1;
    height: 1px;
    background: linear-gradient(90deg, var(--primary-accent) 0%, transparent 100%);
    opacity: 0.3;
}

.settings-global-box::before {
    border-color: rgba(255, 255, 255, 0.2);
}

.settings-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.settings-row-top {
    display: flex;
    align-items: center;
    /* Center items instead of flex-end */
    gap: 0.5rem;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.setting-group label {
    font-family: var(--font-tech);
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 1px;
}

.setting-group-inline {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex: 1;
    min-width: 0;
    /* Prevents flex items from pushing bounds */
}

.setting-group-inline label {
    font-family: var(--font-tech);
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 1px;
    white-space: nowrap;
    padding-left: 0.8rem;
}



/* Pill Checkboxes (Decades & Teams) */
.pill-checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.pill-checkbox {
    position: relative;
    cursor: pointer;
}

.pill-checkbox input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.pill-checkbox span {
    display: inline-block;
    padding: 0.5rem 1.2rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    font-family: var(--font-tech);
    font-weight: bold;
    color: rgba(255, 255, 255, 0.5);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
}

.pill-checkbox:hover span {
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.1);
}

.pill-checkbox.decade-pill span {
    padding: 0.2rem 0.6rem !important;
    font-size: 0.7rem !important;
    border-radius: 12px !important;
    background: rgba(10, 15, 20, 0.95) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5) !important;
    backdrop-filter: blur(5px) !important;
}

.pill-checkbox.decade-pill input:checked~span {
    background: rgba(35, 139, 78, 0.85) !important;
    border-color: #ffffff !important;
}

.pill-checkbox input:checked~span {
    background: rgba(255, 255, 255, 0.15);
    border-color: #ffffff;
    color: #ffffff;
}



/* --- Preset Modes Grid --- */
.preset-modes-grid {
    display: grid;
    min-width: 0;
    max-width: 100%;
    grid-template-columns: repeat(2, 1fr);
    column-gap: 0.75rem;
    row-gap: 0.75rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: start;
}

/* Custom preset spans full width only in multiplayer settings */
/* Custom preset spans full width only in multiplayer settings (where id is multiplayer-settings or body has multiplayer route) */
body:not([data-route="/solo"]) .preset-card[data-preset="custom"] {
    grid-column: 1 / -1;
}

.preset-card {
    box-sizing: border-box;
    width: 100%;
    height: 82px;
    min-height: 82px;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: 12px;
    padding: 0.8rem 1rem;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    gap: 1rem;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    overflow: visible;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.preset-card::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: inherit;
    transition: box-shadow 0.3s ease;
}

.preset-card:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.2);
}

.preset-card:active {
    transform: translateY(1px) scale(0.97);
    transition: transform 0.1s ease;
}

.preset-card.active {
    background: var(--primary-accent);
    border-color: var(--primary-accent);
    z-index: 10;
    transform: translateY(-2px);
}

.preset-card.active:active {
    transform: translateY(1px) scale(0.97);
}

.preset-card.active:not([data-preset="custom"]) {
    margin-bottom: 2.2rem;
}

.preset-card.active .preset-title,
.preset-card.active .preset-desc,
.preset-card.active .preset-desc span,
.preset-card.active .preset-icon {
    color: #ffffff !important;
}

.preset-icon {
    width: 36px;
    height: 36px;
    color: #ffffff;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.preset-card.active .preset-icon {
    color: var(--primary-accent);
    transform: scale(1.1);
}

.preset-icon svg {
    width: 100%;
    height: 100%;
}

.preset-text {
    display: flex;
    min-width: 0;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 0.2rem;
}

.preset-title {
    font-family: var(--font-head);
    font-size: 1rem;
    color: #fff;
    letter-spacing: 0.5px;
    margin-bottom: 0;
    line-height: 1;
}

.preset-card.active .preset-title {
    color: var(--primary-accent);
}

.preset-desc {
    display: flex;
    min-width: 0;
    align-items: baseline;
    flex-wrap: nowrap;
    gap: 0.15rem 0.5rem;
    overflow: hidden;
    font-family: var(--font-tech);
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    line-height: 1.25;
}

.preset-desc span {
    display: block;
    margin-left: 0;
    font-size: 0.75rem;
    opacity: 0.82;
    white-space: nowrap;
}

.preset-desc span:first-child {
    flex: 0 0 auto;
}

.preset-desc span:last-child {
    min-width: 0;
    overflow: hidden;
    flex: 1 1 auto;
    text-overflow: ellipsis;
}

/* On extra small screens... */
/* --- Modal Button Match --- */
.btn-modal-action-wrapper {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    z-index: 2010;
}

.btn-modal-action {
    background: rgba(35, 139, 78, 0.1);
    border: 1px solid var(--primary-accent);
    color: var(--primary-accent);
    box-shadow: 0 4px 15px rgba(35, 139, 78, 0.3);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-family: var(--font-head);
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    padding: 0.8rem 2rem;
    border-radius: 40px;
    white-space: nowrap;
    outline: none;
}

.btn-modal-action svg {
    width: 22px;
    height: 22px;
}

.btn-modal-action:hover,
.btn-modal-action:active {
    background: rgba(35, 139, 78, 0.2);
    box-shadow: 0 4px 25px rgba(35, 139, 78, 0.5);
    transform: translateY(-2px);
}

/* Mobile Core Overrides */
@media (max-width: 768px) {

    /* Match desktop overlay opacity & blur */
    .modal-overlay {
        background: rgba(0, 0, 0, 0.8);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    .modal-content {
        position: fixed;
        top: 80px;
        bottom: 65px;
        left: 0;
        right: 0;
        margin: 0;
        width: 100%;
        max-width: 100%;
        height: auto;
        padding: 0 1rem !important;
        border-radius: 0 !important;
    }

    .settings-rounds-container {
        gap: 0.5rem;
        padding: 1rem 0.5rem !important;
    }
    .preset-modes-grid {
        grid-template-columns: 1fr;
        column-gap: 0.6rem;
        row-gap: 0.6rem;
        align-items: start;
    }

    .preset-card[data-preset="custom"] {
        grid-column: 1;
    }

    .settings-round-box {
        padding: 1rem;
        border-radius: 8px;
    }

    .round-header-inline {
        font-size: 1rem;
    }

    .pill-checkbox span {
        padding: 0.5rem 0.8rem;
        font-size: 0.85rem;
    }

    .cyber-select.select-sm {
        padding: 0.4rem 0.4rem;
        font-size: 0.85rem;
        background-position: right 0.2rem top 50%;
        background-size: 0.4rem auto;
    }


    .setting-group-inline label {
        font-size: 0.75rem;
        padding-left: 0.3rem;
    }

    .btn-modal-action {
        padding: 0.7rem 1.6rem;
        font-size: 1rem;
    }

    .btn-modal-action svg {
        width: 20px;
        height: 20px;
    }
}

/* --- Settings Full View (Desktop layout matching Room style) --- */
@media (min-width: 1024px) {
    .settings-rounds-container {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding-top: 0;
        padding-bottom: 2rem;
    }

    .btn-modal-action-wrapper {
        border-radius: 24px;
        bottom: 1rem !important;
    }

    .page-header-row {
        width: 100%;
        max-width: 100%;
        margin: 0;
    }
}

/* --- Inline Style Replacements --- */
/* Root Settings View acts as its own container now */
.settings-view {
    max-width: 800px;
    /* Matches settings-header-wrapper max-width */
    width: 90vw;
    height: 80vh;
    max-height: 80vh;
    background: transparent;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    margin: 0 auto;
    padding-top: 0 !important;
    overflow: visible !important;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

@media (max-width: 768px) {
    .settings-view {
        position: fixed;
        top: max(15px, env(safe-area-inset-top));
        bottom: calc(112px + env(safe-area-inset-bottom));
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        margin: 0;
        padding: 0 0.5rem !important;
        box-sizing: border-box;
        border-radius: 0 !important;
        justify-content: flex-start !important;
    }

    .settings-rounds-container {
        width: 100%;
        /* The view already owns the mobile gutter. A second horizontal
           padding made the mode cards look optically shifted, especially
           once the scroll track consumed the right edge. */
        padding-inline: 0 !important;
        padding-bottom: 1.5rem !important;
        margin-inline: 0;
        box-sizing: border-box;
    }

    .preset-modes-grid {
        width: 100%;
        max-width: none;
        margin-inline: 0;
        box-sizing: border-box;
    }

    .preset-desc {
        color: rgba(255, 255, 255, 0.76);
        font-size: 0.78rem;
    }

    .preset-desc span {
        font-size: 0.75rem;
        opacity: 0.9;
    }
}

/* 320–359px remains a supported fallback for narrow browser windows and
   embedded webviews. Content may scroll vertically, never horizontally. */
@media (max-width: 359px) {
    .settings-view {
        padding-inline: 6px !important;
    }

    .settings-rounds-container {
        padding-inline: 6px !important;
    }

    .preset-card {
        width: 100%;
        max-width: 100%;
        min-height: 78px;
        height: auto;
        gap: 10px;
        padding: 10px 12px;
    }

    .preset-icon {
        width: 32px;
        height: 32px;
    }

    .preset-title {
        font-size: 0.9rem;
    }

    .preset-desc {
        flex-wrap: wrap;
        row-gap: 1px;
    }

    .preset-desc span {
        font-size: 0.68rem;
    }

    .preset-card.active:not([data-preset="custom"]) {
        margin-bottom: 1.8rem;
    }

    .action-bar-fixed {
        width: calc(100% - 16px);
        max-width: calc(100% - 16px);
    }
}

.settings-header-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding-bottom: 0.5rem;
    gap: 0.5rem;
    height: auto;
    flex: 0 0 auto;
    min-height: 0;
    padding-top: 0;
}

/* Make sure mobile uses full height and no padding */
.icon-back {
    fill: none !important;
}

.text-white {
    color: #ffffff;
}

.settings-group-right {
    align-items: flex-start;
    padding-left: 2rem;
    margin-left: auto;
}

.pl-0 {
    padding-left: 0 !important;
}

.m-0 {
    margin: 0 !important;
}

.p-0 {
    padding: 0 !important;
}

.toggle-wrapper {
    display: flex;
    align-items: center;
}

/* Force exact height matching for select arrays and toggles to align setting tabs */
.settings-round-box .cyber-select.select-sm,
.settings-round-box .toggle-wrapper {
    height: 34px !important;
    box-sizing: border-box;
}



.action-bar-fixed {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    display: flex;
    justify-content: center;
    align-items: stretch;
    z-index: 1000;
}

.action-btn-wide {
    padding: 1.2rem 2.0rem;
    border-radius: 50px;
    font-family: var(--font-head);
    font-size: 1.1rem;
    font-weight: 700;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease, box-shadow 0.3s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--primary-accent) !important;
    border: 2px solid transparent !important;
    color: #ffffff !important;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3), inset 0 -2px 0 rgba(0, 0, 0, 0.1) !important;
    cursor: pointer;
    margin: 0;
    text-transform: uppercase;
    font-style: italic;
    transform: translateZ(0);
    will-change: transform;
}

.action-btn-wide svg {
    width: 22px;
    height: 22px;
    transition: all 0.3s ease;
    stroke: #ffffff !important;
}

.action-btn-wide span {
    font-size: 1.1rem;
    letter-spacing: 2px;
    font-weight: bold;
}

.action-btn-wide:hover {
    background: var(--primary-accent) !important;
    transform: translateY(-2px) translateZ(0);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3), inset 0 -2px 0 rgba(0, 0, 0, 0.1) !important;
    color: #ffffff !important;
}

.action-btn-wide:active {
    transform: translateY(1px) translateZ(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), inset 0 -1px 0 rgba(0, 0, 0, 0.1) !important;
}

@media (max-width: 900px) {
    .action-bar-fixed {
        bottom: max(1rem, env(safe-area-inset-bottom));
        width: 95%;
        max-width: 95%;
    }

    .action-btn-wide {
        width: 100%;
        margin: 0;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
}

/* --- Solo Custom Layout Refactor --- */
.solo-energy-wrapper {
    max-width: 37.5rem; /* 600px */
    margin: 0.5rem auto 0;
}

.solo-settings-container {
    /* Rely on the parent .settings-view constraints for consistent width */
}

.solo-config-box {
    margin-top: 1.5rem;
}

.round-header-center {
    justify-content: center;
}

.solo-config-title {
    font-size: 1.2rem;
    letter-spacing: 2px;
}

.pt-1-5rem {
    padding-top: 1.5rem;
}

.solo-config-row {
    justify-content: flex-start;
    gap: 15px;
}

.setting-group-expanded {
    flex: 1;
}

.setting-group-small {
    width: 5rem; /* ~80px */
}

@media (max-width: 480px) {
    .setting-group-small {
        width: 4rem; /* 64px roughly instead of fixed 80px */
    }
}

/* Four controls cannot share a narrow phone row while keeping readable values
   and native select arrows. Reflow the custom editor, not the control text. */
@media (max-width: 560px) {
    .settings-view .accordion-inner > .settings-row-top {
        display: grid;
        grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
        align-items: end;
        gap: 12px 8px;
    }

    .settings-view .accordion-inner > .settings-row-top > .setting-group-inline {
        width: auto;
        min-width: 0;
    }

    .settings-view .solo-config-row > .setting-group-expanded {
        grid-column: 1 / -1;
    }

    .settings-view .accordion-inner > .settings-row-top > .setting-group-inline > label {
        white-space: normal;
        overflow-wrap: break-word;
    }
}

/* --- Energy Modal --- */
.energy-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.energy-modal-content {
    background: var(--glass-bg, rgba(10, 14, 20, 0.92));
    backdrop-filter: var(--glass-blur, blur(16px));
    -webkit-backdrop-filter: var(--glass-blur, blur(16px));
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 2rem 1.5rem;
    max-width: 360px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
}

.energy-modal-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.energy-modal-title {
    font-family: var(--font-head);
    font-size: 1.8rem;
    font-weight: 900;
    font-style: italic;
    color: #fff;
    margin: 0 0 0.5rem;
    letter-spacing: 2px;
}

.energy-modal-desc {
    font-family: var(--font-tech);
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.55);
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.energy-btn {
    display: block;
    width: 100%;
    padding: 0.85rem 1rem;
    border: none;
    border-radius: 10px;
    font-family: var(--font-head);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 0.6rem;
}

.energy-btn-ad {
    background: rgba(35, 139, 78, 0.2);
    border: 1px solid var(--primary-accent, #238B4E);
    color: var(--primary-accent, #238B4E);
}

.energy-btn-ad:hover {
    background: rgba(35, 139, 78, 0.35);
}

.energy-btn-vip {
    background: rgba(218, 165, 32, 0.15);
    border: 1px solid #DAA520;
    color: #DAA520;
}

.energy-btn-vip:hover {
    background: rgba(218, 165, 32, 0.3);
}

.energy-btn-close {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.5);
}

.energy-btn-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
}

.solo-energy-multiplayer {
    flex: 0 0 auto;
    text-align: center;
    text-decoration: none;
}
