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

/* Global hidden utility – used by StartScreen and overlays */
.hidden { display: none !important; }

:root {
    --bg-dark:    #1a1d23;
    --bg-medium:  #23272e;
    --bg-light:   #2d323b;
    --border:     #3d434e;
    --accent:     #4a9eff;
    --accent-hover:#6bb0ff;
    --success:    #4caf7c;
    --text-primary:#e8ecf0;
    --text-secondary:#8a92a0;
    --text-dim:   #555d6a;
    --sidebar-w:  196px;
    --topbar-h:   60px;
}

/* ── Global reset for tablet ── */
body {
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    /* Prevent pull-to-refresh and other browser gestures */
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
    /* Zentriert das skalierte #app */
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
}

#app {
    display: flex;
    flex-direction: column;
    /* Feste Maße werden per JS gesetzt; CSS-Transform skaliert das Ganze */
    flex-shrink: 0;
    overflow: hidden;
}

/* ── TOP BAR ── */
#topbar {
    height: var(--topbar-h);
    background: var(--bg-medium);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    flex-shrink: 0;
    z-index: 10;
}

#title {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--accent);
    white-space: nowrap;
    min-width: 130px;
}

#hint-area {
    flex: 1;
    text-align: center;
}

#hint-text {
    color: var(--text-secondary);
    font-size: 13px;
    font-style: italic;
}

#controls {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

/* Buttons – minimum 44×44 touch target */
.btn {
    min-height: 44px;
    padding: 0 22px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, opacity 0.12s;
    letter-spacing: 0.3px;
    /* Touch: remove tap highlight flash */
    -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
    opacity: 0.35;
    pointer-events: none;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { background: #2a7de0; }

.btn-secondary {
    background: var(--bg-light);
    color: var(--text-primary);
    border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-secondary:active:not(:disabled) { background: #4a505c; }

.btn-stop {
    background: #d93025;
    color: #fff;
    border-color: #d93025;
}
.btn-stop:hover:not(:disabled) { background: #b52a1f; }
.btn-stop:active:not(:disabled) { background: #9c2319; }

/* ── MAIN AREA ── */
#main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── SIDEBAR ── */
#sidebar {
    width: var(--sidebar-w);
    background: var(--bg-medium);
    border-right: 1px solid var(--border);
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    /* Smooth momentum scrolling on iOS */
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
    user-select: none;
    /* Hide scrollbar visually on tablets */
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
#sidebar::-webkit-scrollbar { width: 3px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-section {
    padding: 8px 6px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-light);
    transition: opacity 0.2s;
}

.sidebar-section.locked {
    opacity: 0.35;
    pointer-events: none;
}

.section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-dim);
    margin-bottom: 6px;
    padding: 0 2px;
}

/* Element items – 44px minimum height for comfortable tapping */
.element-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px 7px;
    min-height: 74px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.element-item:hover {
    background: rgba(74, 158, 255, 0.1);
    border-color: rgba(74, 158, 255, 0.3);
}

.element-item:active {
    background: rgba(74, 158, 255, 0.22);
    border-color: rgba(74, 158, 255, 0.5);
}

.element-icon {
    width: 48px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.element-item span {
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    word-break: break-word;
    hyphens: auto;
    line-height: 1.3;
}

/* ── CANVAS AREA ── */
#canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: default;
    /* Prevent browser handling of all touch gestures on the canvas */
    touch-action: none;
}

/* ── OVERLAY ── */
#overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(4px);
    z-index: 50;
}

/* #overlay.hidden covered by global .hidden rule */

#success-box {
    background: var(--bg-medium);
    border: 2px solid var(--success);
    border-radius: 20px;
    padding: 44px 64px;
    text-align: center;
    animation: popIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes popIn {
    from { transform: scale(0.6); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

#success-icon { font-size: 56px; margin-bottom: 14px; }

#success-text {
    font-size: 30px;
    font-weight: 700;
    color: var(--success);
    letter-spacing: 1px;
}

/* ── DRAG GHOST (unused div, kept for compatibility) ── */
#drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.75;
}
#drag-ghost.hidden { display: none; }

/* ═══════════════════════════════════════════════════════════════════════
   SCREENS  (full-viewport overlays used for menu and level select)
═══════════════════════════════════════════════════════════════════════ */

.screen {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-dark);
    transition: opacity 0.25s;
}

.screen.hidden {
    display: none;
}

/* ── App visibility ─────────────────────────────────────────────────── */
#app.hidden { display: none; }
#app.visible { display: flex; }

/* ═══════════════════════════════════════════════════════════════════════
   MAIN MENU
═══════════════════════════════════════════════════════════════════════ */

/* Animated background orbs */
.menu-bg {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.menu-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.18;
    animation: orbFloat 8s ease-in-out infinite;
}

.orb1 {
    width: 420px; height: 420px;
    background: #4a9eff;
    top: -120px; left: -80px;
    animation-delay: 0s;
}
.orb2 {
    width: 320px; height: 320px;
    background: #ffd700;
    bottom: -80px; right: -60px;
    animation-delay: -3s;
}
.orb3 {
    width: 260px; height: 260px;
    background: #4caf7c;
    top: 40%; left: 55%;
    animation-delay: -5s;
}

@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50%       { transform: translate(20px, -30px) scale(1.05); }
}

/* Menu content */
.menu-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 48px;
    width: 100%;
    max-width: 900px;
    padding: 0 24px;
}

.menu-logo {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#menu-ball-canvas {
    border-radius: 50%;
    filter: drop-shadow(0 0 18px rgba(74,158,255,0.5));
}

.menu-title {
    font-size: 52px;
    font-weight: 900;
    letter-spacing: 3px;
    color: var(--text-primary);
    text-shadow: 0 0 40px rgba(74,158,255,0.3);
    margin: 0;
}

.menu-tagline {
    font-size: 16px;
    color: var(--text-secondary);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 0;
}

/* Mode cards */
.mode-cards {
    display: flex;
    gap: 24px;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
}

.mode-card {
    position: relative;
    width: 230px;
    min-height: 220px;
    background: var(--bg-medium);
    border: 1.5px solid var(--border);
    border-radius: 20px;
    padding: 30px 20px 26px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.mode-card:not(.mode-card-soon):hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 8px 32px rgba(74,158,255,0.2);
}

.mode-card:not(.mode-card-soon):active {
    transform: translateY(-1px);
}

.mode-card-mission:hover {
    border-color: #ffd700 !important;
    box-shadow: 0 8px 32px rgba(255,215,0,0.2) !important;
}

.mode-card-glow {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 0%, rgba(74,158,255,0.08) 0%, transparent 70%);
    pointer-events: none;
}

.mode-card-mission .mode-card-glow {
    background: radial-gradient(circle at 50% 0%, rgba(255,215,0,0.1) 0%, transparent 70%);
}

.mode-card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    background: var(--bg-light);
    border-radius: 50%;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.mode-card-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.5px;
}

.mode-card-desc {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.5;
}

/* "Coming soon" card */
.mode-card-soon {
    opacity: 0.5;
    cursor: default;
    pointer-events: none;
}

.mode-soon-badge {
    position: absolute;
    top: 14px;
    right: 14px;
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ═══════════════════════════════════════════════════════════════════════
   LEVEL SELECT
═══════════════════════════════════════════════════════════════════════ */

#screen-level-select {
    justify-content: flex-start;
    overflow: hidden;
}

.ls-header {
    width: 100%;
    display: flex;
    align-items: center;
    padding: 16px 24px;
    gap: 16px;
    background: var(--bg-medium);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.ls-back-btn {
    min-width: 100px;
    flex-shrink: 0;
}

.ls-title {
    flex: 1;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.ls-mode-label {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 1px;
}

.ls-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.ls-header-spacer { min-width: 100px; }

.ls-reset-btn {
    min-width: 80px;
    font-size: 12px;
    padding: 0 12px;
    opacity: 0.65;
    flex-shrink: 0;
}
.ls-reset-btn:hover { opacity: 1; }

/* Level grid */
.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
    padding: 24px;
    overflow-y: auto;
    width: 100%;
    flex: 1;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    align-content: start;
}

.level-card {
    position: relative;
    background: var(--bg-medium);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 18px 12px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    min-height: 130px;
}

.level-card:hover {
    transform: translateY(-3px);
    border-color: var(--accent);
    box-shadow: 0 6px 20px rgba(74,158,255,0.18);
}

.level-card.locked {
    opacity: 0.38;
    cursor: default;
    pointer-events: none;
}

.level-card.solved {
    border-color: var(--success);
    background: rgba(76,175,124,0.06);
}

.level-card.solved:hover {
    border-color: var(--success);
    box-shadow: 0 6px 20px rgba(76,175,124,0.18);
}

.lc-id {
    font-size: 26px;
    font-weight: 900;
    color: var(--accent);
    line-height: 1;
}

.level-card.solved .lc-id { color: var(--success); }

.lc-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    line-height: 1.3;
}

.lc-stars {
    font-size: 12px;
    color: #ffd700;
    letter-spacing: 1px;
}

.lc-diff {
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.lc-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 14px;
}

.solved-badge { color: var(--success); }

.lc-lock {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 13px;
    opacity: 0.6;
}

/* ── In-card progress bar (shown while validating) ── */
.lc-progress-track {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 3px;
    background: var(--border);
    border-radius: 0 0 14px 14px;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.2s;
}
.lc-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.25s ease;
}

/* ── Spinner icon (shown during validation) ── */
.lc-spinner {
    display: none;
    width: 20px; height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    position: absolute;
    bottom: 10px; right: 10px;
}

/* ── Validating state ── */
.level-card.validating .lc-progress-track { opacity: 1; }
.level-card.validating .lc-spinner        { display: block; }
.level-card.validating .lc-id            { opacity: 0.5; }

/* ── Invalid state (brief flash) ── */
.level-card.invalid {
    border-color: #e53935;
    animation: invalidFlash 0.4s ease 3;
}
@keyframes invalidFlash {
    0%, 100% { background: var(--bg-medium); }
    50%       { background: rgba(229,57,53,0.15); }
}

/* ── Generation overlay ─────────────────────────────────────────────── */

.gen-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    background: rgba(26,29,35,0.96);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(6px);
}

.gen-overlay.hidden { display: none; }

.gen-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    max-width: 380px;
    padding: 0 24px;
    text-align: center;
}

.gen-spinner {
    width: 52px;
    height: 52px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

.gen-headline {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.5px;
}

.gen-text {
    font-size: 14px;
    color: var(--text-secondary);
    min-height: 22px;
}

.gen-bar-track {
    width: 280px;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.gen-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), #6bb0ff);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.gen-hint {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.5;
}

/* ═══════════════════════════════════════════════════════════════════════
   MISSION SIDEBAR  (replaces free-mode sidebar when a level is active)
═══════════════════════════════════════════════════════════════════════ */

.mission-level-header {
    padding: 8px 4px 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.mission-back-btn {
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    padding: 6px 10px;
    cursor: pointer;
    margin-bottom: 4px;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.1s, color 0.1s;
}

.mission-back-btn:hover   { background: var(--border); color: var(--text-primary); }
.mission-back-btn:active  { background: #4a505c; }

.mission-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
}

.mission-stars {
    font-size: 14px;
    letter-spacing: 1px;
}

.star-on  { color: #ffd700; }
.star-off { color: var(--text-dim); }

.mission-difficulty {
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.mission-constraints {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 2px;
}

.constraint-badge {
    font-size: 10px;
    background: rgba(255,160,30,0.15);
    border: 1px solid rgba(255,160,30,0.3);
    border-radius: 4px;
    padding: 2px 6px;
    color: #ffb030;
}

.mission-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.mission-tools-header {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-dim);
    padding: 0 2px;
    margin-bottom: 4px;
}

.mission-tools {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mission-tool-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 6px;
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 9px;
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.mission-tool-row:hover   { background: rgba(74,158,255,0.1); border-color: rgba(74,158,255,0.3); }
.mission-tool-row:active  { background: rgba(74,158,255,0.2); }

.mission-tool-row.depleted {
    opacity: 0.32;
    pointer-events: none;
}

.mission-tool-icon {
    width: 44px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mission-tool-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.mission-tool-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mission-tool-count {
    font-size: 10px;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════════════════════════
   REBUILD DIFFICULTY SELECT
═══════════════════════════════════════════════════════════════════════ */

.rd-content {
    position: relative; z-index: 1;
    display: flex; flex-direction: column;
    align-items: center; gap: 32px;
}

.rd-title {
    font-size: 40px; font-weight: 900; letter-spacing: 2px;
    color: var(--text-primary);
    text-shadow: 0 0 40px rgba(76,175,124,0.3);
}

.rd-subtitle {
    font-size: 15px; color: var(--text-secondary);
    margin-top: -20px; letter-spacing: 0.5px;
}

.rd-cards {
    display: flex; gap: 20px; flex-wrap: wrap; justify-content: center;
}

.rd-card {
    width: 145px; height: 120px;
    background: var(--bg-medium); border: 2px solid var(--border);
    border-radius: 20px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent; user-select: none;
}

.rd-card:hover  { transform: translateY(-6px); }
.rd-card:active { transform: translateY(-2px); }
.rd-card[data-diff="leicht"]:hover { border-color:#4caf7c; box-shadow:0 8px 32px rgba(76,175,124,0.22); }
.rd-card[data-diff="mittel"]:hover { border-color:#ff9f4a; box-shadow:0 8px 32px rgba(255,159,74,0.22); }
.rd-card[data-diff="schwer"]:hover { border-color:#e53935; box-shadow:0 8px 32px rgba(229,57,53,0.22); }

.rd-level { font-size: 24px; font-weight: 900; line-height: 1; }
.rd-count { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.rd-tol   { font-size: 11px; color: var(--text-secondary); }
.rd-hint  { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.8px; }

/* Rebuild sidebar hint */
.rebuild-hint {
    padding: 8px 8px; font-size: 11px; color: var(--text-secondary);
    line-height: 1.45;
}

/* Rebuild result buttons */
.rebuild-result-btns {
    display: flex; flex-direction: column; gap: 10px; margin-top: 18px;
    align-items: center;
}

.rebuild-res-btn { min-width: 220px; }

/* ═══════════════════════════════════════════════════════════════════════
   PLAYER COUNT SELECT
═══════════════════════════════════════════════════════════════════════ */

.pc-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 32px;
}

.pc-title {
    font-size: 40px;
    font-weight: 900;
    letter-spacing: 2px;
    color: var(--text-primary);
    text-shadow: 0 0 40px rgba(74,158,255,0.3);
}

.pc-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    margin-top: -20px;
    letter-spacing: 0.5px;
}

.pc-cards {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.pc-card {
    width: 130px;
    height: 155px;
    background: var(--bg-medium);
    border: 2px solid var(--border);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.pc-card:hover  { transform: translateY(-6px); }
.pc-card:active { transform: translateY(-2px); }

.pc-card[data-count="1"]:hover { border-color: #4a9eff; box-shadow: 0 8px 32px rgba(74,158,255,0.22); }
.pc-card[data-count="2"]:hover { border-color: #4caf7c; box-shadow: 0 8px 32px rgba(76,175,124,0.22); }
.pc-card[data-count="3"]:hover { border-color: #ff9f4a; box-shadow: 0 8px 32px rgba(255,159,74,0.22); }
.pc-card[data-count="4"]:hover { border-color: #9a5abb; box-shadow: 0 8px 32px rgba(154,90,187,0.22); }

.pc-num {
    font-size: 62px;
    font-weight: 900;
    line-height: 1;
}

.pc-card[data-count="1"] .pc-num { color: #4a9eff; }
.pc-card[data-count="2"] .pc-num { color: #4caf7c; }
.pc-card[data-count="3"] .pc-num { color: #ff9f4a; }
.pc-card[data-count="4"] .pc-num { color: #9a5abb; }

.pc-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1.2px;
}

/* ═══════════════════════════════════════════════════════════════════════
   CO-OP SIDEBAR ADDITIONS
═══════════════════════════════════════════════════════════════════════ */

.coop-player-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 8px;
    border-radius: 10px;
    border: 2px solid;
    margin-bottom: 4px;
}

.coop-player-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
}

.coop-player-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.coop-player-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.coop-zone-name {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.coop-progress-row {
    display: flex;
    gap: 5px;
    align-items: center;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.coop-pip {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-dim);
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    flex-shrink: 0;
}

.coop-pip.done {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
    font-size: 12px;
}

.coop-pip.active {
    border-width: 2.5px;
    color: var(--accent);
    box-shadow: 0 0 6px rgba(74,158,255,0.4);
}

.coop-pip-label {
    font-size: 10px;
    color: var(--text-dim);
    font-weight: 600;
    flex-shrink: 0;
}

.coop-next-btn {
    display: block;
    width: 100%;
    padding: 10px 8px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 8px;
    text-align: center;
    transition: background 0.12s;
    -webkit-tap-highlight-color: transparent;
    letter-spacing: 0.2px;
}

.coop-next-btn:hover  { background: var(--accent-hover); }
.coop-next-btn:active { background: #2a7de0; }
.coop-next-btn.ready  { background: var(--success); }
.coop-next-btn.ready:hover { background: #5dc08a; }

.coop-all-ready {
    text-align: center;
    padding: 14px 6px 8px;
    color: var(--success);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.5;
}

.coop-all-ready span {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 400;
    margin-top: 4px;
}

.mission-hint {
    margin-top: 10px;
    padding: 8px 8px;
    background: rgba(74,158,255,0.07);
    border: 1px solid rgba(74,158,255,0.2);
    border-radius: 8px;
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.45;
}

/* ── Nachbauen: Übereinstimmungsanzeige ──────────────────────────────────── */
.rebuild-match-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 2px 3px;
}
.rebuild-match-label { font-size: 11px; color: var(--text-secondary); }
.rebuild-match-pct   { font-size: 13px; font-weight: 700; color: var(--text-primary); }

.rebuild-match-bar-track {
    height: 6px;
    background: var(--bg-light);
    border-radius: 4px;
    overflow: hidden;
}
.rebuild-match-bar {
    height: 100%;
    border-radius: 4px;
    transition: width 0.25s ease, background 0.4s ease;
    background: #e53935;
}

.rebuild-match-bar.match-reached {
    animation: matchPulse 1s ease-in-out infinite alternate;
    box-shadow: 0 0 8px rgba(76,175,124,0.7);
}

@keyframes matchPulse {
    from { opacity: 0.85; box-shadow: 0 0 6px rgba(76,175,124,0.5); }
    to   { opacity: 1;    box-shadow: 0 0 14px rgba(76,175,124,1); }
}


/* ── Nachbauen: Raster-Schieberegler ─────────────────────────────────────── */
.rebuild-grid-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 2px 4px;
}
.rebuild-grid-label { font-size: 11px; color: var(--text-secondary); flex-shrink: 0; }
.rebuild-grid-slider-wrap {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    flex: 1;
}
.rebuild-grid-slider-wrap input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    cursor: pointer;
}
.rb-grid-valtxt {
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
}

/* ═══════════════════════════════════════════════════════════════════════
   MOBILE / RESPONSIVE
═══════════════════════════════════════════════════════════════════════ */

/* Phones in portrait (≤ 540 px) – schmälere Sidebar, kompaktere Topbar */
@media (max-width: 540px) {
    :root { --sidebar-w: 100px; }

    #topbar { padding: 0 8px; gap: 5px; }
    #title { font-size: 13px; min-width: 52px; letter-spacing: 0; }
    #hint-area { display: none; }
    .btn { padding: 0 8px; font-size: 12px; min-height: 40px; letter-spacing: 0; }

    #sidebar { padding: 8px 5px; gap: 5px; }
    .sidebar-section { padding: 6px 4px; }
    .section-label { font-size: 9px; letter-spacing: 0.8px; margin-bottom: 4px; }
    .element-item { min-height: 52px; padding: 5px 1px 4px; gap: 3px; }
    .element-icon { width: 36px; height: 26px; }
    .element-item span { font-size: 8px; }

    .mission-tool-row { padding: 5px 4px; gap: 5px; }
    .mission-tool-icon { width: 34px; height: 26px; }
    .mission-tool-name { font-size: 10px; }
    .mission-tool-count { font-size: 9px; }
    .mission-back-btn { font-size: 11px; padding: 5px 7px; }

    /* Menu */
    .menu-title { font-size: 32px; letter-spacing: 1px; }
    .menu-tagline { font-size: 12px; letter-spacing: 1px; }
    .menu-content { gap: 24px; padding: 0 16px; }
    .mode-cards { gap: 12px; }
    .mode-card { width: 140px; min-height: 150px; padding: 20px 12px 16px; border-radius: 16px; }
    .mode-card-icon { width: 56px; height: 56px; }
    .mode-card-name { font-size: 16px; }
    .mode-card-desc { font-size: 10px; }

    /* Level-Select */
    .ls-header { padding: 10px 12px; gap: 8px; }
    .ls-mode-label { font-size: 16px; }
    .ls-subtitle { font-size: 10px; }
    .ls-back-btn, .ls-reset-btn { min-width: 64px; font-size: 11px; padding: 0 8px; }
    .level-grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; padding: 14px; }
    .level-card { min-height: 90px; padding: 12px 8px 10px; }
    .lc-id { font-size: 22px; }
    .lc-title { font-size: 9px; }
    .lc-stars { font-size: 10px; }

    /* Rebuild difficulty */
    .rd-title { font-size: 28px; }
    .rd-subtitle { font-size: 13px; margin-top: -14px; }
    .rd-cards { gap: 12px; }
    .rd-card { width: 115px; height: 95px; border-radius: 14px; }
    .rd-level { font-size: 19px; }

    /* Player count */
    .pc-title { font-size: 28px; }
    .pc-subtitle { font-size: 13px; margin-top: -14px; }
    .pc-cards { gap: 10px; }
    .pc-card { width: 105px; height: 120px; border-radius: 16px; }
    .pc-num { font-size: 46px; }
    .pc-label { font-size: 11px; }
}

/* Landscape phones / small tablets (541–767 px) – leicht schmalere Sidebar */
@media (min-width: 541px) and (max-width: 767px) {
    :root { --sidebar-w: 155px; }
    .mode-card { width: 185px; }
}
