@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

:root {
    --primary: #6C5CE7;
    --primary-light: #A29BFE;
    --primary-dark: #5A4BD1;
    --accent: #FD79A8;
    --accent-light: #FDCBDD;
    --success: #00B894;
    --warning: #FDCB6E;
    --danger: #E17055;
    --bg: #F8F9FD;
    --bg-card: #FFFFFF;
    --text: #2D3436;
    --text-light: #636E72;
    --text-muted: #B2BEC3;
    --border: #DFE6E9;
    --shadow: 0 4px 15px rgba(108, 92, 231, 0.1);
    --shadow-hover: 0 8px 25px rgba(108, 92, 231, 0.2);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Nunito', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-2px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.4);
}

.btn-accent {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 12px rgba(253, 121, 168, 0.3);
}

.btn-accent:hover {
    background: #e8608e;
    box-shadow: 0 6px 20px rgba(253, 121, 168, 0.4);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: #fff;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
}

.btn-lg {
    padding: 16px 32px;
    font-size: 17px;
}

input[type="text"],
input[type="number"],
select {
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Nunito', sans-serif;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    background: var(--bg-card);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    width: 100%;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.1);
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    transition: box-shadow 0.2s;
}

.card:hover {
    box-shadow: var(--shadow-hover);
}

/* ==================== LOBBY ==================== */

.lobby-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 40px 20px;
}

.lobby-header {
    text-align: center;
    margin-bottom: 40px;
}

.lobby-header h1 {
    font-size: 48px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.lobby-header p {
    color: var(--text-light);
    font-size: 18px;
    font-weight: 600;
}

.lobby-join-section {
    display: flex;
    gap: 16px;
    margin-bottom: 32px;
}

.lobby-join-section .name-input-wrap {
    flex: 1;
}

.lobby-join-section .code-input-wrap {
    display: flex;
    gap: 8px;
}

.lobby-join-section .code-input-wrap input {
    width: 160px;
    text-transform: uppercase;
    letter-spacing: 3px;
    text-align: center;
    font-weight: 800;
}

.lobby-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.lobby-actions h2 {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
}

.room-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.room-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.room-item:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-hover);
    transform: translateY(-1px);
}

.room-item-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.room-item-host {
    font-weight: 700;
    font-size: 16px;
}

.room-item-code {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 1px;
}

.room-item-players {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    color: var(--primary);
    font-size: 15px;
}

.room-item-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.room-item-status.waiting {
    background: var(--success);
    color: #fff;
}

.room-item-status.playing {
    background: var(--warning);
    color: var(--text);
}

.room-list-empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 16px;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 24px;
    text-align: center;
    justify-content: center;
}

.connection-status.connected {
    background: rgba(0, 184, 148, 0.1);
    color: var(--success);
}

.connection-status.disconnected {
    background: rgba(225, 112, 85, 0.1);
    color: var(--danger);
}

.connection-status.connecting {
    background: rgba(253, 203, 110, 0.1);
    color: #E17055;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

/* ==================== MODAL ==================== */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: flex-start;
    justify-content: center;
    backdrop-filter: blur(4px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 0;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    padding: 32px;
    width: 100%;
    max-width: 480px;
    margin: auto;
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal h2 {
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 24px;
    text-align: center;
}

.modal-field {
    margin-bottom: 20px;
}

.modal-field label {
    display: block;
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--text-light);
}

.modal-field .inline-inputs {
    display: flex;
    gap: 12px;
}

.modal-field .inline-inputs input,
.modal-field .inline-inputs select {
    flex: 1;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.category-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-xs);
    border: 2px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
    font-size: 14px;
}

.category-item:hover {
    border-color: var(--primary-light);
}

.category-item.selected {
    border-color: var(--primary);
    background: rgba(108, 92, 231, 0.05);
}

.category-item input[type="checkbox"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
}

.difficulty-grid {
    display: flex;
    gap: 8px;
}

.difficulty-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-xs);
    border: 2px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
    font-size: 14px;
    flex: 1;
    justify-content: center;
}

.difficulty-item:hover {
    border-color: var(--primary-light);
}

.difficulty-item.selected {
    border-color: var(--primary);
    background: rgba(108, 92, 231, 0.05);
}

.difficulty-item[data-diff="1"].selected {
    border-color: var(--success);
    background: rgba(0, 184, 148, 0.08);
}

.difficulty-item[data-diff="2"].selected {
    border-color: #f39c12;
    background: rgba(243, 156, 18, 0.08);
}

.difficulty-item[data-diff="3"].selected {
    border-color: var(--accent);
    background: rgba(253, 121, 168, 0.08);
}

.difficulty-item input[type="checkbox"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.modal-actions .btn {
    flex: 1;
}

/* ==================== GAME PAGE ==================== */

.game-container {
    display: grid;
    grid-template-columns: 240px 1fr 280px;
    grid-template-rows: auto 1fr;
    height: 100vh;
    gap: 0;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.chat-input-wrap input,
.word-choice-btn {
    -webkit-user-select: auto;
    user-select: auto;
}

.game-header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-card);
    border-bottom: 2px solid var(--border);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.game-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.game-header h1 {
    font-size: 22px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.game-header .round-info {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-light);
    padding: 4px 12px;
    background: var(--bg);
    border-radius: 20px;
}

.game-header-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.word-category {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 1px;
    background: rgba(108, 92, 231, 0.1);
    padding: 1px 10px;
    border-radius: 10px;
}

.word-category:empty {
    display: none;
}

.word-hint {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: 6px;
    color: var(--text);
}

.word-hint-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

.game-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

.room-code-display {
    font-size: 14px;
    font-weight: 800;
    color: var(--primary);
    background: rgba(108, 92, 231, 0.08);
    padding: 6px 14px;
    border-radius: 8px;
    letter-spacing: 2px;
    cursor: pointer;
}

.room-code-display:hover {
    background: rgba(108, 92, 231, 0.15);
}

/* Timer Bar */
.timer-bar-container {
    grid-column: 2;
    height: 6px;
    background: var(--border);
    position: relative;
}

.timer-bar {
    height: 100%;
    width: 100%;
    background: var(--success);
    transition: width linear, background-color 0.5s;
    border-radius: 0 3px 3px 0;
}

.timer-bar.warning {
    background: var(--warning);
}

.timer-bar.danger {
    background: var(--danger);
    animation: timerPulse 1s ease infinite;
}

@keyframes timerPulse {
    0%, 100% { opacity: 1; box-shadow: none; }
    50% { opacity: 0.7; box-shadow: 0 0 12px var(--danger); }
}

.timer-bar.critical {
    background: var(--danger);
    animation: timerCritical 0.5s ease infinite;
    height: 100%;
}

@keyframes timerCritical {
    0%, 100% { opacity: 1; box-shadow: 0 0 8px var(--danger); }
    50% { opacity: 0.6; box-shadow: 0 0 20px var(--danger); }
}

.timer-bar-container.critical {
    height: 8px;
    transition: height 0.3s;
}

.timer-countdown {
    display: none;
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    font-size: 22px;
    font-weight: 800;
    z-index: 15;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(225, 112, 85, 0.5);
    animation: countdownPop 1s ease infinite;
    font-family: 'Nunito', sans-serif;
}

.timer-countdown.active {
    display: flex;
}

@keyframes countdownPop {
    0% { transform: translateY(-50%) scale(1); }
    15% { transform: translateY(-50%) scale(1.2); }
    30% { transform: translateY(-50%) scale(1); }
}

.start-countdown {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.85);
    font-size: 72px;
    font-weight: 900;
    color: var(--primary);
    font-family: 'Nunito', sans-serif;
    pointer-events: none;
}

.start-countdown.active {
    display: flex;
}

.start-countdown .start-num {
    animation: startCountPop 0.8s ease-out;
}

.start-countdown .start-go {
    color: var(--success);
    font-size: 56px;
    animation: startCountPop 0.6s ease-out;
}

@keyframes startCountPop {
    0% { transform: scale(2); opacity: 0; }
    40% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.settings-toggle {
    display: none;
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg);
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    position: relative;
}

.settings-toggle:hover {
    background: var(--border);
}

.settings-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    border: 2px solid var(--border);
    padding: 12px;
    z-index: 100;
    min-width: 180px;
    flex-direction: column;
    gap: 10px;
}

.settings-dropdown.open {
    display: flex;
}

.settings-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
}

.settings-dropdown-item .item-label {
    white-space: nowrap;
    color: var(--text-light);
}

.settings-divider {
    height: 1px;
    background: var(--border);
}

/* Left Sidebar — Players */
.sidebar-left {
    background: var(--bg-card);
    border-right: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-title {
    padding: 16px 16px 12px;
    font-size: 14px;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.player-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.player-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.player-item.drawing {
    background: rgba(108, 92, 231, 0.08);
    border: 2px solid var(--primary-light);
}

.player-item.guessed {
    background: rgba(0, 184, 148, 0.08);
}

.player-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
    color: #fff;
    flex-shrink: 0;
}

.player-info {
    flex: 1;
    min-width: 0;
}

.player-name {
    font-weight: 700;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-role {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
}

.player-score {
    font-weight: 800;
    font-size: 16px;
    color: var(--primary);
}

/* Center — Canvas Area */
.canvas-area {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
}

.canvas-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    position: relative;
    overflow: hidden;
}

.canvas-container {
    background: #FFFFFF;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
    height: 100%;
    max-width: 100%;
    aspect-ratio: 9 / 16;
}

.canvas-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 12px 20px;
    background: var(--bg-card);
    border-top: 2px solid var(--border);
    flex-wrap: wrap;
}

.toolbar.disabled {
    display: none;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.toolbar-divider {
    width: 2px;
    height: 32px;
    background: var(--border);
    border-radius: 1px;
}

.size-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.2s;
}

.size-btn:hover {
    border-color: var(--primary-light);
}

.size-btn.active {
    border-color: var(--primary);
    background: rgba(108, 92, 231, 0.08);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}

.size-btn .size-dot {
    border-radius: 50%;
    background: var(--text);
}

.color-swatch {
    display: inline-block;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    border-radius: 6px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.active {
    border-color: var(--text);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.25);
    transform: scale(1.15);
}

.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg-card);
    cursor: pointer;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 13px;
    color: var(--text);
    transition: all 0.2s;
}

.tool-btn:hover {
    border-color: var(--primary-light);
}

.tool-btn.active {
    border-color: var(--primary);
    background: rgba(108, 92, 231, 0.08);
    color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}

.tool-btn.danger {
    color: var(--danger);
}

.tool-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg-card);
    cursor: pointer;
    color: var(--text);
    transition: all 0.2s;
    padding: 0;
}

.tool-icon-btn:hover {
    border-color: var(--primary-light);
    color: var(--primary);
}

.tool-icon-btn.active {
    border-color: var(--primary);
    background: rgba(108, 92, 231, 0.08);
    color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}

.tool-icon-btn.danger {
    color: var(--danger);
}

.tool-icon-btn.danger:hover {
    color: #fff;
    background: var(--danger);
    border-color: var(--danger);
}

.tool-icon-btn.confirm {
    color: #fff;
    background: var(--danger);
    border-color: var(--danger);
    animation: pulse 0.5s ease infinite;
}

.focus-btn {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--bg-card);
    font-size: 20px;
    cursor: pointer;
    z-index: 10;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    transition: all 0.2s;
    color: var(--text);
    line-height: 1;
}

.focus-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.canvas-area.fullscreen-mode {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: var(--bg);
}

.canvas-area.fullscreen-mode .focus-btn {
    display: flex;
    font-size: 18px;
}

.canvas-area.fullscreen-mode .canvas-wrapper {
    flex: 1;
    padding: 0;
}

.canvas-area.fullscreen-mode .canvas-container {
    border-radius: 0;
    max-width: 100%;
    max-height: 100%;
}

.canvas-area.fullscreen-mode .floating-toolbar-toggle {
    display: flex;
}

.tool-btn.danger:hover {
    border-color: var(--danger);
    background: rgba(225, 112, 85, 0.08);
}

.floating-toolbar-toggle {
    display: none;
    position: absolute;
    top: 12px;
    left: 12px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--bg-card);
    font-size: 18px;
    cursor: pointer;
    z-index: 20;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    transition: all 0.2s;
    color: var(--text);
    line-height: 1;
    padding: 0;
}

.floating-toolbar-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.floating-toolbar-toggle.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.floating-toolbar-panel {
    display: none;
    position: absolute;
    top: 60px;
    left: 12px;
    z-index: 20;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    border: 2px solid var(--border);
    padding: 8px;
    flex-direction: column;
    gap: 6px;
    max-height: calc(100% - 80px);
    overflow-y: auto;
    overflow-x: hidden;
    width: 46px;
    align-items: center;
}

.floating-toolbar-panel.open {
    display: flex;
}

.floating-toolbar-panel .toolbar-divider {
    width: 24px;
    height: 2px;
    background: var(--border);
    border-radius: 1px;
}

.floating-toolbar-panel .tool-icon-btn,
.floating-toolbar-panel .size-btn {
    width: 30px;
    height: 30px;
    min-width: 30px;
    min-height: 30px;
}

.floating-toolbar-panel .tool-icon-btn svg {
    width: 16px;
    height: 16px;
}

/* Right Sidebar — Chat */
.sidebar-right {
    background: var(--bg-card);
    border-left: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-msg {
    padding: 6px 12px;
    border-radius: var(--radius-xs);
    font-size: 14px;
    font-weight: 600;
    word-break: break-word;
}

.chat-msg .chat-author {
    font-weight: 800;
    margin-right: 6px;
}

.chat-msg.system {
    color: var(--text-muted);
    font-style: italic;
    font-size: 13px;
    text-align: center;
}

.chat-msg.correct {
    background: rgba(0, 184, 148, 0.1);
    color: var(--success);
    font-weight: 700;
    text-align: center;
}

.chat-msg.close-hint {
    background: rgba(253, 203, 110, 0.15);
    color: #B8860B;
    font-weight: 700;
    font-size: 13px;
}

.chat-msg.guess {
    color: var(--text);
}

.chat-input-wrap {
    padding: 12px;
    border-top: 2px solid var(--border);
    display: flex;
    gap: 8px;
}

.chat-input-wrap input {
    flex: 1;
    min-width: 0;
}

.chat-input-wrap input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-send {
    padding: 10px 16px;
    font-size: 14px;
    flex-shrink: 0;
    min-height: 44px;
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* ==================== OVERLAYS ==================== */

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 500;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.overlay.active {
    display: flex;
}

.overlay-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 40px;
    text-align: center;
    max-width: 500px;
    width: 90%;
    animation: modalIn 0.3s ease;
}

.overlay-content h2 {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 16px;
}

.overlay-content h3 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-light);
    margin-bottom: 24px;
}

.word-choices {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
    max-width: 100%;
}

.word-choice-btn {
    padding: 16px 20px;
    border: 3px solid var(--primary-light);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: 18px;
    color: var(--primary);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 0;
    max-width: 160px;
    flex: 1 1 0;
    word-break: break-word;
    overflow-wrap: break-word;
    text-align: center;
}

.word-choice-main {
    font-size: 17px;
    font-weight: 800;
    word-break: break-word;
    overflow-wrap: break-word;
    line-height: 1.2;
}

.word-choice-translations {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0;
}

.word-choice-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(108, 92, 231, 0.3);
}

.word-choice-btn:hover .word-choice-translations {
    color: rgba(255, 255, 255, 0.7);
}

.turn-end-translations {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Scoreboard */
.scoreboard {
    margin-top: 20px;
}

.scoreboard-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: var(--radius-xs);
    margin-bottom: 6px;
    font-weight: 700;
}

.scoreboard-row:nth-child(1) {
    background: rgba(253, 203, 110, 0.2);
    font-size: 18px;
}

.scoreboard-row:nth-child(2) {
    background: rgba(178, 190, 195, 0.2);
}

.scoreboard-row:nth-child(3) {
    background: rgba(205, 127, 50, 0.15);
}

.scoreboard-rank {
    width: 30px;
    font-weight: 800;
    color: var(--primary);
}

.scoreboard-name {
    flex: 1;
    text-align: left;
}

.scoreboard-points {
    font-weight: 800;
    color: var(--primary);
}

.scoreboard-delta {
    font-size: 13px;
    color: var(--success);
    margin-left: 8px;
}

.winner-crown {
    font-size: 48px;
    margin-bottom: 12px;
}

/* Waiting room */
.waiting-room {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px;
}

.waiting-room h2 {
    font-size: 24px;
    font-weight: 800;
}

.waiting-room .room-code-big {
    font-size: 36px;
    font-weight: 800;
    letter-spacing: 6px;
    color: var(--primary);
    background: rgba(108, 92, 231, 0.08);
    padding: 12px 28px;
    border-radius: var(--radius-sm);
}

.waiting-players {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    margin: 16px 0;
}

.waiting-player-chip {
    padding: 8px 16px;
    background: var(--bg);
    border-radius: 20px;
    font-weight: 700;
    font-size: 14px;
}

.waiting-player-chip.host {
    background: rgba(108, 92, 231, 0.1);
    color: var(--primary);
}

/* ==================== TOASTS ==================== */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 14px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    animation: toastIn 0.3s ease;
    max-width: 320px;
}

.toast.info {
    background: var(--primary);
    color: #fff;
}

.toast.success {
    background: var(--success);
    color: #fff;
}

.toast.warning {
    background: var(--warning);
    color: var(--text);
}

.toast.removing {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100px);
    }
}

/* ==================== LOADING ==================== */

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.drawer-info {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
    padding: 4px 12px;
    background: rgba(253, 121, 168, 0.1);
    border-radius: 20px;
}

.guess-counter {
    font-size: 13px;
    font-weight: 700;
    color: var(--success);
    padding: 4px 10px;
    background: rgba(0, 184, 148, 0.1);
    border-radius: 20px;
}

.mute-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg);
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.mute-btn:hover {
    background: var(--border);
}

.next-drawer-name {
    font-size: 42px;
    font-weight: 800;
    color: var(--primary);
    animation: bounceIn 0.5s ease;
    margin-top: 12px;
}

@keyframes bounceIn {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.1); opacity: 1; }
    70% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

.toast.guess {
    background: rgba(108, 92, 231, 0.9);
    color: #fff;
}

.lang-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
    font-weight: 700;
    font-size: 14px;
    color: var(--text-light);
}

.lang-btn {
    padding: 6px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg-card);
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-light);
}

.lang-btn:hover {
    border-color: var(--primary-light);
}

.lang-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.lang-selector {
    display: flex;
    gap: 2px;
}

.lang-btn-small {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
}

.lang-btn-small:hover {
    border-color: var(--primary-light);
    color: var(--primary);
}

.lang-btn-small.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.bgm-control {
    display: flex;
    align-items: center;
}

.bgm-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.bgm-btn:hover {
    border-color: var(--primary-light);
    color: var(--primary);
}

.word-choice-timer {
    font-size: 32px;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 3px solid var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    margin-right: auto;
    transition: color 0.3s, border-color 0.3s;
}

.word-choice-timer.urgent {
    color: var(--danger);
    border-color: var(--danger);
    animation: pulse 0.5s ease infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.word-choice-category {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

@media (max-width: 900px) {
    html, body {
        height: 100%;
        overflow: hidden;
    }

    .game-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr auto;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }

    .game-header {
        flex-wrap: wrap;
        gap: 0;
        padding: 4px 10px;
        align-items: center;
    }

    .game-header h1 {
        display: none;
    }

    .game-header-left {
        gap: 4px;
        flex-shrink: 0;
    }

    .game-header .round-info {
        font-size: 10px;
        padding: 1px 6px;
    }

    .game-header .drawer-info {
        font-size: 10px;
        padding: 1px 6px;
    }

    .game-header-center {
        order: 3;
        width: 100%;
        flex: none;
        min-width: 0;
        padding: 2px 0;
    }

    .word-category {
        font-size: 9px;
        padding: 0 6px;
    }

    .word-hint {
        font-size: 18px;
        letter-spacing: 3px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .word-hint-label {
        font-size: 10px;
    }

    .sidebar-left {
        border-right: none;
        border-bottom: 2px solid var(--border);
        max-height: 60px;
        overflow: hidden;
        order: 2;
    }

    .player-list {
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 4px;
        padding: 4px 8px;
        overflow-x: auto;
        overflow-y: hidden;
    }

    .player-item {
        padding: 4px 8px;
        font-size: 12px;
        flex-shrink: 0;
    }

    .player-avatar {
        width: 24px;
        height: 24px;
        font-size: 10px;
    }

    .player-score {
        font-size: 12px;
    }

    .sidebar-title {
        display: none;
    }

    .canvas-area {
        order: 3;
        min-height: 0;
        overflow: hidden;
    }

    .canvas-wrapper {
        padding: 2px;
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    .canvas-container {
        width: auto;
        height: 100%;
        max-width: 100%;
    }

    .sidebar-right {
        border-left: none;
        border-top: 2px solid var(--border);
        order: 4;
        max-height: 120px;
        min-height: 0;
        overflow: hidden;
    }

    .chat-messages {
        min-height: 0;
    }

    .chat-input-wrap {
        padding: 8px;
    }

    .chat-input-wrap input {
        padding: 10px 14px;
        font-size: 16px;
    }

    .lobby-join-section {
        flex-direction: column;
    }

    .lobby-join-section .code-input-wrap {
        width: 100%;
    }

    .lobby-join-section .code-input-wrap input {
        width: 100%;
        flex: 1;
    }

    .lobby-header h1 {
        font-size: 36px;
    }

    .word-choices {
        flex-direction: column;
        gap: 10px;
    }

    .word-choice-btn {
        padding: 14px 20px;
        font-size: 16px;
        max-width: none;
        width: 100%;
    }

    .category-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .overlay-content {
        padding: 24px;
        width: 95%;
    }

    .modal-overlay {
        padding: 12px;
    }

    .modal {
        padding: 20px;
        max-width: 100%;
    }

    .modal h2 {
        font-size: 20px;
        margin-bottom: 16px;
    }

    .modal-field .inline-inputs {
        flex-direction: column;
        gap: 8px;
    }

    .lang-selector {
        gap: 1px;
    }

    .lang-btn-small {
        padding: 3px 6px;
        font-size: 10px;
    }

    .bgm-btn {
        font-size: 11px;
        padding: 3px 8px;
    }

    .game-header-right {
        gap: 4px;
        flex-wrap: nowrap;
        justify-content: flex-end;
        flex-shrink: 0;
        margin-left: auto;
    }

    .game-header-right .guess-counter {
        font-size: 10px;
        padding: 1px 6px;
    }

    .game-header-right > .room-code-display,
    .game-header-right > .bgm-control,
    .game-header-right > .lang-selector,
    .game-header-right > .mute-btn {
        display: none;
    }

    .game-header-right .settings-toggle {
        display: flex;
        width: 30px;
        height: 30px;
        font-size: 16px;
    }

    .word-choice-timer {
        width: 44px;
        height: 44px;
        font-size: 24px;
    }

    .drawing-mode .sidebar-right {
        display: none;
    }

    .drawing-mode .sidebar-left {
        display: none;
    }

    .drawing-mode .game-container {
        grid-template-rows: auto 1fr;
    }

    .drawing-mode .canvas-area {
        order: 2;
    }

    .drawing-mode .focus-btn {
        display: flex;
    }

    .drawing-mode .toolbar {
        display: none;
    }

    .drawing-mode .floating-toolbar-toggle {
        display: flex;
    }

    .tool-icon-btn {
        width: 38px;
        height: 38px;
    }

    .tool-icon-btn svg {
        width: 18px;
        height: 18px;
    }

    .size-btn {
        width: 38px;
        height: 38px;
    }

    .color-swatch {
        width: 30px;
        height: 30px;
        min-width: 30px;
        min-height: 30px;
    }

    .toolbar {
        gap: 6px;
        padding: 6px 8px;
    }

    .toolbar-group {
        gap: 4px;
    }

    .toolbar-divider {
        height: 24px;
    }
}
