/* SS_Ensemble Styles - Mobile-First Responsive Design */

:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --primary-hover: #3b82f6;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --danger-color: #dc2626;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    --text-muted: #64748b;
    --border: #475569;
    --shadow: rgba(0, 0, 0, 0.5);
}

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

body,
h1, h2, h3, h4, h5, h6,
p,
figure,
blockquote,
fieldset,
pre {
    margin: 0;
}

fieldset,
legend {
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
        sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Screen Management */
.screen {
    display: none;
    min-height: 100vh;
    width: 100%;
    /* padding: 1rem; */
    animation: fadeIn 0.3s ease-in;
}

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

/* Full-height layout for conductor and player screens */
#conductor-screen.active,
#player-screen.active {
    justify-content: flex-start;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport for mobile */
    padding: 0;
    overflow: hidden;
}

#conductor-screen > .container,
#player-screen > .container {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 0.25rem;
    gap: 0.25rem;
    overflow: hidden;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Container */
.container {
    /* max-width: 1200px; */
    width: 100%;
    margin: 0 auto;
    /* padding: 1rem; */
}

/* Conductor setup screen - add top padding to clear fixed buttons */
#conductor-setup-screen .container {
    position: absolute;
    top: 4rem;
}

/* Landing Page - Dual Panel Layout */
.landing-container {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.landing-header {
    text-align: center;
    margin-bottom: 2rem;
}

.landing-header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.landing-panels {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: stretch;
}

@media (min-width: 768px) {
    .landing-panels {
        flex-direction: row;
        gap: 2rem;
    }
}



/* Landing Page Divider */
.landing-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0;
}

.landing-divider span {
    background-color: var(--bg-primary);
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

@media (min-width: 768px) {
    .landing-divider {
        flex-direction: column;
        padding: 0 0.5rem;
    }

    .landing-divider::before,
    .landing-divider::after {
        content: '';
        flex: 1;
        width: 1px;
        background-color: var(--border-color);
        min-height: 2rem;
    }
}




/* Typography */
h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-align: center;
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

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

.info-text {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 1rem;
}

/* Hide info text in header sections to save vertical space */
.header .info-text {
    display: none;
}



/* Loading Screen */
#loading-screen {
    justify-content: center;
    align-items: center;
}

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

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

#loading-message {
    text-align: center;
    color: var(--text-secondary);
}

/* Form Elements */
label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-secondary);
}

select {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    background-color: var(--surface);
    color: var(--text-primary);
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    outline: none;
    transition: border-color 0.2s;
    appearance: none;
    cursor: pointer;
}

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

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23cbd5e1' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

/* Slice Search Box */
#slide-search-box {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1rem;
    position: relative;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
}

#slice-search-input {
    width: 22rem;
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    background-color: var(--surface);
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#slice-search-input::placeholder {
    color: var(--text-secondary);
}

#slice-search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

#slice-search-clear {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
}

#slice-search-clear:hover {
    color: var(--text-primary);
}

#slice-search-input:not(:placeholder-shown) + #slice-search-clear {
    opacity: 1;
}

/* Slice Cards Grid */
.slice-cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
    margin: 2rem;
    padding: 0;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    display: block;
}

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

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--surface-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

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

.btn-danger:hover:not(:disabled) {
    background-color: #b91c1c;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

/* Header Section */
.header {
    background-color: var(--surface);
    padding: 0.25rem 0.5rem;
    border-radius: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
}

/* Header Actions - inline button and status */
.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.header-actions .btn-danger {
    width: auto;
    max-width: none;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    flex-shrink: 0;
}


.session-info {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: center;
}

/* Play/Pause Button */
.btn-play-pause {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background-color: var(--primary-color);
    color: white;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-play-pause:hover:not(:disabled) {
    background-color: var(--primary-dark);
    transform: scale(1.1);
}

.btn-play-pause:disabled {
    background-color: var(--secondary-color);
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-play-pause.playing {
    background-color: var(--success-color);
}

.btn-play-pause.playing:hover:not(:disabled) {
    background-color: #059669;
}

/* Playback Time Display */
.playback-time {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.2;
}

.playback-time #current-time {
    font-weight: bold;
    color: var(--text-primary);
}

.playback-time #total-time {
    font-size: 0.75rem;
}

/* Long-press interaction feedback */
.playback-time {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    transition: transform 0.1s, background-color 0.2s;
    padding: 0.5rem;
    border-radius: 0.5rem;
}

.playback-time:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.playback-time:active,
.playback-time.pressing {
    transform: scale(0.95);
    background-color: rgba(37, 99, 235, 0.2);
}

.playback-time.pressing {
    animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
    0%, 100% { background-color: rgba(37, 99, 235, 0.2); }
    50% { background-color: rgba(37, 99, 235, 0.4); }
}


/* Audio Debug Button */
.audio-debug-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    width: 32px;
    padding: 0;
    background: #f97316;
    color: white;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.audio-debug-btn:hover {
    background: #ea580c;
}

.audio-debug-btn .debug-icon {
    font-size: 1rem;
    line-height: 1;
}

.audio-debug-btn.loading {
    pointer-events: none;
    opacity: 0.7;
}

.audio-debug-btn.loading .debug-icon {
    animation: spin 1s linear infinite;
}

.badge {
    display: inline-block;
    padding: 0.375rem 0.75rem;
    background-color: var(--primary-color);
    color: white;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.player-count {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.player-count strong {
    color: var(--text-primary);
    font-size: 1rem;
}

.sync-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

#sync-status-text,
#player-sync-status {
    color: var(--text-secondary);
    font-size: 0.875rem;
    max-width: 5em;
    text-align: center;
    line-height: 1.2;
}



/* Tablet and Desktop Styles */
@media (min-width: 768px) {
    h1 {
        font-size: 2.5rem;
    }

    h2 {
        font-size: 1.75rem;
    }

    /* Responsive grid for iPad landscape */
    .slice-cards-grid {
        grid-template-columns: repeat(5, 1fr);
    }

    .header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .header-content {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }


    .session-info {
        justify-content: flex-end;
    }

    .btn {
        width: auto;
    }

}

@media (min-width: 1024px) {
    /* More columns on large desktop */
    .slice-cards-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* Portrait Mobile Optimization */
@media (max-width: 767px) and (orientation: portrait) {
    .header-content {
        gap: 0.5rem;
    }

    .header {
        padding: 0.25rem;
    }

    /* Tighter sync status */
    .sync-status {
        gap: 0.5rem;
    }

    /* Smaller text on mobile */
    #sync-status-text {
        font-size: 0.75rem;
    }

    .session-info {
        gap: 0.5rem;
    }

    .btn-play-pause {
        width: 36px;
        height: 36px;
    }
}

/* Landscape Mobile Optimization */
@media (max-width: 767px) and (orientation: landscape) {
    .screen {
        padding: 0.5rem;
    }

    .container {
        padding: 0.5rem;
    }

    .header {
        padding: 0.75rem;
    }

    h2 {
        font-size: 1.25rem;
        margin-bottom: 0.5rem;
    }

    .info-text {
        display: none; /* Hide on landscape mobile to save space */
    }
}

/* iPhone-specific optimizations (≤430px width) */
@media (max-width: 430px) and (orientation: portrait) {
    .header {
        padding: 0.125rem;
    }

    .header-content {
        gap: 0.375rem;
    }


    /* Stack status elements more tightly */
    .header-actions {
        gap: 0.375rem;
    }

    /* Hide info text on very small screens */
    .info-text {
        display: none;
    }
}

/* Touch-friendly tap targets */
@media (hover: none) and (pointer: coarse) {
    .btn,
    button,
    select {
        min-height: 24px; /* iOS recommended tap target size */
    }
}

/* Prevent text selection on double-tap */
.btn,
.badge {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Improve performance on mobile */
.screen {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: transform;
}

/* Screen Footer */
.screen-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* padding: 0.5rem; */
    background: var(--surface);
    border-radius: 0.5rem;
    margin-top: 0.25rem;
    flex-shrink: 0; /* Prevent shrinking in flex layout */
}

/* Conductor and Player screen footer - tracks on right */
#conductor-screen .screen-footer,
#player-screen .screen-footer {
    justify-content: flex-end;
}


/* =============================================================================
   ADMIN UI STYLES
   ============================================================================= */

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.form-actions .btn {
    flex: 1;
}



/* Loading States */
.btn.loading {
    position: relative;
    color: transparent;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin: -8px 0 0 -8px;
    border: 2px solid var(--text-secondary);
    border-radius: 50%;
    border-top-color: var(--text-primary);
    animation: spin 0.8s linear infinite;
}

/* ===========================================
   TEST MODE STYLES
   =========================================== */

/* Test Mode Container */
.test-mode-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: 8px;
}

/* Hide elements when Test mode is active */
#conductor-screen.test-mode-active #conductor-join-status {
    display: none;
}

#conductor-screen.test-mode-active .player-list-container {
    display: none;
}


/* ===========================================
   SESSION MANAGEMENT STYLES
   =========================================== */

/* Sessions Table */
.sessions-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.sessions-table th,
.sessions-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.sessions-table th {
    background: var(--surface);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sessions-table tr:hover {
    background: var(--surface-light);
}

.sessions-table .join-code-cell {
    font-family: monospace;
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: 0.1em;
}

.sessions-table .players-cell {
    text-align: center;
}

/* Status Badge */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: capitalize;
}

.status-playing {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success-color);
}

.status-paused {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning-color);
}

.status-stopped {
    background: rgba(100, 116, 139, 0.2);
    color: var(--secondary-color);
}

/* Terminate Button */
.btn-terminate {
    background: transparent;
    border: 1px solid var(--error-color);
    color: var(--error-color);
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.btn-terminate:hover {
    background: var(--error-color);
    color: white;
}

.btn-terminate:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}


/* Responsive Sessions Table */
@media (max-width: 768px) {
    .sessions-table {
        font-size: 0.85rem;
    }

    .sessions-table th,
    .sessions-table td {
        padding: 0.5rem;
    }

    /* Hide less important columns on mobile */
    .sessions-table th:nth-child(5),
    .sessions-table td:nth-child(5) {
        display: none;
    }
}

/* ============================================
   Piano Keyboard Wrapper
   ============================================ */

.piano-keyboard-wrapper {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    background: #2a2a2a;
    border-top: 1px solid #444;
    padding: 10px 0;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
}

.piano-keyboard {
    display: flex;
    justify-content: center;
    min-width: fit-content;
    padding: 0 10px;
}
