/* ========================================
   YouTube Piano Visualizer - Custom Styles
   ======================================== */

/* 自定義滾動條 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.5);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.5);
}

/* Range Input 自定義 */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    background: linear-gradient(to right,
            rgba(14, 165, 233, 0.8) 0%,
            rgba(14, 165, 233, 0.8) var(--progress, 0%),
            rgba(30, 41, 59, 0.8) var(--progress, 0%),
            rgba(30, 41, 59, 0.8) 100%);
    border-radius: 4px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    margin-top: -4px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

input[type="range"]::-moz-range-track {
    width: 100%;
    height: 8px;
    background: rgba(30, 41, 59, 0.8);
    border-radius: 4px;
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ========================================
   鋼琴鍵盤樣式
   ======================================== */
.piano-keyboard {
    display: flex;
    position: relative;
    height: 140px;
    user-select: none;
}

@media (min-width: 768px) {
    .piano-keyboard {
        height: 180px;
    }
}

@media (min-width: 1024px) {
    .piano-keyboard {
        height: 220px;
    }
}

/* 🎹 兒童模式：更大的鍵盤 */
.piano-keyboard.kids-mode {
    width: 100% !important;
    height: 250px !important;
}

@media (min-width: 768px) {
    .piano-keyboard.kids-mode {
        height: 300px !important;
    }
}

@media (min-width: 1024px) {
    .piano-keyboard.kids-mode {
        height: 350px !important;
    }
}

/* 兒童模式白鍵 */
.piano-keyboard.kids-mode .piano-key {
    flex: 1;
    width: auto !important;
    min-width: 40px;
}

/* 兒童模式黑鍵 */
.piano-keyboard.kids-mode .piano-key.black {
    /* 黑鍵寬度：白鍵的 55-60%，更接近真實鋼琴比例 */
    width: calc(100% / 14 * 0.55) !important;
    min-width: 35px;
    /* 黑鍵高度：白鍵的 60%，標準鋼琴比例 */
    height: 60% !important;
    /* 向左偏移自身寬度的一半 */
    transform: translateX(-50%);
    margin-left: 0;
}

/* 白鍵 */
.piano-key {
    position: relative;
    width: 24px;
    height: 100%;
    background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 0 0 6px 6px;
    box-shadow:
        inset 0 -4px 8px rgba(0, 0, 0, 0.05),
        0 4px 8px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: all 0.1s ease;
    z-index: 1;
}

@media (min-width: 768px) {
    .piano-key {
        width: 30px;
    }
}

@media (min-width: 1024px) {
    .piano-key {
        width: 36px;
    }
}

.piano-key:hover {
    background: linear-gradient(180deg, #ffffff 0%, #f1f5f9 100%);
}

.piano-key.active {
    background: linear-gradient(180deg, #7dd3fc 0%, #38bdf8 100%);
    box-shadow:
        inset 0 2px 8px rgba(0, 0, 0, 0.1),
        0 0 20px rgba(14, 165, 233, 0.6),
        0 0 40px rgba(14, 165, 233, 0.3);
    transform: translateY(2px);
    animation: key-press 0.15s ease-out;
}

/* 黑鍵 */
.piano-key.black {
    position: absolute;
    width: 16px;
    height: 60%;
    background: linear-gradient(180deg, #334155 0%, #1e293b 50%, #0f172a 100%);
    border-radius: 0 0 4px 4px;
    box-shadow:
        inset 0 -2px 4px rgba(255, 255, 255, 0.05),
        0 4px 8px rgba(0, 0, 0, 0.4);
    z-index: 2;
    margin-left: -8px;
}

@media (min-width: 768px) {
    .piano-key.black {
        width: 20px;
        margin-left: -10px;
    }
}

@media (min-width: 1024px) {
    .piano-key.black {
        width: 24px;
        margin-left: -12px;
    }
}

.piano-key.black:hover {
    background: linear-gradient(180deg, #475569 0%, #334155 50%, #1e293b 100%);
}

.piano-key.black.active {
    background: linear-gradient(180deg, #a855f7 0%, #9333ea 50%, #7c3aed 100%);
    box-shadow:
        inset 0 2px 4px rgba(0, 0, 0, 0.2),
        0 0 15px rgba(168, 85, 247, 0.6),
        0 0 30px rgba(168, 85, 247, 0.3);
    transform: translateY(2px);
}

/* 音符標籤 */
.piano-key .note-label {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.4);
    pointer-events: none;
}

.piano-key.black .note-label {
    color: rgba(255, 255, 255, 0.5);
    bottom: 6px;
    font-size: 8px;
}

/* C 音符特殊標記 */
.piano-key[data-note^="C"]:not(.black) .note-label {
    color: rgba(14, 165, 233, 0.8);
    font-weight: 700;
}

/* ========================================
   簡譜數字標籤
   ======================================== */
.piano-key .solfege-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    font-weight: 700;
    color: rgba(0, 0, 0, 0.35);
    pointer-events: none;
    z-index: 3;
}

@media (min-width: 768px) {
    .piano-key .solfege-label {
        font-size: 16px;
    }
}

@media (min-width: 1024px) {
    .piano-key .solfege-label {
        font-size: 18px;
    }
}

.piano-key.black .solfege-label {
    color: rgba(255, 255, 255, 0.4);
    font-size: 10px;
}

@media (min-width: 768px) {
    .piano-key.black .solfege-label {
        font-size: 11px;
    }
}

@media (min-width: 1024px) {
    .piano-key.black .solfege-label {
        font-size: 12px;
    }
}

/* Active 狀態的簡譜數字 */
.piano-key.active .solfege-label {
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
}

.piano-key.black.active .solfege-label {
    color: rgba(255, 255, 255, 0.95);
}

/* ========================================
   撞擊面特效區域 - 超級兒童版
   ======================================== */
.impact-zone {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 12px;
    border-radius: 0;
    pointer-events: none;
    overflow: visible;
    z-index: 5;
}

@media (min-width: 768px) {
    .impact-zone {
        height: 15px;
    }
}

@media (min-width: 1024px) {
    .impact-zone {
        height: 18px;
    }
}

/* 超級撞擊特效 */
.impact-zone.super-impact {
    animation: super-flash 0.4s ease-out;
}

.impact-zone.super-impact::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 300%;
    height: 60px;
    background: radial-gradient(ellipse 100% 200% at center bottom,
            var(--impact-color, #f39c12) 0%,
            transparent 70%);
    animation: mega-expand 0.4s ease-out;
    filter: blur(2px);
}

.impact-zone.super-impact::after {
    content: '';
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 0 20px 10px rgba(255, 255, 255, 0.8);
    animation: spark-burst 0.4s ease-out;
}

@keyframes super-flash {
    0% {
        box-shadow:
            0 0 40px 20px var(--impact-color, #f39c12),
            0 0 80px 40px var(--impact-color, #f39c12),
            0 -30px 60px 10px rgba(255, 255, 255, 0.8);
    }

    50% {
        box-shadow:
            0 0 60px 30px var(--impact-color, #f39c12),
            0 0 100px 50px transparent,
            0 -50px 80px 20px rgba(255, 255, 255, 0.4);
    }

    100% {
        box-shadow: 0 0 0 0 transparent;
    }
}

@keyframes mega-expand {
    0% {
        opacity: 1;
        transform: translateX(-50%) scaleX(0.2) scaleY(0.5);
    }

    100% {
        opacity: 0;
        transform: translateX(-50%) scaleX(1.5) scaleY(1.5);
    }
}

@keyframes spark-burst {
    0% {
        opacity: 1;
        transform: translateX(-50%) scale(0.5);
    }

    50% {
        opacity: 1;
        transform: translateX(-50%) scale(2);
    }

    100% {
        opacity: 0;
        transform: translateX(-50%) scale(3) translateY(-40px);
    }
}

/* 漣漪擴散動畫 */
@keyframes ripple-expand {
    0% {
        width: 10px;
        height: 10px;
        opacity: 1;
    }

    100% {
        width: 100px;
        height: 100px;
        opacity: 0;
        margin-left: -45px;
        margin-top: -50px;
    }
}

/* 光柱效果 */
.piano-key.active::before {
    content: '';
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    height: 100px;
    background: linear-gradient(to top,
            var(--active-color, #38bdf8) 0%,
            transparent 100%);
    opacity: 0.6;
    animation: light-beam 0.3s ease-out;
    pointer-events: none;
}

@keyframes light-beam {
    0% {
        height: 0;
        opacity: 1;
    }

    100% {
        height: 100px;
        opacity: 0.6;
    }
}

/* 活動鍵的額外發光 */
.piano-key.active {
    transform: translateY(3px);
    transition: all 0.1s ease;
}

.piano-key.active .solfege-label {
    text-shadow:
        0 0 10px rgba(255, 255, 255, 1),
        0 0 20px rgba(255, 255, 255, 0.8),
        0 0 30px var(--active-color, #38bdf8);
    animation: pulse-glow 0.5s ease-in-out infinite;
}

@keyframes pulse-glow {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
    }

    50% {
        transform: translate(-50%, -50%) scale(1.1);
    }
}

/* ========================================
   瀑布流 Canvas 樣式
   ======================================== */
.waterfall-canvas {
    display: block;
    border-radius: 8px;
}

/* 瀑布流容器 - 不設 justify-content，讓它自然對齊 */
#waterfall-container {
    display: block;
    overflow: hidden;
}

/* 兒童模式：瀑布流和鋼琴佔滿寬度 */
#waterfall-container.kids-mode,
#piano-container.kids-mode {
    width: 100% !important;
}

/* 鋼琴容器 */
#piano-container {
    display: block;
}

/* ========================================
   Toast 通知
   ======================================== */
.toast {
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 280px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: toast-in 0.3s ease-out;
}

.toast.success {
    border-left: 4px solid #22c55e;
}

.toast.error {
    border-left: 4px solid #ef4444;
}

.toast.info {
    border-left: 4px solid #3b82f6;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* ========================================
   響應式調整
   ======================================== */
@media (max-width: 640px) {
    #piano-container {
        transform: scale(0.9);
        transform-origin: center;
    }
}

/* 無障礙：專注狀態 */
button:focus-visible,
input:focus-visible {
    outline: 2px solid #0ea5e9;
    outline-offset: 2px;
}

/* 減少動畫偏好 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}