/* =========================================
   1. 基礎設定與變數 (Base & Variables)
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
    --brand-blue: #3b82f6;
    --transition-fast: 0.1s ease;
    --transition-base: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

.font-mono {
    font-family: 'JetBrains Mono', monospace;
}

/* =========================================
      2. 通用 UI 元件 (Common UI Components)
      ========================================= */
/* 視圖切換 */
.view-section {
    display: none;
    height: 100%;
    overflow-y: auto;
    padding-bottom: 80px;
}

.view-section.active {
    display: block;
}

/* 模態視窗過渡 */
.modal {
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    transform: translateY(100%);
}

.modal.open {
    transform: translateY(0);
}

/* 隱藏原生捲軸 */
.no-scrollbar::-webkit-scrollbar {
    display: none;
}

.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* 自訂捲軸 (HoldFocus 面板使用) */
.custom-scrollbar::-webkit-scrollbar {
    width: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}

/* 通用滑桿 (Range Input) */
input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: var(--brand-blue);
    cursor: pointer;
    margin-top: -7px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform var(--transition-fast);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: #e5e7eb;
    border-radius: 2px;
}

/* 步進按鈕 (+ / -) */
.slider-btn {
    touch-action: none;
    user-select: none;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f3f4f6;
    border-radius: 6px;
    font-weight: bold;
    color: #4b5563;
    flex-shrink: 0;
    transition: transform var(--transition-fast);
}

.slider-btn:active {
    transform: scale(0.9);
    background-color: #e5e7eb;
}

/* 通用顏色選擇器按鈕 */
.color-btn {
    transition: all var(--transition-base);
}

.color-btn.selected {
    transform: scale(1.15);
    box-shadow: 0 0 0 2px white, 0 0 0 4px currentColor;
}

.dark .color-btn.selected {
    box-shadow: 0 0 0 2px #1f2937, 0 0 0 4px currentColor;
}

/* Toggle Switch (設定頁面) */
.toggle-checkbox:checked {
    right: 0;
    border-color: var(--brand-blue);
}

.toggle-checkbox:checked+.toggle-label {
    background-color: var(--brand-blue);
}

/* 隱藏原生檔案上傳 */
#file-upload {
    display: none;
}


/* =========================================
      3. 動畫與視覺反饋 (Animations & Effects)
      ========================================= */
/* 語音狀態動畫 */
.mic-listening {
    animation: pulse-red 1.5s infinite;
    background-color: #ef4444 !important;
    color: white !important;
}

@keyframes pulse-red {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* 急迫感呼吸燈效果 (計時器背景) */
.pulse-urgent {
    animation: urgent-pulse 0.5s infinite ease-in-out;
}

@keyframes urgent-pulse {

    0%,
    100% {
        filter: brightness(1);
    }

    50% {
        filter: brightness(1.3);
    }
}

/* 點擊標記時的高亮反饋 (HoldFocus) */
.flash-active {
    animation: flash-highlight 0.5s ease-out;
}

@keyframes flash-highlight {
    0% {
        background-color: #FEF08A;
        transform: scale(1.02);
    }

    100% {
        background-color: white;
        transform: scale(1);
    }
}

/* 處理中載入動畫 */
.loader {
    border: 3px solid #f3f3f3;
    border-radius: 50%;
    border-top: 3px solid var(--brand-blue);
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* 心率跳動動畫 */
.pulse-animation {
    animation: pulse-ring 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);
}

@keyframes pulse-ring {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

/* =========================================
      4. Hangboard 專屬模組 (Timer & Routines)
      ========================================= */
/* 積木樣式基礎 */
.block-item {
    touch-action: none;
    transition: transform var(--transition-fast);
}

.block-item:active {
    transform: scale(0.98);
}

.sortable-ghost {
    opacity: 0.4;
    background: #e5e7eb;
    border: 1px dashed #9ca3af;
}

.sortable-drag {
    opacity: 0.9;
    transform: scale(1.02);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* 巢狀縮排線條 */
.nested-container {
    min-height: 50px;
    margin-top: 0.5rem;
    border-radius: 0.5rem;
    background-color: rgba(0, 0, 0, 0.03);
    border: 1px dashed #cbd5e1;
}

.dark .nested-container {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: #4b5563;
}

/* 屬性面板陰影 */
#prop-sheet {
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
}

/* 鎖定遮罩樣式 */
#lock-overlay {
    backdrop-filter: blur(2px);
    background: rgba(0, 0, 0, 0.2);
}

/* 日曆格點容器 */
.cal-day {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    border-radius: 0.75rem;
    transition: background-color var(--transition-base);
}

.cal-date-num {
    font-size: 0.875rem;
    font-weight: 600;
    z-index: 1;
}

.is-today {
    background-color: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.5);
}

/* 日曆點點容器 */
.dots-container {
    position: absolute;
    bottom: 6px;
    display: flex;
    gap: 2px;
    justify-content: center;
    width: 100%;
    height: 4px;
}

.dot {
    width: 4px;
    height: 4px;
    border-radius: 999px;
    background-color: var(--brand-blue);
}


/* =========================================
      5. HoldFocus 專屬模組 (Canvas & Editor)
      ========================================= */
#canvas-container {
    touch-action: none;
    overflow: hidden;
}

/* 畫布層級與轉化 */
.canvas-stack {
    position: relative;
    width: 0;
    height: 0;
    max-width: none !important;
    max-height: none !important;
}

.layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: none !important;
    max-height: none !important;
}

#layer-bg {
    z-index: 1;
}

#layer-mask {
    z-index: 2;
    mix-blend-mode: normal;
}

#layer-ui {
    z-index: 3;
    pointer-events: none;
}

/* 裁切預覽與遮罩 */
.crop-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.crop-frame {
    border: 2px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6);
    position: relative;
    display: none;
}

/* 九宮格輔助線 */
.crop-frame::before,
.crop-frame::after {
    content: '';
    position: absolute;
    border: 1px dashed rgba(255, 255, 255, 0.3);
}

.crop-frame::before {
    top: 33.33%;
    bottom: 33.33%;
    left: 0;
    right: 0;
    border-left: none;
    border-right: none;
}

.crop-frame::after {
    left: 33.33%;
    right: 33.33%;
    top: 0;
    bottom: 0;
    border-top: none;
    border-bottom: none;
}

#crop-inner-backdrop {
    position: absolute;
    inset: 0;
    z-index: 0;
    display: none;
}

/* 工具列與按鈕 */
.tool-btn {
    color: #6b7280;
    transition: all 0.2s;
    touch-action: manipulation;
}

.tool-btn.active {
    background-color: var(--brand-blue);
    color: white;
}

/* 輔助吸附線 */
.snap-line {
    position: absolute;
    background-color: var(--brand-blue);
    z-index: 70;
    pointer-events: none;
    box-shadow: 0 0 4px rgba(255, 255, 255, 0.8);
}

/* 放大鏡 */
#loupe {
    position: absolute;
    width: 130px;
    height: 130px;
    border: 3px solid white;
    border-radius: 50%;
    pointer-events: none;
    z-index: 100;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    display: none;
    background: #000;
}

/* =========================================
   6. 品牌視覺與首頁樣式 (Brand & Index)
   ========================================= */
/* 核心功能卡片樣式 */
.feature-card {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background-color: white;
    border-radius: 1.5rem;
    /* 24px */
    border: 1px solid #e2e8f0;
    /* slate-200 */
}

.feature-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* 漸層標題 */
.text-gradient {
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
    background-image: linear-gradient(to right, #0f172a, #475569);
    /* slate-900 to slate-600 */
}

/* 狀態標籤 */
.status-badge {
    padding: 0.125rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 700;
}

/* 導航欄毛玻璃效果 */
.nav-blur {
    position: sticky;
    top: 0;
    z-index: 50;
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid #e2e8f0;
}

/* =========================================
   7. Hangboard Timer 視覺強化 (配合新版 UI)
   ========================================= */

/* BLE 數值強對比文字陰影：確保文字在複雜圖表背景上絕對清晰 */
.ble-text-overlay {
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8), 0 0 12px rgba(0, 0, 0, 0.5);
}

/* BLE Gauge 指針進階光暈與過渡 */
#ble-gauge-pointer {
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.8), 0 0 2px rgba(0, 0, 0, 0.3) inset;
    transition: left 0.1s cubic-bezier(0.4, 0, 0.2, 1), transform 0.1s;
}

/* 確保 BLE 圖表所在的 Canvas 響應式縮放不失真 */
#ble-live-chart {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* 針對所有可拖曳的積木 (包含新增區與編輯畫布區) */
.palette-item,
#editor-canvas>div {
    -webkit-user-select: none !important;
    user-select: none !important;
    -webkit-touch-callout: none !important;
    /* 避免內部文字或圖示成為拖曳的干擾點 */
    touch-action: none;
}

.select-none {
    -webkit-user-select: none !important;
    user-select: none !important;
    -webkit-touch-callout: none !important;
    /* 徹底禁用 iOS 長按選單 */
}