/* Drum Sight Time Attack — 스타일
   ⓒ2026 SomeMusicT. All rights reserved.
   인라인 <style> 을 외부 파일로 분리했습니다.
   → CSP 를 style-src 'self' 로 잠글 수 있어 XSS 방어가 실제로 동작합니다. */

:root { --primary: #2c3e50; --accent: #e67e22; --success: #27ae60; --error: #e74c3c; --bg: #f4f7f6; }

/* 화면 스크롤 방지 및 꽉 차는 레이아웃 설정 */
html, body {
    height: 100%; margin: 0; padding: 0; overflow: hidden;
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg); text-align: center; user-select: none; touch-action: manipulation;
}

body { display: flex; flex-direction: column; padding: 10px; box-sizing: border-box; }

#game-container {
    flex: 1; display: flex; flex-direction: column;
    width: 100%; max-width: 800px; margin: auto; background: white;
    padding: 15px; border-radius: 20px; box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    box-sizing: border-box; overflow: hidden;
}

.header-bar { display: flex; justify-content: space-between; margin-bottom: 10px; height: 35px; align-items: center; flex-shrink: 0; }
.left-controls { display: flex; align-items: center; gap: 8px; }

/* 시작 화면에서는 숨김. 게임 시작 시 JS 가 display 를 flex 로 바꿉니다.
   (인라인 style 속성 대신 CSS 로 둬야 CSP style-src 'self' 를 위반하지 않습니다) */
.home-btn { background: none; border: none; cursor: pointer; padding: 5px; color: #95a5a6; display: none; align-items: center; }
.home-btn svg { width: 24px; height: 24px; fill: currentColor; }

.rank-btn {
    background: white; border: 2px solid #ddd; color: var(--primary);
    padding: 5px 12px; border-radius: 8px; font-weight: bold; cursor: pointer;
    font-size: 0.9rem; display: flex; align-items: center; gap: 5px; height: 32px; white-space: nowrap; transition: 0.2s;
}
.rank-btn.is-active { background: var(--accent); color: white; }

select#lang-select { padding: 5px; border-radius: 8px; border: 2px solid #ddd; font-weight: bold; color: var(--primary); height: 32px; outline: none; }

#score-board {
    display: flex; justify-content: space-around; font-size: 1.1rem; font-weight: bold; margin-bottom: 10px;
    background: var(--primary); color: white; padding: 8px; border-radius: 10px; flex-shrink: 0; transition: 0.3s;
}

.timer-warning { color: #ff0000 !important; font-weight: 900; animation: hardBlink 0.25s infinite; }
@keyframes hardBlink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

/* 음원을 못 불러왔을 때만 보이는 안내 (기본은 hidden 속성으로 숨김) */
#audio-warning {
    flex-shrink: 0; margin-bottom: 8px; padding: 8px 12px;
    background: #fdecea; color: #a12b1e; border: 1px solid #f5c6c0;
    border-radius: 10px; font-size: 0.82rem; line-height: 1.5; text-align: left;
}

#combo-display { height: 25px; font-weight: 900; font-size: 1.1rem; color: var(--accent); margin-bottom: 5px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

#staff-container {
    position: relative; background: white; border: 2px solid #eee;
    border-radius: 15px; display: flex; justify-content: center; align-items: center;
    height: 140px; width: 100%; overflow: hidden; margin-bottom: 10px; flex-shrink: 0; transition: 0.3s;
}

#start-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.98); display: flex; flex-direction: column;
    justify-content: center; align-items: center; z-index: 20; gap: 10px;
}

.txt-title { margin: 0; color: var(--primary); font-size: 1.5rem; line-height: 1.2; }

select#level-select, select#rank-filter {
    padding: 8px; font-size: 0.9rem; border: 2px solid var(--accent);
    border-radius: 10px; font-weight: bold; width: 90%; max-width: 300px;
    cursor: pointer; outline: none; background: white;
}

#start-btn {
    background: var(--success); color: white; border: none; padding: 10px 30px;
    border-radius: 20px; font-size: 1.1rem; cursor: pointer; font-weight: bold;
}

#feedback-display {
    position: absolute; bottom: 10px; width: 100%; text-align: center;
    font-weight: 900; font-size: 1.5rem; z-index: 10; height: 30px; pointer-events: none;
}

.correct-msg { color: var(--success); animation: pop 0.15s; text-shadow: 2px 2px 0px #fff; }
.wrong-msg { color: var(--error); animation: shake 0.3s; font-size: 1.2rem; background: rgba(255,255,255,0.8); padding: 0 10px; border-radius: 5px; }

#drum-view {
    flex: 1; display: flex; justify-content: center; align-items: center;
    position: relative; min-height: 0;
}

#drum-wrapper {
    position: relative;
    display: inline-block;
    max-height: 100%;
    max-width: 100%;
}

/* <picture> 가 레이아웃 상자를 만들지 않게 해서 hit-zone 절대배치 기준을
   #drum-wrapper 로 유지합니다. */
#drum-wrapper picture { display: contents; }

#drum-image {
    display: block;
    /* ⚠️ 이 비율은 setdrum_image 의 실제 비율(1600x893)과 반드시 같아야 합니다.
       상자 비율이 그림 비율과 어긋나면 object-fit:contain 이 좌우에 여백을 만들고,
       hit-zone 은 그림이 아니라 '상자' 기준으로 배치되므로 타격 영역이 통째로 어긋납니다.
       이미지를 교체하면 이 값도 함께 바꾸세요. */
    aspect-ratio: 1600 / 893;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 40vh;
    object-fit: contain;
    border-radius: 10px;
    transition: max-height 0.3s ease;
}
#drum-image.free-mode { max-height: 70vh; }

/* 🚀 멀티 터치 및 모바일 완벽 방어 스타일 */
.hit-zone {
    position: absolute;
    /* 악기 테두리가 타원이므로 50% 로 완전한 타원을 만듭니다.
       모서리 밖은 클릭이 통과하므로 인접 악기끼리 겹칠 일이 없습니다.
       --rot 은 악기별 기울기(아래 #btn-* 규칙). :active 에서도 회전을 유지해야
       하므로 transform 을 덮어쓰지 말고 항상 rotate 를 함께 쓰세요. */
    border-radius: 50%;
    transform: rotate(var(--rot, 0deg));
    cursor: pointer;
    border: 2px dashed rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.05);
    transition: 0.1s;
    touch-action: none; /* 브라우저 제스처 차단 (스크롤, 확대 등) */
    -webkit-user-select: none; /* 텍스트 선택 방지 */
    user-select: none;
    -webkit-touch-callout: none; /* 길게 누르기 메뉴 차단 */
}

.hit-zone:hover { background: rgba(255, 255, 255, 0.2); border-color: rgba(51, 154, 240, 0.5); }
.hit-zone:active { transform: rotate(var(--rot, 0deg)) scale(0.95); background: rgba(255, 255, 255, 0.4); }
.hit-zone.correct { background: rgba(39, 174, 96, 0.5) !important; border-color: #27ae60 !important; }
.hit-zone.wrong { background: rgba(231, 76, 60, 0.5) !important; border-color: #e74c3c !important; }

/* 드럼 타격 영역 — 눈대중이 아니라 이미지에서 악기 픽셀을 분리해
   2차 모멘트로 '기울어진 타원'을 직접 맞춘 값입니다(맞춤 정확도 0.97~1.00).
   심벌은 기울어져 있어 rotate() 가 있어야 테두리에 정확히 붙습니다.
   값은 #drum-wrapper(=이미지) 기준 백분율이라 화면 크기가 변해도 따라갑니다. */
#btn-crash { left: 13.29%; top:  1.95%; width: 22.24%; height: 20.13%; --rot: 1.54deg; }
#btn-hihat { left: 15.24%; top: 24.65%; width: 18.56%; height: 16.42%; --rot: -1.11deg; }
#btn-tom1  { left: 36.04%; top: 15.29%; width: 11.46%; height: 16.01%; --rot: 7.75deg; }
#btn-tom2  { left: 52.16%; top: 15.14%; width: 11.86%; height: 17.27%; --rot: -5.59deg; }
/* 스네어·베이스는 자주 치는 악기라 맞춘 값보다 조금 넓혔습니다
   (스네어 ×1.20, 베이스 ×1.25 — 베이스는 헤드 안쪽 링에 맞춰져 작았습니다). */
#btn-snare { left: 22.01%; top: 42.87%; width: 19.34%; height: 22.75%; --rot: -3.22deg; }
#btn-bass  { left: 39.13%; top: 47.27%; width: 21.93%; height: 29.41%; --rot: 1.19deg; }
#btn-floor { left: 62.22%; top: 43.18%; width: 20.02%; height: 21.19%; --rot: 5.30deg; }
#btn-ride  { left: 65.16%; top:  3.45%; width: 25.95%; height: 27.32%; --rot: 4.21deg; }

#result-section { display: none; margin-top: 10px; padding-top: 10px; border-top: 2px solid #eee; overflow-y: auto; flex: 1; }
.chart-container { position: relative; height: 140px; width: 100%; margin-bottom: 10px; }
.result-heading { margin: 0 0 5px 0; }
#stats-summary { margin: 0 0 10px 0; font-size: 0.9rem; }

.rank-table { width: 100%; border-collapse: collapse; margin-top: 5px; font-size: 0.8rem; }
.rank-table th { background: #f8f9fa; color: var(--primary); padding: 5px; border-bottom: 2px solid #ddd; }
.rank-table td { padding: 5px; border-bottom: 1px solid #eee; color: #555; }
.rank-date { font-size: 0.85rem; color: #888; }
.rank-acc { color: var(--success); font-weight: bold; }
.rank-empty { padding: 20px; }
.rank-level { background: var(--bg); padding: 2px 8px; border-radius: 10px; font-size: 0.8rem; font-weight: bold; color: var(--primary); }

#rank-modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 100; justify-content: center; align-items: center; }
#rank-modal.is-open { display: flex; }
.modal-content { background: white; padding: 20px; border-radius: 15px; width: 85%; max-width: 450px; text-align: center; position: relative; max-height: 80vh; overflow-y: auto; }
.close-btn { position: absolute; top: 10px; right: 15px; font-size: 1.5rem; cursor: pointer; border: none; background: none; }

@keyframes pop { 0% { transform: scale(0.8); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes shake { 0% { transform: translateX(0); } 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 100% { transform: translateX(0); } }

/* ⓒ 하단 권리 표시 */
#site-footer {
    flex-shrink: 0; width: 100%; max-width: 800px; margin: 6px auto 0;
    font-size: 0.72rem; color: #7f8c8d; line-height: 1.5;
    display: flex; flex-wrap: wrap; justify-content: center;
    align-items: center; gap: 4px 10px; user-select: text;
}
#site-footer a { color: #7f8c8d; text-decoration: underline; text-underline-offset: 2px; }
#site-footer a:hover { color: var(--accent); }
#site-footer .sep { color: #cfd6d5; }

/* 📱 스마트폰 모바일 최적화 미디어 쿼리 */
@media (max-width: 600px) {
    #game-container { padding: 10px; border-radius: 10px; }
    .header-bar { height: auto; flex-wrap: wrap; gap: 5px; margin-bottom: 5px; }
    .left-controls { width: 100%; justify-content: space-between; }
    select#lang-select { width: 100%; }
    .txt-title { font-size: 1.2rem; }
    #score-board { font-size: 0.95rem; padding: 5px; margin-bottom: 5px; }
    #combo-display { font-size: 1rem; height: 20px; }
    #staff-container { height: 110px; }
    .rank-btn { font-size: 0.8rem; padding: 5px 8px; }
    #site-footer { font-size: 0.65rem; gap: 2px 8px; margin-top: 4px; }
}

/* 📄 정보·개인정보처리방침 문서 페이지 */
body.doc { display: block; overflow: auto; text-align: left; user-select: text; background: var(--bg); }
.docwrap {
    max-width: 760px; margin: 0 auto; padding: 28px 20px 60px; background: white;
    min-height: 100%; box-sizing: border-box; color: #2f3640; line-height: 1.75; font-size: 0.95rem;
}
.docwrap h1 { color: var(--primary); font-size: 1.5rem; margin: 0 0 12px; }
.docwrap h2 { color: var(--primary); font-size: 1.05rem; margin: 28px 0 8px; padding-top: 12px; border-top: 1px solid #eee; }
.docwrap ul { padding-left: 20px; }
.docwrap li { margin-bottom: 4px; }
.docwrap code { background: #f4f7f6; padding: 1px 5px; border-radius: 4px; font-size: 0.85em; }
.docwrap a { color: #b35c0f; }
.lead { background: #fdf3e8; border-left: 4px solid var(--accent); padding: 12px 14px; border-radius: 0 8px 8px 0; }
.meta { color: #8a949e; font-size: 0.85rem; }
.back { margin-top: 32px; }
.docfoot { margin-top: 20px; padding-top: 14px; border-top: 1px solid #eee; color: #8a949e; font-size: 0.8rem; }
.docfoot a { color: #8a949e; }
