/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 50%, #16213e 100%);
    color: #ffffff;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 50%, #16213e 100%);
}

/* Header Styles */
.app-header {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem 2rem;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 600;
    color: #64ffda;
}

.logo i {
    font-size: 1.75rem;
    color: #64ffda;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: #8892b0;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #64ffda;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.current-train-info {
    display: flex;
    align-items: center;
    gap: 3rem;
}

.station-info {
    text-align: right;
}

.station-name {
    font-size: 1.75rem;
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 0.25rem;
}

.route-name {
    font-size: 1rem;
    font-weight: 400;
    color: #8892b0;
}

.train-timer {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(100, 255, 218, 0.1);
    padding: 0.75rem 1rem;
    border-radius: 12px;
    border: 1px solid rgba(100, 255, 218, 0.2);
}

.timer-icon {
    color: #64ffda;
    font-size: 1.25rem;
}

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

.timer-label {
    font-size: 0.75rem;
    color: #8892b0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.timer-value {
    font-size: 1.125rem;
    font-weight: 600;
    color: #64ffda;
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Video Section */
.video-section {
    flex: 1;
    position: relative;
    background: #000;
    border-radius: 16px;
    margin: 1rem;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.video-container {
    width: 100%;
    height: 100%;
    position: relative;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.8);
    color: #ffffff;
    gap: 1rem;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(100, 255, 218, 0.3);
    border-top: 3px solid #64ffda;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-header i {
    color: #64ffda;
}

.upcoming-trains {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.loading-message {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #8892b0;
    font-size: 0.875rem;
}

.upcoming-train-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

.upcoming-train-item:hover {
    background: rgba(100, 255, 218, 0.1);
    border-color: rgba(100, 255, 218, 0.3);
    transform: translateY(-2px);
}

.upcoming-train-item a {
    color: #ffffff;
    text-decoration: none;
    display: block;
    font-size: 0.875rem;
    line-height: 1.4;
}

.upcoming-train-item a:hover {
    color: #64ffda;
}

/* Footer */
.app-footer {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem 2rem;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
}

.footer-text {
    color: #8892b0;
    font-size: 0.875rem;
}

.refresh-btn {
    background: rgba(100, 255, 218, 0.1);
    border: 1px solid rgba(100, 255, 218, 0.3);
    color: #64ffda;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.refresh-btn:hover {
    background: rgba(100, 255, 218, 0.2);
    transform: translateY(-1px);
}

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

/* YouTube iframe styles */
.ytiframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 16px;
}

#ytboxes {
    display: flex;
    width: 100%;
    height: 100%;
    gap: 1rem;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .current-train-info {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-end;
    }
    
    .station-info {
        text-align: right;
    }
}

@media (max-width: 768px) {
    .app-header {
        padding: 1rem;
    }
    
    .header-content {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }
    
    .current-train-info {
        width: 100%;
        flex-direction: row;
        justify-content: space-between;
    }
    
    .main-content {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: 200px;
        border-left: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .video-section {
        margin: 0.5rem;
    }
    
    .app-footer {
        padding: 1rem;
    }
    
    .footer-content {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }
}

/* Scrollbar Styling */
.upcoming-trains::-webkit-scrollbar {
    width: 6px;
}

.upcoming-trains::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.upcoming-trains::-webkit-scrollbar-thumb {
    background: rgba(100, 255, 218, 0.3);
    border-radius: 3px;
}

.upcoming-trains::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 255, 218, 0.5);
}

/* Animation for new content */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.upcoming-train-item {
    animation: fadeInUp 0.3s ease-out;
}

/* Loading states */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Error states */
.error {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
    border-color: rgba(255, 107, 107, 0.3);
}

/* Departure Board (Split-Flap) */
.upcoming-trains.board {
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.35);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.splitflap-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.5rem 0.25rem;
    border-radius: 8px;
}

.splitflap-row:hover {
    background: rgba(255, 255, 255, 0.04);
}

.splitflap-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.splitflap-meta {
    color: #64ffda;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    min-width: 44px;
    text-align: right;
}

.splitflap {
    display: flex;
    gap: 3px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* Smaller cell size to prevent overflow */
.flap-cell {
    position: relative;
    width: 14px;
    height: 24px;
    perspective: 400px;
}

@media (min-width: 1280px) {
    .flap-cell { width: 15px; height: 26px; }
}

/* Split-flap tuning variables */
:root {
    --glyph-top-offset: -0.10em;
    --glyph-bottom-offset: -0.8em;
}

.flap-top, .flap-bottom {
    opacity: 1; /* prevent any fade-in/out */
}

/* Ensure glyphs are tall enough to be clipped by halves */
.flap-top, .flap-bottom {
    font-size: 20px;
    line-height: 1.1;
}

@media (min-width: 1280px) {
    .flap-top, .flap-bottom { font-size: 22px; }
}

/* Make halves clip real glyph halves - adjusted positioning for better readability */
.flap-top, .flap-bottom {
    position: absolute;
    left: 0;
    right: 0;
    display: block;            /* no vertical centering; we control offset with inner span */
    text-align: center;
    font-weight: 600;
    color: #e5f7f3;
    text-shadow: 0 1px 0 rgba(0,0,0,0.6);
    backface-visibility: hidden;
    overflow: hidden;          /* clip to half area */
    line-height: 1em;          /* consistent line height */
    will-change: transform;    /* performance */
    transform-style: preserve-3d;
    transition: none;          /* avoid opacity/transform fade */
    -webkit-font-smoothing: antialiased;
}

.flap-top {
    top: 0;
    height: 50%;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    transform-origin: center bottom;
    z-index: 2;
}

.flap-bottom {
    bottom: 0;
    height: 50%;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
    transform-origin: center top;
}

.flap-top .glyph, .flap-bottom .glyph {
    display: inline-block;
    line-height: 1em;
    font-size: 16px; /* slightly smaller to fit more columns */
}

@media (min-width: 1280px) {
    .flap-top .glyph, .flap-bottom .glyph { font-size: 17px; }
}

/* Adjusted positioning to show more of each character */
.flap-top .glyph { transform: translateZ(0) translateY(var(--glyph-top-offset)); }
.flap-bottom .glyph { transform: translateZ(0) translateY(var(--glyph-bottom-offset)); }

/* Flip animation states - more realistic flip down effect */
.flipping .flap-top { animation: flapTopDown 200ms ease-in forwards; }
.flipping .flap-bottom { animation: flapBottomUp 250ms ease-out 150ms forwards; }

@keyframes flapTopDown { 0% { transform: rotateX(0deg); } 100% { transform: rotateX(-90deg); } }
@keyframes flapBottomUp { 0% { transform: rotateX(90deg); } 100% { transform: rotateX(0deg); } }

/* While flipping, keep bottom half hidden until its animation runs */
.flipping .flap-bottom { transform: rotateX(90deg); }

/* Slightly tighter spacing to fit */
.splitflap { letter-spacing: 0.3px; }

/* Disable generic fade-in on splitflap rows to avoid perceived fading */
.splitflap-row { animation: none !important; }

/* Compact row container to keep the board tidy */
.upcoming-trains .upcoming-train-item {
    background: transparent;
    border: none;
    padding: 0.35rem 0.25rem;
    margin-bottom: 0.25rem;
}

.upcoming-trains .upcoming-train-item a { color: inherit; }

/* Make the entire row clickable with subtle hover */
.upcoming-trains .upcoming-train-item:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: transparent;
    transform: none;
}
