/* Force browser to respect EXIF rotation */
img {
    image-orientation: from-image;
}

:root {
    --bg: #0f172a; --card: #1e293b; --text: #f8fafc;
    --primary: #6366f1; --primary-hover: #4f46e5;
    --secondary: #475569; --border: #334155; --lock: #fbbf24;
    --text-dim: #94a3b8; --danger: #ef4444; --draft: #f59e0b;
    --input-bg: rgba(15, 23, 42, 0.6);
}
* { box-sizing: border-box; }
body { background: var(--bg); color: var(--text); font-family: 'Noto Sans KR', sans-serif; margin: 0; user-select: none; overflow-x: hidden; }
.hidden { display: none !important; }
.container { max-width: 1200px; margin: 0 auto; padding: 15px; }

/* Modal Styles */
.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 2000;
    display: flex; align-items: center; justify-content: center;
}
.modal-content {
    background: var(--card); padding: 30px; border-radius: 20px;
    width: 90%; max-width: 480px; border: 1px solid var(--border);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); position: relative;
    max-height: 90vh; overflow-y: auto;
}

nav { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem 1.5rem; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1000; }
.logo { font-size: 1.3rem; font-weight: 900; color: var(--primary); cursor: pointer; flex-shrink: 0; }
.nav-right { display: flex; align-items: center; gap: 12px; }
.nav-actions { display: flex; align-items: center; gap: 10px; flex-direction: row !important; }
.nav-actions button { white-space: nowrap; height: 44px; display: flex; align-items: center; padding: 0 18px; }

.user-badge-container {
    background: rgba(99, 102, 241, 0.1); padding: 0 15px; height: 44px;
    border-radius: 12px; border: 1px solid var(--primary);
    display: flex; align-items: center; justify-content: center; transition: 0.2s;
}
.user-badge-container:hover { background: rgba(99, 102, 241, 0.3); }
#user-display { color: var(--primary); font-weight: 700; font-size: 0.95rem; white-space: nowrap; }

.auth-box { max-width:400px; margin: 80px auto; text-align:center; background:var(--card); padding:40px; border-radius:25px; border:1px solid var(--border); }
.search-container { margin-bottom: 25px; }
.main-search-bar { width: 100%; padding: 15px 20px; font-size: 1.1rem; border-radius: 15px; background: var(--card); border: 2px solid var(--border); color: #fff; outline: none; transition: 0.3s; }
.main-search-bar:focus { border-color: var(--primary); box-shadow: 0 0 15px rgba(99,102,241,0.2); }

/* Filter Toolbar */
.filter-toolbar { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 10px; }
.sort-toggle-btn { flex: 1; display: flex; align-items: center; justify-content: space-between; padding: 0 15px; height: 40px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; color: var(--text); font-size: 0.95rem; cursor: pointer; transition: 0.2s; }
.sort-toggle-btn:hover { border-color: var(--primary); }
#sort-options { display: none; flex-wrap: wrap; gap: 8px; background: rgba(0,0,0,0.3); padding: 15px; border-radius: 12px; margin-top: 10px; border: 1px solid var(--border); animation: fadeIn 0.2s ease-out; }
#sort-options.expanded { display: flex; }

.pw-container { position: relative; width: 100%; display: flex; align-items: center; }
.pw-toggle { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); cursor: pointer; color: var(--text-dim); font-size: 1.2rem; z-index: 10; filter: grayscale(100%) contrast(0.5); opacity: 0.7; display: flex; align-items: center; justify-content: center; }
.pw-toggle:hover { opacity: 1; }

input[type="text"], input[type="password"], input[type="email"] { background: var(--input-bg); border: 1px solid var(--border); color: #fff; padding: 14px 16px; border-radius: 12px; outline: none; transition: 0.3s; width: 100%; }

.btn-row { display: grid; grid-template-columns: 2fr 1.2fr 1fr; gap: 12px; }
.btn-row button, .btn-danger-large { height: 54px; font-size: 1.05rem; }

#file-preview-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 15px; margin-top: 15px; }
.preview-item { background: rgba(255,255,255,0.03); border-radius: 12px; border: 1px solid var(--border); position: relative; padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow: hidden; }
.preview-media { width: 100%; aspect-ratio: 16/9; object-fit: contain; background: #000; border-radius: 8px; display: block; cursor: pointer; }
.preview-input { width: 100%; font-size: 0.8rem; padding: 8px; border-radius: 6px; background: #000; border: 1px solid var(--border); color: #fff; margin-top: 0; }

.preview-del { 
    position: absolute; 
    top: 5px; 
    right: 5px; 
    background: var(--danger); 
    color: #fff; 
    border-radius: 50%; 
    width: 26px; 
    height: 26px; 
    font-size: 12px; 
    border: 2px solid var(--card); 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    z-index: 10; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.preview-rotate {
    position: absolute;
    top: 5px;
    right: 36px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    font-size: 14px;
    border: 2px solid var(--card);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.preview-rotate:hover {
    background: var(--primary-hover);
    transform: rotate(90deg);
}

.collab-box { margin: 25px 0; background: rgba(0,0,0,0.1); padding: 15px; border-radius: 15px; border: 1px dashed var(--border); }
.collab-item { background: var(--primary); padding: 5px 12px; border-radius: 20px; font-size: 0.9rem; display: flex; align-items: center; gap: 8px; margin-top: 5px;}
.collab-badge { font-size: 0.7rem; background: rgba(0,0,0,0.2); padding: 2px 6px; border-radius: 4px; margin-left: 5px; }
.collab-del { cursor: pointer; font-weight: bold; opacity: 0.7; }
.collab-del:hover { opacity: 1; }

#user-search-results, .result-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: var(--card); border: 1px solid var(--border); border-radius: 12px; z-index: 100; max-height: 200px; overflow-y: auto; box-shadow: 0 4px 15px rgba(0,0,0,0.5); margin-top: 5px; }
.search-result-item { padding: 12px 15px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,0.05); transition: 0.2s; }
.search-result-item:hover { background: var(--primary); color: #fff; }

.option-row { display:flex; justify-content: space-between; align-items: center; margin: 30px 0; background: rgba(0,0,0,0.1); padding: 20px; border-radius: 15px; }

/* [FIXED] Game Flex Container */
.game-flex { display: flex; gap: 20px; height: 72vh; max-width: 1000px; margin: 20px auto; align-items: stretch; position: relative; }

/* [FIXED] Match Card */
.match-card { 
    flex: 1; 
    min-width: 0; 
    border-radius: 24px; 
    overflow: hidden; 
    cursor: pointer; 
    background: #000; 
    display: flex; 
    flex-direction: column; 
    border: 3px solid var(--border); 
    /* Smoothly animate flex-grow to create the push effect */
    transition: flex 0.8s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.8s ease, transform 0.8s ease, border-width 0.8s; 
    position: relative; 
}

.match-card:hover { border-color: var(--primary); transform: scale(1.02); z-index: 5; }

/* [FIXED] Winner: Expands to fill the entire container */
.anim-expand { 
    flex: 100 !important; /* Dominates the flex container */
    z-index: 20; 
    border-color: var(--primary); 
    transform: scale(1);
    opacity: 1;
}

/* [FIXED] Loser: Shrinks to 0 width (pushed out) and fades */
.anim-shrink { 
    flex: 0 !important; 
    min-width: 0 !important;
    opacity: 0 !important; 
    border-width: 0 !important; /* Hide border so it doesn't leave a line */
    pointer-events: none;
    transform: scale(0.9);
}

/* [FIXED] Media Container */
.media-container { 
    flex: 1; 
    width: 100%; 
    height: 100%;
    background: #000; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    position: relative; 
    overflow: hidden;
}

/* [FIXED] Images/Videos inside game: Force contain */
.media-container img, 
.media-container video { 
    display: block; 
    width: auto; 
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain !important; /* Prevents distortion */
}

/* [FIXED] YouTube Container needs to fill space */
.media-container .iframe-container {
    width: 100% !important;
    height: 100% !important;
    border: none;
}
.iframe-container iframe { 
    width: 100%; 
    height: 100%; 
    object-fit: contain; 
    border: none; 
}

.anim-winner-fullscreen { position: absolute !important; top: 0; left: 0; width: 100% !important; height: 100% !important; z-index: 50; border-color: var(--primary); transform: none !important; flex: none !important; transition: all 0.4s ease-out; }
.anim-text-hero span { display: block; animation: textHeroPop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }
@keyframes textHeroPop { 0% { opacity: 0; transform: translateY(100px) scale(0.5); } 100% { opacity: 1; transform: translateY(0) scale(2.0); } }
.anim-text-pop { animation: textPopUp 0.5s ease-out forwards; }
@keyframes textPopUp { 0% { opacity:0; transform:translateY(20px); } 100% { opacity:1; transform:translateY(0); } }

.name-tag-static { background: #1e293b; padding: 20px 10px; text-align: center; border-top: 2px solid var(--border); flex-shrink: 0; transition: all 0.5s; }
.name-tag-static span { font-weight: 900; font-size: clamp(1rem, 2.5vh, 1.6rem); color: #fff; word-break: keep-all; }

/* Watermark */
.watermark { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-25deg); font-size: clamp(2rem, 6vw, 5rem); font-weight: 900; color: rgba(255, 255, 255, 0.1); pointer-events: none; z-index: 10; white-space: nowrap; mix-blend-mode: overlay; }

.vs-badge { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) skewX(-15deg); font-size: 4rem; font-weight: 900; color: #fff; -webkit-text-stroke: 3px #f97316; text-shadow: 4px 4px 0px #c2410c; z-index: 20; pointer-events: none; font-style: italic; transition: opacity 0.2s; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 25px; margin-top: 20px; }
.cup-card { background: var(--card); border-radius: 20px; border: 1px solid var(--border); overflow: hidden; transition: 0.3s; position: relative; }
.thumb-wrap { position: relative; width: 100%; aspect-ratio: 16/9; background: #000; overflow: hidden; }
.thumb-wrap img, .thumb-wrap video { width: 100%; height: 100%; object-fit: cover; }
.draft-badge { position: absolute; top: 10px; left: 10px; background: var(--draft); color: #000; padding: 4px 10px; border-radius: 6px; font-weight: bold; font-size: 0.8rem; z-index: 3; }
.creator-tooltip { cursor: help; text-decoration: underline; text-decoration-style: dotted; }
.creator-link { cursor: pointer; text-decoration: underline; text-decoration-style: dotted; transition: 0.2s; }
.creator-link:hover { color: var(--primary); }

button { border: none; font-weight: 700; cursor: pointer; transition: 0.2s; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.upload-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 9999; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.progress-box { width: 80%; max-width: 400px; background: #334155; height: 12px; border-radius: 6px; overflow: hidden; margin: 20px 0; }
#upload-fill { width: 0%; height: 100%; background: var(--primary); transition: 0.1s; }

.ranking-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 15px; }
.ranking-scroll-area { max-height: 500px; overflow-y: auto; margin-bottom: 0; border: 1px solid var(--border); border-radius: 15px; }
.comment-scroll-area { height: 440px; overflow-y: auto; background: rgba(0,0,0,0.2); padding: 15px; border-radius: 15px; border: 1px solid var(--border); }

.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 20px; border-radius: 12px; border: 1px solid var(--border); }
.rank-bar-bg { width: 100%; height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.rank-bar-fill { height: 100%; background: var(--primary); border-radius: 3px; }
.rank-table { width: 100%; border-collapse: collapse; margin-top: 0; table-layout: fixed; min-width: 500px; }
.rank-table th, .rank-table td { padding: 12px 5px; text-align: center; border-bottom: 1px solid var(--border); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-table th { background: var(--card); font-weight: bold; color: var(--text-dim); font-size: 0.9rem; position: sticky; top: 0; z-index: 10; } 
.rank-table tr:hover { background: rgba(255,255,255,0.03); }
.rank-num { font-weight: 900; color: var(--primary); font-size: 1.1rem; }
.rank-thumb { width: 80px; height: 60px; overflow: hidden; border-radius: 6px; cursor: pointer; display: inline-block; vertical-align: middle; }
.rank-thumb img, .rank-thumb video { width: 100%; height: 100%; object-fit: cover; }
.rank-name { font-weight: bold; font-size: 1rem; }
.rank-stat { font-size: 0.95rem; }
.rank-sub { font-size: 0.75rem; color: var(--text-dim); display: block; margin-top: 2px; }

.comment-item { margin-bottom: 10px; position: relative; padding: 10px; background: rgba(255,255,255,0.05); border-radius: 10px; word-break: break-all; overflow-wrap: break-word; }
.reply-item { margin-top: 8px; margin-left: 20px; padding: 8px; border-left: 2px solid var(--border); background: rgba(0,0,0,0.2); border-radius: 0 8px 8px 0; position: relative; font-size: 0.9rem; }
.del-btn { color: var(--danger); cursor: pointer; font-weight: bold; position: absolute; top: 8px; right: 8px; font-size: 0.9rem; }

.tag-chip { display: inline-block; padding: 4px 10px; border-radius: 15px; background: rgba(99,102,241,0.2); color: #fff; font-size: 0.8rem; cursor: pointer; white-space: nowrap; border: 1px solid var(--primary); transition: 0.2s; margin-right: 5px; margin-bottom: 5px; }
.tag-chip:hover, .tag-chip.active { background: var(--primary); }
#tag-filters { margin-top: 10px; display: none; flex-wrap: wrap; gap: 5px; background: rgba(0,0,0,0.2); padding: 10px; border-radius: 10px; }
#tag-filters.expanded { display: flex; }
.hashtag-search-container { position: relative; margin-top: 8px; }
#create-tag-results { position: absolute; top: 100%; left: 0; right: 0; background: var(--card); border: 1px solid var(--primary); border-radius: 0 0 10px 10px; z-index: 50; max-height: 200px; overflow-y: auto; }

.icon-btn { background: transparent; border: 1px solid var(--border); color: #fff; padding: 8px 15px; border-radius: 20px; cursor: pointer; display: flex; align-items: center; gap: 5px; font-size: 0.9rem; transition: 0.2s; }
.icon-btn:hover, .icon-btn.active { background: rgba(255,255,255,0.1); border-color: #fff; }
.icon-btn.liked { color: #f43f5e; border-color: #f43f5e; background: rgba(244, 63, 94, 0.1); }
.icon-btn.bookmarked { color: #fbbf24; border-color: #fbbf24; background: rgba(251, 191, 36, 0.1); }
.active-tab { background: var(--primary) !important; color: #fff; border-color: var(--primary); }
.iframe-container { position: relative; width: 100%; height: 100%; overflow: hidden; }
.rank-thumb iframe { width: 100%; height: 100%; pointer-events: none; }

.control-row { display: flex; gap: 10px; }
.admin-tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.admin-tab-btn { padding: 12px 20px; background: transparent; color: var(--text-dim); font-size: 1rem; border-radius: 12px 12px 0 0; border: none; cursor: pointer; }
.admin-tab-btn:hover { color: #fff; background: rgba(255,255,255,0.05); }
.admin-tab-btn.active { color: var(--primary); font-weight: bold; border-bottom: 3px solid var(--primary); background: rgba(99, 102, 241, 0.1); }

.report-group { background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 15px; overflow: hidden; }
.report-header { background: rgba(0,0,0,0.2); padding: 10px 15px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); }
.report-title { font-weight: bold; color: var(--primary); cursor: pointer; }
.report-count { font-size: 0.8rem; background: var(--danger); color: white; padding: 2px 6px; border-radius: 10px; }
.report-details { padding: 10px; }
.report-item-row { display: flex; justify-content: space-between; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.report-item-row:last-child { border-bottom: none; }
.reason-badge { background: rgba(244, 63, 94, 0.1); color: #f43f5e; padding: 4px 8px; border-radius: 6px; font-weight: bold; font-size: 0.9rem; display: inline-block; }
.trash-item { display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,0.03); border: 1px solid var(--border); padding: 15px; border-radius: 12px; margin-bottom: 10px; }
.intro-thumb-wrap img, .intro-thumb-wrap video { width: 100%; height: 100%; object-fit: cover; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 768px) {
    .container { padding: 10px; }
    nav { padding: 0.8rem 1rem; }
    .nav-right { overflow-x: auto; max-width: 70vw; padding-bottom: 5px; }
    .nav-actions button { padding: 0 10px; font-size: 0.8rem; height: 36px; }
    .user-badge-container { height: 36px; padding: 0 8px; }
    .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .cup-card { border-radius: 12px; }
    .cup-card h3 { font-size: 0.95rem !important; } 
    .cup-card p { font-size: 0.75rem !important; margin: 8px 0 !important; }
    .cup-card .btn-primary, .cup-card .btn-outline { height: 32px; font-size: 0.8rem; padding: 0 5px; }
    #file-preview-list { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .preview-media { height: auto; aspect-ratio: 16/9; } 
    .mobile-stack { grid-template-columns: 1fr !important; }
    .btn-row { display: flex; gap: 8px; }
    .btn-row button { flex: 1; font-size: 0.8rem; padding: 0 5px; }
    .control-row button { font-size: 0.8rem; padding: 0 10px; }
    .option-row { flex-direction: column; gap: 15px; align-items: stretch; }
    .pw-container { width: 100% !important; }
    .ranking-layout { display: block; }
    .ranking-scroll-area { max-height: none; overflow: visible; margin-bottom: 30px; border: none; }
    .table-responsive { border: 1px solid var(--border); } 
    .comment-scroll-area { height: 300px; }
    .rank-table th { font-size: 0.75rem; padding: 8px 4px; }
    .rank-table td { font-size: 0.8rem; padding: 8px 4px; }
    .rank-thumb { width: 50px; height: 40px; }
    .game-flex { flex-direction: row; height: auto; }
    .match-card { height: 40vh; }
    .name-tag-static span { font-size: 0.9rem; } 
    .admin-input-group { flex-direction: column; }
    .admin-tab-btn { padding: 10px 10px; font-size: 0.9rem; }
}