/* ============================================
   Viewer Page CSS - Page-Specific Styles
   ============================================
   Game Viewer, Wide/Fullscreen Layouts, Chat Panel
   Only used in viewer.html
   ============================================ */

/* Viewer Page Layout (Fixed Positioning) */
/* Grid layout removed - using fixed positioning from shared.css */
body {
    min-height: 100vh;
    min-width: 1280px;
    overflow-x: hidden; /* Prevent horizontal scrolling only */
    overflow-y: auto; /* Allow vertical scrolling for page content */
}

/* Wide View Mode - Full Width Game */
body.viewer--wide {
    padding-right: 0;
}

/* Main Container: Grid layout for wide mode */
body.viewer--wide .main-container {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr 400px var(--space-6);
    grid-template-rows: auto auto;
    grid-template-areas:
        "sidebar game game gap"
        "sidebar info chat gap";
    gap: 0;
}

/* Game Area: Use display contents to lift children to grid */
body.viewer--wide .game-area {
    display: contents;
}

/* Game Viewer: Full width row */
body.viewer--wide .game-viewer-section {
    grid-area: game;
    padding: var(--space-6);
    padding-left: var(--space-6);
    max-height: calc(100vh - var(--topbar-height) - 80px); /* Prevent overflow in wide mode */
}

body.viewer--wide .game-viewer {
    max-width: 100%;
    max-height: min(calc(100vh - var(--topbar-height) - 80px), 900px); /* Safe height limit in wide mode */
    height: auto; /* Allow aspect-ratio and max-height to work together */
}

/* Game Info: Left column */
body.viewer--wide .game-info {
    grid-area: info;
    margin-left: var(--space-6);
    margin-top: var(--space-6); /* Start below game viewer */
    padding: var(--space-6);
    margin-right: var(--space-3);
    max-height: 400px;
    overflow-y: auto;
    align-self: start;
}

/* Chat Panel: Right column */
body.viewer--wide .chat-panel {
    grid-area: chat;
    position: static;
    width: 400px;
    margin: 0;
    margin-top: var(--space-6); /* Start below game viewer */
    margin-right: 0; /* Remove right margin in wide mode (grid gap handles spacing) */
    padding: var(--space-6);
    padding-left: 0;
    padding-right: 0;
    height: auto; /* Allow content to determine height */
    max-height: calc((100vh - var(--topbar-height) - var(--space-12)) * 0.65); /* 1/2 * 1.3 = 0.65 (30% increase) */
    min-height: calc((100vh - var(--topbar-height) - 80px) * 0.65); /* 1/2 * 1.3 = 0.65 (30% increase) */
    display: flex;
    flex-direction: column;
}

body.viewer--wide .stats-bar {
    margin-bottom: 0;
}

/* Fullscreen Mode */
body.viewer--fullscreen {
}

body.viewer--fullscreen .top-bar,
body.viewer--fullscreen .sidebar,
body.viewer--fullscreen .game-info,
body.viewer--fullscreen .chat-panel {
    display: none;
}

body.viewer--fullscreen .game-viewer-section {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    padding: 0;
    z-index: var(--z-modal);
}

body.viewer--fullscreen .game-viewer {
    max-width: none;
    width: 100%;
    height: 100%;
    border-radius: 0;
}

/* Game Area */
.game-area {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
    padding: var(--space-6);
    padding-right: var(--space-6); /* Right gap for balanced layout */
    flex: 1;
    margin-left: var(--sidebar-width); /* Account for fixed sidebar */
}

.game-viewer-section {
    position: relative;
    width: 100%;
}

.game-viewer {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: calc(100vh - var(--topbar-height) - 120px); /* Prevent overflow on wide screens */
    background: #000;
    border-radius: var(--radius-lg);
    overflow: hidden;
    padding: 10px;
}

.game-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    background: #000;
    overflow: hidden;
    pointer-events: auto;
}

.game-title-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: var(--space-4);
    background: linear-gradient(to bottom, rgba(0,0,0,0.7) 0%, transparent 100%);
    text-align: center;
    z-index: 10;
    pointer-events: none;
}

.game-title-overlay img {
    max-width: 200px;
    height: auto;
}

.volume-control {
    position: absolute;
    bottom: 16px;
    left: 16px;
    background: rgba(26, 26, 46, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 8px 12px;
    border-radius: var(--radius-lg);
    z-index: var(--z-overlay);
    transition: opacity var(--duration-normal);
}

.game-viewer:not(:hover) .volume-control {
    opacity: 0.7;
}

.game-viewer:hover .volume-control {
    opacity: 1;
}

.game-controls {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(26, 26, 46, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 8px 12px;
    border-radius: var(--radius-lg);
    z-index: var(--z-overlay);
    transition: opacity var(--duration-normal);
}

.game-viewer:not(:hover) .game-controls {
    opacity: 0.7;
}

.game-viewer:hover .game-controls {
    opacity: 1;
}

.control-btn {
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: all var(--duration-fast);
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

.control-btn img {
    width: 24px;
    height: 24px;
    opacity: 0.9;
}

.control-btn:hover img {
    opacity: 1;
}

.control-btn svg {
    opacity: 0.9;
    color: rgba(255, 255, 255, 0.9);
}

.control-btn:hover svg {
    opacity: 1;
    color: rgba(255, 255, 255, 1);
}

.control-btn--active {
    background: rgba(124, 58, 237, 0.3);
}

/* Fullscreen icon toggle - YouTube style */
.control-btn .icon-exit-fullscreen {
    display: none;
}

.control-btn--active .icon-enter-fullscreen {
    display: none !important;
}

.control-btn--active .icon-exit-fullscreen {
    display: block !important;
}

.control-btn--muted {
    background: rgba(239, 68, 68, 0.25);
}

.control-btn--muted img {
    opacity: 0.5;
    filter: grayscale(70%) brightness(0.9);
}

.control-btn--muted:hover {
    background: rgba(239, 68, 68, 0.35);
}

.control-btn--muted:hover img {
    opacity: 0.7;
    filter: grayscale(50%) brightness(1.0);
}

/* Game Info Section */
.game-info {
    position: relative;
    background: #151619;
    border-radius: var(--radius-lg);
    padding: var(--space-6);
}

.creator-section {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    column-gap: var(--space-3);
    row-gap: 0;
    padding: 0;
    background: transparent;
    margin-bottom: var(--space-4);
}

.creator-avatar {
    grid-column: 1;
    grid-row: 1 / 3;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: var(--font-bold);
    flex-shrink: 0;
    align-self: end;
    margin-bottom: -8px;
}

.creator-header-row {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.creator-meta {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
}

.creator-meta::before {
    content: '·';
    margin: 0 var(--space-1);
    color: var(--text-tertiary);
}

.creator-name-text {
    font-size: 22px;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    color: #6a81e5;
    margin: 0;
}

.btn-follow {
    padding: 6px 16px;
    background: var(--gradient-primary);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    cursor: pointer;
    transition: all var(--duration-fast);
}

.btn-follow:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.game-title {
    grid-column: 2;
    grid-row: 2;
    font-size: 27px;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
}

.game-description {
    font-size: 20px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: var(--space-4);
    background: transparent;
    padding-left: calc(64px + var(--space-3));
}

.description-text {
    max-height: 4.8em;
    overflow: hidden;
    position: relative;
}

.description-text--expanded {
    max-height: none;
}

.read-more {
    color: var(--brand-primary);
    cursor: pointer;
    font-size: var(--text-sm);
    text-decoration: none;
}

.read-more:hover {
    text-decoration: underline;
}

.game-tags-actions-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
    padding-left: calc(64px + var(--space-3));
}

.game-tags {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.action-buttons {
    display: flex;
    gap: var(--space-3);
    align-items: center;
}

.action-btn {
    width: 48px;
    height: 48px;
    background: #ffffff;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--duration-fast);
}

.action-btn:hover {
    background: #f5f5f5;
    border-color: var(--brand-primary);
}

.action-btn img {
    width: 24px;
    height: 24px;
    opacity: 0.8;
    filter: brightness(0.3) saturate(1);
}

.action-btn:hover img {
    opacity: 1;
    filter: brightness(0.2) saturate(1);
}

.action-btn--active {
    background: rgba(124, 58, 237, 0.2);
    border-color: var(--brand-primary);
}

.btn-share {
    margin-left: auto;
    padding: 12px 24px;
    width: auto;
    gap: var(--space-2);
}

.btn-share img {
    width: 20px;
    height: 20px;
}

.btn-share span {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
}

/* Share Button - Top Right Positioned */
.btn-share-top {
    position: absolute;
    top: var(--space-6);
    right: var(--space-6);
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    transition: all var(--duration-fast);
    z-index: 10;
}

.btn-share-top:hover {
    background: var(--bg-hover);
    border-color: var(--brand-primary);
}

.btn-share-top img {
    width: 20px;
    height: 20px;
    opacity: 0.7;
    filter: brightness(1.3) saturate(0.8);
}

.btn-share-top:hover img {
    opacity: 0.9;
    filter: brightness(1.5) saturate(0.9);
}

.btn-share-top span {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-primary);
}

/* Chat Panel (Stats + Chat Integrated) */
.chat-panel {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin-top: var(--space-6);
    margin-right: var(--space-6); /* Right gap for balanced layout */
    align-self: start;
    height: auto;
    max-height: calc(100vh - var(--topbar-height) - 120px); /* Match game viewer height */
    min-height: calc(100vh - var(--topbar-height) - 120px); /* Match game viewer height */
    width: 400px;
}

/* Stats Bar - Top section of chat panel */
.stats-bar {
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    padding: var(--space-7) var(--space-8) var(--space-4);
    background: rgba(55, 59, 86, 0.5);
    position: relative;
}

.stats-bar .action-btn {
    position: absolute;
    top: -12px;
    right: 16px;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    background: var(--bg-card);
}

.stats-bar .action-btn img {
    opacity: 0.7;
    filter: brightness(1.3) saturate(0.8);
}

.stats-bar .action-btn:hover {
    background: var(--bg-hover);
}

.stats-bar .action-btn:hover img {
    opacity: 0.9;
    filter: brightness(1.5) saturate(0.9);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
}

.stat-item__icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-item__icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.stat-item__count {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
}

.stat-item__label {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

/* Chat Tabs */
.chat-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-default);
}

.chat-tab {
    flex: 1;
    padding: var(--space-3) var(--space-4);
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    font-size: var(--text-base);
    font-weight: var(--font-medium);
    cursor: pointer;
    transition: all var(--duration-fast);
    position: relative;
}

.chat-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.chat-tab--active {
    color: var(--text-primary);
}

.chat-tab--active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--brand-primary);
}

/* Chat Content */
.chat-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
    min-height: 0;
}

.comment-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.comment-item {
    display: flex;
    gap: var(--space-3);
    position: relative;
}

.comment-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: var(--font-semibold);
    flex-shrink: 0;
}

.comment-content {
    flex: 1;
    min-width: 0;
}

.comment-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-1);
}

.comment-author {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
}

.comment-time {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

/* Comment menu button (3-dot menu) - Figma style */
.comment-menu-btn {
    margin-left: auto;
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    padding: 0;
    border-radius: 4px;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.comment-menu-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* Comment dropdown menu - Figma style */
.comment-dropdown {
    position: absolute;
    right: 8px;
    top: 36px;
    background: #2a2d42;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.2);
    padding: 4px;
    z-index: 100;
    min-width: 120px;
}

/* Delete button - Red text like Figma */
.comment-delete-btn {
    width: 100%;
    padding: 8px 12px;
    background: transparent;
    border: none;
    color: #ef4444;
    text-align: left;
    cursor: pointer;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s ease;
}

.comment-delete-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* Legacy menu button (kept for compatibility) */
.comment-menu {
    margin-left: auto;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 18px;
}

.comment-text {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.5;
    word-wrap: break-word;
}

/* Message Input */
.message-input-container {
    padding: var(--space-4);
    border-top: 1px solid var(--border-default);
    background: rgba(42, 45, 66, 0.5);
}

.message-input-row {
    display: flex;
    gap: var(--space-2);
}

.message-input {
    flex: 1;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-family: var(--font-primary);
}

.message-input::placeholder {
    color: var(--text-tertiary);
}

.btn-send {
    padding: var(--space-3) var(--space-5);
    background: var(--gradient-primary);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    cursor: pointer;
    transition: all var(--duration-fast);
}

.btn-send:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Leaderboard Section */
.leaderboard-content {
    padding: var(--space-4);
}

.leaderboard-row {
    display: grid;
    grid-template-columns: 40px 1fr auto auto;
    gap: var(--space-3);
    padding: var(--space-3);
    align-items: center;
    border-bottom: 1px solid var(--border-light);
}

.leaderboard-row:last-child {
    border-bottom: none;
}

.leaderboard-rank {
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    color: var(--text-tertiary);
    text-align: center;
}

.leaderboard-rank--top {
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.leaderboard-player {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.leaderboard-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: var(--font-semibold);
}

.leaderboard-name {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-primary);
}

.leaderboard-score {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--text-accent);
}

.leaderboard-change {
    font-size: var(--text-xs);
    display: flex;
    align-items: center;
    gap: 4px;
}

.leaderboard-change--up {
    color: var(--accent-green);
}

.leaderboard-change--down {
    color: #f87171;
}

.leaderboard-change img {
    width: 12px;
    height: 12px;
}

/* Hidden Elements */
.hidden {
    display: none !important;
}

/* Game Loading Indicator */
.game-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 16px;
    z-index: 5;
    display: none;
}

/* Responsive Design */
@media (max-width: 1280px) {
    .game-viewer {
        max-width: 700px;
    }

    .chat-panel {
        min-width: 300px;
    }
}

@media (max-width: 1024px) {
    body {
        grid-template-columns: 56px 1fr;
        grid-template-areas:
            "header header"
            "sidebar main-content";
    }

    .game-area {
        grid-area: main-content;
    }

    .chat-panel {
        grid-area: auto;
        width: 100%;
        max-width: none;
        margin-top: var(--space-6);
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        position: fixed;
    }

    .sidebar--open {
        transform: translateX(0);
    }

    body {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "main-content";
    }

    .game-viewer {
        aspect-ratio: 4 / 3;
    }

    .creator-section {
        flex-direction: column;
    }

    .btn-follow {
        position: static;
        width: 100%;
    }

    .stats-bar {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
    }
}
