:root {
    --primary-color: #007bff;
    --primary-glow: rgba(0, 123, 255, 0.4);
    --bg-dark: #030406;
    --glass-bg: rgba(13, 17, 23, 0.3);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-color: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.5);
    --font-main: 'Outfit', sans-serif;
    --input-bg: rgba(255, 255, 255, 0.05);
    --input-border: rgba(255, 255, 255, 0.1);
    --danger: #ef5350;
    --danger-glow: rgba(239, 83, 80, 0.4);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    background-color: var(--bg-dark);
    /* Keep html dark */
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overscroll-behavior: none;
}

body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: transparent;
    /* Transparent to let pseudo elements show? Or just rely on stacking */
    color: var(--text-color);
    font-family: var(--font-main);
    overflow: hidden;
    position: relative;
    z-index: auto;
    /* Remove explicit z-index to avoid trapping pseudos if messed up */
    overscroll-behavior: none;
}

/* Dinamikus Háttér Overlay - Radial Glows Only */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -2;
    /* Behind image */
    background:
        radial-gradient(circle at 20% 30%, rgba(0, 123, 255, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(255, 107, 0, 0.1) 0%, transparent 40%);
    pointer-events: none;
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    /* Behind content, above glows */
    background-image: url('../img/bg.jpg');
    background-size: cover;
    background-position: center;
    filter: blur(1px) brightness(0.8) saturate(1.1);
    opacity: 0.85;
}

#app {
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 10;
}

/* Default Screen - Top aligned flow */
.screen {
    position: absolute;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 0;
}

.screen.active {
    display: flex;
}

/* Menu Screens: Center content, absolute header */
#screen-home,
#screen-organizer-menu,
#screen-password,
#screen-auth,
#screen-events {
    justify-content: flex-start;
    padding-top: 0;
}

/* Logo Styles */
.logo-container {
    margin-bottom: 20px;
    text-align: center;
    flex-shrink: 0;
}

/* Absolute Logo for Menus */
#screen-home .logo-container,
#screen-organizer-menu .logo-container,
#screen-password .logo-container {
    position: absolute;
    top: 40px;
    left: 0;
    width: 100%;
    margin: 0;
}

/* Glass Card Alaposztály */
.glass-card {
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0.55) 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: none;
    border-radius: 0;
    padding: 20px 30px 40px;
    box-shadow: none;
    width: 100%;
    max-width: 100% !important;
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 10;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
    padding-bottom: clamp(80px, 12vh, 110px) !important;
}

/* Home screen fixálás: ne legyen görgethető */
#screen-home .glass-card {
    height: 100dvh !important;
    min-height: 100dvh !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
    justify-content: flex-start !important;
    padding-top: 15px !important;
    padding-bottom: 0 !important;
}

/* Home screen button container: tighter gaps */
#screen-home #home-default-buttons {
    gap: clamp(8px, 1.5vh, 12px) !important;
}

/* Globális Vissza gomb fixálás minden glass-card-on belül */
.glass-card .btn-back {
    position: absolute !important;
    bottom: calc(clamp(15px, 3.5vh, 25px) + env(safe-area-inset-bottom, 15px)) !important;
    left: clamp(15px, 4vw, 25px) !important;
    right: clamp(15px, 4vw, 25px) !important;
    margin-top: 0 !important;
    width: auto !important;
    z-index: 100 !important;
}

/* Vizuális elválasztó a vissza gomb felett */
.glass-card .btn-back::before {
    content: '';
    display: block;
    position: absolute;
    top: -12px;
    left: 0;
    width: 100%;
    height: 1px;
    background: rgba(255, 82, 82, 0.15) !important;
}

/* Sötétebb háttér az időterv szerkesztőnek, hogy ne látszódjon át a vezérlő */
/* Eltávolítva a kényszerített fekete háttér, hogy látszódjon a kép és a blur */

#screen-timetable-editor .btn-back,
#screen-add-timetable .btn-back {
    background: rgba(211, 47, 47, 0.2) !important;
    border: 2px solid #ff5252 !important;
    color: #ff5252 !important;
    font-weight: 700 !important;
    box-shadow: 0 0 20px rgba(211, 47, 47, 0.2);
}

/* Időterv oldal tighter layout */
#screen-timetable-editor .glass-card {
    padding-top: 10px !important;
    gap: 0 !important;
}

#screen-timetable-editor .logo-section {
    min-height: 0 !important;
    padding: 0 !important;
    margin-bottom: 0 !important;
    margin-top: 0 !important;
}

#screen-timetable-editor .title {
    margin: 4px 0 4px 0 !important;
    padding: 0 !important;
    font-size: 22px !important;
}

#screen-timetable-editor .btn-primary {
    margin-top: 0 !important;
    margin-bottom: 8px !important;
}

#screen-timetable-editor #timetable-entries-list {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

.logo-section {
    text-align: center;
    margin-bottom: 0px;
    /* Reduced from 25px to move everything up */
    width: 100%;
    min-height: 80px;
    /* Reduced from 140px so logo is closer to content */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 0 0px;
}

.logo {
    height: 120px;
    width: auto;
    filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.4)) drop-shadow(0 0 40px rgba(255, 255, 255, 0.1));
    /* Layered shadow for a softer, more natural glow */
}

.logo-small {
    max-height: 100px !important;
}

.title {
    font-size: 26px;
    font-weight: 700;
    text-align: center;
    margin: 0 0 25px 0;
    color: #fff;
}

/* ... existing logic ... */

/* Button Styles */
.button-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 500px;
}

.button-container button {
    margin-top: 0;
}

/* Remove auto margins from home since we use flex center now */
/* Home screen buttons smaller padding */
#home-default-buttons button {
    padding: 12px 16px !important;
}

#screen-home .button-container {
    margin-top: 0;
    margin-bottom: 0;
}

button {
    font-family: inherit;
    font-size: 16px;
    font-weight: 600;
    padding: 16px;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    width: 100%;
    margin-top: 10px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 15px var(--primary-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-danger {
    background: var(--danger);
    color: white;
    box-shadow: 0 4px 15px var(--danger-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border: none;
}

.btn-danger:active {
    transform: scale(0.98);
    background: #d32f2f;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.12);
    /* Lightened from 0.08 */
    color: #ffffff;
    border: 1.5px solid rgba(255, 255, 255, 0.25) !important;
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.btn-secondary:active {
    background: rgba(255, 255, 255, 0.05);
}

.btn-white {
    background: #ffffff !important;
    color: #000000 !important;
    border: none !important;
    box-shadow: 0 4px 15px rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.btn-white:active {
    background: #e0e0e0 !important;
    transform: scale(0.98);
}

.btn-white svg,
.btn-primary svg,
.btn-secondary svg,
.btn-danger svg,
.btn-back svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.8;
}

.btn-back {
    border: 1.5px solid rgba(211, 47, 47, 0.4) !important;
    color: #ff5252;
    background: rgba(211, 47, 47, 0.1);
}

.btn-back:active {
    background: rgba(211, 47, 47, 0.2);
    transform: scale(0.98);
}

.btn-event {
    background: rgba(0, 150, 255, 0.2);
    border: 1px solid rgba(0, 150, 255, 0.4);
    color: #fff;
    padding: 18px;
    margin-bottom: 12px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 17px;
    width: 100%;
    text-align: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    text-shadow: 0 0 10px rgba(0, 150, 255, 0.5);
}

.btn-event:active {
    background: rgba(0, 150, 255, 0.4);
    transform: scale(0.96);
    box-shadow: 0 0 20px rgba(0, 150, 255, 0.4);
}

.btn-action {
    border: 1.5px solid rgba(251, 192, 45, 0.3) !important;
    color: #fbc02d;
    background: transparent;
}

.btn-warning {
    background: #ff6b00;
    color: white;
    box-shadow: 0 4px 15px rgba(255, 107, 0, 0.3);
}

.btn-warning:active {
    transform: scale(0.98);
    background: #e66000;
}

.btn-danger {
    background: #dc3545;
    color: white;
    box-shadow: 0 4px 15px rgba(220, 53, 69, 0.3);
}

.btn-danger:active {
    transform: scale(0.98);
}

.btn-success {
    background: #4caf50;
    color: white;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
}

.btn-success:active {
    transform: scale(0.98);
}

/* Footer */
.footer {
    position: absolute;
    bottom: 20px;
    width: 100%;
    padding: 0 20px;
    font-size: 12px;
    color: #555;
    font-family: monospace;
}

/* Password Input Screen Styles */
/* Input Styles */
/* Input stílusok */
.input-group {
    width: 100%;
    margin-bottom: 5px;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper .icon {
    position: absolute;
    left: 16px;
    color: var(--text-muted);
    pointer-events: none;
    display: flex;
    align-items: center;
}

.input-wrapper .icon svg {
    width: 20px;
    height: 20px;
}

input[type="text"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="file"],
textarea {
    width: 100%;
    resize: none;
    background: var(--input-bg);
    border: 1.5px solid var(--input-border);
    border-radius: 14px;
    padding: 16px 16px 16px 16px;
    color: white;
    font-size: 16px;
    font-family: inherit;
    transition: all 0.3s ease;
    outline: none;
    margin-bottom: 0px;
    /* Overriding old style */
}

input.has-icon {
    padding-left: 50px;
}

input:focus,
textarea:focus {
    border-color: var(--primary-color);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 4px rgba(0, 123, 255, 0.15);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

/* Auth Screens */
#screen-auth,
#screen-profile {
    justify-content: center;
    padding-top: 0;
    overflow: hidden;
}

#screen-register .glass-card {
    justify-content: flex-start;
    overflow: hidden !important;
}

/* Register form scrollable inner area */
#screen-register .auth-form,
#screen-register .login-form {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 20px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

/* Timetable editor inner content scrollable */
#screen-timetable-editor .glass-card>*:not(.btn-back):not(.logo-section):not(.editor-header),
#screen-add-timetable .glass-card>*:not(.btn-back):not(.logo-section):not(.editor-header) {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

#screen-auth .logo-container,
#screen-register .logo-container {
    position: absolute;
    top: 40px;
    left: 0;
    width: 100%;
    margin: 0;
    pointer-events: none;
}

#screen-auth .logo {
    max-height: 150px;
}

/* post-selector/post-selection: inner padding override only */
#screen-post-selector .glass-card,
#screen-post-selection .glass-card {
    padding-bottom: clamp(10px, 3vh, 30px) !important;
}

.login-form,
.auth-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.footer-links {
    margin-top: 25px;
    text-align: center;
    font-size: 20px;
    color: var(--text-muted);
}

.auth-link {
    color: var(--primary-color);
    text-align: center;
    margin-top: 15px;
    cursor: pointer;
    font-size: 17px;
    font-weight: 600;
}

/* Profile Image */
.profile-image-container {
    width: 90px;
    height: 90px;
    background: #222;
    margin: 0 auto 20px;
    border: 2px solid var(--accent-color);
    position: relative;
    cursor: pointer;
    border-radius: 50%;
}

.profile-image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.profile-image-container .overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 10px;
    text-align: center;
    padding: 5px 0;
    border-bottom-left-radius: 60px;
    border-bottom-right-radius: 60px;
}

.btn-delete-img {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 24px;
    height: 24px;
    background: #d32f2f;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 20;
    padding: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.btn-delete-img:active {
    background: #f44336;
    transform: scale(0.9);
}

/* Timer Warning Animation */
@keyframes pulse-red {
    0% {
        color: #fff;
        text-shadow: none;
    }

    50% {
        color: #ff0000;
        text-shadow: 0 0 10px #ff0000;
    }

    100% {
        color: #fff;
        text-shadow: none;
    }
}

.timer-warning {
    animation: pulse-red 1s infinite;
    font-weight: bold;
}

.ref-timer-pulse {
    animation: pulse-red 1s infinite;
    font-weight: bold;
}

@keyframes pulse-blue-glow {
    0% {
        box-shadow: 0 0 15px var(--primary-glow);
    }

    50% {
        box-shadow: 0 0 50px rgba(0, 123, 255, 0.85);
    }

    100% {
        box-shadow: 0 0 15px var(--primary-glow);
    }
}

@keyframes pulse-green-glow {
    0% {
        box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
    }

    50% {
        box-shadow: 0 0 25px rgba(76, 175, 80, 0.7);
    }

    100% {
        box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
    }
}

/* Racer List Styles */
.racer-row {
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.15);
    /* Even lighter background */
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    /* Stronger border */
    border-radius: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    transition: all 0.3s ease;
    backdrop-filter: blur(12px);
}

.racer-row:active {
    background: rgba(255, 255, 255, 0.12);
    transform: translateY(-2px);
    border-color: rgba(0, 123, 255, 0.5);
}

.racer-sign {
    color: #00ff88;
    /* Even brighter neon green */
    font-weight: 800;
    font-size: 22px;
    width: auto;
    text-align: center;
    text-shadow: 0 0 15px rgba(0, 255, 136, 0.6);
}

.racer-name {
    flex: 0 1 auto;
    /* Don't take all space for centering */
    color: #fff;
    font-weight: 600;
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-transform: capitalize;
    /* Capitalize first letters */
    white-space: nowrap;
    /* Force single line as requested */
}

/* Animations */
@keyframes pulse-red-glow {
    0% {
        box-shadow: 0 4px 15px var(--danger-glow);
    }

    50% {
        box-shadow: 0 0 25px rgba(239, 83, 80, 0.7);
    }

    100% {
        box-shadow: 0 4px 15px var(--danger-glow);
    }
}



.premium-title {
    text-align: center;
    color: #fff;
    font-weight: 800;
    margin: 10px 0 30px 0;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 30px;
    /* Even larger */
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.4);
    position: relative;
    padding-bottom: 12px;
    width: 100%;
}

.premium-title::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 4px;
    background: linear-gradient(90deg, transparent, var(--primary-color), transparent);
    border-radius: 2px;
}

/* Timetable & Form Premium Styles */
.timetable-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    margin-bottom: 12px;
    background: rgba(255, 255, 255, 0.15);
    /* Lightened from 0.05 */
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    gap: 12px;
    transition: all 0.3s ease;
}

.timetable-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.premium-label {
    display: block;
    margin: 15px 0 8px 5px;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
}

.premium-input,
.premium-select {
    width: 100%;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.05);
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: #fff;
    font-size: 16px;
    font-family: inherit;
    transition: all 0.3s ease;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.premium-input:focus,
.premium-select:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--primary-color);
    box-shadow: 0 0 15px var(--primary-glow);
}

.grid-selection {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 10px 0;
    width: 100%;
}

.grid-selection-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.btn-toggle {
    padding: 12px;
    font-size: 15px;
    background: rgba(255, 255, 255, 0.1);
    /* Lightened from 0.03 */
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-toggle.active {
    background: rgba(251, 192, 45, 0.1);
    border-color: #fbc02d;
    color: #fbc02d;
    box-shadow: 0 0 10px rgba(251, 192, 45, 0.2);
}

.btn-toggle.active-green {
    background: rgba(76, 175, 80, 0.1);
    border-color: #4caf50;
    color: #4caf50;
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.2);
}

.btn-toggle.active-blue {
    background: rgba(0, 123, 255, 0.1);
    border-color: #007bff;
    color: #4da3ff;
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.2);
}

.active-orange {
    background: rgba(255, 140, 0, 0.3) !important;
    border-color: #ff8c00 !important;
    color: #ff8c00 !important;
    box-shadow: none !important;
}

.btn-icon-round {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon-round:active {
    transform: scale(0.9);
}

.btn-icon-gray {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.btn-icon-danger {
    background: rgba(239, 83, 80, 0.25);
    color: #ef5350;
    border: 1px solid rgba(239, 83, 80, 0.4);
}

.btn-icon-primary {
    background: rgba(0, 123, 255, 0.1);
    color: #007bff;
    border: 1px solid rgba(0, 123, 255, 0.2);
}

/* Redesign for Timetable Headers */
.editor-header {
    text-align: center;
    padding: 20px 0;
    margin-bottom: 10px;
}

.editor-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
}

.editor-header p {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 13px;
}

/* Organizer Control Interface Styles */
.control-grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    padding: 2px;
    background: #000;
    width: 100%;
    box-sizing: border-box;
}

.post-card {
    background: #111;
    border: 1px solid #333;
    border-radius: 2px;
    display: flex;
    flex-direction: column;
    aspect-ratio: 1 / 1.15;
    padding: 2px;
}

.post-card-row {
    display: flex;
    justify-content: space-between;
    gap: 2px;
    flex: 1;
}

.post-number {
    font-size: 20px;
    font-weight: 800;
    color: #ff9800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 2px 0;
}

.flag-btn {
    background: #222;
    color: #888;
    border: 1px solid #444;
    font-size: 11px;
    font-weight: 700;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.1s;
}

.flag-btn:active {
    transform: scale(0.95);
}

.flag-btn.active {
    background: #fff;
    color: #000;
}

/* Control Posts Grid - Compact spacing and scrollable */
#control-posts-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
    padding: 20px 8px 8px 8px;
    background: #000;
    overflow-y: auto;
    max-height: 480px;
}

.heat-list-container {
    flex: 0 0 auto;
    background: #222;
    overflow-y: auto;
    border-top: 1px solid #444;
    display: flex;
    flex-direction: column;
    width: 100%;
    box-sizing: border-box;
    max-height: 120px;
    /* Increased to show 3 events */
}

.heat-item {
    padding: 8px 20px;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #2a2a2a;
}

.heat-item.active {
    background: #333;
    border-left: 4px solid #fff;
}

.heat-title {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
}

.heat-laps {
    font-size: 18px;
    font-weight: 700;
    color: #00ff88;
}

.bottom-controls {
    padding: 6px 6px max(12px, env(safe-area-inset-bottom)) 6px;
    margin-bottom: 0px;
    background: #000;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    border-top: 1px solid #333;
    width: 100%;
    box-sizing: border-box;
    flex-shrink: 0;
}

.ctrl-btn {
    height: 45px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.btn-ready {
    background: #f0f0f0;
    color: #000;
}

.btn-red-flag {
    background: #f0f0f0;
    color: #000;
}

/* Dark red default */
.btn-timetable {
    background: #f0f0f0;
    color: #000;
}

.btn-back-custom {
    background: #2a0a0a;
    color: #ff5252;
    border: 1px solid #ff5252;
}

/* Responsive Desktop Layout for Control Interface */
@media (min-width: 768px) {

    /* Limit control screen width on desktop and center it */
    #screen-organizer-control {
        display: flex !important;
        flex-direction: column !important;
        height: 100vh !important;
        overflow: hidden !important;
        padding: 0 !important;
    }

    /* Control Posts Grid - Limit width, center, and make compact */
    .control-grid-container,
    #control-posts-grid {
        max-width: 650px !important;
        margin: 0 auto !important;
        width: 100% !important;
        flex: 1 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        padding: 20px 10px 10px 10px !important;
        gap: 6px !important;
        scrollbar-width: none;
        /* Firefox */
    }

    #control-posts-grid::-webkit-scrollbar {
        display: none;
        /* Chrome/Safari */
    }

    /* Heat List - Match grid width and ensure visibility */
    .heat-list-container,
    #control-timetable-container {
        max-width: 650px !important;
        margin: 0 auto !important;
        width: 100% !important;
        min-height: 120px !important;
        max-height: 200px !important;
        flex-shrink: 0 !important;
    }

    /* Bottom Controls - Match grid width */
    .bottom-controls {
        max-width: 650px !important;
        margin: 0 auto !important;
        width: 100% !important;
        padding: 10px 10px 30px 10px !important;
        flex-shrink: 0 !important;
        background: #000;
    }

    /* Make post boxes MUCH larger on desktop */
    .post-box {
        max-width: none !important;
        height: 160px !important;
        font-size: 14px !important;
    }

    /* Target the number inside post-box to be much bigger */
    .post-box>div:nth-child(2) {
        font-size: 44px !important;
    }

    /* Smaller button heights on desktop */
    .ctrl-btn {
        height: 45px !important;
        font-size: 15px !important;
    }
}

/* Even wider screens - tighter layout */
@media (min-width: 1200px) {

    .control-grid-container,
    #control-posts-grid,
    .heat-list-container,
    #control-timetable-container,
    .bottom-controls {
        max-width: 500px !important;
    }
}

/* Desktop Layout Refinements */
@media (min-width: 768px) {

    .login-form,
    .auth-form,
    .input-group,
    #event-list-container,
    #home-active-post-container,
    #home-active-enrollment-container,
    .button-container,
    #screen-public-profile .racer-row,
    #owner-car-upload-controls,
    #ref-modern-header,
    #ref-call-header,
    #ref-flags-container,
    #ref-timetable-container,
    #ref-controls,
    #posts-list-container,
    #timetable-entries-list,
    #categories-manage-list {
        max-width: 500px !important;
        margin-left: auto !important;
        margin-right: auto !important;
        width: 100% !important;
        box-sizing: border-box;
    }

    .grid-selection,
    .grid-selection-3 {
        max-width: 500px !important;
        margin-left: auto !important;
        margin-right: auto !important;
        width: 100% !important;
        box-sizing: border-box;
    }

    .premium-label,
    .premium-input,
    .premium-select,
    #racer-check-feedback,
    #categories-container,
    #laps-settings-container,
    #split-settings-container,
    #break-settings-container,
    #palyakarb-settings-container,
    #varakozas-settings-container,
    #timetable-insert-container {
        max-width: 500px !important;
        margin-left: auto !important;
        margin-right: auto !important;
        width: 100% !important;
        box-sizing: border-box;
    }

    /* Override label text alignment for better desktop look */
    .premium-label {
        text-align: left;
    }



    /* Ensure Dashboard bottom buttons are same as top buttons */
    #screen-organizer-dashboard .login-form {
        margin-top: 15px !important;
        gap: 15px !important;
    }

    #screen-referee-control {
        background: transparent !important;
    }

    #screen-referee-control .glass-card {
        width: 100% !important;
        max-width: 650px !important;
        margin: 0 auto !important;
        min-height: 100vh;
        border-left: 1px solid rgba(255, 255, 255, 0.1) !important;
        border-right: 1px solid rgba(255, 255, 255, 0.1) !important;
        border-radius: 0 !important;
        height: 100vh !important;
        display: flex !important;
        flex-direction: column !important;
    }

    #screen-racer-timetable .glass-card,
    #screen-public-profile .glass-card {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        min-height: 100vh;
        border: none !important;
    }

    #ref-flags-container {
        grid-template-columns: repeat(4, 1fr) !important;
        max-width: 100% !important;
    }

    #ref-flags-container .btn-ref-flag {
        font-size: 14px !important;
        padding: 15px 5px !important;
        white-space: nowrap !important;
    }

    #ref-timetable-container {
        flex: 1 !important;
        margin-top: 10px !important;
    }

    #ref-controls {
        flex-shrink: 0 !important;
        padding-bottom: 20px !important;
    }

    #screen-referee-control .logo-section,
    #screen-racer-timetable .logo-section,
    #screen-public-profile .logo-section {
        max-width: 500px;
        margin-left: auto;
        margin-right: auto;
    }

    #ref-timetable-container,
    #racer-timetable-container,
    #car-photo-section,
    .profile-header-row {
        max-width: 600px;
        margin-left: auto !important;
        margin-right: auto !important;
    }
}

.dashboard-bottom-form {
    padding-bottom: 40px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Fix for dropdown options visibility */
.premium-select option {
    background-color: #1a1a1a;
    color: #fff;
}

/* --- LIGHTBOX STYLES --- */
.image-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.image-lightbox.active {
    display: flex;
    opacity: 1;
}

.image-lightbox img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.image-lightbox.active img {
    transform: scale(1);
}

.clickable-img {
    cursor: pointer;
    transition: transform 0.2s ease, filter 0.2s ease;
}

.clickable-img:hover {
    filter: brightness(1.1);
    transform: scale(1.02);
}

/* Desktop adjustments for Public Profile */
@media (min-width: 768px) {
    #car-photo-section>div {
        height: 250px !important;
        /* Fixed smaller height */
        aspect-ratio: 16/9 !important;
        /* Force 16:9 aspect ratio */
        width: auto !important;
        /* Let width calculate based on ratio */
        margin: 0 auto;
        /* Center it */
        max-width: 100%;
        /* Ensure it doesn't overflow container */
    }
}

/* --- AUDIO STREAMING & DEBUG CONSOLE --- */
.debug-console {
    width: 100%;
    height: 150px;
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 10px;
    font-family: monospace;
    font-size: 11px;
    color: #00ff88;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 15px 0;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
    scrollbar-width: thin;
    scrollbar-color: #00ff88 transparent;
}

.debug-console::-webkit-scrollbar {
    width: 4px;
}

.debug-console::-webkit-scrollbar-thumb {
    background: #00ff88;
    border-radius: 4px;
}

.btn-pcm {
    background: #e91e63 !important;
    color: white !important;
    box-shadow: 0 4px 15px rgba(233, 30, 99, 0.4) !important;
    border: none !important;
}

.btn-pcm:active {
    background: #c2185b !important;
    transform: scale(0.98);
}

.btn-pcm.stopping {
    background: #880e4f !important;
}

/* =============================================
   RESPONSIVE HOME SCREEN - no-scroll, fit-to-screen
   ============================================= */

#screen-home .glass-card,
#screen-events .glass-card,
#screen-auth .glass-card,
#screen-organizer-dashboard .glass-card,
#screen-organizer-menu .glass-card,
#screen-referee-control .glass-card,
#screen-ref-categories .glass-card,
#screen-profile .glass-card,
#screen-racer-timetable .glass-card,
#screen-racer-categories .glass-card,
#screen-racer-entries .glass-card,
#screen-public-profile .glass-card,
#screen-password .glass-card,
#screen-post-selector .glass-card,
#screen-post-selection .glass-card,
#screen-racer-list .glass-card,
#screen-post-editor .glass-card,
#screen-categories .glass-card,
#screen-speaker-broadcast .glass-card {
    min-height: 100dvh;
    height: 100dvh;
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
    padding: 0 clamp(15px, 4vw, 25px) clamp(10px, 3.5vw, 35px);
    box-sizing: border-box;
    justify-content: flex-start;
}

/* Scrollable editor screens: fixed frame, inner content scrolls */
#screen-register .glass-card,
#screen-timetable-editor .glass-card,
#screen-add-timetable .glass-card {
    min-height: 100dvh;
    height: 100dvh;
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
    padding: 0 clamp(15px, 4vw, 25px) clamp(10px, 3.5vw, 35px);
    box-sizing: border-box;
    justify-content: flex-start;
}

/* 100dvh fixed screens (No Scroll) */
#screen-ref-categories,
#screen-profile,
#screen-racer-timetable,
#screen-racer-categories,
#screen-racer-entries,
#screen-public-profile,
#screen-password,
#screen-register,
#screen-post-selector,
#screen-post-selection,
#screen-racer-list,
#screen-timetable-editor,
#screen-add-timetable,
#screen-post-editor,
#screen-categories,
#screen-speaker-broadcast {
    height: 100dvh;
    width: 100vw;
    display: none;
    flex-direction: column;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    background: transparent;
}

/* Organizer control: fixed fullscreen, internal layout handles scroll */
#screen-organizer-control {
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
}

/* Specific active state to prevent ghosting */
#screen-home.active,
#screen-events.active,
#screen-auth.active,
#screen-organizer-dashboard.active,
#screen-organizer-menu.active,
#screen-referee-control.active,
#screen-ref-categories.active,
#screen-profile.active,
#screen-racer-timetable.active,
#screen-racer-categories.active,
#screen-racer-entries.active,
#screen-public-profile.active,
#screen-password.active,
#screen-register.active,
#screen-post-selector.active,
#screen-post-selection.active,
#screen-racer-list.active,
#screen-timetable-editor.active,
#screen-add-timetable.active,
#screen-organizer-control.active,
#screen-post-editor.active,
#screen-categories.active,
#screen-speaker-broadcast.active {
    display: flex !important;
}

#screen-auth .glass-card,
#screen-organizer-menu .glass-card {
    justify-content: center;
}

/* Dashboard: show background through glass, flex-start layout */
#screen-organizer-dashboard .glass-card {
    justify-content: flex-start;
    background: linear-gradient(to bottom, rgba(3, 4, 6, 0.6) 0%, rgba(13, 17, 23, 0.2) 200px) !important;
    backdrop-filter: blur(14px) !important;
    -webkit-backdrop-filter: blur(14px) !important;
    overflow: hidden !important;
}

/* Logo section: shrinks aggressively when needed */
.logo-section {
    flex-shrink: 1;
    min-height: 0;
    padding: clamp(2px, 1.2vh, 8px) 0;
    display: flex;
    justify-content: center;
    margin-bottom: clamp(2px, 0.5vh, 8px);
}

.logo {
    height: clamp(35px, 15vh, 120px) !important;
    /* Slightly larger as requested */
    width: auto;
    object-fit: contain;
}

/* Welcome message & Titles spacing */
.title {
    margin-bottom: clamp(2px, 0.8vh, 10px) !important;
    font-size: clamp(16px, 4.5vw, 20px) !important;
    flex-shrink: 0;
    text-align: center;
}

/* Auth screen title gets bigger treatment */
#screen-auth .title,
#screen-register .title {
    font-size: clamp(22px, 5.5vw, 30px) !important;
    margin-top: 0 !important;
    margin-bottom: 14px !important;
}

/* Button containers: shrink and distribute space */
#screen-home #home-default-buttons,
#screen-home #home-bottom-section,
#screen-events .login-form,
#screen-organizer-dashboard .button-container,
#screen-organizer-dashboard .login-form,
#screen-organizer-menu .button-container,
#screen-organizer-menu .login-form {
    flex-shrink: 1;
    gap: clamp(4px, 1vh, 10px);
    width: 100%;
}

#screen-home #home-bottom-section,
#screen-events .login-form:last-child,
#screen-organizer-dashboard .login-form:last-child,
#screen-organizer-menu .login-form:last-child {
    margin-top: clamp(6px, 1.5vh, 15px) !important;
}

/* HOME: Thicker main buttons */
#screen-home button {
    padding: clamp(18px, 3vh, 24px) 16px;
    /* Slightly thicker as requested */
    font-size: clamp(16px, 4.5vw, 19px);
    margin-top: 0;
    flex-shrink: 1;
    min-height: 0;
}

/* Other screens: compact buttons (more items fit) */
#screen-events button,
#screen-auth button,
#screen-organizer-menu button,
#screen-referee-control button,
#screen-ref-categories button,
#screen-profile button,
#screen-password button,
#screen-register button,
#screen-post-selector button,
#screen-post-selection button,
#screen-racer-list button,
#screen-timetable-editor button,
#screen-add-timetable button,
#screen-post-editor button,
#screen-categories button,
#screen-speaker-broadcast button {
    padding: clamp(12px, 1.8vh, 15px) 16px;
    font-size: clamp(15px, 4.2vw, 17px);
    margin-top: 0;
    flex-shrink: 1;
    min-height: 0;
}

/* Logout button base (width overridden by JS to fit-content) */
#btn-logout.btn-secondary {
    font-size: clamp(13px, 3.5vw, 15px) !important;
    font-weight: 500 !important;
}

/* Internal scrolling content (middle sections) */
.scroll-content,
#home-active-post-container,
#home-active-enrollment-container,
#home-default-buttons,
#category-list,
#racer-timetable-container,
#racer-categories-container,
#racer-entries-container,
#screen-public-profile .glass-card>div:nth-child(3) {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: visible;
    padding: 10px 10px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#screen-home #home-active-post-container,
#screen-home #home-active-enrollment-container,
#screen-home #home-default-buttons,
#screen-ref-categories #category-list,
#screen-racer-timetable #racer-timetable-container,
#screen-racer-categories #racer-categories-container,
#screen-racer-entries #racer-entries-container,
#screen-post-editor #posts-list-container,
#screen-categories #categories-manage-list {
    flex: 1;
    min-height: 0;
    overflow-x: visible;
    overflow-y: auto;
    padding: 10px 20px 30px;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: clamp(10px, 2.5vh, 22px);
}

/* Referee Screen Specifics */
#screen-referee-control #ref-flags-container {
    margin-bottom: 8px !important;
    gap: 6px !important;
}

#screen-referee-control #ref-timetable-container {
    flex: 1;
    min-height: 50px;
    overflow-y: auto;
    padding: 5px;
}

#screen-referee-control #ref-timetable {
    font-size: clamp(12px, 3.2vw, 14px) !important;
}

#screen-referee-control #ref-controls {
    margin-top: auto;
    gap: 4px !important;
    padding: 10px 0;
}

/* Profile Screen Specifics */
#screen-profile .avatar-edit-container {
    display: flex;
    gap: clamp(10px, 4vw, 25px);
    justify-content: center;
    margin-bottom: clamp(5px, 1.5vh, 15px);
    flex-shrink: 1;
}

.profile-image-section,
.car-image-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    text-align: center;
}

#screen-profile .label-mini {
    font-size: 10px;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
    margin-bottom: 6px;
    display: block;
    width: 100%;
    text-align: center;
}

#screen-profile .login-form {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: clamp(2px, 0.4vh, 6px);
    /* Very tight gap since we have labels now */
    overflow: visible;
    /* Final glow fix for Mentés button */
}

#screen-profile .input-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

#screen-profile .input-group label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    margin-left: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#screen-profile .input-group input,
#screen-profile .input-group textarea {
    padding: clamp(10px, 1.5vh, 15px) 14px;
    font-size: clamp(14px, 3.8vw, 16px);
}

.button-group-vertical {
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 1.2vh, 12px);
    margin-top: auto;
    overflow: visible;
    /* For button shadows */
}

/* Active post / enrollment containers */
#home-active-post-container,
#home-active-enrollment-container {
    flex-shrink: 1;
    min-height: 0;
}

/* Extra tight layout for very small screens (e.g. iPhone SE, 568px height) */
@media (max-height: 640px) {

    .logo {
        height: clamp(30px, 8vh, 60px) !important;
    }

    .logo-section {
        padding-top: 0px;
    }

    .title {
        margin-bottom: 1px !important;
        font-size: 15px !important;
    }

    #screen-home button,
    #screen-events button,
    #screen-auth button,
    #screen-organizer-dashboard button,
    #screen-organizer-menu button,
    #screen-referee-control button,
    #screen-ref-categories button,
    #screen-profile button,
    #screen-password button,
    #screen-register button,
    #screen-post-selector button,
    #screen-post-selection button,
    #screen-racer-list button,
    #screen-timetable-editor button,
    #screen-add-timetable button,
    #screen-speaker-broadcast button {
        padding: 7px 10px;
        font-size: 14px;
        border-radius: 8px;
    }

    .login-form,
    #home-default-buttons,
    #home-bottom-section,
    #ref-controls {
        gap: 2px !important;
    }

    #screen-profile .avatar-edit-container {
        scale: 0.9;
        margin-bottom: 2px;
    }

    #screen-profile .input-group input,
    #screen-profile .input-group textarea {
        padding: 6px 10px;
        font-size: 13px;
    }
}

/* Fallback for browsers without dvh support */
@supports not (height: 100dvh) {

    #screen-home .glass-card,
    #screen-password .glass-card,
    #screen-register .glass-card,
    #screen-post-selector .glass-card,
    #screen-post-selection .glass-card,
    #screen-racer-list .glass-card,
    #screen-timetable-editor .glass-card,
    #screen-add-timetable .glass-card,
    #screen-speaker-broadcast .glass-card {
        min-height: 100vh;
        height: 100vh;
    }

    #screen-password,
    #screen-register,
    #screen-post-selector,
    #screen-post-selection,
    #screen-racer-list,
    #screen-timetable-editor,
    #screen-add-timetable,
    #screen-speaker-broadcast {
        height: 100vh;
    }
}

/* =============================================
   DASHBOARD SCREEN - spacing & back button
   ============================================= */

/* Dashboard button container: larger gap between buttons */
#screen-organizer-dashboard .button-container,
#screen-organizer-dashboard .login-form,
#screen-organizer-dashboard .dashboard-bottom-form {
    gap: clamp(14px, 2.5vh, 22px) !important;
    width: 100%;
    flex-shrink: 0;
}

/* Dashboard: center the main content */
#screen-organizer-dashboard .glass-card {
    justify-content: safe center !important;
    position: relative;
    padding-top: clamp(15px, 3vh, 30px) !important;
}

/* Eltávolítva a duplikált abszolút pozicionálás, mivel a .glass-card .btn-back már kezeli globálisan */

/* Visual separator line above the back button - már globális */

/* Dashboard buttons: slightly compact to fit all above back button */
#screen-organizer-dashboard button:not(.btn-back) {
    padding: clamp(12px, 1.8vh, 16px) 16px;
    font-size: clamp(15px, 4.2vw, 17px);
    margin-top: 0;
}

/* Globális Vissza gomb és Főoldali Kijelentkezés gomb fixálása */
.glass-card .btn-back,
#screen-home .btn-logout {
    position: absolute !important;
    bottom: calc(clamp(15px, 3.5vh, 25px) + env(safe-area-inset-bottom, 15px)) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: calc(100% - clamp(30px, 8vw, 50px)) !important;
    margin: 0 !important;
    z-index: 100 !important;
}

/* Speciális margó a kijelentkezés gombnak ha csak fit-content */
#screen-home .btn-logout {
    width: fit-content !important;
    padding: 8px 35px !important;
}

/* Vizuális elválasztó a gombok felett */
.glass-card .btn-back::before,
#screen-home .btn-logout::before {
    content: '';
    display: block;
    position: absolute;
    top: -12px;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(255, 255, 255, 0.1) !important;
}

.btn-back {
    max-width: 600px;
}