/* ===== Light (일반모드) : 기본 ===== */
:root {
	--bg: #f3f5fa;
	--surface: #ffffff;
	--surface-2: #eceff5;
	--border: #dfe3ec;
	--text: #1b1e28;
	--muted: #626878;
	--accent: #6c5ce7;
	--accent-2: #0aa6b6;
	--shadow: 0 10px 24px rgba(20, 24, 45, .10);
	--radius: 12px;
	color-scheme: light;
}

/* ===== Dark (다크모드) ===== */
[data-theme="dark"] {
	--bg: #0f1220;
	--surface: #191d2e;
	--surface-2: #232840;
	--border: #2f3557;
	--text: #e8eaf2;
	--muted: #9aa0b5;
	--accent: #7c6cf0;
	--accent-2: #00d2d3;
	--shadow: 0 10px 24px rgba(0, 0, 0, .40);
	color-scheme: dark;
}

* { box-sizing: border-box; }

body {
	margin: 0;
	font-family: "Segoe UI", Roboto, "Malgun Gothic", sans-serif;
	background: var(--bg);
	color: var(--text);
	line-height: 1.5;
	transition: background-color .2s ease, color .2s ease;
}

a { color: inherit; text-decoration: none; }

/* ================= App shell (3분할) ================= */
:root { --topbar-h: 56px; --sidebar-w: 250px; --right-w: 300px; }

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

/* --- Top bar --- */
.topbar {
	height: var(--topbar-h);
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 0 20px;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	position: sticky;
	top: 0;
	z-index: 30;
}
.brand { font-size: 20px; font-weight: 800; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* 테마(라이트/다크) 전환 버튼 */
.theme-toggle {
	width: 38px;
	height: 38px;
	border: 1px solid var(--border);
	border-radius: 50%;
	background: var(--surface-2);
	color: var(--text);
	font-size: 16px;
	line-height: 1;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	transition: background-color .15s ease, transform .1s ease;
}
.theme-toggle:hover { transform: translateY(-1px); }

/* 언어 선택기 */
.lang-menu { position: relative; }
.lang-toggle {
	display: flex;
	align-items: center;
	gap: 6px;
	background: var(--surface-2);
	border: none;
	color: var(--text);
	padding: 6px 10px;
	border-radius: 20px;
	font-size: 13px;
	cursor: pointer;
}
.lang-menu .dropdown {
	display: none;
	position: absolute;
	right: 0;
	top: calc(100% + 8px);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 10px;
	min-width: 150px;
	overflow: hidden;
	box-shadow: var(--shadow);
	z-index: 40;
}
.lang-menu .dropdown.open { display: block; }
.lang-menu .dropdown a {
	display: block;
	padding: 9px 14px;
	font-size: 14px;
	color: var(--text);
}
.lang-menu .dropdown a:hover { background: var(--surface-2); }
.lang-menu .dropdown a.active { color: var(--accent-2); font-weight: 700; }
.side-toggle {
	display: none;
	background: none;
	border: none;
	color: var(--text);
	font-size: 20px;
	cursor: pointer;
}

/* --- Body grid: sidebar | main | right --- */
.app-body {
	flex: 1;
	display: grid;
	grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--right-w);
	align-items: start;
}
.app-body.no-right { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }

/* --- Left sidebar (2뎁스 메뉴) --- */
.app-sidebar {
	position: sticky;
	top: var(--topbar-h);
	height: calc(100vh - var(--topbar-h));
	overflow-y: auto;
	background: var(--surface);
	border-right: 1px solid var(--border);
	padding: 16px 12px;
}
.side-search { display: flex; margin-bottom: 14px; }
.side-search input {
	flex: 1;
	min-width: 0;
	padding: 8px 10px;
	border: 1px solid var(--border);
	border-radius: 8px 0 0 8px;
	background: var(--bg);
	color: var(--text);
}
.side-search button {
	padding: 8px 12px;
	border: none;
	border-radius: 0 8px 8px 0;
	background: var(--accent);
	color: #fff;
	cursor: pointer;
}
.side-nav { display: flex; flex-direction: column; gap: 1px; }
.side-all, .side-games a {
	display: flex;
	align-items: center;
	padding: 6px 12px;
	border-radius: 8px;
	font-size: 13px;
	color: var(--muted);
	cursor: pointer;
}
.side-all { font-weight: 700; color: var(--text); }
.side-all:hover, .side-games a:hover { background: var(--surface-2); color: var(--text); }
.side-all.active, .side-games a.active { background: var(--accent); color: #fff; }

/* depth1: 타입 헤더 (항상 표시, 접기 없음) */
.side-cat { margin-top: 6px; }
.side-cat-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 4px 12px;
}
.side-cat-name {
	flex: 1;
	font-size: 12px;
	font-weight: 700;
	letter-spacing: .04em;
	text-transform: uppercase;
	color: var(--muted);
}
.side-cat-head.active .side-cat-name { color: var(--accent-2); }
.side-cat-count {
	font-size: 11px;
	color: var(--muted);
	background: var(--surface-2);
	border-radius: 20px;
	padding: 1px 8px;
}
/* depth2: 게임 목록 */
.side-games { list-style: none; margin: 1px 0 0; padding: 0; }
.side-games a { padding: 5px 12px 5px 18px; font-size: 12.5px; }
.side-empty { padding: 5px 18px; font-size: 12px; color: var(--muted); }

/* --- Main & right columns --- */
.app-main { padding: 24px; min-width: 0; }
.app-right {
	position: sticky;
	top: var(--topbar-h);
	max-height: calc(100vh - var(--topbar-h));
	overflow-y: auto;
	padding: 24px 20px;
	border-left: 1px solid var(--border);
}

/* --- Banner ads --- */
.ad-banner {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	text-align: center;
	background: repeating-linear-gradient(45deg, var(--surface), var(--surface) 12px, var(--surface-2) 12px, var(--surface-2) 24px);
	border: 1px dashed var(--border);
	border-radius: var(--radius);
	color: var(--muted);
	margin-bottom: 16px;
	min-height: 180px;
}
.ad-banner.tall { min-height: 320px; }
.ad-banner .ad-label {
	position: absolute;
	top: 8px;
	left: 8px;
	font-size: 10px;
	font-weight: 700;
	letter-spacing: 1px;
	background: var(--bg);
	padding: 2px 6px;
	border-radius: 4px;
}
.ad-banner .ad-body strong { display: block; color: var(--text); }
.ad-slot { margin-top: 20px; }

/* ---------- Hero ---------- */
.hero {
	background: linear-gradient(135deg, var(--accent), var(--accent-2));
	border-radius: var(--radius);
	padding: 40px 30px;
	margin: 0 0 24px;
}
.hero h1 { margin: 0 0 8px; font-size: 28px; }
.hero p { margin: 0; opacity: .9; }

/* ---------- Blocks ---------- */
.block { margin: 32px 0; }
.block-head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	margin-bottom: 16px;
}
.block-head h2 { margin: 0; font-size: 20px; }
.more { color: var(--accent-2); font-size: 14px; }

/* ---------- Game grid ---------- */
.game-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
	gap: 16px;
}
.game-card {
	background: var(--surface);
	border-radius: var(--radius);
	overflow: hidden;
	transition: transform .12s ease, box-shadow .12s ease;
	border: 1px solid var(--border);
}
.game-card:hover {
	transform: translateY(-4px);
	box-shadow: var(--shadow);
}
.game-card .thumb { aspect-ratio: 4 / 3; background: var(--surface-2); }
.game-card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.game-card .meta { padding: 10px 12px; }
.game-card h3 { margin: 0 0 6px; font-size: 15px; }
.cat, .plays, .provider {
	display: inline-block;
	font-size: 12px;
	color: var(--muted);
	margin-right: 8px;
}
.cat {
	background: var(--surface-2);
	padding: 2px 8px;
	border-radius: 20px;
}

/* ---------- Play page ---------- */
.play-title { margin: 0 0 16px; font-size: 22px; }

/* 내 순위 배너 */
.my-rank {
	margin: 0 0 16px;
	padding: 10px 16px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--surface-2);
}
.my-rank .mr-line {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-wrap: wrap;
	font-size: 14px;
	color: var(--text);
}
.my-rank .mr-badge { font-size: 18px; }
.my-rank .mr-label { color: var(--muted); }
.my-rank .mr-pos b { font-size: 20px; color: var(--accent); }
.my-rank .mr-pos .mr-total { color: var(--muted); }
.my-rank .mr-best { margin-left: auto; font-weight: 600; color: var(--accent-2); }
.my-rank .mr-none, .my-rank .mr-login { color: var(--muted); }
.game-frame {
	position: relative;
	width: 100%;
	aspect-ratio: 16 / 9;
	background: #000;
	border-radius: var(--radius);
	overflow: hidden;
}
.game-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.game-info { margin-top: 16px; }
.game-info p { color: var(--muted); margin-top: 12px; }

/* ---------- Pagination ---------- */
.pagination {
	display: flex;
	gap: 16px;
	align-items: center;
	justify-content: center;
	margin-top: 24px;
}
.pagination a {
	color: var(--accent-2);
	padding: 6px 12px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
}

.empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* ---------- Footer ---------- */
.site-footer {
	border-top: 1px solid var(--border);
	margin-top: 48px;
	padding-top: 20px;
	color: var(--muted);
	font-size: 13px;
	text-align: center;
}
.site-footer p { margin: 0; }

/* ---------- Auth (topbar) ---------- */
.btn-login {
	padding: 8px 18px;
	border: none;
	border-radius: var(--radius);
	background: var(--accent);
	color: #fff;
	font-weight: 600;
	cursor: pointer;
}
.btn-login:hover { filter: brightness(1.1); }

.profile-menu { position: relative; }
.profile-toggle {
	display: flex;
	align-items: center;
	gap: 8px;
	background: var(--surface-2);
	border: none;
	color: var(--text);
	padding: 6px 12px;
	border-radius: 20px;
	cursor: pointer;
}
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.profile-menu .dropdown {
	display: none;
	position: absolute;
	right: 0;
	top: calc(100% + 8px);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 10px;
	min-width: 160px;
	overflow: hidden;
	box-shadow: var(--shadow);
}
.profile-menu .dropdown.open { display: block; }
.profile-menu .dropdown a,
.profile-menu .dropdown button {
	display: block;
	width: 100%;
	text-align: left;
	padding: 10px 14px;
	background: none;
	border: none;
	color: var(--text);
	font-size: 14px;
	cursor: pointer;
}
.profile-menu .dropdown a:hover,
.profile-menu .dropdown button:hover { background: var(--surface-2); }

/* ---------- Login modal ---------- */
.modal-overlay {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 1000;
	background: rgba(6, 8, 18, .72);
	backdrop-filter: blur(3px);
	align-items: center;
	justify-content: center;
	padding: 20px;
	animation: fadeIn .15s ease;
}
.modal-overlay.open { display: flex; }
body.modal-open { overflow: hidden; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
	from { opacity: 0; transform: translateY(12px) scale(.98); }
	to   { opacity: 1; transform: none; }
}

.modal {
	position: relative;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 18px;
	width: 100%;
	max-width: 380px;
	padding: 34px 28px 26px;
	box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
	animation: popIn .18s ease;
}
.modal-close {
	position: absolute;
	top: 14px;
	right: 14px;
	width: 32px;
	height: 32px;
	border: none;
	border-radius: 50%;
	background: var(--surface-2);
	color: var(--muted);
	font-size: 15px;
	cursor: pointer;
	line-height: 1;
}
.modal-close:hover { color: var(--text); }

.login-modal-head { text-align: center; margin-bottom: 22px; }
.login-logo {
	width: 60px;
	height: 60px;
	margin: 0 auto 12px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 30px;
	border-radius: 18px;
	background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.login-modal-head h2 { margin: 0 0 6px; font-size: 20px; }
.login-modal-head p { margin: 0; color: var(--muted); font-size: 14px; }

/* 소셜 버튼: 아이콘 + 브랜드 컬러 */
.social-buttons { display: flex; flex-direction: column; gap: 10px; }
.social {
	position: relative;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 16px;
	border-radius: 12px;
	font-weight: 700;
	font-size: 14.5px;
	border: 1px solid transparent;
	transition: transform .1s ease, filter .1s ease, box-shadow .1s ease;
}
.social:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(0,0,0,.35); }
.social:active { transform: translateY(0); }
.social-ico {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 22px;
}
/* 라벨을 아이콘과 무관하게 가운데 정렬 */
.social-label { flex: 1; text-align: center; margin-right: 22px; }

.social-google { background: #ffffff; color: #1f1f1f; border-color: #dadce0; }
.social-kakao  { background: #FEE500; color: #191600; }
.social-naver  { background: #03C75A; color: #ffffff; }

.modal-note {
	margin: 18px 0 0;
	font-size: 11.5px;
	color: var(--muted);
	text-align: center;
	line-height: 1.6;
}

/* 공용 알림 모달 (alert 대체) */
.notice-modal { max-width: 340px; text-align: center; padding: 30px 26px 24px; }
.notice-msg { margin: 4px 0 20px; font-size: 15px; line-height: 1.6; }
.notice-ok { min-width: 110px; }

/* 폴백 /login 단독 페이지 */
.popup-body {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 100vh;
	padding: 24px;
}
.login-modal.standalone { animation: none; }
.back-home {
	display: block;
	text-align: center;
	margin-top: 16px;
	color: var(--muted);
	font-size: 13px;
}
.back-home:hover { color: var(--text); }

/* ---------- Profile ---------- */
.profile-card {
	display: grid;
	gap: 12px;
	max-width: 480px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 24px;
}
.profile-avatar, .profile-card dl { grid-column: 1; }
.profile-avatar { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; }
.profile-card dl { display: grid; grid-template-columns: 80px 1fr; gap: 8px 12px; margin: 0; }
.profile-card dt { color: var(--muted); }

.form { max-width: 480px; display: grid; gap: 18px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 14px; color: var(--muted); }
.field input, .field select {
	padding: 10px 12px;
	border: 1px solid var(--border);
	border-radius: 10px;
	background: var(--bg);
	color: var(--text);
}
.field .error { color: #ff6b6b; font-size: 13px; }
.actions { display: flex; gap: 12px; }
.btn-primary {
	padding: 10px 20px;
	border: none;
	border-radius: 10px;
	background: var(--accent);
	color: #fff;
	font-weight: 600;
	cursor: pointer;
}
.btn-cancel {
	padding: 10px 20px;
	border-radius: 10px;
	border: 1px solid var(--border);
	color: var(--muted);
	display: inline-flex;
	align-items: center;
}

/* ---------- Leaderboard (right column) ---------- */
.leaderboard .block-head { margin-bottom: 12px; }
.leaderboard .block-head h2 { font-size: 18px; }
.score-submit { display: flex; gap: 8px; margin-bottom: 10px; }
.score-submit input {
	width: 100px;
	padding: 6px 10px;
	border: 1px solid var(--border);
	border-radius: 8px;
	background: var(--bg);
	color: var(--text);
}
.score-submit button {
	padding: 6px 14px;
	border: none;
	border-radius: 8px;
	background: var(--accent-2);
	color: #062024;
	font-weight: 600;
	cursor: pointer;
}
.login-hint { color: var(--muted); font-size: 13px; }
.rank-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.rank-table th, .rank-table td {
	padding: 10px 12px;
	text-align: left;
	border-bottom: 1px solid var(--border);
	font-size: 14px;
}
.rank-table th { color: var(--muted); font-weight: 600; }
.rank-table th, .rank-table td { padding: 8px 6px; }
.rank-table .rank { width: 28px; font-weight: 700; color: var(--accent-2); }
.rank-table .score { text-align: right; font-weight: 700; }
.rank-table .player { display: flex; align-items: center; gap: 6px; }
.rank-table .player small { color: var(--muted); font-size: 11px; }

/* 전체 순위 보기 버튼 + 모달 */
.rank-all-btn {
	border: 1px solid var(--border);
	background: var(--surface-2);
	color: var(--accent-2);
	font-size: 12.5px;
	font-weight: 700;
	padding: 4px 10px;
	border-radius: 999px;
	cursor: pointer;
}
.rank-all-btn:hover { color: var(--text); }
.full-rank-modal { max-width: 520px; padding: 26px 24px 22px; }
.full-rank-title { margin: 0 0 14px; font-size: 18px; }
.full-rank-scroll { max-height: 62vh; overflow-y: auto; }
.full-rank-scroll .rank-table { margin-top: 0; }
.full-rank-scroll .rank-table thead th {
	position: sticky;
	top: 0;
	background: var(--surface);
}
.rank-avatar { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
	/* 우측 컬럼 숨김 → 사이드바 + 메인 2분할 */
	.app-body,
	.app-body.no-right { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
	.app-right { display: none; }
}

@media (max-width: 760px) {
	.side-toggle { display: block; }
	.app-body,
	.app-body.no-right { grid-template-columns: 1fr; }
	/* 사이드바를 오버레이 서랍으로 */
	.app-sidebar {
		position: fixed;
		top: var(--topbar-h);
		left: 0;
		bottom: 0;
		width: 78%;
		max-width: 300px;
		z-index: 25;
		transform: translateX(-100%);
		transition: transform .2s ease;
	}
	.app-sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.6); }
	.app-main { padding: 16px; }
}
