:root {
    --primary-color: #5c5346;
    --secondary-color: #eae6de;
    --highlight-bg: #e8e4d9;
    --selected-bg: #d5d0c5;
    --same-num-bg: #dfdacd;
    --error-color: #c27b73;
    --text-fixed: #4a4238;
    --text-input: #738269;
    --border-color: #d1cabe;
    --thick-border: 2px solid #5c5346;
}

body {
    font-family: sans-serif;
    display: flex;
    justify-content: center;
    background-color: #f4f1eb;
    margin: 0;
    padding: 10px;
    user-select: none;
    touch-action: manipulation;
}

.app-container {
    display: flex;
    gap: 20px;
    max-width: 900px;
    width: 100%;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
}

.game-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 400px;
}

.side-panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 300px;
    background: white;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    height: 600px;
}

.side-panel-tabs {
    display: flex;
    background: var(--border-color);
}

.tab-btn {
    flex: 1;
    padding: 15px;
    background: #d1cabe;
    color: #4a4238;
    border: none;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
    font-size: 15px;
}

.tab-btn:hover {
    background: #e1dacd;
}

.tab-btn.active {
    background: linear-gradient(135deg, #848c74 0%, #6e7561 100%);
    color: white;
}

.side-panel-view {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.side-panel-view.active {
    display: flex;
}

.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 14px;
}

/* 🏆 新增：排行榜內容樣式 */
.leaderboard-content {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    padding: 10px;
    background: #f0ece3;
    border-radius: 8px;
    border-left: 4px solid #738269;
    font-size: 13px;
    gap: 8px;
}

.leaderboard-rank {
    font-weight: bold;
    color: #738269;
    width: 25px;
    text-align: center;
}

.leaderboard-rank.rank-1 {
    color: #c5a75c;
    font-size: 16px;
}

.leaderboard-rank.rank-2 {
    color: #b4b3ab;
    font-size: 16px;
}

.leaderboard-rank.rank-3 {
    color: #b88a64;
    font-size: 16px;
}

.leaderboard-player-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.leaderboard-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.leaderboard-name {
    flex: 1;
    font-weight: bold;
    color: var(--primary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-scores {
    display: flex;
    gap: 12px;
    font-size: 12px;
}

.leaderboard-correct {
    color: #7c936b;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 3px;
}

.leaderboard-incorrect {
    color: #c27b73;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 3px;
}

.sys-msg {
    color: #8e877e;
    font-size: 12px;
    text-align: center;
    font-style: italic;
}

.chat-input-area {
    display: flex;
    border-top: 1px solid var(--border-color);
    padding: 10px;
    background: #f9f7f2;
}

#chat-input {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    outline: none;
}

#btn-send-chat {
    margin-left: 5px;
    padding: 8px 15px;
    background: var(--text-input);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

#top-bar {
    display: none;
    width: 100%;
    justify-content: space-between;
    font-size: 16px;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 10px;
}

#board-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    box-sizing: border-box;
}

#board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    width: 100%;
    height: 100%;
    background-color: white;
    border: var(--thick-border);
    box-sizing: border-box;
}

#doodle-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.doodle-active #doodle-canvas {
    pointer-events: auto;
    cursor: crosshair;
}

.cell {
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    box-sizing: border-box;
    overflow: visible;
}

.cell:nth-child(3n) {
    border-right: var(--thick-border);
}
.cell:nth-child(9n) {
    border-right: none;
}
.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
    border-bottom: var(--thick-border);
}

.cell.selected {
    background-color: var(--selected-bg) !important;
}
.cell.highlighted {
    background-color: var(--highlight-bg);
}
.cell.same-number {
    background-color: var(--same-num-bg);
}
.cell.fixed {
    color: var(--text-fixed);
}
.cell.input {
    color: var(--text-input);
}
.cell.error {
    color: var(--error-color);
    background-color: #ebdada;
}

.player-cursor {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 3px solid;
    pointer-events: none;
    z-index: 10;
}

.player-name-tag {
    position: absolute;
    top: -20px;
    right: -5px;
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
    font-weight: bold;
    pointer-events: none;
    z-index: 11;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.notes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    font-size: 10px;
    color: #7f8c8d;
    line-height: 1;
    padding: 2px;
    box-sizing: border-box;
}

.note-num {
    display: flex;
    justify-content: center;
    align-items: center;
}

.tools {
    display: flex;
    width: 100%;
    justify-content: space-around;
    margin: 15px 0;
}

.tool-btn {
    background: none;
    border: none;
    font-size: 14px;
    color: var(--primary-color);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    transition: 0.2s;
}

.tool-btn.active {
    color: var(--text-input);
    font-weight: bold;
    transform: scale(1.1);
}

.doodle-panel {
    display: none;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    background: var(--secondary-color);
    padding: 10px 15px;
    border-radius: 8px;
    box-sizing: border-box;
    margin-bottom: 10px;
    gap: 10px;
}

.doodle-panel input[type="color"] {
    cursor: pointer;
    border: none;
    border-radius: 4px;
    height: 30px;
    width: 40px;
}
.doodle-panel input[type="range"] {
    flex: 1;
    cursor: pointer;
}

.doodle-btn {
    padding: 6px 12px;
    border-radius: 6px;
    border: none;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
}

#btn-eraser {
    background: white;
    color: var(--primary-color);
    border: 1px solid #ccc;
}
#btn-eraser.active {
    background: var(--text-fixed);
    color: white;
}
#btn-clear-doodles {
    background: var(--error-color);
    color: white;
}

.numpad {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    width: 100%;
    gap: 5px;
    margin-bottom: 15px;
}

.num-btn {
    background-color: var(--secondary-color);
    color: var(--text-input);
    border: none;
    border-radius: 8px;
    font-size: 24px;
    padding: 12px 0;
    cursor: pointer;
    font-weight: bold;
}

.num-btn:active {
    background-color: #d9d5cb;
}

#action-btn {
    background-color: var(--text-input);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 15px 40px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
}

#result-screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 100;
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }
    .side-panel {
        max-width: 400px;
        height: 350px;
    }
    .cell {
        font-size: 20px;
    }
    .num-btn {
        font-size: 20px;
        padding: 8px 0;
    }
    .player-name-tag {
        font-size: 9px;
        padding: 1px 4px;
        top: -15px;
    }
    #action-group button {
        font-size: 14px !important;
        padding: 12px !important;
    }
    .doodle-panel {
        flex-wrap: wrap;
    }
}
/* ==========================================
   暱稱輸入畫面樣式 (Login Screen)
   ========================================== */
#login-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(244, 241, 235, 0.95); /* 帶有透明度的背景 */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200; /* 確保它蓋在最上層 */
}

.login-box {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    text-align: center;
    width: 100%;
    max-width: 300px;
    border: 1px solid var(--border-color);
}

#nickname-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 16px;
    box-sizing: border-box;
    outline: none;
    text-align: center;
    transition: 0.2s;
}

#nickname-input:focus {
    border-color: var(--text-input);
    box-shadow: 0 0 5px rgba(115, 130, 105, 0.3);
}

#btn-join:hover {
    background-color: #5c6a53;
}
