/* =====================================================================
 * Mini Game — 미니멀/모던 리디자인
 * 차분한 zinc 뉴트럴 + 블루 포인트 1색 · Pretendard / JetBrains Mono
 * ===================================================================== */

:root {
    --ac: #3d63dd;
    --ac-hover: #2f4fc0;
    --ac-tint: #eef2fe;
    --ac-tint-2: #f4f6fe;

    --bg: #f5f5f6;
    --surface: #ffffff;
    --muted: #f4f4f5;
    --muted-2: #fafafa;

    --border: #e4e4e7;
    --border-strong: #d4d4d8;
    --line: #f0f0f1;

    --ink: #18181b;
    --ink-2: #3f3f46;
    --ink-3: #71717a;
    --ink-4: #a1a1aa;
    --faint: #c4c4cc;

    --danger: #b91c1c;
    --danger-bg: #fef2f2;
    --danger-border: #fee2e2;

    --radius: 14px;
    --radius-lg: 16px;
    --radius-sm: 10px;
    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    --shadow-card: 0 8px 24px rgba(24, 24, 27, 0.07);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

::selection { background: var(--ac); color: #fff; }

:focus-visible { outline: 2px solid var(--ac); outline-offset: 2px; }

/* 스크롤바 */
.chat-messages::-webkit-scrollbar,
.user-list::-webkit-scrollbar { width: 6px; height: 6px; }
.chat-messages::-webkit-scrollbar-thumb,
.user-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.chat-messages::-webkit-scrollbar-track,
.user-list::-webkit-scrollbar-track { background: transparent; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: none; }
}

/* =========================== 화면 공통 =========================== */
.screen { min-height: 100vh; }
#login-screen { display: flex; align-items: center; justify-content: center; padding: 24px; position: relative; overflow: hidden; }
#lobby-screen { flex-direction: column; }

/* =========================== 로그인 =========================== */
.login-box { width: 100%; max-width: 384px; position: relative; animation: fadeUp .5s ease; display: flex; flex-direction: column; align-items: center; }
.login-brand { margin-bottom: 22px; }
.login-card {
    width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card); padding: 32px 28px;
}
.login-kicker { font-family: var(--mono); font-size: 11px; letter-spacing: .18em; color: var(--ac); text-transform: uppercase; margin-bottom: 14px; }
.login-title { font-size: 26px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; margin-bottom: 10px; }
.login-sub { color: var(--ink-3); font-size: 14px; line-height: 1.6; margin-bottom: 26px; }
.login-label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 8px; }

#nickname {
    width: 100%; padding: 13px 16px; border: 1px solid var(--border-strong);
    border-radius: 12px; font-size: 15px; outline: none; background: var(--surface);
    font-family: inherit; color: var(--ink); margin-bottom: 14px; transition: border-color .15s, box-shadow .15s;
}
#nickname:focus { border-color: var(--ac); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ac) 16%, transparent); }

.btn-login {
    width: 100%; padding: 14px; border: none; border-radius: 12px;
    background: var(--ac); color: #fff; font-size: 15px; font-weight: 600;
    cursor: pointer; font-family: inherit; transition: background .15s;
}
.btn-login:hover { background: var(--ac-hover); }

.login-foot { margin-top: 30px; display: flex; gap: 14px; font-size: 12px; color: var(--ink-4); }
.login-foot .sep { color: var(--border-strong); }

/* =========================== 상단 바 =========================== */
.topbar {
    position: sticky; top: 0; z-index: 30;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    max-width: 1280px; margin: 0 auto; padding: 0 28px; height: 64px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--ac); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }

.topbar-controls { display: flex; align-items: center; gap: 8px; min-width: 0; }
.welcome { font-size: 13.5px; font-weight: 600; color: var(--ink-2);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }

.btn-ghost {
    padding: 8px 13px; border: 1px solid var(--border); border-radius: 9px;
    background: var(--surface); color: var(--ink-2); font-size: 13px; font-weight: 500;
    cursor: pointer; font-family: inherit; transition: all .15s; white-space: nowrap;
}
.btn-ghost:hover { border-color: var(--border-strong); background: var(--muted-2); }

.btn-logout {
    padding: 8px 13px; border: none; border-radius: 9px; background: transparent;
    color: var(--ink-4); font-size: 13px; font-weight: 500; cursor: pointer;
    font-family: inherit; transition: color .15s; white-space: nowrap;
}
.btn-logout:hover { color: var(--ink-2); }

/* =========================== 로비 본문 =========================== */
.lobby-main { max-width: 1280px; width: 100%; margin: 0 auto; padding: 28px; }

.lobby-grid { display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: start; }

/* 공지 배너 */
.notice-banner {
    align-items: center; gap: 12px; padding: 13px 16px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 12px; margin-bottom: 24px;
}
.notice-banner strong {
    font-family: var(--mono); font-size: 10px; font-weight: 500; letter-spacing: .08em;
    color: var(--ac); background: var(--ac-tint); padding: 4px 8px; border-radius: 6px; white-space: nowrap;
}
#notice-text { font-size: 13.5px; color: var(--ink-2); }

/* 게임 목록 */
.game-list { display: flex; flex-direction: column; }

.section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.section-head:not(:first-child) { margin-top: 8px; }
.sec-num { font-family: var(--mono); font-size: 11px; color: var(--ink-4); }
.section-head h2 { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.sec-meta { margin-left: auto; font-size: 12px; color: var(--ink-4); }

.game-grid { display: grid; gap: 14px; }
.study-grid { grid-template-columns: repeat(3, 1fr); margin-bottom: 32px; }
.multi-grid { grid-template-columns: repeat(2, 1fr); margin-bottom: 32px; }
.single-grid { grid-template-columns: repeat(4, 1fr); }

.game-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    cursor: pointer; color: var(--ink-3); transition: all .18s ease;
}
.game-card:hover {
    border-color: var(--ac); color: var(--ac);
    transform: translateY(-2px); box-shadow: var(--shadow-card);
}
.gc-icon {
    width: 40px; height: 40px; border-radius: 10px; background: var(--muted);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.gc-body { display: flex; flex-direction: column; }
.gc-name { font-weight: 600; color: var(--ink); }
.gc-meta { color: var(--ink-4); }

/* 멀티 카드 (가로형) */
.game-card.multi { display: flex; align-items: center; gap: 16px; padding: 20px; border-radius: var(--radius-lg); }
.game-card.multi .gc-icon { width: 46px; height: 46px; border-radius: 12px; }
.game-card.multi .gc-body { flex: 1; gap: 3px; }
.game-card.multi .gc-name { font-size: 16px; font-weight: 700; }
.game-card.multi .gc-meta { font-size: 12px; }
.gc-tag {
    font-family: var(--mono); font-size: 10px; color: var(--ac);
    background: var(--ac-tint); padding: 4px 8px; border-radius: 6px;
}

/* 싱글 카드 (세로형) */
.game-card.single { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.game-card.single .gc-body { gap: 2px; }
.game-card.single .gc-name { font-size: 14px; }
.game-card.single .gc-meta { font-size: 11px; }

/* =========================== 사이드바 =========================== */
.side-col { display: flex; flex-direction: column; }

.notice-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; margin-bottom: 16px; }
.notice-card-head { display: flex; align-items: center; gap: 7px; margin-bottom: 11px; }
.notice-card-head .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ac); }
.nc-title { font-size: 13px; font-weight: 700; }
.notice-card-body { font-size: 13px; color: var(--ink-2); line-height: 1.65; white-space: pre-wrap; }
.notice-textarea {
    width: 100%; margin-top: 10px; border: 1px solid var(--border); border-radius: 10px; padding: 10px;
    font-family: inherit; font-size: 13px; resize: vertical; outline: none; color: var(--ink);
}
.notice-textarea:focus { border-color: var(--ac); }
.notice-editor-actions { display: flex; gap: 8px; margin-top: 8px; }
.notice-editor-actions .btn-primary-sm, .notice-editor-actions .btn-ghost-sm { flex: 1; }

/* 채팅 */
.chat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    display: flex; flex-direction: column; height: 520px; overflow: hidden; }
.chat-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-title { font-size: 13px; font-weight: 700; }

.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; background: var(--muted-2); }
.chat-empty { margin: auto; text-align: center; color: var(--ink-4); font-size: 13px; line-height: 1.7; }

/* JS 렌더 메시지 */
.msg { display: flex; flex-direction: column; max-width: 82%; gap: 3px; align-self: flex-start; animation: msgIn .22s ease-out; }
.msg-sender { font-size: 11px; color: var(--ink-4); margin-left: 2px; }
.msg-wrapper { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.msg-text {
    background: var(--surface); color: var(--ink); border: 1px solid #ececef;
    padding: 8px 12px; border-radius: 4px 14px 14px 14px; font-size: 13.5px; line-height: 1.45; word-break: break-word;
}
.msg-time { font-size: 10px; color: var(--faint); min-width: 28px; }

.my-msg { align-self: flex-end; align-items: flex-end; }
.my-msg .msg-sender { display: none; }
.my-msg .msg-wrapper { flex-direction: row-reverse; }
.my-msg .msg-text { background: var(--ac); color: #fff; border: none; border-radius: 14px 4px 14px 14px; }

.chat-date-divider { align-self: center; font-size: 11px; color: var(--ink-4); margin: 6px 0; }

.btn-delete {
    align-self: flex-start; font-size: 10px; color: var(--danger); cursor: pointer;
    border: 1px solid var(--danger-border); background: var(--danger-bg);
    padding: 2px 7px; border-radius: 6px; margin-top: 2px;
}
.my-msg .btn-delete { align-self: flex-end; }

.chat-input-row { padding: 12px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
#chat-input {
    flex: 1; min-width: 0; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px;
    font-size: 13.5px; outline: none; background: var(--muted-2); font-family: inherit; color: var(--ink);
    transition: border-color .15s, background .15s;
}
#chat-input:focus { border-color: var(--ac); background: var(--surface); }
.btn-send {
    padding: 10px 16px; border: none; border-radius: 10px; background: var(--ac); color: #fff;
    font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit; white-space: nowrap; transition: background .15s;
}
.btn-send:hover { background: var(--ac-hover); }

/* =========================== 게임 플레이 뷰 =========================== */
.play-view { flex-direction: column; animation: fadeUp .25s ease; }
.play-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.play-head-left { display: flex; align-items: center; gap: 14px; }
.play-title { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }

.play-body { display: grid; grid-template-columns: 1fr 280px; gap: 20px; align-items: start; }
.game-frame { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    overflow: hidden; height: 600px; }
.game-frame iframe { width: 100%; height: 100%; border: 0; display: block; }

.leaderboard-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; }
.lb-head { font-size: 13px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 6px; }
.lb-head .btn-danger-sm { margin-left: auto; padding: 4px 10px; }
.lb-head span { color: var(--ink-4); font-weight: 400; font-size: 11px; }
.lb-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.lb-list li:first-child { background: var(--ac-tint-2); border-radius: 11px; }
.lb-loading { padding: 10px; text-align: center; color: var(--ink-4); font-size: 13px; }

/* =========================== 관리자 콘솔 =========================== */
.admin-console { margin-bottom: 26px; border: 1px solid var(--border); border-radius: var(--radius-lg);
    background: var(--surface); overflow: hidden; animation: fadeUp .25s ease; }
.admin-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.admin-title { font-size: 14px; font-weight: 700; }
.admin-badge { font-family: var(--mono); font-size: 10px; letter-spacing: .08em; color: var(--danger);
    background: var(--danger-bg); border: 1px solid var(--danger-border); padding: 3px 7px; border-radius: 6px; }
.admin-body { display: grid; grid-template-columns: 300px 1fr; }
.admin-users { padding: 20px; border-right: 1px solid var(--line); }
.admin-settings { padding: 20px; }
.admin-label { font-size: 12px; font-weight: 600; color: var(--ink-3); margin-bottom: 12px; }

.user-list { list-style: none; display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.user-item { display: flex; align-items: center; justify-content: space-between; padding: 9px 11px;
    background: var(--muted-2); border-radius: 9px; font-size: 13px; color: var(--ink-2); }
.btn-kick { font-size: 11px; color: var(--danger); background: var(--danger-bg); border: 1px solid var(--danger-border);
    padding: 3px 9px; border-radius: 7px; cursor: pointer; font-family: inherit; }
.btn-kick:hover { background: #fde8e8; }

.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.admin-field.full { grid-column: 1 / -1; }
.admin-field label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.field-row { display: flex; gap: 6px; }
.field-row input {
    flex: 1; min-width: 0; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
    font-size: 13px; outline: none; font-family: inherit; color: var(--ink);
}
.field-row input:focus { border-color: var(--ac); }
.btn-dark-sm {
    padding: 9px 14px; border: none; border-radius: 9px; background: var(--ink); color: #fff;
    font-size: 13px; font-weight: 500; cursor: pointer; font-family: inherit; white-space: nowrap;
}
.btn-dark-sm:hover { background: #000; }

/* 공용 작은 버튼 */
.btn-primary-sm { padding: 8px 14px; border: none; border-radius: 9px; background: var(--ac); color: #fff;
    font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; transition: background .15s; }
.btn-primary-sm:hover { background: var(--ac-hover); }
.btn-ghost-sm { padding: 8px 13px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
    color: var(--ink-3); font-size: 12px; font-weight: 500; cursor: pointer; font-family: inherit; }
.btn-ghost-sm:hover { border-color: var(--border-strong); background: var(--muted-2); }
.btn-danger-sm { padding: 6px 12px; border: 1px solid var(--danger-border); border-radius: 8px; background: var(--danger-bg);
    color: var(--danger); font-size: 12px; font-weight: 500; cursor: pointer; font-family: inherit; }
.btn-danger-sm:hover { background: #fde8e8; }

/* =========================== 반응형 =========================== */
@media (max-width: 980px) {
    .lobby-grid { grid-template-columns: 1fr; }
    .side-col { order: 2; }
    .chat-card { height: 440px; }
    .play-body { grid-template-columns: 1fr; }
    .leaderboard-panel { order: -1; }
    .admin-body { grid-template-columns: 1fr; }
    .admin-users { border-right: none; border-bottom: 1px solid var(--line); }
}

@media (max-width: 640px) {
    .topbar-inner { padding: 0 16px; }
    .lobby-main { padding: 18px 16px; }
    .welcome { display: none; }
    .study-grid { grid-template-columns: repeat(2, 1fr); }
    .single-grid { grid-template-columns: repeat(2, 1fr); }
    .multi-grid { grid-template-columns: 1fr; }
    .login-card { padding: 26px 20px; }
    .game-frame { height: 460px; }
    .btn-ghost, .btn-logout { min-height: 40px; }
}

/* =========================== 모바일 게임 풀스크린 =========================== */
@media (max-width: 980px), (hover: none) and (pointer: coarse) {
    body[data-active-game] .topbar,
    body[data-active-game] #notice-banner,
    body[data-active-game] #admin-panel,
    body[data-active-game] .side-col,
    body[data-active-game] #leaderboard-panel { display: none !important; }

    body[data-active-game] .lobby-main { padding: 8px; }
    body[data-active-game] .play-body { grid-template-columns: 1fr; gap: 0; }
    body[data-active-game] .game-frame { height: calc(100dvh - 80px); border-radius: 10px; }
    body[data-active-game] .play-head { margin-bottom: 10px; }
    body[data-active-game] .play-title { font-size: 16px; }
}

/* =========================== 입출입 로그 (관리자) =========================== */
.admin-logs { margin-top: 18px; }
.admin-logs .admin-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.log-list { list-style: none; margin-top: 8px; max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.log-item { display: grid; grid-template-columns: 46px 1fr auto auto; align-items: center; gap: 10px;
    padding: 7px 11px; background: var(--muted-2); border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 12.5px; }
.log-act { font-family: var(--mono); font-size: 10.5px; font-weight: 500; text-align: center; padding: 3px 0; border-radius: 5px; }
.log-item.enter .log-act { color: var(--ac); background: var(--ac-tint); }
.log-item.exit  .log-act { color: var(--ink-3); background: var(--muted); }
.log-nick { font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-ip   { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.log-time { font-family: var(--mono); font-size: 11px; color: var(--ink-4); white-space: nowrap; }
.log-empty { padding: 16px; text-align: center; color: var(--ink-4); font-size: 12.5px; }

/* 채팅 발신자 IP 표시 */
.msg .msg-sender { display: inline-flex; align-items: baseline; gap: 4px; flex-wrap: wrap; }
.msg.my-msg .msg-sender { justify-content: flex-end; }
.msg-ip { font-family: var(--mono); font-size: 10.5px; color: var(--ink-4); font-weight: 400; }
.msg-admin { color: var(--ac); font-weight: 600; }
