@import url('https://fonts.googleapis.com/css2?family=Cinzel+Decorative:wght@400;700&family=Outfit:wght@300;400;600&display=swap');

:root {
    --bg-dark: hsl(230, 25%, 8%);
    --bg-deep: hsl(230, 30%, 4%);
    --panel-glass: hsla(230, 25%, 12%, 0.76);
    --border-glass: hsla(0, 0%, 100%, 0.08);
    --border-glass-bright: hsla(0, 0%, 100%, 0.16);
    --text-primary: hsl(220, 20%, 93%);
    --text-muted: hsl(220, 12%, 70%);
    --text-dark: hsl(230, 25%, 15%);
    --rune-gold: hsl(42, 85%, 60%);
    --rune-gold-glow: hsla(42, 85%, 60%, 0.55);
    
    /* 음계별 고유 마법 시각 컬러 (C4 ~ C5) */
    --color-C: hsl(5, 85%, 60%);
    --color-D: hsl(32, 90%, 58%);
    --color-E: hsl(54, 90%, 56%);
    --color-F: hsl(125, 75%, 58%);
    --color-G: hsl(182, 80%, 54%);
    --color-A: hsl(218, 85%, 60%);
    --color-B: hsl(272, 80%, 64%);
    --color-C5: hsl(322, 85%, 60%);
    
    /* 그림자 및 흐림 이펙트 */
    --shadow-main: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
    --blur-strength: 14px;
}

/* 기본 페이지 스타일링 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: var(--bg-deep);
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    background-image: 
        radial-gradient(at 10% 20%, hsla(240, 30%, 15%, 0.4) 0px, transparent 50%),
        radial-gradient(at 90% 80%, hsla(200, 30%, 15%, 0.3) 0px, transparent 50%);
}

/* 스크롤바 커스텀 */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg-deep);
}
::-webkit-scrollbar-thumb {
    background: var(--border-glass-bright);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--rune-gold);
}

/* 헤더 및 전체 감싸는 메인 컨테이너 */
.app-container {
    width: 100%;
    max-width: 1100px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: fadeIn 1s cubic-bezier(0.16, 1, 0.3, 1) both;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--panel-glass);
    backdrop-filter: blur(var(--blur-strength));
    border: 1px solid var(--border-glass);
    border-radius: 12px;
    box-shadow: var(--shadow-main);
}

.logo h1 {
    font-family: 'Cinzel Decorative', serif;
    font-size: 26px;
    font-weight: 700;
    color: var(--rune-gold);
    text-shadow: 0 0 10px var(--rune-gold-glow);
    letter-spacing: 2px;
}

.system-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn-ctrl {
    background: var(--panel-glass);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-ctrl:hover {
    border-color: var(--rune-gold);
    color: var(--rune-gold);
    box-shadow: 0 0 12px var(--rune-gold-glow);
    transform: translateY(-1px);
}

.btn-ctrl:active {
    transform: translateY(1px);
}

/* --- 16:9 반응형 게임 스크린 뷰포트 --- */
.game-screen-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: #000;
    border-radius: 16px;
    overflow: hidden;
    border: 3px solid var(--border-glass-bright);
    box-shadow: 
        0 20px 50px -15px rgba(0, 0, 0, 0.9),
        0 0 0 1px hsla(42, 85%, 60%, 0.15);
    transition: border-color 0.5s;
}

/* CRT 필터 효과 오버레이 (선택형 토글 가능) */
.crt-screen::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0; left: 0; bottom: 0; right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.22) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.04), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.04));
    z-index: 999;
    background-size: 100% 4px, 6px 100%;
    pointer-events: none;
}

.crt-screen::before {
    content: " ";
    display: block;
    position: absolute;
    top: 0; left: 0; bottom: 0; right: 0;
    background: radial-gradient(circle, transparent 65%, rgba(0,0,0,0.45) 100%);
    z-index: 998;
    pointer-events: none;
}

/* CRT 화면 둥글게 굴리는 굴곡 애니메이션 및 깜빡임 */
.crt-screen-flicker {
    animation: crt-flicker 0.15s infinite;
}

@keyframes crt-flicker {
    0% { opacity: 0.992; }
    50% { opacity: 1; }
    100% { opacity: 0.995; }
}

/* 게임 플레이 화면 메인 뷰포트 */
.game-viewport {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* 씬 마스터 레이아웃 */
.scene {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.8s ease-in-out;
}

.scene.active {
    opacity: 1;
    pointer-events: auto;
}

/* 패럴랙스 요소 배경화면 설정 */
.sky-layer, .bg-layer, .mid-layer, .fg-layer {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

/* 다이내믹 핫스팟 (클릭 대상) */
.hotspot {
    cursor: pointer;
    transition: filter 0.3s, opacity 0.3s;
}

.hotspot:hover {
    filter: drop-shadow(0 0 6px white) brightness(1.2);
}

.hotspot-active {
    filter: drop-shadow(0 0 12px var(--rune-gold)) brightness(1.3) !important;
}

/* 캐릭터 바빈 스레드베어 */
#bobbin-character {
    position: absolute;
    width: 60px;
    height: 110px;
    bottom: 80px;
    left: 100px;
    transform: translateX(-50%);
    pointer-events: none;
    transition: left 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94), bottom 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    z-index: 100;
}

.bobbin-sprite {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: none;
}

/* 바빈 걷기 애니메이션 */
.bobbin-walking .bobbin-cloak {
    animation: cloak-swing 0.4s infinite alternate ease-in-out;
}

.bobbin-walking .bobbin-feet {
    animation: feet-walk 0.4s infinite alternate linear;
}

@keyframes cloak-swing {
    0% { transform: rotate(-3deg) skewX(-2deg); }
    100% { transform: rotate(3deg) skewX(2deg); }
}

@keyframes feet-walk {
    0% { transform: translateY(-1px) scaleY(0.95); }
    100% { transform: translateY(1px) scaleY(1.05); }
}

/* --- 대사창 및 내레이션 상단 바 (오리지널 황금 자막 고증) --- */
.dialogue-box {
    position: absolute;
    bottom: 50px;
    left: 5%;
    width: 90%;
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    padding: 0;
    z-index: 200;
    pointer-events: none;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    text-align: center;
}

.dialogue-box.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.dialogue-speaker {
    font-family: 'Cinzel Decorative', serif;
    font-size: 14px;
    color: var(--rune-gold);
    font-weight: 700;
    margin-bottom: 6px;
    letter-spacing: 2px;
    text-shadow: 
        2px 2px 0px #000, 
        -2px -2px 0px #000, 
        2px -2px 0px #000, 
        -2px 2px 0px #000;
}

.dialogue-text {
    font-size: 18px;
    line-height: 1.6;
    color: #ffeb3b !important; /* 선명한 노란색 자막 */
    font-weight: 700;
    text-shadow: 
        2px 2px 0px #000, 
        -2px -2px 0px #000, 
        2px -2px 0px #000, 
        -2px 2px 0px #000,
        0 4px 8px rgba(0, 0, 0, 0.9);
}

/* 마법 파티클 및 스펠 진행 버퍼 이펙트 */
.spell-particles-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 90;
    pointer-events: none;
}

/* 화면 전환용 암전 레이어 */
.screen-fade {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: black;
    z-index: 900;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.6s ease-in-out;
}

.screen-fade.active {
    opacity: 1;
    pointer-events: auto;
}

/* --- 하단 및 사이드 컨트롤 레이아웃 --- */
.bottom-controls-section {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 16px;
}

@media (max-width: 768px) {
    .bottom-controls-section {
        grid-template-columns: 1fr;
    }
}

/* --- 마법의 실타래 (Distaff) 보드 --- */
.distaff-board {
    background: var(--panel-glass);
    backdrop-filter: blur(var(--blur-strength));
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow-main);
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    overflow: hidden;
}

.distaff-board::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-glass-bright), transparent);
}

.distaff-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.distaff-title {
    font-family: 'Cinzel Decorative', serif;
    font-size: 14px;
    color: var(--rune-gold);
    letter-spacing: 1px;
    font-weight: 700;
}

.distaff-buffer {
    display: flex;
    gap: 6px;
    height: 24px;
}

.buffer-note {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px dashed var(--border-glass-bright);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: transparent;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.buffer-note.filled {
    border-style: solid;
    color: var(--bg-deep);
    text-shadow: 0 0 2px white;
    transform: scale(1.1);
}
/* --- 오선지용 클래식 4분음표 (Quarter Note) 스타일 고증 --- */
.staff-note {
    position: absolute;
    width: 14px;
    height: 10px;
    border-radius: 50%;
    transform: translateY(-50%) rotate(-18deg);
    z-index: 5;
}

/* 4분음표 수직 기둥 (Stem) - 스템 업 (G4 이하 저음역대) */
.staff-note.stem-up::after {
    content: "";
    position: absolute;
    bottom: 5px; /* 머리 중심에서 위로 */
    right: 0px;
    width: 2px;
    height: 24px; /* 기둥 높이 */
    background-color: var(--text-primary);
    transform: rotate(18deg); /* 머리 회전 상쇄용 */
}

/* 4분음표 수직 기둥 (Stem) - 스템 다운 (A4 이상 고음역대) */
.staff-note.stem-down::after {
    content: "";
    position: absolute;
    top: 5px; /* 머리 중심에서 아래로 */
    left: 0px;
    width: 2px;
    height: 24px;
    background-color: var(--text-primary);
    transform: rotate(18deg);
}

/* 오선지 스태프 영역 (Standard 난이도용) */
.distaff-staff {
    height: 48px;
    position: relative;
    border-top: 1px solid hsla(0, 0%, 100%, 0.05);
    border-bottom: 1px solid hsla(0, 0%, 100%, 0.05);
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 8px 0;
    opacity: 0.8;
}

.staff-line {
    width: 100%;
    height: 1px;
    background-color: hsla(0, 0%, 100%, 0.06);
}

/* 실타래 본체 디자인 (나무 막대 형상) */
.distaff-shaft {
    position: relative;
    height: 72px;
    background: linear-gradient(180deg, #2b1708 0%, #150802 100%);
    border: 1px solid #3d210a;
    border-radius: 10px;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.6);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 20px;
    overflow: hidden;
}

.distaff-wood-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 1;
    opacity: 0.9;
}

.distaff-shaft::after {
    content: "";
    position: absolute;
    top: 50%; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--color-C), var(--color-E), var(--color-G), var(--color-C5));
    opacity: 0.08;
    transform: translateY(-50%);
    pointer-events: none;
    z-index: 2;
}

/* 개별 음계 연주 룬 버튼 */
.rune-string {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: radial-gradient(circle, #2f1d0b 0%, #150802 100%);
    border: 2px solid #5a3c22;
    color: hsla(42, 85%, 60%, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-family: 'Cinzel Decorative', serif;
    font-weight: 700;
    font-size: 16px;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
    z-index: 10;
}

.rune-string:hover {
    color: var(--rune-gold);
    border-color: var(--rune-gold);
    box-shadow: 
        0 0 15px var(--rune-gold-glow),
        inset 0 0 8px var(--rune-gold-glow);
    transform: translateY(-2px);
}

/* 음계가 아직 미해금된 비활성화 상태 */
.rune-string.locked {
    opacity: 0.22;
    cursor: not-allowed;
    pointer-events: none;
    border-color: #2a1a0b;
}

/* 음계가 활성화되었을 때 발산하는 컬러별 빛 */
.rune-string.active-C { border-color: var(--color-C); color: white; box-shadow: 0 0 20px var(--color-C); background: var(--color-C); }
.rune-string.active-D { border-color: var(--color-D); color: white; box-shadow: 0 0 20px var(--color-D); background: var(--color-D); }
.rune-string.active-E { border-color: var(--color-E); color: var(--text-dark); box-shadow: 0 0 20px var(--color-E); background: var(--color-E); }
.rune-string.active-F { border-color: var(--color-F); color: var(--text-dark); box-shadow: 0 0 20px var(--color-F); background: var(--color-F); }
.rune-string.active-G { border-color: var(--color-G); color: var(--text-dark); box-shadow: 0 0 20px var(--color-G); background: var(--color-G); }
.rune-string.active-A { border-color: var(--color-A); color: white; box-shadow: 0 0 20px var(--color-A); background: var(--color-A); }
.rune-string.active-B { border-color: var(--color-B); color: white; box-shadow: 0 0 20px var(--color-B); background: var(--color-B); }
.rune-string.active-C5 { border-color: var(--color-C5); color: white; box-shadow: 0 0 20px var(--color-C5); background: var(--color-C5); }

/* 키바인딩 단축키 힌트 */
.rune-keyhint {
    position: absolute;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Outfit', sans-serif;
    font-size: 9px;
    font-weight: 600;
    color: var(--text-muted);
    opacity: 0.6;
}

/* --- 바빈의 양장본 마법 일지 (Journal) --- */
.journal-panel {
    background: var(--panel-glass);
    backdrop-filter: blur(var(--blur-strength));
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow-main);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.journal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-glass);
    padding-bottom: 6px;
}

.journal-title {
    font-family: 'Cinzel Decorative', serif;
    font-size: 13px;
    color: var(--rune-gold);
    font-weight: 700;
}

.journal-count {
    font-size: 11px;
    color: var(--text-muted);
}

.journal-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 106px;
    overflow-y: auto;
    padding-right: 4px;
}

.journal-item {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-glass);
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.spell-info {
    display: flex;
    flex-direction: column;
}

.spell-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--rune-gold);
}

.spell-desc {
    font-size: 11px;
    color: var(--text-muted);
}

.spell-notes {
    font-family: 'Cinzel Decorative', serif;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 2px;
    display: flex;
    gap: 4px;
}

.journal-empty {
    display: flex;
    height: 100%;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
    text-align: center;
}

/* --- 모달 대화 상자 (난이도 설정 및 오디오 활성화 창) --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: radial-gradient(circle at top, hsl(230, 25%, 15%) 0%, hsl(230, 30%, 8%) 100%);
    border: 1px solid var(--border-glass-bright);
    border-radius: 20px;
    padding: 32px;
    width: 90%;
    max-width: 480px;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    gap: 24px;
    text-align: center;
    transform: scale(0.95);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.visible .modal-content {
    transform: scale(1);
}

.modal-logo {
    font-family: 'Cinzel Decorative', serif;
    font-size: 38px;
    font-weight: 700;
    color: var(--rune-gold);
    text-shadow: 0 0 15px var(--rune-gold-glow);
    margin-bottom: -10px;
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-desc {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.6;
}

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

.choice-card {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-glass);
    border-radius: 12px;
    padding: 12px 16px;
    cursor: pointer;
    text-align: left;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.choice-card:hover {
    border-color: var(--rune-gold);
    background: rgba(255, 255, 255, 0.02);
}

.choice-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--rune-gold);
    margin-bottom: 2px;
}

.choice-desc {
    font-size: 12px;
    color: var(--text-muted);
}

.btn-start {
    background: linear-gradient(135deg, var(--rune-gold) 0%, #b38600 100%);
    color: var(--bg-deep);
    border: none;
    padding: 14px 28px;
    border-radius: 10px;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(179, 134, 0, 0.25);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-start:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(179, 134, 0, 0.4);
}

/* 시스템 단축키 안내 윈도우 */
.system-overlay-hint {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    margin-top: 10px;
    line-height: 1.4;
}

/* 공통 애니메이션 효과 */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

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

/* 실타래 배경 룬 가이드 (Expert 모드 대비 연습용 가이드 텍스트) */
.pitch-guide {
    position: absolute;
    top: 2px;
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.5;
}

/* --- 엔딩 오버레이 씬 --- */
.ending-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: black;
    z-index: 800;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1.5s ease-in-out;
    padding: 30px;
    text-align: center;
}

.ending-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.ending-title {
    font-family: 'Cinzel Decorative', serif;
    font-size: 32px;
    color: var(--rune-gold);
    text-shadow: 0 0 20px var(--rune-gold-glow);
    margin-bottom: 20px;
    animation: pulsate 2.5s infinite ease-in-out;
}

.ending-text {
    font-size: 16px;
    line-height: 1.7;
    color: var(--text-primary);
    max-width: 600px;
    margin-bottom: 30px;
}

@keyframes pulsate {
    0% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.02); opacity: 1; text-shadow: 0 0 30px var(--rune-gold); }
    100% { transform: scale(1); opacity: 0.9; }
}

/* --- 파티클 이펙트용 키프레임 --- */
.magical-glow-anim {
    animation: magical-glow 2s infinite alternate ease-in-out;
}

@keyframes magical-glow {
    0% { filter: drop-shadow(0 0 2px rgba(255,255,255,0.4)); }
    100% { filter: drop-shadow(0 0 10px var(--rune-gold)); }
}
