/* 전역 리셋 및 기본 설정 */
:root {
    --bg-color: #0b0c15;
    --panel-bg: rgba(20, 24, 45, 0.6);
    --panel-border: rgba(255, 255, 255, 0.08);
    --primary-color: #4361ee;
    --primary-glow: rgba(67, 97, 238, 0.4);
    --accent-color: #f72585;
    --accent-glow: rgba(247, 37, 133, 0.4);
    --text-color: #e2e8f0;
    --text-muted: #94a3b8;
    --neon-green: #4ade80;
    --neon-orange: #ff9f1c;
    --neon-orange-glow: rgba(255, 159, 28, 0.4);
    --font-main: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-english: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    /* [최적화] 터치 드래그 및 블록 선택 전역 차단 */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-user-drag: none;
    -webkit-tap-highlight-color: transparent; /* 터치 피드백 음영 제거 */
}

/* [최적화] 스와이프 제스처, 당겨서 새로고침 및 스크롤 완전 차단 */
html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(at 0% 0%, rgba(26, 21, 62, 0.3) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(13, 27, 65, 0.4) 0px, transparent 50%);
    color: var(--text-color);
    height: 100%; /* 100vh 대신 100% 실 높이 대응 */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.app-container {
    width: 100%; /* 100vw 대신 100% */
    height: 100%; /* 100vh 대신 100% */
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 화면 전환 공통 */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    opacity: 0;
    transition: opacity 0.4s ease;
    flex-direction: column;
}

.screen.active {
    display: flex;
    opacity: 1;
}

/* ========================================== */
/* 1. 로비 화면 (Lobby Screen) */
/* ========================================== */
#lobby-screen {
    justify-content: center;
    align-items: center;
    padding: 40px;
    height: 100%;
    position: relative;
}

.lobby-content {
    display: flex;
    width: 100%;
    max-width: 1600px;
    height: 100%;
    max-height: 85vh;
    gap: 40px;
}

/* 로비 왼쪽 영역 (설정 & 타이틀) */
.lobby-left {
    flex: 1.2;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    padding: clamp(15px, 2.5vh, 30px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

.logo-area {
    margin-bottom: 5px;
}

.game-title {
    font-family: var(--font-english);
    font-weight: 800;
    font-size: clamp(30px, 4.5vh, 52px);
    letter-spacing: -1.5px;
    background: linear-gradient(135deg, #fff 30%, #a5b4fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 30px rgba(255, 255, 255, 0.1);
    line-height: 1.1;
}

.game-title span {
    background: linear-gradient(135deg, var(--accent-color) 0%, #7209b7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-left: 5px;
    text-shadow: 0 0 30px var(--accent-glow);
}

.game-subtitle {
    font-size: clamp(12px, 1.6vh, 15px);
    color: var(--text-muted);
    margin-top: 3px;
    letter-spacing: 1px;
    font-weight: 500;
}

/* 게임 안내 가이드 박스 */
.game-info-box {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    padding: clamp(10px, 1.4vh, 14px);
    margin-bottom: clamp(6px, 1vh, 10px);
    backdrop-filter: blur(5px);
}

.info-box-title {
    font-size: clamp(13px, 1.8vh, 15px);
    font-weight: 700;
    margin-bottom: clamp(4px, 0.6vh, 6px);
    color: #fff;
    text-shadow: 0 0 10px rgba(255,255,255,0.15);
}

.info-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: clamp(4px, 0.6vh, 6px);
}

.info-list li {
    font-size: clamp(12px, 1.6vh, 14px);
    color: var(--text-muted);
    line-height: 1.45;
}

.info-list li strong {
    color: #fff;
    font-weight: 600;
}

/* 학생 설정 박스 */
.player-setup-box {
    margin: clamp(8px, 1.5vh, 16px) 0;
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 1vh, 10px);
}

.player-names-section,
.player-number-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-label {
    font-size: clamp(12px, 1.6vh, 14px);
    font-weight: 600;
    color: #fff;
}

.input-hint {
    font-size: clamp(11px, 1.4vh, 13px);
    color: var(--text-muted);
    font-weight: 400;
}

.names-textarea {
    width: 100%;
    padding: clamp(8px, 1.2vh, 12px) clamp(12px, 1.4vw, 16px);
    font-size: clamp(13px, 1.7vh, 15px);
    font-family: var(--font-main);
    background: rgba(0, 0, 0, 0.3);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    color: #fff;
    outline: none;
    resize: none;
    line-height: 1.5;
    transition: all 0.3s ease;
    touch-action: pan-y;
    -webkit-user-select: text;
    user-select: text;
}

.names-textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 15px var(--primary-glow);
}

.names-textarea::placeholder {
    color: rgba(255,255,255,0.25);
}

.player-or-divider {
    text-align: center;
    color: var(--text-muted);
    font-size: clamp(12px, 1.5vh, 14px);
    font-weight: 500;
    position: relative;
}

.player-or-divider::before,
.player-or-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 42%;
    height: 1px;
    background: rgba(255,255,255,0.08);
}

.player-or-divider::before { left: 0; }
.player-or-divider::after { right: 0; }

.number-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.number-label {
    font-size: clamp(13px, 1.7vh, 15px);
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

/* school-selector-box 하위 호환 (제거됨) */
.school-selector-box {
    margin: clamp(10px, 2vh, 20px) 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.section-title {
    font-size: clamp(14px, 2vh, 18px);
    font-weight: 700;
    margin-bottom: 8px;
    color: #fff;
}

.search-container {
    position: relative;
    width: 100%;
}

#school-input {
    width: 100%;
    padding: clamp(8px, 1.3vh, 12px) clamp(12px, 1.5vw, 18px);
    font-size: clamp(13px, 1.7vh, 15px);
    background: rgba(0, 0, 0, 0.3);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    color: #fff;
    outline: none;
    transition: all 0.3s ease;
}

#school-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 15px var(--primary-glow);
}

#btn-clear-school {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
}

/* 학교 검색 자동완성 드롭다운 */
.autocomplete-list {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 100%;
    max-height: clamp(150px, 25vh, 250px);
    background: #121528;
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

.autocomplete-item {
    padding: clamp(10px, 1.6vh, 16px) 24px;
    font-size: clamp(13px, 1.8vh, 16px);
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    transition: background 0.2s ease;
}

.autocomplete-item:hover {
    background: rgba(67, 97, 238, 0.15);
    color: #fff;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.warning-text {
    margin-top: 10px;
    font-size: clamp(12px, 1.8vh, 15px);
    color: var(--neon-orange);
    text-shadow: 0 0 10px rgba(255, 159, 28, 0.2);
    font-weight: 500;
}

/* 등록 완료 배지 */
.school-badge {
    display: flex;
    align-items: center;
    background: rgba(74, 222, 128, 0.1);
    border: 1.5px solid var(--neon-green);
    padding: clamp(8px, 1.3vh, 12px) clamp(12px, 1.5vw, 18px);
    border-radius: 10px;
    margin-top: 5px;
    font-size: clamp(13px, 1.7vh, 15px);
    font-weight: 600;
    color: var(--neon-green);
    box-shadow: 0 0 15px rgba(74, 222, 128, 0.15);
    animation: pulseGlow 2s infinite alternate;
}

.badge-icon {
    margin-right: 10px;
    font-size: 20px;
}

#badge-name {
    flex: 1;
}

#btn-change-school {
    background: transparent;
    border: none;
    color: var(--neon-green);
    font-size: 24px;
    cursor: pointer;
    margin-left: 10px;
    font-weight: bold;
}

@keyframes pulseGlow {
    0% { box-shadow: 0 0 10px rgba(74, 222, 128, 0.1); }
    100% { box-shadow: 0 0 20px rgba(74, 222, 128, 0.3); }
}

/* 로비 메뉴 조작 버튼부 */
.menu-actions {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1vh, 10px);
}

.start-buttons-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.btn {
    width: 100%;
    padding: clamp(10px, 1.4vh, 14px);
    font-size: clamp(14px, 1.7vh, 16px);
    font-weight: 700;
    border-radius: 10px;
    cursor: pointer;
    border: none;
    text-align: center;
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, #3f37c9 100%);
    color: white;
    box-shadow: 0 8px 24px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(67, 97, 238, 0.6);
}

.btn-primary:active {
    transform: translateY(1px);
}

.accent-btn {
    background: linear-gradient(135deg, var(--accent-color) 0%, #b5179e 100%);
    box-shadow: 0 8px 24px var(--accent-glow);
}

.accent-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(247, 37, 133, 0.6);
}

.accent-btn:active {
    transform: translateY(1px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
    border: 1px solid var(--panel-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* 로비 오른쪽 영역 (랭킹 보드) */
.lobby-right {
    flex: 1;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    padding: clamp(20px, 4vh, 40px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
}

.ranking-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.ranking-title {
    font-size: clamp(18px, 2.6vh, 26px);
    font-weight: 800;
    color: #fff;
    margin-bottom: clamp(15px, 2.5vh, 25px);
    letter-spacing: -0.5px;
    text-shadow: 0 0 15px rgba(255,255,255,0.1);
}

.ranking-list-container {
    flex: 1;
    overflow-y: auto;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.ranking-table {
    width: 100%;
    border-collapse: collapse;
    font-size: clamp(14px, 1.8vh, 18px);
}

.ranking-table th {
    padding: clamp(10px, 1.5vh, 16px) clamp(10px, 1.5vw, 20px);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-muted);
    font-weight: 600;
    font-size: clamp(12px, 1.5vh, 15px);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    text-align: left;
}

.ranking-table td {
    padding: clamp(10px, 1.5vh, 16px) clamp(10px, 1.5vw, 20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-color);
}

.ranking-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.rank-num {
    font-family: var(--font-english);
    font-weight: 800;
    font-size: 18px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

/* 1, 2, 3위 메달 디자인 */
.rank-num-1 { background: linear-gradient(135deg, #ffd700 0%, #ffa500 100%); color: #000; box-shadow: 0 0 10px rgba(255, 215, 0, 0.4); }
.rank-num-2 { background: linear-gradient(135deg, #c0c0c0 0%, #808080 100%); color: #000; box-shadow: 0 0 10px rgba(192, 192, 192, 0.3); }
.rank-num-3 { background: linear-gradient(135deg, #cd7f32 0%, #8b4513 100%); color: #fff; box-shadow: 0 0 10px rgba(205, 127, 50, 0.3); }
.rank-num-other { color: var(--text-muted); }

.rank-school-name {
    font-weight: 600;
}

.rank-score-val {
    font-family: var(--font-english);
    font-weight: 700;
    text-align: right;
    color: var(--accent-color);
    text-shadow: 0 0 10px var(--accent-glow);
}

.no-rank-data {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-style: italic;
}

.ranking-notice {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 15px;
    text-align: right;
}

/* ========================================== */
/* 2. 게임 본 화면 (Game Screen) */
/* ========================================== */
#game-screen {
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow: hidden;
}

/* 게임 헤더 */
.game-header {
    height: 70px;
    min-height: 70px;
    background: rgba(13, 14, 27, 0.85);
    border-bottom: 1.5px solid var(--panel-border);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 30px;
    z-index: 10;
}

.header-logo {
    font-family: var(--font-english);
    font-weight: 800;
    font-size: 26px;
    background: linear-gradient(135deg, #fff 0%, var(--primary-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

/* 실시간 최고점 배너 */
.high-score-banner {
    background: rgba(255, 159, 28, 0.08);
    border: 1.5px solid var(--neon-orange);
    color: var(--neon-orange);
    font-size: clamp(14px, 2vh, 20px);
    font-weight: 700;
    padding: clamp(6px, 1vh, 10px) clamp(15px, 2vw, 30px);
    border-radius: 30px;
    box-shadow: 0 0 15px rgba(255, 159, 28, 0.15);
    letter-spacing: -0.5px;
    animation: flashOrange 3s infinite alternate;
}

@keyframes flashOrange {
    0% { box-shadow: 0 0 10px rgba(255, 159, 28, 0.1); border-color: rgba(255, 159, 28, 0.6); }
    100% { box-shadow: 0 0 20px rgba(255, 159, 28, 0.35); border-color: rgba(255, 159, 28, 1); }
}

/* 최고점 달성 시 빵빠레 축하 애니메이션 */
.high-score-banner.celebrate {
    animation: celebratePulse 0.4s infinite alternate, celebrateRainbow 2s infinite linear !important;
    border-color: #ffd700 !important;
    color: #ffd700 !important;
}

@keyframes celebratePulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
    }
    100% {
        transform: scale(1.22);
        box-shadow: 0 0 40px rgba(255, 215, 0, 0.85), 0 0 60px #ffd700;
    }
}

@keyframes celebrateRainbow {
    0% { filter: hue-rotate(0deg); }
    100% { filter: hue-rotate(360deg); }
}

.btn-lobby {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--panel-border);
    color: var(--text-color);
    padding: clamp(6px, 1vh, 10px) clamp(12px, 1.5vw, 20px);
    border-radius: 10px;
    font-size: clamp(13px, 1.8vh, 16px);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-lobby:hover {
    background: rgba(255,255,255,0.12);
    color: #fff;
}

/* 게임 메인 그리드 영역 */
.game-main {
    flex: 1;
    min-height: 0;
    padding: clamp(8px, 1.5vh, 15px);
    display: flex;
    align-items: center;
    justify-content: center;
    background: #08090f;
    position: relative;
    overflow: hidden;
}

.tetris-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    width: 100%;
    height: 100%;
    max-height: 100%;
    max-width: 1800px;
    gap: clamp(8px, 1.5vw, 15px);
}

/* 1인용 모드 강제 적용 시 슬롯 1~3 숨김 및 슬롯 0 확장 */
.tetris-grid.mode-1p {
    grid-template-columns: 1fr;
}
.tetris-grid.mode-1p #slot-1,
.tetris-grid.mode-1p #slot-2,
.tetris-grid.mode-1p #slot-3 {
    display: none !important;
}
.tetris-grid.mode-1p #slot-0 {
    width: 100%;
    height: 100%;
    max-width: 500px; /* 1인용 시 화면 중앙에 아담하게 피팅 */
    margin: 0 auto;
}

/* 개별 테트리스 슬롯 */
.tetris-slot {
    background: rgba(20, 24, 45, 0.4);
    border: 1.5px solid rgba(255,255,255,0.05);
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    position: relative;
    padding: clamp(8px, 1.2vh, 12px);
    height: 100%;
    max-height: 100%;
}

.slot-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: clamp(6px, 1vh, 12px);
    padding: 0 5px;
}

.slot-player {
    font-family: var(--font-english);
    font-weight: 800;
    font-size: clamp(16px, 2.4vh, 24px);
    color: #fff;
    text-shadow: 0 0 10px rgba(255,255,255,0.2);
}

.slot-score {
    font-family: var(--font-english);
    font-weight: 800;
    font-size: clamp(18px, 2.6vh, 26px);
    color: var(--accent-color);
    text-shadow: 0 0 10px var(--accent-glow);
}

/* 캔버스 컨테이너 */
.canvas-wrapper {
    flex: 1;
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
}

.tetris-canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* 게임오버 도전하기 오버레이 */
.slot-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(6px);
    z-index: 5;
}

.slot-overlay.active {
    display: flex;
    animation: fadeInOverlay 0.3s forwards;
}

@keyframes fadeInOverlay {
    from { opacity: 0; }
    to { opacity: 1; }
}

.overlay-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(10px, 2vh, 20px);
}

.gameover-text {
    font-family: var(--font-english);
    font-weight: 800;
    font-size: clamp(20px, 3vh, 32px);
    color: var(--accent-color);
    text-shadow: 0 0 20px var(--accent-glow);
    letter-spacing: 2px;
    animation: pulseGameOver 1.5s infinite alternate;
}

@keyframes pulseGameOver {
    from { transform: scale(1); text-shadow: 0 0 10px var(--accent-glow); }
    to { transform: scale(1.08); text-shadow: 0 0 25px var(--accent-glow), 0 0 40px var(--accent-color); }
}

.btn-challenge {
    background: linear-gradient(135deg, var(--neon-orange) 0%, #d45d00 100%);
    border: none;
    color: #fff;
    font-size: clamp(14px, 2vh, 20px);
    font-weight: 700;
    padding: clamp(10px, 1.8vh, 16px) clamp(20px, 3vw, 36px);
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 8px 20px var(--neon-orange-glow);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-challenge:hover {
    transform: scale(1.06);
    box-shadow: 0 12px 25px rgba(255, 159, 28, 0.6);
}

.btn-challenge:active {
    transform: scale(0.96);
}

/* 터치 제어 버튼부: 왼쪽에 좌우 이동, 오른쪽에 아래/회전 */
.slot-controls {
    margin-top: clamp(6px, 1.2vh, 15px);
    display: flex;
    justify-content: space-between;
    gap: clamp(12px, 2.5vw, 40px);
    height: clamp(46px, 7.8vh, 65px);
}

.ctrl-group {
    display: flex;
    gap: clamp(4px, 0.8vw, 8px);
    min-width: 0;
}

/* 왼쪽(좌·우 2개) : 오른쪽(회전 1개) = 2 : 1 → 버튼 크기 동일 */
.ctrl-group-left { flex: 2; }
.ctrl-group-right { flex: 1; }

.ctrl-group .ctrl-btn {
    flex: 1;
    min-width: 0;
}

.ctrl-btn {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    color: var(--text-color);
    font-size: 22px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.1s ease;
}

.ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* 조작성 피드백을 높이기 위한 active 발광 */
.ctrl-btn:active {
    transform: scale(0.9);
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
    box-shadow: 0 0 15px var(--primary-glow);
}

/* 아래 이동(소프트 드롭) 버튼의 시각적 강조 */
.ctrl-btn.move-down {
    background: rgba(67, 97, 238, 0.1);
    border-color: rgba(67, 97, 238, 0.2);
    color: #818cf8;
}

.ctrl-btn.move-down:active {
    background: var(--primary-color);
    color: #fff;
}

/* 회전 버튼(이모지 순서 바꾸기) 강조 */
.ctrl-btn.rotate {
    background: rgba(247, 37, 133, 0.1);
    border-color: rgba(247, 37, 133, 0.25);
    font-size: 20px;
}

.ctrl-btn.rotate:active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    box-shadow: 0 0 15px var(--accent-glow);
}

/* 스크롤바 커스텀 */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ========================================== */
/* 3. 스마트폰 대응 모바일 미디어 쿼리 (세로형 1인용) */
/* ========================================== */
@media (max-width: 768px) {
    /* 로비 화면 세로 스택 */
    #lobby-screen {
        padding: 20px 15px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
        align-items: stretch;
        touch-action: pan-y;
    }

    .lobby-content {
        flex-direction: column;
        height: auto;
        max-height: none;
        gap: 20px;
    }

    .lobby-left, .lobby-right {
        flex: none;
        width: 100%;
        padding: 20px;
        border-radius: 16px;
    }

    .together-config-area {
        display: none !important;
    }

    .game-title {
        font-size: 38px;
        text-align: center;
    }

    .game-subtitle {
        font-size: 14px;
        text-align: center;
        letter-spacing: 1px;
    }

    .school-selector-box {
        margin: 20px 0;
    }

    /* 게임 화면 분기 - P1만 단독 노출 */
    .game-header {
        padding: 0 15px;
        height: 60px;
        min-height: 60px;
    }

    .header-logo {
        font-size: 20px;
    }

    .high-score-banner {
        font-size: 12px;
        padding: 6px 15px;
    }

    .btn-lobby {
        padding: 6px 12px;
        font-size: 13px;
    }

    .game-main {
        padding: 10px;
    }

    .tetris-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }

    /* 스마트폰에서 슬롯 2~4 숨김 (전자칠판 전용 앱이므로 참고용 스타일) */
    #slot-1, #slot-2, #slot-3 {
        display: none !important;
    }

    #slot-0 {
        width: 100%;
        height: 100%;
        padding: 10px;
    }

    .slot-header {
        margin-bottom: 8px;
    }

    .slot-player {
        font-size: 20px;
    }

    .slot-score {
        font-size: 22px;
    }

    .slot-controls {
        margin-top: 10px;
        height: 55px; /* 모바일 터치 최적화 */
        gap: 6px;
    }

    .ctrl-btn {
        font-size: 20px;
        border-radius: 10px;
    }
}

/* 상단 배너 내 학교 이름 무지개 그라데이션 애니메이션 */
.rainbow-school {
    background: linear-gradient(to right, #ff3366, #ff9933, #33cc66, #3399ff, #9933ff, #ff3366);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.05);
    animation: rainbowShift 3s linear infinite;
    display: inline-block;
}

@keyframes rainbowShift {
    0% { background-position: 0% center; }
    100% { background-position: 200% center; }
}

/* 전체화면 버튼 헤더 마진 */
#btn-fullscreen {
    margin-right: 8px;
}

/* 함께 하기 모드 설정 박스 */
.together-config-area {
    background: rgba(255, 255, 255, 0.03);
    border: 1.5px solid rgba(255, 255, 255, 0.05);
    border-radius: 14px;
    padding: clamp(6px, 1vh, 10px) clamp(10px, 1.2vw, 15px);
    margin-bottom: clamp(6px, 1vh, 10px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.together-toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.together-icon {
    font-size: 20px;
}

.together-label {
    font-size: clamp(13px, 1.8vh, 15px);
    font-weight: 500;
    color: var(--text-color);
}

.together-limit-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 네온 스위치 */
.together-switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
}

.together-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.together-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: .3s;
    border-radius: 24px;
}

.together-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: #fff;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 0 5px rgba(255,255,255,0.5);
}

.together-switch input:checked + .together-slider {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 0 10px var(--primary-glow);
}

.together-switch input:checked + .together-slider:before {
    transform: translateX(22px);
}

/* 끝 번호 입력 */
.together-input {
    width: 60px;
    height: 32px;
    background: rgba(0, 0, 0, 0.4);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: #fff;
    font-family: var(--font-english);
    font-size: 16px;
    font-weight: 700;
    text-align: center;
    outline: none;
    transition: all 0.2s;
}

.together-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 10px var(--primary-glow);
}

/* 함께 하기 대기 오버레이 박스 */
.game-ready-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(12px, 2vh, 22px);
    text-align: center;
    width: 100%;
}

.ready-title {
    font-size: clamp(16px, 2.4vh, 24px);
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.5px;
    margin-bottom: 5px;
}

.ready-number {
    font-family: var(--font-english);
    font-weight: 800;
    font-size: clamp(26px, 4.5vh, 44px);
    color: var(--primary-color);
    text-shadow: 0 0 20px var(--primary-glow);
    display: block;
    margin-bottom: 2px;
}

.btn-start-game {
    background: linear-gradient(135deg, var(--neon-green) 0%, #008f1f 100%);
    border: none;
    color: #fff;
    font-size: clamp(13px, 1.8vh, 18px);
    font-weight: 700;
    padding: clamp(10px, 1.8vh, 15px) clamp(20px, 3.5vw, 36px);
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 6px 15px rgba(0, 240, 0, 0.3);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-start-game:hover {
    transform: scale(1.06);
    box-shadow: 0 10px 20px rgba(0, 240, 0, 0.55);
}

.btn-start-game:active {
    transform: scale(0.96);
}

.btn-pass-game {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.6);
    font-size: clamp(11px, 1.5vh, 14px);
    font-weight: 500;
    padding: clamp(5px, 1vh, 8px) clamp(12px, 2vw, 20px);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-pass-game:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.3);
}

.btn-pass-game:active {
    transform: scale(0.95);
}

/* 게임오버 박스 */
.gameover-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
