/* Barrierefreiheits-Unterstützung */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Grundlegende Resets und Variablen */
:root {
    --primary: #6a11cb;
    --primary-gradient: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    --primary-light: rgba(106, 17, 203, 0.15);
    --secondary: #2575fc;
    --background: #f8f9fa;
    --dark: #212529;
    --light: #f8f9fa;
    --success: #20c997;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #0dcaf0;
    --cell-size: min(calc((100vh - 120px) / 16), calc((100vw - 20px) / 16));
    --cell-size-mobile: min(calc((100vh - 120px) / 20), calc((100vw - 20px) / 20));
    --border-radius: 10px;
    --shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    --modal-background: rgba(0, 0, 0, 0.5);
    --transition-speed: 0.3s;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: manipulation;
    position: fixed; /* Verhindert Elastisches Scrollen auf iOS */
}

/* Textauswahl für alle Spielelemente deaktivieren */
body, .container, #game-board, .game-board-container, .cell, .game-info, 
.info-item, #game-message, .controls, .instructions {
    -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none;   /* Safari */
    -khtml-user-select: none;    /* Konqueror HTML */
    -moz-user-select: none;      /* Firefox */
    -ms-user-select: none;       /* Internet Explorer/Edge */
    user-select: none;           /* Non-prefixed version */
    touch-action: manipulation;  /* Verhindert Zoom bei Doppeltippen */
}

body {
    font-family: 'Montserrat', sans-serif;
    background-color: var(--background);
    color: var(--dark);
    display: flex;
    justify-content: center;
    align-items: center;
}

.container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    max-width: 100vw;
    max-height: 100vh;
    padding: 10px;
}

/* Header Styles */
.game-header {
    padding: 5px 0;
    margin-bottom: 5px;
}

.header-top {
    display: flex;
    justify-content: center; /* Center content instead of space-between */
    align-items: center;
    margin-bottom: 8px;
}

.game-header h1 {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    font-weight: 700;
    font-size: 1.5rem;
    margin: 0;
}

.controls-toggle button {
    background: rgba(255, 255, 255, 0.8);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
    color: var(--primary);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    transition: transform var(--transition-speed) ease, background-color var(--transition-speed) ease;
}

.controls-toggle button:hover {
    transform: rotate(30deg);
    background: white;
}

/* Dark theme update for the settings button */
@media (prefers-color-scheme: dark) {
    .controls-toggle button {
        background: rgba(30, 30, 30, 0.8);
    }
    
    .controls-toggle button:hover {
        background: #2d2d2d;
    }
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.info-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    font-size: 0.9rem;
}

.info-item i {
    color: var(--primary);
}

.action-btn-small {
    background: var(--primary-gradient);
    border: none;
    border-radius: var(--border-radius);
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
}

/* Controls Panel */
.controls {
    background: white;
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.controls.hidden {
    display: none;
}

.controls-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.controls-header h3 {
    color: var(--primary);
    margin: 0;
    font-size: 1.2rem;
}

.close-btn {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--dark);
    padding: 5px;
}

.difficulty-selector {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.difficulty-btn {
    background: transparent;
    border: 2px solid var(--primary);
    border-radius: 20px;
    padding: 10px;
    font-family: inherit;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.difficulty-btn:hover {
    background: rgba(106, 17, 203, 0.1);
}

.difficulty-btn.active {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(106, 17, 203, 0.2);
}

.custom-settings {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group label {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.input-group input {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    font-family: inherit;
    width: 100%;
    height: 40px;
}

.input-group input:disabled {
    background-color: #f0f0f0;
    color: #999;
    cursor: not-allowed;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.action-btn {
    background: var(--primary-gradient);
    border: none;
    border-radius: var(--border-radius);
    padding: 12px 15px;
    color: white;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: var(--shadow);
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.text-btn {
    background: transparent;
    border: none;
    color: var(--primary);
    font-family: inherit;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.text-btn:hover {
    text-decoration: underline;
}

/* Game Board Styles */
.game-board-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Verhindert Scrollen */
    padding: 5px;
    width: 100%;
}

#game-board {
    display: grid;
    gap: 2px;
    background: white;
    padding: 10px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin: 10px auto 0;
    max-width: 100%;
    max-height: 100%;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e9ecef;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease, transform 0.1s ease;
    position: relative;
    font-size: calc(var(--cell-size) / 2.5);
}

.cell:hover {
    background: #dee2e6;
    transform: scale(1.05);
    z-index: 1;
}

.cell.revealed {
    background: white;
    transform: none;
}

.cell.mine {
    background: var(--danger);
    color: white;
}

.cell.flag::before {
    content: "🚩";
    position: absolute;
}

.cell.question::before {
    content: "❓";
    position: absolute;
}

.cell.mine-exploded {
    background: var(--danger);
    animation: explode 0.5s ease;
}

@keyframes explode {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.cell[data-value="1"] { color: #0d6efd; }
.cell[data-value="2"] { color: #198754; }
.cell[data-value="3"] { color: #dc3545; }
.cell[data-value="4"] { color: #6f42c1; }
.cell[data-value="5"] { color: #fd7e14; }
.cell[data-value="6"] { color: #20c997; }
.cell[data-value="7"] { color: #000; }
.cell[data-value="8"] { color: #6c757d; }

/* Instructions Panel */
.instructions {
    background: white;
    padding: 15px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    width: 90%;
    max-width: 500px;
}

.instructions.hidden {
    display: none;
}

.instructions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.instructions-header h3 {
    margin: 0;
    color: var(--primary);
}

.instruction-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.instruction-item {
    display: flex;
    flex-direction: column;
    margin-bottom: 5px;
}

.instruction-label {
    font-weight: 600;
}

.instruction-desc {
    font-size: 0.9rem;
    color: #6c757d;
}

/* Game Message Styles */
.game-message {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-background);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.game-message.hidden {
    display: none;
}

.message-content {
    background: white;
    padding: 20px;
    border-radius: var(--border-radius);
    text-align: center;
    max-width: 90%;
    width: 300px;
}

.message-content h2 {
    margin-bottom: 20px;
}

/* Selected cell highlight */
.cell.selected {
    box-shadow: 0 0 0 2px var(--primary);
    z-index: 2;
}

/* Responsive Adaptations */
@media (max-width: 768px) {
    :root {
        --cell-size: var(--cell-size-mobile);
    }
    
    .game-header h1 {
        font-size: 1.2rem;
    }
    
    .info-item {
        padding: 4px 8px;
        font-size: 0.8rem;
    }
    
    .custom-settings {
        grid-template-columns: 1fr;
    }
    
    .difficulty-selector {
        flex-direction: column;
    }
    
    /* Verbesserte vertikale Abstände auf kleinen Bildschirmen */
    .game-header {
        padding: 3px 0;
        margin-bottom: 3px;
    }
    
    .header-top {
        margin-bottom: 4px;
    }
    
    .game-board-container {
        max-height: calc(100vh - 80px);
    }
}

/* Focus states for accessibility */
button:focus, input:focus {
    outline: none; /* Standard-Outline entfernen */
    box-shadow: 0 0 0 3px rgba(37, 117, 252, 0.3); /* Schatten statt Outline für besseres Aussehen */
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #121212;
        --dark: #e0e0e0;
        --primary: #8a42e3; /* Helleres Lila für Dark Mode */
        --primary-gradient: linear-gradient(135deg, #8a42e3 0%, #45a0ff 100%); /* Angepasster Gradient */
        --primary-light: rgba(138, 66, 227, 0.3); /* Helleres und sichtbareres Lila */
    }
    
    .controls, .instructions, .info-item, #game-board, .message-content {
        background: #1e1e1e;
        color: #e0e0e0;
    }
    
    .cell {
        background: #2d2d2d;
    }
    
    .cell.revealed {
        background: #3d3d3d;
    }
    
    .cell:hover {
        background: #3d3d3d;
    }
    
    .input-group input {
        background: #2d2d2d;
        border-color: #444;
        color: #e0e0e0;
    }
    
    .input-group input:disabled {
        background-color: #1e1e1e;
        color: #777;
        cursor: not-allowed;
    }

    .difficulty-btn.active {
        background: var(--primary-light);
        box-shadow: 0 2px 8px rgba(138, 66, 227, 0.4);
    }
}

/* Theme Toggle Styles */
.theme-toggle-container {
    margin: 15px 0;
}

.setting-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--dark);
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.theme-icon {
    color: var(--primary);
    font-size: 1.1rem;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 100%;
    transition: .4s;
}

input:checked + .slider {
    background: var(--primary-gradient);
}

input:focus + .slider {
    box-shadow: 0 0 1px var(--primary);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

.slider.round {
    border-radius: 24px;
}

slider.round:before {
    border-radius: 50%;
}

/* Dark theme specific styles for toggle */
@media (prefers-color-scheme: dark) {
    .setting-label {
        color: var(--light);
    }
    
    .slider {
        background-color: #555;
    }
    
    .slider:before {
        background-color: #ddd;
    }
}

/* Light/Dark Theme classes - These will override media queries */
html.light-theme {
    --background: #f8f9fa;
    --dark: #212529;
    --light: #f8f9fa;
    --primary-light: rgba(106, 17, 203, 0.15);
}

html.light-theme .controls, 
html.light-theme .instructions, 
html.light-theme .info-item, 
html.light-theme #game-board, 
html.light-theme .message-content {
    background: white;
    color: #212529;
}

html.light-theme .cell {
    background: #e9ecef;
}

html.light-theme .cell.revealed {
    background: white;
}

html.light-theme .cell:hover {
    background: #dee2e6;
}

html.light-theme .input-group input {
    background: white;
    border-color: #ddd;
    color: #212529;
}

html.light-theme .input-group input:disabled {
    background-color: #f0f0f0;
    color: #999;
}

html.light-theme .controls-toggle button {
    background: rgba(255, 255, 255, 0.8);
    color: var(--primary);
}

html.light-theme .controls-toggle button:hover {
    background: white;
}

html.dark-theme {
    --background: #121212;
    --dark: #e0e0e0;
    --light: #f8f9fa;
    --primary: #8a42e3; /* Helleres Lila für Dark Mode */
    --primary-gradient: linear-gradient(135deg, #8a42e3 0%, #45a0ff 100%); /* Angepasster Gradient */
    --primary-light: rgba(138, 66, 227, 0.3); /* Helleres und sichtbareres Lila */
}

html.dark-theme .controls, 
html.dark-theme .instructions, 
html.dark-theme .info-item, 
html.dark-theme #game-board, 
html.dark-theme .message-content {
    background: #1e1e1e;
    color: #e0e0e0;
}

html.dark-theme .cell {
    background: #2d2d2d;
}

html.dark-theme .cell.revealed {
    background: #3d3d3d;
}

html.dark-theme .cell:hover {
    background: #3d3d3d;
}

html.dark-theme .input-group input {
    background: #2d2d2d;
    border-color: #444;
    color: #e0e0e0;
}

html.dark-theme .input-group input:disabled {
    background-color: #1e1e1e;
    color: #777;
}

/* Creator Info Styles */
.creator-info {
    position: fixed;
    bottom: 10px;
    right: 10px;
    font-size: 0.8rem;
}

.creator-info a {
    color: var(--light);
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.creator-info a:hover {
    opacity: 1;
    text-decoration: underline;
}

/* Mobile Controls für Hochformat */
.mobile-controls {
    display: none;
    position: fixed;
    flex-direction: column;
    gap: 15px;
    z-index: 10;
    bottom: 15%;  /* Etwa bei 3/4 der Bildschirmhöhe von oben */
}

.mobile-controls.left {
    left: 15px;
}

.mobile-controls.right {
    right: 15px;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(255, 255, 255, 0.15);
    padding: 10px;
    border-radius: 16px;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.action-btn-mobile {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    outline: none;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.action-btn-mobile:active {
    transform: scale(0.95);
}

.action-btn-mobile.active {
    background: var(--primary-gradient);
    color: white;
    border: none;
}

/* Spezielles Styling für den Positions-Toggle-Button */
.toggle-position-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--background);
    border: 1px solid var(--primary);
    color: var(--primary);
    font-size: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-top: 10px;
}

.toggle-position-btn:active {
    transform: scale(0.95);
}