/* ===========================
   Padel Scoreboard - Modern Sports Design
   =========================== */

:root {
    /* Padel Court Color Palette */
    --primary-bg: #0a1628;
    --secondary-bg: #132844;
    --accent-blue: #005BBB;
    --accent-lime: #C7F000;
    --accent-turquoise: #00C9B7;
    --team-a-color: #C7F000;
    --team-b-color: #00C9B7;
    --text-primary: #ffffff;
    --text-secondary: #b8c5d6;
    --success-color: #C7F000;
    --warning-color: #ff9800;
    --danger-color: #ff4757;
    --border-radius: 16px;
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
}

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

html {
    height: 100%;
    height: -webkit-fill-available; /* Safari fix */
}

body {
    font-family: 'Inter', 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--primary-bg);
    background-image: 
        radial-gradient(circle at 20% 50%, rgba(0, 91, 187, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 50%, rgba(199, 240, 0, 0.1) 0%, transparent 50%);
    color: var(--text-primary);
    overflow-x: hidden;
    height: 100vh;
    min-height: 100vh;
    min-height: -webkit-fill-available; /* Safari fix */
    width: 100vw;
    position: fixed;
    top: 0;
    left: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* ===========================
   Screens
   =========================== */

.screen {
    display: none;
    min-height: 100vh;
    height: 100vh;
    width: 100vw;
    position: fixed;
    top: 0;
    left: 0;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* ===========================
   Setup Screen
   =========================== */

#setupScreen {
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 500px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    padding: 32px;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.app-title {
    font-size: 2.5rem;
    font-weight: 900;
    text-align: center;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--accent-lime) 0%, var(--accent-turquoise) 50%, var(--accent-blue) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
    text-transform: uppercase;
}

.subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 1rem;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 14px;
    background-color: var(--accent-color);
    border: 2px solid transparent;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--team-b-color);
}

.toggle-group label {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 12px;
    background-color: var(--accent-color);
    border-radius: 8px;
    transition: background-color 0.2s;
}

.toggle-group label:hover {
    background-color: rgba(15, 52, 96, 0.8);
}

.toggle-group input[type="checkbox"] {
    width: 24px;
    height: 24px;
    margin-right: 12px;
    cursor: pointer;
}

.toggle-group span {
    font-size: 1rem;
    color: var(--text-primary);
}

.btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-lime) 0%, var(--accent-turquoise) 100%);
    color: var(--primary-bg);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(199, 240, 0, 0.4);
    transition: all 0.3s ease;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;\n    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s ease;
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(199, 240, 0, 0.6);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background-color: var(--accent-color);
    color: var(--text-primary);
}

/* ===========================
   Scoreboard Screen
   =========================== */

#scoreboardScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
}

.scoreboard-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: -webkit-fill-available; /* Safari fix */
    width: 100vw;
    padding: 4px;
    overflow: hidden;
    -webkit-overflow-scrolling: touch; /* Safari smooth scrolling */
    gap: 4px;
    position: relative;
}

.scoreboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    margin-bottom: 0;
    background-color: var(--secondary-bg);
    border-radius: 8px;
    flex-shrink: 0;
}

.match-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.separator {
    color: var(--text-secondary);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.icon-btn:hover {
    background-color: var(--accent-color);
}

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

/* Team Sections */
.main-score-display {
    flex: 1 1 auto;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    gap: 4px;
    -webkit-box-align: stretch;
    -webkit-align-items: stretch;
    align-items: stretch;
    height: 100%;
    -webkit-box-flex: 1;
    -webkit-flex: 1 1 auto;
}

.team-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: var(--secondary-bg);
    border-radius: 8px;
    padding: 12px 8px;
    transition: transform 0.3s, box-shadow 0.3s, background-color 0.2s;
    position: relative;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}

.team-section:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.team-section:active {
    transform: scale(0.98);
}

.team-section.scoring {
    animation: scoreFlash 0.5s ease-out;
}

@keyframes scoreFlash {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); box-shadow: 0 0 30px currentColor; }
}

.team-a {
    border: 3px solid var(--team-a-color);
}

.team-b {
    border: 3px solid var(--team-b-color);
}

.team-section.serving {
    box-shadow: 0 0 25px rgba(255, 255, 255, 0.4);
}

/* Server Indicator */
.server-indicator-wrapper {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.server-indicator {
    font-size: 3.5rem;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: scale(0.8);
}

.server-indicator.active {
    opacity: 1;
    transform: scale(1);
    animation: serverPulse 2s ease-in-out infinite;
}

@keyframes serverPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.team-name {
    font-size: 1.4rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

/* Score Details */
.score-details {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    justify-content: center;
}

.score-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-width: 50px;
}

.sets-score,
.games-score {
    font-weight: 700;
    line-height: 1;
    font-size: 1.8rem;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: left;
}

/* Points Score - Large and Dominant */
.points-score {
    font-size: 16rem;
    font-weight: 900;
    line-height: 1;
    margin-top: 12px;
}

.team-a .points-score {
    color: var(--team-a-color);
}

.team-b .points-score {
    color: var(--team-b-color);
}

/* VS Separator */
.vs-separator {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    position: relative;
}

.vs-text {
    font-size: 3rem;
    font-weight: 300;
    color: var(--text-secondary);
    opacity: 0.3;
}

/* Touch Controls */
.touch-controls {
    display: none; /* Hidden - using clickable score sections instead */
}

.score-btn {
    flex: 1;
    padding: 20px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
}

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

.team-a-btn {
    background-color: var(--team-a-color);
}

.team-b-btn {
    background-color: var(--team-b-color);
}

/* Control Menu */
.control-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.control-menu.active {
    display: flex;
}

.menu-content {
    background-color: var(--secondary-bg);
    border-radius: var(--border-radius);
    padding: 32px;
    max-width: 400px;
    width: 90%;
}

.menu-content h2 {
    margin-bottom: 24px;
    text-align: center;
}

.menu-btn {
    width: 100%;
    padding: 16px;
    margin-bottom: 12px;
    background-color: var(--accent-color);
    border: none;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.menu-btn:hover {
    background-color: rgba(15, 52, 96, 0.8);
}

.menu-btn.danger {
    background-color: var(--danger-color);
}

.menu-btn.danger:hover {
    background-color: rgba(244, 67, 54, 0.8);
}

/* Match End Overlay */
.match-end-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.98), rgba(15, 52, 96, 0.98));
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(10px);
}

.match-end-overlay.active {
    display: flex;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.match-end-content {
    text-align: center;
    padding: 40px;
    max-width: 600px;
}

.match-end-title {
    font-size: 3rem;
    margin-bottom: 24px;
    animation: slideDown 0.6s ease-out;
}

@keyframes slideDown {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.winner-display {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--team-b-color);
}

.final-score {
    font-size: 1.5rem;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.match-end-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Bluetooth Debug Panel */
.bluetooth-debug {
    position: fixed;
    top: 50px;
    right: 10px;
    width: 320px;
    max-height: 400px;
    background-color: rgba(26, 26, 46, 0.95);
    border: 2px solid var(--team-b-color);
    border-radius: 8px;
    z-index: 2000;
    display: none;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.bluetooth-debug.active {
    display: flex;
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background-color: var(--secondary-bg);
    border-bottom: 1px solid var(--team-b-color);
    font-weight: 600;
    font-size: 0.9rem;
}

.debug-close {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.debug-close:hover {
    color: var(--danger-color);
}

.debug-content {
    padding: 12px;
    overflow-y: auto;
    max-height: 340px;
}

.debug-status {
    padding: 8px;
    background-color: var(--accent-color);
    border-radius: 4px;
    margin-bottom: 10px;
    font-size: 0.85rem;
    font-weight: 500;
}

.debug-status.connected {
    background-color: var(--success-color);
}

.debug-log {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    line-height: 1.4;
}

.debug-entry {
    padding: 6px 8px;
    margin-bottom: 4px;
    background-color: rgba(255, 255, 255, 0.05);
    border-left: 3px solid var(--text-secondary);
    border-radius: 2px;
    word-break: break-all;
}

.debug-entry.key {
    border-left-color: var(--warning-color);
}

.debug-entry.action {
    border-left-color: var(--success-color);
    font-weight: 600;
}

.debug-entry.error {
    border-left-color: var(--danger-color);
}

.debug-time {
    color: var(--text-secondary);
    font-size: 0.7rem;
    margin-right: 6px;
}

/* ===========================
   Portrait Mode Overlay
   =========================== */

.portrait-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--primary-bg);
    z-index: 20000;
    justify-content: center;
    align-items: center;
}

.portrait-content {
    text-align: center;
    padding: 40px;
    max-width: 400px;
}

.rotate-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    animation: rotatePrompt 2s ease-in-out infinite;
}

@keyframes rotatePrompt {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}

.portrait-content h2 {
    font-size: 1.8rem;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.portrait-content p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Show overlay only on mobile devices in portrait mode during match */
@media (orientation: portrait) and (max-width: 768px) {
    #scoreboardScreen .portrait-overlay {
        display: flex;
    }
}

/* ===========================
   Game Score Flash
   =========================== */

.game-score-flash {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    background: rgba(10, 22, 40, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 3px solid var(--accent-lime);
    box-shadow: 
        0 0 60px rgba(199, 240, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 40px 60px;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.game-score-flash.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.game-score-flash-content {
    text-align: center;
}

.game-flash-label {
    font-size: 3rem;
    font-weight: 900;
    color: var(--text-primary);
    margin-bottom: 20px;
    letter-spacing: 8px;
}

.game-flash-score {
    font-size: 8rem;
    font-weight: 900;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
}

#gameFlashTeamA {
    color: var(--team-a-color);
}

#gameFlashTeamB {
    color: var(--team-b-color);
}

.game-flash-separator {
    color: var(--text-secondary);
    font-size: 6rem;
}

/* Responsive adjustments for game flash */
@media (max-width: 768px) {
    .game-score-flash {
        padding: 30px 40px;
    }
    
    .game-flash-label {
        font-size: 2rem;
        letter-spacing: 4px;
    }
    
    .game-flash-score {
        font-size: 6rem;
        gap: 20px;
    }
    
    .game-flash-separator {
        font-size: 4rem;
    }
}

@media (max-width: 480px) {
    .game-score-flash {
        padding: 20px 30px;
    }
    
    .game-flash-label {
        font-size: 1.5rem;
        margin-bottom: 15px;
    }
    
    .game-flash-score {
        font-size: 4rem;
        gap: 15px;
    }
    
    .game-flash-separator {
        font-size: 3rem;
    }
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--secondary-bg);
    color: var(--text-primary);
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    transition: bottom 0.3s ease-out;
    z-index: 3000;
    max-width: 90%;
    text-align: center;
}

.toast.show {
    bottom: 24px;
}

/* ===========================
   Landscape Optimizations
   =========================== */

/* Small landscape (phones) */
@media (orientation: landscape) and (max-height: 600px) {
    .main-score-display {
        gap: 3px;
    }

    .scoreboard-container {
        padding: 2px;
        gap: 2px;
    }

    .scoreboard-header {
        padding: 1px 4px;
        margin-bottom: 0;
        min-height: 28px;
    }

    .match-info {
        font-size: 0.65rem;
    }

    .icon-btn {
        font-size: 0.9rem;
        padding: 2px 4px;
    }

    .team-section {
        padding: 6px 4px;
        gap: 2px;
    }

    .server-indicator-wrapper {
        height: 18px;
    }

    .server-indicator {
        font-size: 1rem;
    }

    .team-name {
        font-size: 0.85rem;
        margin-bottom: 2px;
    }

    .score-details {
        gap: 6px;
    }

    .score-label {
        font-size: 0.65rem;
        min-width: 35px;
    }

    .sets-score,
    .games-score {
        font-size: 1.2rem;
    }

    .points-score {
        font-size: 8rem;
        margin-top: 2px;
    }

    .vs-separator {
        width: 40px;
    }

    .vs-text {
        font-size: 2rem;
    }

    .touch-controls {
        margin-top: 4px;
    }

    .score-btn {
        padding: 6px 12px;
        font-size: 0.8rem;
        border-radius: 6px;
    }
}

/* Medium landscape (tablets) */
@media (orientation: landscape) and (min-height: 601px) and (max-height: 900px) {
    .scoreboard-container {
        padding: 3px;
        gap: 3px;
    }

    .scoreboard-header {
        padding: 3px 6px;
        min-height: 32px;
    }

    .team-section {
        padding: 12px 8px;
        gap: 4px;
    }

    .team-name {
        font-size: 1.3rem;
        margin-bottom: 4px;
    }

    .server-indicator {
        font-size: 2rem;
    }

    .server-indicator-wrapper {
        height: 35px;
    }

    .score-details {
        gap: 10px;
    }

    .score-label {
        font-size: 0.75rem;
    }

    .sets-score,
    .games-score {
        font-size: 1.6rem;
    }

    .points-score {
        font-size: 16rem;
        margin-top: 8px;
    }

    .touch-controls {
        margin-top: 6px;
    }

    .score-btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }
}

/* Large landscape (desktop) */
@media (orientation: landscape) and (min-height: 901px) {
    .scoreboard-container {
        padding: 4px;
        gap: 4px;
    }

    .scoreboard-header {
        padding: 4px 8px;
        min-height: 36px;
    }

    .team-section {
        padding: 20px 12px;
        gap: 6px;
    }

    .server-indicator {
        font-size: 2.5rem;
    }

    .server-indicator-wrapper {
        height: 45px;
    }

    .team-name {
        font-size: 1.8rem;
        margin-bottom: 6px;
    }

    .score-details {
        gap: 14px;
    }

    .score-label {
        font-size: 0.9rem;
    }

    .sets-score,
    .games-score {
        font-size: 2rem;
    }

    .points-score {
        font-size: 22rem;
        margin-top: 10px;
    }

    .vs-separator {
        width: 80px;
    }

    .vs-text {
        font-size: 4rem;
    }

    .touch-controls {
        margin-top: 8px;
    }

    .score-btn {
        padding: 12px 20px;
        font-size: 1rem;
    }
}

/* ===========================
   Tablet & Desktop
   =========================== */

/* Small screens (portrait phones) */
@media (max-width: 400px) and (orientation: portrait) {
    .main-score-display {
        gap: 6px;
    }

    .scoreboard-container {
        padding: 8px;
    }

    .scoreboard-header {
        padding: 8px 0;
        margin-bottom: 8px;
    }

    .team-section {
        padding: 16px 12px;
        gap: 6px;
    }

    .server-indicator-wrapper {
        height: 30px;
    }

    .server-indicator {
        font-size: 1.5rem;
    }

    .team-name {
        font-size: 1.2rem;
        margin-bottom: 6px;
    }

    .score-details {
        gap: 10px;
    }

    .score-label {
        font-size: 0.75rem;
        min-width: 45px;
    }

    .sets-score,
    .games-score {
        font-size: 1.5rem;
    }

    .points-score {
        font-size: 9rem;
        margin-top: 6px;
    }

    .vs-separator {
        width: 50px;
    }

    .vs-text {
        font-size: 2.5rem;
    }

    .touch-controls {
        margin-top: 12px;
    }

    .score-btn {
        padding: 16px;
        font-size: 1rem;
    }
}

@media (min-width: 768px) {
    .container {
        padding: 48px;
    }

    .app-title {
        font-size: 3rem;
    }

    .touch-controls {
        margin-top: 32px;
    }

    .score-btn {
        padding: 32px;
        font-size: 1.5rem;
    }
}

/* ===========================
   Fullscreen Mode
   =========================== */

:fullscreen .scoreboard-header {
    display: none;
}

:-webkit-full-screen .scoreboard-header {
    display: none;
}

:-moz-full-screen .scoreboard-header {
    display: none;
}

/* ===========================
   Print Styles
   =========================== */

@media print {
    body {
        background-color: white;
        color: black;
    }

    .scoreboard-header,
    .touch-controls,
    .control-menu,
    .toast {
        display: none !important;
    }
}
