:root {
    --bg: #1a1a2e;
    --bg-light: #16213e;
    --primary: #e94560;
    --secondary: #0f3460;
    --text: #eee;
    --text-muted: #888;
    --border: #333;
    --success: #4ade80;
    --warning: #fbbf24;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

h1, h2, h3 {
    margin-bottom: 1rem;
}

h1 {
    font-size: 2.5rem;
    color: var(--primary);
}

/* Laden */
.laden {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    text-align: center;
}

.laden p {
    color: var(--text-muted);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Eingangshalle */
.eingangshalle {
    text-align: center;
    padding: 2rem;
}

.eingangshalle p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.aktionen {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    max-width: 800px;
    margin: 0 auto;
}

@media (max-width: 600px) {
    .aktionen {
        grid-template-columns: 1fr;
    }
}

.erstellen-form, .beitreten-form {
    background: var(--bg-light);
    padding: 2rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.erstellen-form h2, .beitreten-form h2 {
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
}

input, select, button {
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    margin-bottom: 1rem;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

button {
    background: var(--primary);
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.1s, opacity 0.2s;
}

button:hover {
    opacity: 0.9;
}

button:active {
    transform: scale(0.98);
}

/* Lobby */
.lobby {
    text-align: center;
    padding: 2rem;
}

.lobby code {
    background: var(--secondary);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 1.2rem;
    user-select: all;
}

.zeichner-liste {
    background: var(--bg-light);
    padding: 2rem;
    border-radius: 12px;
    max-width: 400px;
    margin: 2rem auto;
}

.zeichner-liste ul {
    list-style: none;
    text-align: left;
}

.zeichner-liste li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.zeichner-liste li:last-child {
    border-bottom: none;
}

.zeichner-liste li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.spieler-farbe {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

#btn-starten {
    max-width: 300px;
    margin: 0 auto;
}

.lobby-inhalt {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    max-width: 700px;
    margin: 2rem auto;
}

@media (max-width: 600px) {
    .lobby-inhalt {
        grid-template-columns: 1fr;
    }
}

.lobby-aktionen {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 2rem;
}

.lobby-aktionen button.sekundaer {
    background: var(--secondary);
    color: var(--text);
}

.lobby-aktionen button.sekundaer:hover {
    background: var(--bg-light);
}

.konfiguration-vorschau {
    background: var(--bg-light);
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
}

.config-name {
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--primary);
}

.config-groesse {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.canvas-vorschau {
    position: relative;
    background: #fff;
    border-radius: 4px;
    margin: 0 auto;
}

.slot-vorschau {
    position: absolute;
    border: 2px solid;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.1);
}

/* Zeichnen */
.zeichnen {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.zeichnen .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.zeichnen .header h2 {
    margin: 0;
}

#timer {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-muted);
}

#timer.aktiv {
    color: var(--warning);
}

#timer.warnung {
    color: var(--primary);
    animation: pulse-timer 0.5s infinite;
}

@keyframes pulse-timer {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
}

.canvas-container {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    flex: 1;
    min-height: 0;
    position: relative;
}

#zeichenflaeche {
    display: block;
}

#zonen-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

.werkzeuge {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    background: var(--bg-light);
    padding: 1rem;
    border-radius: 8px;
    flex-shrink: 0;
}

.werkzeug-gruppe {
    display: flex;
    gap: 0.5rem;
}

.werkzeug-gruppe button {
    width: auto;
    padding: 8px 16px;
    background: var(--secondary);
    margin: 0;
}

.werkzeug-gruppe button.aktiv {
    background: var(--primary);
}

.groesse-gruppe {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.groesse-gruppe input[type="range"] {
    width: 100px;
    margin: 0;
}

.farben-gruppe {
    display: flex;
    gap: 4px;
}

#farbpalette {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.farbe {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s, border-color 0.1s;
}

.farbe:hover {
    transform: scale(1.1);
}

.farbe.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--primary);
}

.historie-gruppe {
    display: flex;
    gap: 0.5rem;
}

.historie-gruppe button {
    width: auto;
    padding: 8px 12px;
    background: var(--secondary);
    margin: 0;
}

button.fertig {
    background: var(--success);
    color: #000;
    width: auto;
    padding: 8px 24px;
    margin: 0;
    margin-left: auto;
}

/* Wartend */
.wartend {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-top: 2rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Reveal */
.reveal {
    text-align: center;
    padding: 2rem;
}

.bild-container {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    display: inline-block;
    margin: 2rem 0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.naechste-runde {
    color: var(--text-muted);
}

/* Beendet */
.beendet {
    text-align: center;
    padding: 2rem;
}

.galerie {
    margin: 2rem 0;
}

/* Custom-Builder */
.galerie-builder {
    margin-bottom: 1rem;
}

.modus-auswahl {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.modus-btn {
    padding: 8px 16px;
    background: var(--secondary);
    border: none;
    border-radius: 20px;
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.modus-btn:hover {
    background: var(--primary);
}

.modus-btn:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.modus-btn.aktiv {
    background: var(--primary);
    font-weight: bold;
}

.ketten-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.ketten-nav .nav-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--secondary);
    border: none;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.ketten-nav .nav-btn:hover:not(:disabled) {
    background: var(--primary);
}

.ketten-nav .nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.slot-auswahl {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--bg-light);
    border-radius: 12px;
}

.slot-dropdown {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.slot-dropdown label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.slot-dropdown select {
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
    min-width: 120px;
}

.slot-dropdown select:focus {
    outline: none;
    border-color: var(--primary);
}

.galerie-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.galerie-nav .nav-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--secondary);
    border: none;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.galerie-nav .nav-btn:hover:not(:disabled) {
    background: var(--primary);
}

.galerie-nav .nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.galerie-info {
    color: var(--text-muted);
    font-size: 1rem;
}

#bilder-galerie {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.download-optionen {
    background: var(--bg-light);
    padding: 1.5rem;
    border-radius: 12px;
    max-width: 400px;
    margin: 2rem auto;
}

.download-optionen h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.format-auswahl {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1rem;
}

.download-btn {
    width: auto;
    padding: 10px 24px;
    background: var(--secondary);
    margin: 0;
    flex: 1;
    max-width: 120px;
}

.download-btn.aktiv {
    background: var(--primary);
}

.qualitaet-gruppe {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.qualitaet-gruppe label {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.qualitaet-gruppe input[type="range"] {
    width: 200px;
    margin: 0;
}

.beendet .aktionen {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 2rem;
}

.beendet .aktionen button {
    width: auto;
    padding: 12px 24px;
}

/* Fehler */
.fehler {
    text-align: center;
    padding: 2rem;
}

.fehler pre {
    background: var(--bg-light);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    text-align: left;
    margin-top: 1rem;
}

/* ============================================
   Mobile-Optimierungen
   ============================================ */

/* Touch-freundliche Mindestgröße */
@media (max-width: 768px) {
    #app {
        padding: 10px;
    }

    h1 {
        font-size: 2rem;
    }

    /* Größere Touch-Targets */
    button, input, select {
        min-height: 48px;
        font-size: 16px; /* Verhindert iOS Zoom bei Fokus */
    }

    /* Eingangshalle */
    .eingangshalle {
        padding: 1rem;
    }

    .eingangshalle p {
        margin-bottom: 1.5rem;
    }

    .erstellen-form, .beitreten-form {
        padding: 1.5rem;
    }

    /* Lobby */
    .lobby {
        padding: 1rem;
    }

    .lobby code {
        font-size: 1rem;
        display: block;
        padding: 0.75rem;
        margin-top: 0.5rem;
    }

    .zeichner-liste {
        padding: 1.5rem;
        max-width: 100%;
        margin: 1.5rem 0;
    }

    /* Konfiguration Vorschau */
    .konfiguration-vorschau {
        padding: 1.5rem;
    }

    /* Zeichnen */
    .zeichnen .header {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .werkzeuge {
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .werkzeug-gruppe {
        flex-wrap: wrap;
        justify-content: center;
    }

    .werkzeug-gruppe button {
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    .groesse-gruppe {
        width: 100%;
        justify-content: center;
    }

    .groesse-gruppe input[type="range"] {
        width: 120px;
    }

    .farben-gruppe {
        width: 100%;
        justify-content: center;
    }

    #farbpalette {
        justify-content: center;
    }

    .farbe {
        width: 28px;
        height: 28px;
    }

    .historie-gruppe {
        width: 100%;
        justify-content: center;
    }

    button.fertig {
        width: 100%;
        margin-left: 0;
        margin-top: 0.5rem;
    }

    /* Canvas Container - vollständige Breite auf Mobile */
    .canvas-container {
        margin: 0 -10px;
        border-radius: 0;
    }

    /* Reveal */
    .reveal {
        padding: 1rem;
    }

    .bild-container {
        max-width: 100%;
        margin: 1rem 0;
    }

    .bild-container img {
        max-width: 100%;
        height: auto;
    }

    /* Beendet */
    .beendet {
        padding: 1rem;
    }

    .download-optionen {
        max-width: 100%;
        padding: 1rem;
    }

    .beendet .aktionen {
        flex-direction: column;
    }

    .beendet .aktionen button {
        width: 100%;
    }

    /* Timer */
    #timer {
        font-size: 1.25rem;
    }
}

/* Noch kleinere Bildschirme */
@media (max-width: 400px) {
    h1 {
        font-size: 1.75rem;
    }

    .werkzeug-gruppe button {
        padding: 8px 10px;
        font-size: 0.85rem;
    }

    .farbe {
        width: 24px;
        height: 24px;
    }
}

/* Touch-spezifische Verbesserungen */
@media (hover: none) and (pointer: coarse) {
    /* Größere Klickziele für Touch */
    .farbe {
        width: 32px;
        height: 32px;
    }

    .werkzeug-gruppe button {
        padding: 12px 16px;
    }

    /* Kein Hover-Effekt auf Touch */
    button:hover {
        opacity: 1;
    }

    .farbe:hover {
        transform: none;
    }

    /* Aktive Zustände statt Hover */
    button:active {
        opacity: 0.8;
        transform: scale(0.95);
    }

    .farbe:active {
        transform: scale(1.1);
    }

    /* Canvas Touch-Optimierung */
    #zeichenflaeche {
        touch-action: none; /* Verhindert Scrollen während des Zeichnens */
    }
}

/* Landscape-Modus auf kleinen Bildschirmen (niedrige Höhe) */
@media screen and (max-height: 500px) {
    .zeichnen {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .zeichnen .header {
        width: 100%;
        padding: 0.5rem 0;
    }

    .canvas-container {
        max-height: calc(100vh - 120px);
        width: auto;
        flex-shrink: 0;
    }

    #zeichenflaeche {
        max-height: calc(100vh - 120px);
        width: auto;
        height: auto;
    }

    .werkzeuge {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem;
        max-height: calc(100vh - 120px);
        overflow-y: auto;
    }

    .werkzeug-gruppe {
        flex-direction: row;
        flex-wrap: wrap;
    }

    button.fertig {
        width: auto;
        padding: 0.8rem 2rem;
    }
}

/* =============================================================================
   Konfigurations-Editor
   ============================================================================= */

.editor {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    min-height: 100vh;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-header h1 {
    margin: 0;
}

.editor-inhalt {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 2rem;
    flex: 1;
}

.editor-werkzeuge {
    background: var(--bg-light);
    padding: 1.5rem;
    border-radius: 12px;
    height: fit-content;
}

.editor-werkzeuge h3 {
    font-size: 0.9rem;
    margin: 1.5rem 0 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.editor-werkzeuge h3:first-child {
    margin-top: 0;
}

.editor-werkzeuge select,
.editor-werkzeuge input[type="text"],
.editor-werkzeuge input[type="number"] {
    width: 100%;
    margin-bottom: 0.5rem;
}

.groessen-eingabe {
    display: flex;
    gap: 1rem;
}

.groessen-eingabe label {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.groessen-eingabe input {
    width: 100%;
}

#slot-liste {
    max-height: 200px;
    overflow-y: auto;
    margin-top: 0.5rem;
}

.slot-eintrag {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: 4px;
    background: var(--bg);
    margin-bottom: 0.25rem;
}

.slot-eintrag.selected {
    background: var(--secondary);
}

.slot-farbe {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    flex-shrink: 0;
}

.slot-eintrag .slot-name {
    flex: 1;
    padding: 0.25rem 0.5rem;
    font-size: 0.85rem;
}

.slot-loeschen {
    padding: 0.25rem 0.5rem;
    font-size: 1rem;
    line-height: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

.slot-loeschen:hover {
    color: #e74c3c;
}

.speichern-bereich {
    display: flex;
    gap: 0.5rem;
}

.speichern-bereich input {
    flex: 1;
}

.speichern-bereich button {
    flex-shrink: 0;
}

/* Editor Canvas Bereich */
.editor-canvas-bereich {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.editor-canvas {
    position: relative;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.editor-slot {
    position: absolute;
    border: 3px solid;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.4);
    cursor: move;
    user-select: none;
    box-sizing: border-box;
}

.editor-slot:hover {
    background: rgba(255, 255, 255, 0.6);
}

.editor-slot.selected {
    box-shadow: 0 0 0 3px var(--primary);
    z-index: 10;
}

.slot-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.75rem;
    font-weight: 600;
    color: #333;
    text-shadow: 0 0 3px #fff, 0 0 5px #fff;
    pointer-events: none;
    white-space: nowrap;
}

/* Resize Handles */
.resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--primary);
    border: 2px solid #fff;
    border-radius: 2px;
    z-index: 20;
}

.resize-handle.oben-links {
    top: -6px;
    left: -6px;
    cursor: nwse-resize;
}

.resize-handle.oben-rechts {
    top: -6px;
    right: -6px;
    cursor: nesw-resize;
}

.resize-handle.unten-links {
    bottom: -6px;
    left: -6px;
    cursor: nesw-resize;
}

.resize-handle.unten-rechts {
    bottom: -6px;
    right: -6px;
    cursor: nwse-resize;
}

.hinweis {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 1rem;
    text-align: center;
}

.editor-aktionen {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding-top: 1rem;
}

.editor-aktionen .primaer {
    padding: 1rem 3rem;
    font-size: 1.1rem;
}

/* Button-Varianten */
button.klein {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

button.sekundaer {
    background: var(--bg-light);
    color: var(--text);
}

button.sekundaer:hover {
    background: var(--secondary);
}

/* Editor Mobile */
@media (max-width: 768px) {
    .editor {
        padding: 1rem;
    }

    .editor-inhalt {
        grid-template-columns: 1fr;
    }

    .editor-canvas-bereich {
        order: -1;
    }

    .editor-werkzeuge {
        padding: 1rem;
    }

    .editor-aktionen .primaer {
        width: 100%;
    }
}

/* Toast Benachrichtigungen */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: var(--bg);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 500;
    z-index: 1000;
    animation: toast-slide-in 0.3s ease-out;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

@keyframes toast-slide-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(1rem);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}
