/* System font fallback for full GDPR compliance without external Google requests */

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    
    --success: #16a34a;
    --success-hover: #15803d;
    --success-light: #ecfdf5;

    --warning: #d97706;
    --warning-light: #fef3c7;

    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-light: #fef2f2;

    --purple: #7c3aed;
    --purple-light: #f5f3ff;
    --purple-border: #ddd6fe;

    --bg-main: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;

    /* Theme-Vorgaben */
    --board-bg: #e2e8f0;
    --board-border: #cbd5e1;
    --cell-bg: #ffffff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Outfit', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    -webkit-user-select: none;
    user-select: none;
}

button {
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Haupt-Container */
.app-container {
    max-width: 980px;
    margin: 0 auto;
    padding: 14px;
    width: 100%;
    flex: 1;
}

/* Header & Top Bar */
.top-nav {
    background: #ffffff;
    padding: 10px 18px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 10px;
}

.brand-section {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    font-size: 1.6rem;
    line-height: 1;
}

.brand-title {
    font-size: 1.25rem;
    font-weight: 900;
    color: #0f172a;
    letter-spacing: -0.5px;
    line-height: 1.1;
}

.brand-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.score-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #fffbeb;
    border: 1.5px solid #fde68a;
    color: #b45309;
    padding: 5px 12px;
    border-radius: 999px;
    font-weight: 800;
    font-size: 0.88rem;
    white-space: nowrap;
}

.theme-select {
    padding: 6px 12px;
    border-radius: 10px;
    border: 1.5px solid var(--border-color);
    background: #ffffff;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.86rem;
    color: var(--text-main);
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.theme-select:focus {
    border-color: var(--primary);
}

/* 4 Stufen-Tabs */
.tier-bar {
    display: flex;
    background: #e2e8f0;
    padding: 4px;
    border-radius: 14px;
    gap: 4px;
    margin-bottom: 12px;
    overflow-x: auto;
}

.tier-tab-btn {
    flex: 1;
    min-width: 125px;
    padding: 8px 10px;
    border: none;
    background: transparent;
    border-radius: 10px;
    font-family: inherit;
    font-weight: 800;
    font-size: 0.88rem;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.tier-tab-btn.active {
    background: #ffffff;
    color: var(--primary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.tier-tab-btn[data-tier="1"].active { color: var(--success); }
.tier-tab-btn[data-tier="2"].active { color: var(--warning); }
.tier-tab-btn[data-tier="3"].active { color: #ea580c; }
.tier-tab-btn[data-tier="4"].active { color: var(--purple); }

/* Mission Banner */
.mission-card {
    background: #ffffff;
    border-radius: 14px;
    padding: 9px 16px;
    border: 1px solid var(--border-color);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02);
    min-height: 48px;
    box-sizing: border-box;
}

.mission-text-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    overflow: hidden;
}

.mission-badge {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 900;
    font-size: 0.7rem;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 6px;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

#mission-description {
    font-weight: 700;
    color: #334155;
    font-size: 0.92rem;
    line-height: 1.3;
}

.btn-new-puzzle {
    background: var(--primary-light);
    border: 1.5px solid #bfdbfe;
    color: var(--primary);
    padding: 6px 13px;
    border-radius: 10px;
    font-family: inherit;
    font-weight: 800;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.btn-new-puzzle:hover {
    background: #dbeafe;
}

/* =========================================================
   ROBUSTE, GETRENNTE LAYOUT-STRUKTUR (3 VÖLLIG GETRENNTE KARTEN)
   ========================================================= */

.game-layout-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.top-game-row {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 14px;
    align-items: start;
    width: 100%;
}

@media (max-width: 820px) {
    .top-game-row {
        grid-template-columns: 1fr;
    }
}

.card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 14px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-color);
}

.card-header-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.card-header-title {
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

/* 1. KARTE: SPIELFELD (MAP) */
.board-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
}

.board-grid {
    display: grid;
    gap: 5px;
    padding: 8px;
    border-radius: 16px;
    border: 3px solid var(--board-border);
    background-color: var(--board-bg);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.05);
    width: 100%;
    max-width: 366px;
    aspect-ratio: 1 / 1;
    box-sizing: border-box;
}

.cell {
    border-radius: 9px;
    background: var(--cell-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--cell-font-size, 26px);
    user-select: none;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

/* Board Themes */
.theme-roboter { --board-bg: #e0f2fe; --board-border: #7dd3fc; --cell-bg: #f8fafc; }
.theme-wiese { --board-bg: #dcfce7; --board-border: #86efac; --cell-bg: #ffffff; }
.theme-weltraum { --board-bg: #ede9fe; --board-border: #c4b5fd; --cell-bg: #faf5ff; }
.theme-ritter { --board-bg: #fef3c7; --board-border: #fcd34d; --cell-bg: #fffbeb; }

.cell-start-origin {
    border: 2px dashed #94a3b8;
    background: rgba(148, 163, 184, 0.12) !important;
}

.cell-wall { background: #cbd5e1 !important; border-color: #94a3b8; }
.cell-water { background: #bae6fd !important; border-color: #7dd3fc; }
.theme-roboter .cell-water { background: #e2e8f0 !important; border-color: #94a3b8 !important; }
.theme-weltraum .cell-water { background: #1e1b4b !important; border-color: #4338ca !important; }
.cell-door.locked { background: #fee2e2 !important; border-color: #fca5a5; }
.cell-door.open { background: #dcfce7 !important; border-color: #86efac; }
.cell-player { z-index: 10; }

.player-avatar {
    display: inline-block;
    transition: transform 0.15s ease;
}

.player-avatar.facing-left { transform: scaleX(-1); }
.player-avatar.facing-up { transform: rotate(-90deg); }
.player-avatar.facing-down { transform: rotate(90deg); }

.pulse-anim { animation: pulse 1.6s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }

.star-float { animation: starFloat 2s infinite ease-in-out; }
@keyframes starFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

.shake-anim { animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes shake {
    10%, 90% { transform: translate3d(-2px, 0, 0); }
    20%, 80% { transform: translate3d(3px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-3px, 0, 0); }
    40%, 60% { transform: translate3d(3px, 0, 0); }
}

/* 2. KARTE: REINES STEUERPULT (FESTE KNOPF-GRÖSSE, 0% STRETCH) */
.controls-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
}

.control-group {
    background: #f8fafc;
    border-radius: 14px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
}

.controls-section-title {
    font-size: 0.74rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    text-align: center;
}

/* Feste 4er-Reihe mit exakt 58px Breite pro Knopf - STRETCHEN UNMÖGLICH */
.dpad-row {
    display: grid;
    grid-template-columns: repeat(4, 58px);
    gap: 8px;
    justify-content: center;
    width: 100%;
}

.btn-ctrl {
    width: 58px;
    height: 48px;
    border: 1.5px solid var(--border-color);
    border-radius: 11px;
    font-size: 21px;
    cursor: pointer;
    background: #ffffff;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: all 0.12s ease;
    font-family: inherit;
    font-weight: 800;
    flex-shrink: 0;
}

.btn-ctrl:hover {
    border-color: var(--primary);
    background: #ffffff;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.15);
    transform: translateY(-1px);
}

.btn-ctrl:active {
    transform: translateY(1px);
    background: var(--primary-light);
}

.btn-jump-ctrl {
    background: #ffffff;
    color: var(--purple);
    border-color: var(--purple-border);
    font-size: 0.92rem;
}

.btn-jump-ctrl:hover {
    background: var(--purple-light);
    border-color: var(--purple);
}

.highlight-jump {
    background: #f5f3ff;
    border-color: #ddd6fe;
}

/* Ausführungs-Leiste */
.execution-row {
    display: grid;
    grid-template-columns: 2fr 1.6fr 1fr;
    gap: 8px;
    max-width: 260px;
    width: 100%;
    margin: 2px auto 0 auto;
}

.btn-exec {
    height: 46px;
    border-radius: 11px;
    font-family: inherit;
    font-weight: 800;
    font-size: 0.92rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all 0.12s ease;
}

.btn-run {
    background: var(--success);
    color: #ffffff;
    border: none;
    box-shadow: 0 2px 6px rgba(22, 163, 74, 0.25);
}

.btn-run:hover:not(:disabled) {
    background: var(--success-hover);
    transform: translateY(-1px);
}

.btn-step {
    background: #ffffff;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}

.btn-step:hover:not(:disabled) {
    background: var(--primary-light);
    transform: translateY(-1px);
}

.btn-reset {
    background: #ffffff;
    color: var(--text-muted);
    border: 1.5px solid var(--border-color);
    font-size: 1.1rem;
}

.btn-reset:hover {
    background: #f1f5f9;
    color: var(--text-main);
}

.btn-exec:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* 3. KARTE: VÖLLIG SEPARATE, SCROLLBARE BEFEHLSKETTE (VOLLE BREITE) */
.queue-card {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.queue-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.step-counter-badge {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--primary);
    background: var(--primary-light);
    padding: 2px 8px;
    border-radius: 6px;
}

.btn-clear-queue {
    background: transparent;
    border: none;
    color: var(--danger);
    font-family: inherit;
    font-weight: 700;
    font-size: 0.82rem;
    cursor: pointer;
    padding: 3px 8px;
    border-radius: 6px;
    transition: background 0.15s;
}

.btn-clear-queue:hover {
    background: var(--danger-light);
}

.program-bar-scroll-wrapper {
    background: #f8fafc;
    border-radius: 12px;
    border: 2px dashed #cbd5e1;
    padding: 8px 10px;
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
}

.program-bar {
    height: 50px;
    max-height: 50px;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    align-items: center;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
    width: 100%;
    min-width: 0;
}

.program-bar::-webkit-scrollbar {
    height: 6px;
}
.program-bar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.empty-queue-hint {
    color: #94a3b8;
    font-size: 0.88rem;
    font-weight: 600;
    margin: auto;
    text-align: center;
    white-space: nowrap;
}

.cmd-chip {
    flex-shrink: 0;
    height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #ffffff;
    border: 1.5px solid #cbd5e1;
    border-radius: 9px;
    padding: 0 8px;
    cursor: pointer;
    user-select: none;
    box-sizing: border-box;
    transition: border-color 0.15s, background-color 0.15s;
}

.cmd-chip:hover {
    border-color: var(--danger);
    background: var(--danger-light);
}

.cmd-chip .step-badge {
    font-size: 0.68rem;
    color: var(--text-muted);
    background: #f1f5f9;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 800;
}

.cmd-chip .step-icon {
    font-size: 1.15rem;
    line-height: 1;
}

.cmd-chip .step-remove {
    font-size: 0.68rem;
    color: #94a3b8;
}

.cmd-chip:hover .step-remove {
    color: var(--danger);
}

.cmd-chip.cmd-chip-jump {
    border-color: var(--purple-border);
    background: var(--purple-light);
}

.cmd-chip.cmd-chip-jump .step-badge {
    background: #ede9fe;
    color: var(--purple);
}

.cmd-chip.active-step {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4);
}

.cmd-chip.error-step {
    border-color: var(--danger);
    background: var(--danger-light);
}

/* Toast Benachrichtigung */
.game-toast {
    position: fixed;
    top: 14px;
    left: 50%;
    transform: translateX(-50%) translateY(-60px);
    background: #1e293b;
    color: #ffffff;
    padding: 9px 18px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.9rem;
    box-shadow: 0 8px 20px rgba(0,0,0,0.18);
    z-index: 2000;
    opacity: 0;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    max-width: 90%;
    text-align: center;
}

.game-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-info { background: #1e293b; border: 1.5px solid #475569; }
.toast-success { background: #065f46; border: 1.5px solid var(--success); }
.toast-warning { background: #92400e; border: 1.5px solid var(--warning); }
.toast-error { background: #991b1b; border: 1.5px solid var(--danger); }

/* Win Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay.show { opacity: 1; pointer-events: auto; }

.modal-card {
    background: #ffffff;
    border-radius: 24px;
    padding: 26px;
    max-width: 360px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal-badge-icon { font-size: 52px; margin-bottom: 6px; }
.modal-title { font-size: 1.5rem; font-weight: 900; color: #0f172a; margin-bottom: 4px; }
.modal-subtitle { color: var(--text-muted); font-weight: 600; font-size: 0.92rem; margin-bottom: 16px; }

.modal-stats-box {
    display: flex;
    justify-content: center;
    gap: 18px;
    background: #f8fafc;
    padding: 10px;
    border-radius: 12px;
    margin-bottom: 18px;
    border: 1px solid var(--border-color);
}

.modal-stat-val { font-size: 1.2rem; font-weight: 900; color: var(--primary); }
.modal-stat-lbl { font-size: 0.7rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; }

.btn-modal-action {
    width: 100%;
    background: var(--success);
    color: #ffffff;
    border: none;
    border-radius: 12px;
    padding: 12px;
    font-family: inherit;
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-modal-action:hover { background: var(--success-hover); }

/* Konfetti */
#confetti-container {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    pointer-events: none;
    z-index: 3500;
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    top: -20px;
    width: 8px; height: 12px;
    border-radius: 2px;
    animation: confettiFall 2s linear forwards;
}

@keyframes confettiFall {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 14px 0 18px 0;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.app-footer a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 700;
}

.app-footer a:hover {
    color: var(--primary);
    text-decoration: underline;
}
