/* style.css */

:root {
    /* [다크 모드 - 기본] */
    --bg-dark:   #1a1a2e;
    --bg-panel:  #16213e;
    --bg-canvas: #1a1717;
    --bg-board:  #0f3460;   /* 보드 배경도 변수로 관리 */
    --bg-empty:  rgba(0, 0, 0, 0.25); /* 빈 타격 격자 */

    --text-main:  #fcfafe;
    --text-muted: #7f97ac;

    --accent:       #168f43;
    --accent-hover: #127536;
    --primary:      #7e7291;
    --primary-hover:#655b74;
    --danger:       #c22628;
    --danger-hover: #c33e35;

    --highlight: #f6b655;
}

/* 🚀 [라이트 모드] body에 .light-mode 클래스가 붙으면 이 값들로 덮어씌워짐 */
body.light-mode {
    --bg-dark:   #f0f2f5;
    --bg-panel:  #ffffff;
    --bg-canvas: #e4e6eb;
    --bg-board:  #d1d9e6;
    --bg-empty:  rgba(0, 0, 0, 0.08);

    --text-main:  #1c1e21;
    --text-muted: #65676b;

    --primary:      #9589a8; /* 라이트 모드에 맞춰 살짝 밝게 조정 가능 */
}

/* ───────────── 기본 레이아웃 ───────────── */

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

/* ───────────── 화면 전환 ───────────── */

.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
    animation: fadeIn 0.3s ease-in-out;
}

.screen.active { display: flex; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ───────────── 공통 패널 ───────────── */

.panel {
    background-color: var(--bg-panel);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    text-align: center;
    width: 100%;
    max-width: 450px;
    box-sizing: border-box;
}

h1, h2, h3 { margin-top: 0; color: var(--text-main); }

.text-muted { color: var(--text-muted); font-size: 0.9em; }

/* ───────────── 입력 폼 ───────────── */

.form-group {
    display: flex;
    gap: 10px;
    margin: 20px 0;
    justify-content: center;
}

input[type="text"] {
    padding: 12px;
    border: 2px solid var(--bg-canvas);
    border-radius: 6px;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-size: 16px;
    outline: none;
    text-align: center;
}

input[type="text"]:focus { border-color: var(--primary); }

/* ───────────── 버튼 ───────────── */

button {
    padding: 12px 20px;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    background-color: var(--primary);
    color: var(--text-main);
}

button:hover           { background-color: var(--primary-hover); transform: translateY(-2px); }
button:disabled        { background-color: #555; color: #888; cursor: not-allowed; transform: none; }

.btn-primary           { background-color: var(--primary); }
.btn-primary:hover     { background-color: var(--primary-hover); }
.btn-secondary         { background-color: var(--accent); }
.btn-secondary:hover   { background-color: var(--accent-hover); }
.btn-danger            { background-color: var(--danger); }
.btn-danger:hover      { background-color: var(--danger-hover); }

/* ───────────── 접속자 목록 ───────────── */

ul.list-box {
    list-style: none;
    padding: 10px;
    margin: 15px 0;
    background-color: var(--bg-dark);
    border-radius: 8px;
    max-height: 250px;
    overflow-y: auto;
    text-align: left;
}

ul.list-box li {
    padding: 10px;
    margin-bottom: 5px;
    background-color: var(--bg-canvas);
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ───────────── 게임 화면 레이아웃 ───────────── */

.game-layout {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 30px;
    width: 100%;
    max-width: 1100px;
}

/* 실시간 랭킹바 (좌측) */
.leaderboard-v {
    /* 🚀 핵심: 랭킹판의 너비를 고정하여 점수가 늘어나도 우측을 밀어내지 않게 만듭니다 */
    width: 220px; 
    min-width: 220px;

    /* 🚀 1. 랭킹판 전체에 고정 높이를 주어 게임 보드와 균형을 맞춥니다. */
    height: 525px; 
    overflow-y: auto; /* 🚀 2. 인원이 많아지면 내부에서 스크롤이 생기도록 합니다. */
    flex-shrink: 0;

    /* 🚀 화면이 좁아져도 랭킹판이 찌그러지며 너비가 변하는 것을 방지합니다 */
    flex-shrink: 0; 
    
    /* 혹시 닉네임이 너무 길어서 220px을 넘칠 경우를 대비한 안전장치
    overflow: hidden;
    text-overflow: ellipsis; 
    white-space: nowrap; */

    background-color: var(--bg-panel);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 🚀 [선택 사항] 랭킹판에 예쁜 커스텀 스크롤바 달아주기 (.leaderboard-v 아래에 추가) */
.leaderboard-v::-webkit-scrollbar { width: 6px; }
.leaderboard-v::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 3px; }

.leaderboard-v strong {
    display: block;
    text-align: center;
    color: var(--text-muted);
    font-size: 1.1rem;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 5px;
}

.leaderboard-v div {
    color: var(--text-main);
    font-size: 1rem;
    padding: 5px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-v div:nth-of-type(1) {
    color: var(--highlight);
    font-weight: bold;
}

/* 🚀 랭킹판 각 줄을 가로(Flex)로 배치하여 양끝으로 찢습니다 */
.leaderboard-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    width: 100%;
}

/* 🚀 닉네임 영역: 남는 공간을 다 차지하되, 넘치면 '...' 처리 */
.leaderboard-row .player-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

/* 🚀 점수 영역: 찌그러지지 않고 고정폭 숫자처럼 작동하도록 설정 */
.leaderboard-row .player-score {
    flex-shrink: 0; /* 절대 줄어들지 않음 */
    font-variant-numeric: tabular-nums; /* 숫자 너비가 고정되어 점수가 바뀔 때 안 흔들림 */
    text-align: right;
}

/* 플레이 구역 (우측) */
.play-area {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-info-bar {
    display: flex;
    justify-content: space-between;
    font-size: 1.2rem;
    font-weight: bold;
    width: 100%;
    max-width: 710px;
    margin-bottom: 10px;
}

.game-info-bar > div:first-child { color: var(--highlight); }
.game-info-bar > div:last-child  { color: var(--accent); }

.toggle-container {
    width: 100%;
    max-width: 710px;
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

.toggle-container label {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: bold;
    color: var(--text-muted);
    font-size: 14px;
}

.toggle-container input[type="checkbox"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
}

/* ───────────── 게임 보드 ───────────── */

#game-board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(23, 30px);
    grid-template-rows: repeat(15, 30px);
    gap: 2px;
    background-color: var(--bg-board);
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5); /* 보드 전체 그림자 */
}

@keyframes pop {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.8; }
    100% { transform: scale(0.5); opacity: 0; }
}
.tile-pop {
    animation: pop 0.15s ease-out forwards;
    z-index: 10;
}

.tile {
    width: 100%;
    height: 100%;
    border-radius: 6px; /* 더 부드러운 모서리 */
    box-sizing: border-box;
    transition: transform 0.1s;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    user-select: none;
}

/* ───────────── 결과 화면 ───────────── */

.result-layout {
    display: flex;
    gap: 20px;
    width: 100%;
    max-width: 900px;
    text-align: left;
}

.result-col {
    flex: 1;
    background-color: var(--bg-panel);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.result-card {
    padding: 12px;
    margin-bottom: 8px;
    background-color: var(--bg-canvas);
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s;
    border: 1px solid transparent;
}

.result-card:hover         { transform: scale(1.02); border-color: var(--primary); }
.result-card.first-place   { background-color: rgba(246, 182, 85, 0.1); border: 1px solid var(--highlight); color: var(--highlight); font-weight: bold; }
/* 🚀 본인 표시 (왼쪽 노란색 굵은 줄) */
.result-card.me-card {
    border-left: 3px solid var(--highlight);
}

/* 🚀 클릭되어 선택된 상태 */
.result-card.selected {
    border-color: var(--primary);
    transform: scale(1.02);
}

/* 🚀 본인 카드가 선택되었을 때의 예외 처리 (왼쪽 노란줄은 그대로 유지) */
.result-card.me-card.selected {
    border-left-color: var(--highlight);
}

/* 리플레이 미니 보드 */
#replay-board {
    display: grid;
    grid-template-columns: repeat(23, 15px);
    grid-template-rows: repeat(15, 15px);
    gap: 1px;
    background-color: var(--bg-dark);
    padding: 5px;
    border-radius: 4px;
    margin: 15px auto;
}

.mini-tile {
    width: 100%;
    height: 100%;
    border-radius: 2px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    user-select: none;
}

/* 🚀 [구조 변경] data-color 속성이 비어있지 않은(색상이 있는) 타일에만 광택과 입체감 부여! */
.tile[data-color]:not([data-color=""]),
.mini-tile[data-color]:not([data-color=""]) {
    background: linear-gradient(135deg, rgba(255,255,255,0.4) 0%, rgba(255,255,255,0) 50%, rgba(0,0,0,0.1) 100%); /* 상단 하이라이트와 하단 그림자 */
    box-shadow: 0 3px 6px rgba(0,0,0,0.3), inset 0 2px 2px rgba(255,255,255,0.5); /* 외부 그림자와 내부 광택 테두리 */
}

/* ───────────── 모달 ───────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: fadeIn 0.2s ease-in-out;
}

.modal-box {
    background: var(--bg-panel);
    border-radius: 12px;
    padding: 36px 40px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    text-align: center;
    min-width: 280px;
}

.modal-message {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--text-main);
    margin: 0 0 24px;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.modal-buttons button {
    flex: 1;
}

/* ───────────── 버전 뱃지 ───────────── */
.version-badge {
    position: fixed;
    bottom: 20px;
    right: 20px; /* 좌측 하단을 원하시면 left: 20px; 로 변경하세요 */
    color: var(--text-muted);
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    padding: 8px 14px;
    background-color: rgba(22, 33, 62, 0.7); /* 반투명 배경 */
    border-radius: 8px;
    transition: all 0.2s ease;
    z-index: 50;
}

.version-badge:hover {
    color: var(--text-main);
    background-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* ───────────── 업데이트 로그 ───────────── */
.changelog-content {
    max-height: 300px; /* 내용이 길어지면 스크롤 생성 */
    overflow-y: auto;
    margin-bottom: 10px;
    padding-right: 15px;
    font-size: 14px;
}

.changelog-content h4 {
    color: var(--highlight);
    margin: 15px 0 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 5px;
}

.changelog-content ul {
    margin: 0;
    padding-left: 20px;
    color: var(--text-main);
    line-height: 1.6;
}

/* 스크롤바 커스텀 (업데이트 로그 전용) */
.changelog-content::-webkit-scrollbar { width: 6px; }
.changelog-content::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 3px; }

.player-actions {
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}

.btn-action {
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
    font-weight: bold;
}

.btn-reset {
    background-color: var(--primary);
}
.btn-reset:hover {
    background-color: var(--primary-hover);
}

.btn-kick {
    background-color: var(--danger);
}
.btn-kick:hover {
    background-color: var(--danger-hover);
}

.tile[data-color=""],
.mini-tile[data-color=""] {
    background-color: var(--bg-empty);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4); /* 안으로 파인 그림자 */
}

.room-dashboard {
    width: 100%;
    max-width: 900px; /* 기존 450px에서 2배 넓게! */
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px;
    box-sizing: border-box;
}

.dashboard-header {
    display: flex;
    gap: 20px;
}

.info-card {
    flex: 1;
    background-color: var(--bg-panel);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}
#btn-copy-link:hover { transform: translateY(-3px); border-color: var(--highlight); }

.settings-section {
    display: flex;
    gap: 20px;
}

.setting-item {
    flex: 1;
    background-color: var(--bg-panel);
    padding: 20px;
    border-radius: 12px;
    text-align: left;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.setting-item label {
    display: block;
    color: var(--text-muted);
    font-weight: bold;
    font-size: 0.9rem;
    margin-bottom: 10px;
}

/* 플레이어 목록 넓게 쓰기 */
.wide-list {
    max-height: 400px;
    background-color: transparent;
    padding: 0;
}
.wide-list li {
    background-color: var(--bg-panel);
    padding: 15px 20px;
    margin-bottom: 8px;
    border-radius: 8px;
    font-size: 1.1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* 하단 액션 바 (나가기 / 상태 / 시작) */
.bottom-action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-panel);
    padding: 15px 20px;
    border-radius: 12px;
    margin-top: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* ───────────── 토글 스위치 UI ───────────── */
.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--bg-canvas);
    transition: .3s;
    border-radius: 24px;
    border: 2px solid var(--text-muted);
}
.slider:before {
    position: absolute;
    content: "";
    height: 14px; width: 14px;
    left: 3px; bottom: 3px;
    background-color: var(--text-muted);
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent);
    border-color: var(--accent);
}
input:checked + .slider:before {
    transform: translateX(22px);
    background-color: #fff;
}

/* 방장이 아닐 때 (비활성화 상태) */
input:disabled + .slider {
    cursor: not-allowed;
    opacity: 0.5;
}

/* 🚀 테마 토글 버튼 스타일 (우측 상단 고정) */
.theme-toggle-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background-color: var(--bg-panel);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    font-size: 20px;
    border: 2px solid var(--primary);
}

/* 🚀 라이트 모드일 때의 버전 뱃지 스타일 덮어쓰기 */
body.light-mode .version-badge {
    background-color: rgba(255, 255, 255, 0.8); /* 밝고 반투명한 흰색 배경 */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);  /* 살짝 떠 보이게 그림자 추가 */
}

body.light-mode .version-badge:hover {
    background-color: var(--primary); /* 마우스를 올리면 프라이머리 색상으로 */
    color: #ffffff; /* 글자는 흰색으로 명확하게 */
}

/* 🚀 하는 방법 버튼 스타일 */
.how-to-badge {
    position: absolute;
    bottom: 20px;
    left: 20px;
    padding: 10px 18px;
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.how-to-badge:hover {
    background-color: var(--primary);
    color: #fff;
    border-color: var(--highlight);
    transform: translateY(-2px);
}

/* 라이트 모드 대응 */
body.light-mode .how-to-badge {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-muted);
}
body.light-mode .how-to-badge:hover {
    background-color: var(--primary);
    color: #fff;
}