/* ==========================================================================
   Design Token & Variables (YouTube Signature Red Theme)
   ========================================================================== */
:root {
    --yt-red: #ff0000;
    --yt-red-dark: #cc0000;
    --bg-main: #0f0f0f;
    --bg-card: #1f1f1f;
    --bg-hover: #2f2f2f;
    --bg-modal: #161616;
    --border-color: #272727;
    --text-main: #f1f1f1;
    --text-muted: #aaaaaa;
    --text-dark: #0f0f0f;
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-sm: 4px;
    --transition-smooth: all 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ==========================================================================
   Base reset & Global styles
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: 'Noto Sans KR', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

body.dark-theme {
    background-color: var(--bg-main);
    color: var(--text-main);
}

/* Scrollbar customization */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #333333;
    border-radius: var(--radius-sm);
}
::-webkit-scrollbar-thumb:hover {
    background: #555555;
}

/* ==========================================================================
   Header Area
   ========================================================================== */
.app-header {
    background: #0f0f0f;
    border-bottom: 1px solid var(--border-color);
    height: 56px;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.logo-icon {
    font-size: 24px;
}

.logo-title {
    font-family: 'Outfit', sans-serif;
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.auth-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-display-name {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-muted);
}

/* ==========================================================================
   Main layout structures
   ========================================================================== */
.app-container {
    display: flex;
    flex: 1;
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 20px;
    gap: 24px;
}

.main-content {
    flex: 2;
    min-width: 0;
}

.sidebar {
    flex: 1;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ==========================================================================
   Sidebar layout boxes & listings
   ========================================================================== */
.sidebar-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.feed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.feed-header h2 {
    font-size: 17px;
    font-weight: 700;
}

.feed-header.spacer {
    margin-top: 24px;
}

.grid-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Individual card */
.stream-card {
    display: flex;
    gap: 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.stream-card:hover {
    background: var(--bg-hover);
    transform: translateY(-2px);
}

.card-thumb-wrapper {
    position: relative;
    width: 100px;
    height: 62px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background-color: #000;
    flex-shrink: 0;
}

.card-thumb-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-badge-live {
    position: absolute;
    top: 4px;
    left: 4px;
    background-color: var(--yt-red);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    padding: 1px 4px;
    border-radius: 2px;
}

.card-badge-duration {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background-color: rgba(0,0,0,0.8);
    color: #fff;
    font-size: 9px;
    padding: 1px 4px;
    border-radius: 2px;
}

.card-info {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-width: 0;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.card-meta {
    font-size: 11.5px;
    color: var(--text-muted);
}

/* ==========================================================================
   Player Area
   ========================================================================== */
.player-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background-color: #000000;
    border: 1px solid var(--border-color);
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

#video-player {
    width: 100%;
    height: 100%;
}

.live-indicator {
    position: absolute;
    top: 15px;
    left: 15px;
    background-color: var(--yt-red);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 3px;
    letter-spacing: 0.5px;
    box-shadow: 0 0 10px rgba(255, 0, 0, 0.6);
}

.info-area {
    margin-top: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.stream-title {
    font-size: 20px;
    font-weight: 700;
    line-height: 1.3;
}

.stream-stats {
    display: flex;
    gap: 12px;
    font-size: 13.5px;
    color: var(--text-muted);
    margin-top: 6px;
}

.stream-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

.divider {
    border: none;
    height: 1px;
    background: var(--border-color);
    margin: 16px 0;
}

.stream-description {
    font-size: 14px;
    color: var(--text-main);
    line-height: 1.5;
    white-space: pre-wrap;
}

/* ==========================================================================
   Chat Section
   ========================================================================== */
.chat-box {
    flex: 1;
    height: 480px;
}

.chat-box h3 {
    font-size: 15px;
    font-weight: 700;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-msg {
    font-size: 13.5px;
    line-height: 1.4;
}

.chat-msg-user {
    font-weight: 700;
    color: var(--yt-red);
    margin-right: 6px;
}

.chat-msg-text {
    color: var(--text-main);
}

.chat-input-form {
    display: flex;
    gap: 8px;
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
}

.chat-input-form input {
    flex: 1;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    padding: 10px 14px;
    font-size: 13.5px;
    outline: none;
}

.chat-input-form input:focus {
    border-color: #555;
}

.btn-send {
    background-color: var(--yt-red);
    border: none;
    color: #fff;
    padding: 0 16px;
    font-weight: 700;
    font-size: 13.5px;
    border-radius: var(--radius-md);
    cursor: pointer;
}

.btn-send:hover {
    background-color: var(--yt-red-dark);
}

/* ==========================================================================
   Form controls & buttons
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 18px;
    border: none;
    cursor: pointer;
    transition: var(--transition-smooth);
    outline: none;
}

.btn-primary {
    background-color: var(--text-main);
    color: var(--text-dark);
}

.btn-primary:hover {
    background-color: #ffffff;
}

.btn-secondary {
    background-color: var(--bg-hover);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: #3f3f3f;
}

.btn-success {
    background-color: var(--yt-red);
    color: #fff;
}

.btn-success:hover {
    background-color: var(--yt-red-dark);
}

.btn-danger {
    background-color: #ff3366;
    color: #fff;
}

.btn-danger:hover {
    background-color: #e62255;
}

/* ==========================================================================
   Modal backdrops & forms
   ========================================================================== */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    backdrop-filter: blur(5px);
    transition: opacity 0.25s ease;
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-container {
    width: 100%;
    max-width: 440px;
    background: var(--bg-modal);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    transform: translateY(20px);
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal-backdrop.open .modal-container {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 700;
}

.close-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    color: #fff;
}

.modal-body {
    padding: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.form-group label {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-muted);
}

.form-group input {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: #fff;
    padding: 12px;
    font-size: 14px;
    outline: none;
}

.form-group input:focus {
    border-color: #666;
}

.form-help {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.3;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

/* ==========================================================================
   Responsive Adaptation (Mobile First / Handheld Device Styling)
   ========================================================================== */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        padding: 12px;
        gap: 16px;
    }
    
    .sidebar {
        min-width: 100%;
    }
    
    .chat-box {
        height: 380px;
    }
}

/* ==========================================================================
   PWA Install Banner (Mobile Bottom Sheet)
   ========================================================================== */
.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(22, 22, 22, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    z-index: 200;
    animation: slideUp 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
    /* iOS safe area */
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.pwa-install-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.pwa-install-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(255, 0, 0, 0.3);
}

.pwa-install-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.pwa-install-text strong {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-main);
}

.pwa-install-text span {
    font-size: 11.5px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pwa-install-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* ==========================================================================
   Camera Flip Button (Floating Action Button during broadcast)
   ========================================================================== */
/* Style removed as the button is now an inline button under the video player */

.camera-flip-btn:hover {
    transform: scale(1.1);
    background: rgba(255, 0, 0, 1);
}

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

@keyframes fabPulse {
    0%, 100% { box-shadow: 0 6px 20px rgba(255, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3); }
    50% { box-shadow: 0 6px 30px rgba(255, 0, 0, 0.6), 0 2px 12px rgba(0, 0, 0, 0.4); }
}

/* ==========================================================================
   iOS Standalone Mode & Safe Area Adjustments
   ========================================================================== */
@supports (padding: env(safe-area-inset-top)) {
    .app-header {
        padding-top: env(safe-area-inset-top, 0px);
        height: calc(56px + env(safe-area-inset-top, 0px));
    }
    
    body {
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
    }
}

/* When running as installed PWA (standalone) */
@media (display-mode: standalone) {
    .app-header {
        padding-top: env(safe-area-inset-top, 0px);
        height: calc(56px + env(safe-area-inset-top, 0px));
    }
    
    .pwa-install-banner {
        display: none !important;
    }
}

.back-nav {
    margin-bottom: 12px;
}
