/* Global Menu Background Layer */
#menu-background-layer {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 2000;
    pointer-events: none;
}

#menu-bg-gradient {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(circle at center, rgba(30, 45, 60, 0.85) 0%, rgba(5, 10, 15, 0.95) 100%);
    z-index: 1;
}

#menu-bg-cards {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    overflow: hidden;
    z-index: 2;
}

/* Main Menu Overlay - Transparent background now */
#main-menu,
#multiplayer-menu,
#lobby-waiting-room {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    /* backdrop-filter moved to content or handled by overlay */
    animation: menuFadeIn 0.6s ease-out;
    overflow: hidden;
    /* Background removed to allow layers to show through */
}

#menu-bg-cards .bg-card-wrapper {
    position: absolute;
    top: 0;
    pointer-events: none;
}

#menu-bg-cards .card {
    /* Removed position: absolute so it sits inside the wrapper */
    opacity: 1;
    pointer-events: none;
}

@keyframes menuFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Glass Card Container */
.menu-content {
    background: rgba(30, 41, 59, 0.6);
    padding: 25px;
    border-radius: 20px;
    box-shadow: 
        0 20px 50px rgba(0,0,0,0.5),
        0 0 0 1px rgba(255, 255, 255, 0.1) inset,
        0 0 30px rgba(0, 0, 0, 0.3) inset;
    width: 90%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: cardSlideUp 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
    position: relative;
    z-index: 10;
}

@keyframes cardSlideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Typography */
/* §2: Ueberschrift in der UI-Schrift, negatives Tracking, Trennlinie darunter —
   statt des goldenen Verlaufs. */
.menu-content h1 {
    margin: 0;
    text-align: center;
    font-family: var(--arc-font-ui);
    font-size: 40px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: -0.02em;
    color: var(--arc-text);
    padding-bottom: 10px;
    border-bottom: 1px solid var(--arc-line);
}

.menu-content h2 {
    color: var(--arc-text);
    text-align: center;
    margin: 0 0 10px 0;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.subtitle {
    text-align: center;
    color: #94a3b8;
    font-style: italic;
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.credit {
    text-align: center;
    color: #cbd5e1;
    font-size: 12px;
    margin-top: -5px;
    margin-bottom: 10px;
    font-weight: 500;
    opacity: 0.8;
}

/* Controls Group */
.menu-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--arc-field);
    padding: 12px 15px;
    border-radius: 12px;
    border: 1px solid var(--arc-line);
    transition: background 0.2s;
    flex-shrink: 0;
}

.menu-group:hover {
    background: var(--arc-line);
}

.menu-group label {
    font-size: 13px;
    font-weight: 700;
    color: #e2e8f0;
    display: flex;
    justify-content: space-between;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.menu-group label span {
    color: var(--arc-accent);
}

/* Custom Range Input */
input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
    margin: 6px 0;
}

input[type=range]:focus-visible {
    outline: 2px solid var(--arc-focus, #ffaa00);
    outline-offset: 2px;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

input[type=range]::-webkit-slider-thumb {
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: var(--arc-accent);
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -6px;
    border: 2px solid var(--arc-line-strong);
    transition: transform 0.1s;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Select Box */
select {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--arc-field);
    border: 1px solid var(--arc-line-strong);
    color: var(--arc-text);
    font-size: 15px;
    cursor: pointer;
    font-family: inherit;
}
select:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
}
select option {
    background: #2c3e50;
    color: white;
}

/* Buttons */
.menu-row {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping on small screens */
    gap: 12px;
    width: 100%;
    flex-shrink: 0;
}

.menu-row > button {
    flex: 1;
    min-width: 120px; /* Prevent squishing too small */
}

.menu-btn {
    width: 100%; /* Ensure full width */
    max-width: 100%;
    box-sizing: border-box;
    padding: 14px;
    font-size: 16px;
    font-weight: 800;
    border-radius: var(--arc-radius);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
    position: relative;
    overflow: hidden;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-top: 5px;
    flex-shrink: 0;
    /* NEW: center text/content in the button */
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: normal; /* Allow text wrapping */
    text-align: center;
    line-height: 1.2;

    /* §2: flach, duenne Linie, kein Verlauf und kein 3D-Sockel.
       Der einzige Akzent der Ansicht sitzt auf #start-game-btn. */
    background: var(--arc-field);
    color: var(--arc-text);
    border: 1px solid var(--arc-line-strong);
    box-shadow: none;
}

.menu-btn:hover {
    background: var(--arc-surface);
    border-color: var(--arc-accent);
}

/* §4: Druck-Feedback <=100ms, sichtbar ab pointerdown. */
.menu-btn:active {
    transform: scale(0.97);
    transition-duration: 0.09s;
}

.menu-btn.secondary {
    font-size: 13px;
    padding: 12px;
}

/* Start Game Button Special — der eine Akzent */
#start-game-btn {
    background: var(--arc-accent);
    color: var(--arc-accent-text);
    border-color: var(--arc-accent);
    font-size: 20px;
    padding: 18px;
    margin-top: 15px;
}

#start-game-btn:hover {
    background: var(--arc-accent);
    filter: brightness(1.08);
}

#roguelike-hud {
    background: rgba(0,0,0,0.6);
    padding: 8px 15px;
    border-radius: 20px;
    color: white;
    font-weight: bold;
    display: flex;
    gap: 15px;
    border: 1px solid rgba(255,255,255,0.2);
    align-items: center;
}

#rl-lives {
    font-size: 18px;
}

#rl-round {
    color: var(--color-yellow);
    text-transform: uppercase;
    font-size: 14px;
    letter-spacing: 1px;
}

/* Modals */
#guide-modal, #deck-config-modal, #rules-modal, #roguelike-draft-modal, #roguelike-deck-modal, #roguelike-view-deck-modal, #card-maker-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--arc-overlay);
    z-index: 4000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(8px);
    animation: menuFadeIn 0.3s;
}

.guide-content {
    background: var(--arc-surface);
    width: 95%;
    height: 90%;
    max-width: 900px;
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 30px 60px rgba(0,0,0,0.8);
    animation: cardSlideUp 0.4s;
}

.guide-header {
    padding: 15px 25px;
    background: rgba(0,0,0,0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.guide-header h2 {
    margin: 0;
    color: var(--arc-text);
    font-family: var(--arc-font-ui);
    font-size: 22px;
    text-transform: uppercase;
    letter-spacing: -0.02em;
}

#guide-close-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    width: 40px;
    height: 40px;
    font-size: 28px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    border-radius: 50%;
}

#guide-close-btn:hover { 
    background: rgba(255,255,255,0.1);
    color: white; 
    transform: rotate(90deg);
}

/* Guide Grid Items */
#config-grid {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px;
    align-content: start;
}

#guide-grid {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    align-content: start;
}

.guide-item {
    background: rgba(255,255,255,0.04);
    padding: 15px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    border: 1px solid transparent;
    transition: all 0.2s;
    cursor: pointer;
    text-align: center;
}

.guide-grid-item {
    background: rgba(255,255,255,0.04);
    padding: 15px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    border: 1px solid transparent;
    transition: all 0.2s;
    cursor: pointer;
    text-align: center;
}

.guide-grid-item:hover {
    background: rgba(255,255,255,0.15);
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    border-color: rgba(255,255,255,0.1);
}

.guide-grid-item .guide-name {
    color: #e2e8f0;
    font-size: 14px;
    font-weight: bold;
    line-height: 1.2;
}

.guide-item:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.05);
}

.guide-info h3 {
    margin: 0 0 4px 0;
    font-size: 17px;
    color: var(--arc-text);
}

.guide-info p {
    color: var(--arc-muted);
    font-size: 13px;
    line-height: 1.4;
    margin-bottom: 6px;
}

.guide-source {
    color: var(--arc-muted);
    font-size: 10px;
    text-transform: uppercase;
    font-weight: bold;
    opacity: 0.7;
    letter-spacing: 0.5px;
}

/* Config Subheader */
.config-subheader {
    padding: 15px 25px;
    background: rgba(0,0,0,0.2);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    color: #94a3b8;
}

.config-footer {
    padding: 15px;
    background: rgba(0,0,0,0.3);
    border-top: 1px solid rgba(255,255,255,0.05);
    display: flex;
    justify-content: center;
}

/* Config Items */
.config-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.config-item {
    background: rgba(255,255,255,0.03);
    padding: 12px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.05);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 15px;
}

.config-item:hover {
    background: rgba(255,255,255,0.07);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.config-item.selected {
    border-color: var(--arc-accent);
    background: var(--arc-field);
    box-shadow: 0 0 0 1px var(--arc-accent) inset;
}

.config-count-input {
    width: 50px;
    background: rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    padding: 6px;
    border-radius: 6px;
    text-align: center;
    font-weight: bold;
}
.config-count-input:focus {
    border-color: var(--arc-focus);
    outline: none;
}

.config-checkbox {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 2px solid #64748b;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    transition: all 0.2s;
    background: rgba(0,0,0,0.2);
}

.config-item.selected .config-checkbox {
    background: var(--arc-accent);
    border-color: var(--arc-accent);
    color: var(--arc-accent-text);
}

.config-info h3 {
    font-size: 16px;
    color: #e2e8f0;
}
.config-info p {
    font-size: 12px;
    color: var(--arc-muted);
}

/* Rule Checkboxes */
.checkbox-group {
    gap: 10px;
}

.checkbox-label {
    background: rgba(255,255,255,0.05);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid transparent;
}

.checkbox-label:hover {
    background: rgba(255,255,255,0.1);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--arc-accent);
}

/* Card Preview Adjustment */
.config-card-preview {
    width: 40px;
    height: 60px;
    position: relative;
    flex-shrink: 0;
}

/* Multiplayer specific */
.lobby-item {
    background: rgba(255,255,255,0.05);
    padding: 15px;
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid rgba(255,255,255,0.1);
    transition: all 0.2s;
}

.lobby-item:hover {
    background: rgba(255,255,255,0.1);
    transform: translateX(5px);
}

.lobby-info {
    display: flex;
    flex-direction: column;
}

.lobby-name {
    font-weight: bold;
    color: var(--arc-text);
}

.lobby-players {
    font-size: 12px;
    color: #aaa;
}

.lobby-join-btn {
    padding: 8px 16px;
    font-size: 13px;
    background: var(--arc-accent);
    border: none;
    border-radius: var(--arc-radius);
    color: var(--arc-accent-text);
    cursor: pointer;
    font-weight: bold;
}

.lobby-join-btn:active {
    transform: scale(0.97);
    transition: transform 0.09s ease;
}

.lobby-item-placeholder {
    text-align: center;
    padding: 20px;
    color: #666;
    font-style: italic;
}

.waiting-player {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: rgba(0,0,0,0.2);
    border-radius: 6px;
}

.waiting-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}

.config-card-preview .card {
    transform: scale(0.6);
    transform-origin: top left;
    position: absolute;
    top: 0;
    left: 0;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.3);
}

/* NEW: Layout for main menu view container to handle gaps properly */
#menu-main-view {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

@media (min-width: 768px) {
    .config-card-preview { width: 55px; height: 80px; }
}

@media (min-width: 1024px) {
    .config-card-preview { width: 75px; height: 110px; }
    .guide-item { padding: 15px; gap: 15px; }
    .guide-info h3 { font-size: 20px; margin-bottom: 5px; }
    .guide-info p { font-size: 14px; }
}

@media (max-width: 600px), (max-height: 700px) {
    .menu-content {
        padding: 20px;
        width: 95%;
        max-height: 95vh;
        overflow-y: auto;
    }
    
    .menu-content h1 {
        font-size: 28px;
        flex-shrink: 0;
    }

    .subtitle {
        display: none;
    }
}

/* Deck Config Layout Refactor */
.presets-container {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.preset-btn {
    margin: 0;
    padding: 8px 12px;
    font-size: 13px;
    flex: 0 1 auto;
    width: auto !important;
}

.w-auto {
    width: auto !important;
    min-width: 0;
    display: inline-flex;
    justify-content: center;
}

.config-control-group {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 10px;
    padding: 10px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
}

.config-label {
    font-weight: bold;
    color: #fff;
    min-width: 80px;
    white-space: nowrap;
}

.config-slider {
    cursor: pointer;
    flex: 1;
    max-width: 200px;
}

.config-preview-row {
    display: flex;
    gap: 4px;
    align-items: center;
}

.config-instruction {
    text-align: center;
    font-size: 14px;
    color: var(--arc-muted);
    margin-bottom: 10px;
}

/* Mobile Optimizations for Config Modal */
@media (max-width: 768px) {
    .guide-header h2 { font-size: 18px; }
    .guide-header { padding: 10px 15px; }
    
    .presets-container {
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 10px;
        margin-bottom: 10px;
        -webkit-overflow-scrolling: touch;
        /* Hide scrollbar visually but keep functionality */
        scrollbar-width: none;
    }
    .presets-container::-webkit-scrollbar { display: none; }
    
    .preset-btn {
        font-size: 11px;
        padding: 8px 10px;
        flex-shrink: 0;
    }

    .config-subheader {
        padding: 10px;
    }

    .config-control-group {
        padding: 5px 10px;
        gap: 10px;
        margin-bottom: 5px;
    }
    
    .config-label {
        font-size: 12px;
        min-width: 60px;
    }
    
    .config-instruction {
        font-size: 12px;
        margin-bottom: 5px;
    }

    /* Grid Items Compactness */
    #config-grid {
        padding: 10px;
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .config-item {
        padding: 8px;
        gap: 10px;
    }

    .config-card-preview {
        transform: scale(0.8);
        margin: -5px;
        width: 45px; /* Force visual spacing match */
    }

    .config-info h3 { font-size: 14px; }
    .config-info p { font-size: 11px; line-height: 1.2; }
}

/* Compact card layout specifically for the roguelike deck view modal */
#roguelike-view-deck-modal #view-deck-draw-grid,
#roguelike-view-deck-modal #view-deck-out-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

#roguelike-view-deck-modal .card {
    /* Reset any fan/overlap transforms from other areas */
    transform: none !important;
    margin: 0 !important;
}

#roguelike-view-deck-modal .card-inner {
    border-width: 2px;
}

#roguelike-view-deck-modal .card-symbol {
    font-size: calc(var(--card-width) * 0.6);
}

/* Card Maker Styles */
#card-maker-modal input:focus {
    outline: 2px solid var(--arc-focus);
    border-color: transparent;
}

#maker-preview-container .card {
    /* Ensure static position logic works in preview */
    position: relative !important;
    transform: none !important;
    margin: 0 !important;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5) !important;
}

#maker-preview-container {
    padding: 10px;
    background: rgba(255,255,255,0.05);
    border-radius: 12px;
}