/* 
======================================================
  sim-components.css 
  阿偉的物理 x AI 實驗室 - 互動式模擬標準元件庫
  
  【重要家規】AI 開發者請注意：
  禁止在此系統外自創與佈局相關的 class 或使用 inline style。
  所有新開發的模擬器必須使用本檔案提供的 .sim- 類別。
======================================================
*/

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700&display=swap');

body {
    font-family: 'Noto Sans TC', sans-serif;
    color: var(--sim-text-main);
}

:root {
    /* 色彩系統 (Color System) */
    --sim-brand-primary: #657954;      /* 主色：綠色 */
    --sim-brand-hover: #526344;
    --sim-action-blue: #3B82F6;        /* 強調色：藍色 */
    --sim-action-blue-hover: #2563EB;
    
    --sim-bg-main: #f8fafc;
    --sim-bg-light: #f8fafc;
    --sim-bg-panel: rgba(255, 255, 255, 0.85);
    
    --sim-text-main: #1e293b;
    --sim-text-muted: #64748b;
    --sim-border: rgba(226, 232, 240, 0.6);
    --sim-border-light: #e2e8f0;
    --sim-warning-amber: #d97706;
    --sim-danger-red: #dc2626;
    
    /* 幾何與間距 (Geometry & Spacing) */
    --sim-radius-sm: 8px;
    --sim-radius-md: 16px;
    --sim-radius-lg: 24px;
    
    --sim-space-xs: 4px;
    --sim-space-sm: 8px;
    --sim-space-md: 16px;
    --sim-space-lg: 24px;
    
    /* 陰影 (Shadows) */
    --sim-shadow-panel: 0 -8px 30px rgba(0, 0, 0, 0.12);
    --sim-shadow-overlay: 0 8px 24px rgba(0, 0, 0, 0.12);

    /* 圖表與強調色 (Charts & Accents) */
    --sim-chart-y: #3B82F6;
    --sim-chart-v: #10B981;
    --sim-chart-a: #EF4444;
    --sim-accent-color: #EF4444;
}

/* 全域重置：確保所有模擬器的 body/main 都能正確撐滿視窗 */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] {
    display: none !important;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

main {
    height: 100%;
    overflow: hidden;
}

/* ==========================================================================
   1. 應用程式外框 (App Shell)
   ========================================================================== */
.sim-app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    background-color: var(--sim-bg-main);
    font-family: 'Noto Sans TC', 'Inter', system-ui, -apple-system, sans-serif;
}

.sim-canvas-container {
    flex: 1; /* 佔滿剩餘空間 */
    min-width: 0; /* 必須設定 0，否則 Flex 子元素無法收縮至小於內容大小 */
    min-height: 0;
    position: relative;
    background: #ffffff;
    /* 避免手勢干擾 */
    overflow: hidden;
    touch-action: none;
}

/* canvas 預設是 inline，會產生 baseline 縫隙（底部白線）。強制 block 修掉。 */
.sim-canvas-container canvas {
    position: absolute;
    left: 0;
    top: 0;
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.sim-canvas-container > #simCanvas {
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* ==========================================================================
   2. 響應式控制面板 & 三段式抽屜 (Responsive Control Panel & 3-State Bottom Sheet)
   ========================================================================== */
.sim-panel {
    background: var(--sim-bg-panel);
    backdrop-filter: blur(24px) saturate(150%);
    -webkit-backdrop-filter: blur(24px) saturate(150%);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

/* --- 手機版 (Mobile First): 預設為底部抽屜 --- */
@media (max-width: 768px) {
    .sim-panel {
        width: 100%;
        border-top-left-radius: var(--sim-radius-lg);
        border-top-right-radius: var(--sim-radius-lg);
        box-shadow: var(--sim-shadow-panel);
        transition: height 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
        overflow: hidden; /* 防止內容在縮放時溢出 */
    }

    /* 三段高度設定 */
    .sim-panel.state-full {
        height: 70dvh;
    }
    
    .sim-panel.state-half {
        height: 35dvh; 
    }
    
    .sim-panel.state-collapsed {
        height: 56px; /* 只顯示標題列的高度 */
    }

    /* 手機版箭頭圖示 */
    .sim-mobile-toggle-icon {
        display: block;
        color: var(--sim-brand-primary);
        font-size: 1.2rem;
        transition: transform 0.3s ease;
    }
    
    .sim-panel.state-collapsed .sim-mobile-toggle-icon {
        transform: rotate(180deg);
    }
}

/* --- 電腦版 (Desktop): 右側邊欄 --- */
@media (min-width: 769px) {
    .sim-app-shell {
        flex-direction: row; /* 水平排列 Canvas 和 Panel */
    }
    
    .sim-panel {
        width: 380px;
        height: 100%;
        border-left: 1px solid var(--sim-border);
        box-shadow: -2px 0 10px rgba(0,0,0,0.05);
        /* 桌面版無三段式抽屜，強制全開 */
    }
    
    .sim-mobile-toggle-icon {
        display: none; /* 隱藏手機版切換箭頭 */
    }
}

/* ==========================================================================
   3. 面板內部結構 (Panel Internals)
   ========================================================================== */
.sim-panel-header {
    padding: var(--sim-space-md);
    background: var(--sim-bg-panel);
    cursor: pointer; /* 點擊/拖曳區 (預設為手機版，可點擊展開) */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sim-panel-header:focus-visible {
    outline: 3px solid rgba(59, 130, 246, 0.65);
    outline-offset: -4px;
    border-radius: var(--sim-radius-sm);
}

@media (min-width: 769px) {
    .sim-panel-header {
        cursor: default !important; /* 電腦版不顯示點擊指標 */
    }
}

@media (max-width: 768px) {
    .sim-panel-header {
        justify-content: space-between;
        padding-left: var(--sim-space-lg);
        padding-right: var(--sim-space-lg);
    }
    /* 手機版：標題 wrapper 置中（flex 容器用 justify-content） */
    .sim-panel-title-wrapper {
        justify-content: center;
    }
    /* 標題本身是 flex，需用 justify-content 置中內部文字 */
    .sim-panel-title {
        justify-content: center;
        width: 100%;
    }
}

.sim-panel-title-wrapper {
    display: flex;
    flex: 1;
    justify-content: flex-start;
    padding-bottom: 4px;
    border-bottom: 2px solid var(--sim-brand-primary);
}

.sim-panel-title {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 700;
    font-family: 'Noto Sans TC', sans-serif;
    line-height: 1.2;
    letter-spacing: normal;
    color: var(--sim-brand-primary);
    display: flex;
    align-items: center;
    gap: var(--sim-space-sm);
}

.sim-panel-body {
    padding: var(--sim-space-md);
    overflow-y: auto;
    /* 防呆排版法：使用 flex column + gap */
    display: flex;
    flex-direction: column;
    gap: var(--sim-space-md);
    flex: 1;
}

/* 控制元件群組 (用來包覆多個按鈕或滑桿，維持統一間距) */
.sim-control-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ==========================================================================
   4. UI 元件 (UI Components)
   ========================================================================== */

/* --- 區塊標題 (Section Group) --- */
.sim-group-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--sim-text-muted);
    border-bottom: 1px solid var(--sim-border);
    padding-bottom: var(--sim-space-xs);
    margin-bottom: var(--sim-space-sm);
    margin-top: var(--sim-space-lg);
}

.sim-group-title:first-child {
    margin-top: 0;
}

/* --- 滑桿包裝 (Slider Wrapper) --- */
.sim-slider-wrapper {
    display: flex;
    flex-direction: column;
    gap: var(--sim-space-sm);
}

.sim-slider-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
    color: var(--sim-text-main);
}

.sim-slider-label {
    font-weight: 500;
}

.sim-slider-val {
    font-family: 'Courier New', Courier, monospace;
    font-weight: 600;
    color: var(--sim-action-blue);
    background: #eff6ff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.sim-slider {
    width: 100%;
    margin: 0;
    cursor: pointer;
    -webkit-appearance: none;
    background: transparent;
}
.sim-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    background: rgba(0,0,0,0.06);
    border-radius: 4px;
}
.sim-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2), 0 0 1px rgba(0,0,0,0.1);
    margin-top: -6px;
    transition: transform 0.1s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sim-slider::-webkit-slider-thumb:active {
    transform: scale(1.15);
}

.sim-slider:focus-visible {
    outline: 3px solid rgba(59, 130, 246, 0.45);
    outline-offset: 4px;
    border-radius: var(--sim-radius-sm);
}

/* --- 按鈕群組 (Button Group) --- */
/* 預設：一行一個按鈕（flex-direction: column） */
.sim-btn-row {
    display: flex;
    flex-direction: row;
    gap: var(--sim-space-sm);
}

/* --- 撥動開關 (Toggle Switch) --- */
/* 垂直清單容器 (iOS Settings 風格) */
.sim-toggle-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sim-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;  /* 文字靠左、開關靠右 */
    gap: var(--sim-space-md);
    padding: 9px 4px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--sim-text-main);
    user-select: none;
    border-bottom: 1px solid rgba(0,0,0,0.05); /* 淡淡分隔線 */
    transition: background 0.15s ease;
    border-radius: var(--sim-radius-sm);
}

.sim-toggle:last-child {
    border-bottom: none;
}

.sim-toggle:hover {
    background: rgba(0,0,0,0.03);
}

.sim-toggle-label {
    flex: 1;  /* 文字區域自動填滿剩餘空間 */
}

.sim-toggle-input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
    margin: 0;
    pointer-events: none;
}

.sim-toggle-track {
    flex-shrink: 0;
    width: 44px;
    height: 24px;
    background: #cbd5e1; /* Clear gray for OFF state */
    border-radius: 24px;
    position: relative;
    transition: background 0.3s ease;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.sim-toggle-thumb {
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.sim-toggle-input:checked + .sim-toggle-track {
    background: var(--sim-brand-primary);
}

.sim-toggle-input:checked + .sim-toggle-track .sim-toggle-thumb {
    transform: translateX(20px);
}

.sim-toggle-input:focus-visible + .sim-toggle-track {
    outline: 3px solid rgba(59, 130, 246, 0.45);
    outline-offset: 3px;
}

.sim-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sim-space-sm);
    padding: 12px 16px;
    border-radius: var(--sim-radius-md);
    font-size: 1rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition:
        background-color 150ms cubic-bezier(0.2, 0.8, 0.2, 1),
        color 150ms cubic-bezier(0.2, 0.8, 0.2, 1),
        box-shadow 150ms cubic-bezier(0.2, 0.8, 0.2, 1),
        opacity 150ms cubic-bezier(0.2, 0.8, 0.2, 1),
        transform 150ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sim-btn:focus-visible {
    outline: 3px solid rgba(59, 130, 246, 0.65);
    outline-offset: 3px;
}

.sim-btn:active {
    transform: scale(0.95);
}

.sim-btn-label {
    line-height: 1.3;
}

.sim-btn-label sub {
    font-size: 0.7em;
    line-height: 0;
    vertical-align: sub;
}

.sim-btn-primary {
    background: var(--sim-brand-primary);
    color: white;
}

.sim-btn-primary:hover {
    background: var(--sim-brand-hover);
}

.sim-btn-secondary {
    background: var(--sim-brand-hover);  /* 深一點的綠，和 primary 有層次感 */
    border: none;
    color: white;
}

.sim-btn-secondary:hover {
    background: var(--sim-brand-primary);
}

/* 重置/危險操作：淺灰色，低調但可辨識 */
.sim-btn-reset {
    background: #dde3ea;
    border: 1px solid #c8d0d9;
    color: #64748b;
}

.sim-btn-reset:hover {
    background: #cdd5de;
    color: #475569;
}

.sim-btn-danger {
    background: #ef4444;
    color: white;
}

.sim-btn-orange {
    background: #f59e0b;
    color: white;
    border: none;
}

.sim-btn-orange:hover {
    background: #fbbf24;
}

/* ==========================================================================
   6. 浮水印 (Watermark)
   ========================================================================== */
.sim-watermark {
    position: absolute;
    bottom: 16px;
    right: 16px;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 700;
    pointer-events: none;
    z-index: 40;
    
    /* 完美置中對齊 */
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    
    /* 預設：淺色畫布適用（深底白字，清晰可見） */
    color: rgba(255, 255, 255, 0.95);
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* 深色畫布適用（白底黑字，對比強烈防盜版） */
.sim-watermark.theme-dark {
    color: var(--sim-text-main);
    background: rgba(255, 255, 255, 0.75);
}

.sim-data-item {
    display: flex;
    justify-content: space-between;
    gap: var(--sim-space-lg);
    font-size: 0.95rem;
}

.sim-data-label {
    color: var(--sim-text-muted);
}

.sim-data-val {
    font-family: 'Courier New', Courier, monospace;
    font-weight: 700;
    color: var(--sim-text-main);
}

.sim-data-val-large {
    font-family: 'Courier New', Courier, monospace;
    font-weight: 700;
    color: var(--sim-action-blue);
    font-size: 1.25rem;
}

/* === 分段按鈕 (Segmented Control) === */
.sim-segmented-control {
    display: flex;
    background: #f1f5f9;
    border-radius: 8px;
    padding: 4px;
    gap: 4px;
    width: 100%;
}

.sim-segmented-control input[type="radio"] {
    display: none;
}

.sim-segmented-control label {
    flex: 1;
    text-align: center;
    padding: 6px 0;
    border-radius: 6px;
    font-size: 0.9em;
    color: var(--sim-text-muted);
    cursor: pointer;
    transition:
        background-color 200ms ease,
        color 200ms ease,
        box-shadow 200ms ease;
}

.sim-segmented-control input[type="radio"]:checked + label {
    background: white;
    color: var(--sim-brand-primary);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.sim-segmented-control input[type="radio"]:focus-visible + label {
    outline: 3px solid rgba(59, 130, 246, 0.45);
    outline-offset: 1px;
}

/* 特殊元件：力學能分佈圖 (Energy Bars) */
.sim-energy-bars {
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    height: 80px;
    background: var(--sim-bg-panel);
    border-radius: 8px;
    padding: 10px 5px 0 5px;
    border: 1px solid var(--sim-border);
}

.sim-energy-bar-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
}

.sim-energy-bar-fill {
    width: 24px;
    height: 0;
    border-radius: 4px 4px 0 0;
    transition: height 0.1s;
}

.sim-energy-bar-ke { background-color: #3B82F6; }
.sim-energy-bar-pe { background-color: #10B981; }
.sim-energy-bar-total { background-color: #F59E0B; }

.sim-energy-bar-label {
    font-size: 0.75rem;
    margin-top: 4px;
    color: var(--sim-text-muted);
    font-weight: 700;
}

/* 特殊元件：可收合的資訊面板按鈕 (Toggle Panel Button) */
.sim-toggle-panel-btn {
    padding: 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    font-size: 0.95rem;
    background-color: var(--sim-bg-light);
    transition: background-color 0.2s;
    border-radius: 8px;
}

.sim-toggle-panel-btn:hover {
    background-color: var(--sim-border);
}

.sim-toggle-panel-btn[aria-expanded="true"] {
    background-color: var(--sim-border);
}

.sim-toggle-panel-btn[aria-expanded="true"] .sim-toggle-panel-icon {
    transform: rotate(180deg);
}

.sim-toggle-panel-icon {
    color: var(--sim-text-muted);
    font-size: 0.8rem;
    transition: transform 0.3s;
}

.sim-toggle-panel-content {
    padding: 0 15px 15px 15px;
}

/* 提示文字 */
.sim-text-strong {
    font-weight: 700;
}

.sim-data-item-tip {
    color: var(--sim-brand-primary);
    font-size: 0.85rem;
    justify-content: center;
}

.sim-data-formula {
    display: inline-block;
    margin-top: 2px;
    color: var(--sim-text-muted);
    font-family: "Times New Roman", serif;
    font-size: 0.82em;
    font-weight: 400;
}

/* 
======================================================
  8. 圖例與數學公式 (Legend & Math Card)
======================================================
*/

/* 實驗圖例 */
.sim-legend-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    gap: 8px;
    margin-bottom: var(--sim-space-sm);
}

.sim-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.sim-legend-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.sim-legend-color-line {
    width: 20px;
    height: 3px;
}

.sim-legend-dot-blue { background-color: var(--sim-action-blue); }
.sim-legend-dot-gray { background-color: var(--sim-text-muted); border: 1px solid var(--sim-border); }
.sim-legend-line-red { background-color: var(--sim-chart-a); }
.sim-legend-dot-purple { background-color: #9333EA; }
.sim-legend-dot-green { background-color: #22C55E; }
.sim-legend-dot-red { background-color: #EF4444; }
.sim-legend-dot-yellow { background-color: #EAB308; }

.sim-field-legend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 4px;
    color: var(--sim-text-main);
    font-size: 0.9rem;
}

.sim-field-legend-swatch {
    flex-shrink: 0;
    border-radius: 999px;
}

.sim-field-legend-dot {
    width: 14px;
    height: 14px;
}

.sim-field-legend-line {
    width: 22px;
    height: 3px;
}

.sim-field-legend-source {
    background-color: #00C7D1;
    box-shadow: 0 0 8px rgb(0 199 209 / 55%);
}

.sim-field-legend-test {
    background-color: #E60073;
    box-shadow: 0 0 8px rgb(230 0 115 / 45%);
}

.sim-field-legend-field {
    background-color: rgb(100 116 139 / 70%);
}

.sim-field-legend-force {
    background-color: #D4A900;
}

/* Unit and dimension puzzle */
.sim-canvas-static-layer {
    pointer-events: none;
    z-index: 0;
}

.sim-text-keep {
    word-break: keep-all;
    overflow-wrap: break-word;
}

.sim-unit-toolbox::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.sim-unit-toolbox::-webkit-scrollbar-track {
    background: #F1F5F9;
    border-radius: 4px;
}

.sim-unit-toolbox::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 4px;
}

.sim-unit-stage {
    scroll-padding-top: 24px;
}

.sim-unit-piece {
    cursor: grab;
    transition: transform 100ms ease, box-shadow 100ms ease;
    user-select: none;
    touch-action: none;
}

.sim-unit-piece:active {
    cursor: grabbing;
    transform: scale(1.05);
    box-shadow: 0 10px 15px -3px rgb(15 23 42 / 12%);
}

.sim-unit-slot {
    transition: background-color 200ms ease, border-color 200ms ease, box-shadow 200ms ease;
}

.sim-unit-slot.hovered {
    background-color: rgb(59 130 246 / 10%);
    border-color: var(--sim-action-blue);
    box-shadow: 0 0 0 4px rgb(59 130 246 / 20%);
}

.sim-fraction-line {
    width: 100%;
    height: 3px;
    margin: 12px 0;
    border-radius: 2px;
    background-color: var(--sim-text-main);
}

.sim-unit-dragging {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    opacity: .95;
    box-shadow: 0 15px 25px -5px rgb(15 23 42 / 22%);
    transform: translate(-50%, -50%);
}

@keyframes sim-unit-pop {
    from { transform: scale(0); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.sim-anim-unit-pop {
    animation: sim-unit-pop 300ms cubic-bezier(.175, .885, .32, 1.275);
}

@keyframes sim-unit-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.sim-anim-unit-shake {
    animation: sim-unit-shake 300ms ease-in-out;
}

@media (prefers-reduced-motion: reduce) {
    .sim-anim-unit-pop,
    .sim-anim-unit-shake {
        animation: none;
    }
}

@media (max-width: 768px) {
    #movable-stage.sim-unit-stage {
        padding-top: 72px;
    }
}

/* 數學公式卡片 */
.sim-math-card {
    background-color: var(--sim-bg-main);
    padding: var(--sim-space-md);
    border-radius: var(--sim-radius-sm);
    border: 1px solid var(--sim-border);
    margin-top: var(--sim-space-sm);
}

.sim-math-card-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--sim-text-muted);
    margin-bottom: var(--sim-space-sm);
}

.sim-math-formula {
    font-family: "Times New Roman", serif;
    font-style: italic;
    text-align: center;
    font-size: 1.1rem;
    color: var(--sim-text-main);
    margin: 10px 0;
}

.sim-math-fraction {
    display: inline-block;
    vertical-align: middle;
    margin: 0 4px;
    font-size: 0.9rem;
}

.sim-math-numerator {
    display: block;
    border-bottom: 1px solid currentColor;
    line-height: 1;
    padding-bottom: 2px;
}

.sim-math-denominator {
    display: block;
    line-height: 1;
    padding-top: 2px;
}

.sim-math-description {
    font-size: 0.8rem;
    color: var(--sim-text-muted);
    line-height: 1.5;
    margin-top: 10px;
}

.sim-math-card canvas {
    display: block;
    width: 100%;
    height: 96px;
}

/* === 模擬器資料、圖表與向量元件 === */
.sim-data-card {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    gap: var(--sim-space-md);
    padding: var(--sim-space-md);
    background: var(--sim-bg-panel);
    border: 1px solid var(--sim-border);
    border-radius: var(--sim-radius-md);
}

.sim-data-card-title {
    padding-bottom: var(--sim-space-sm);
    border-bottom: 1px solid var(--sim-border);
    color: var(--sim-text-main);
    font-size: 1rem;
    font-weight: 600;
}

.sim-data-stack {
    display: flex;
    flex-direction: column;
    gap: var(--sim-space-sm);
}

.sim-data-note {
    color: var(--sim-text-muted);
    font-size: 0.78rem;
    line-height: 1.45;
}

.sim-hint-card {
    padding: 12px;
    color: var(--sim-text-muted);
    background: rgba(15, 23, 42, 0.03);
    border: 1px solid var(--sim-border);
    border-radius: var(--sim-radius-sm);
    font-size: 0.85rem;
    line-height: 1.6;
}

.sim-camera-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 20;
    width: min(82%, 340px);
    padding: 20px 30px;
    transform: translate(-50%, -50%);
    color: var(--sim-brand-primary);
    background: rgb(255 255 255 / 88%);
    border: 1px solid rgb(255 255 255 / 65%);
    border-radius: var(--sim-radius-md);
    box-shadow: var(--sim-shadow-lg);
    backdrop-filter: blur(8px) saturate(130%);
    text-align: center;
    font-weight: 700;
}

.sim-camera-loading-sub {
    margin-top: 8px;
    color: var(--sim-text-muted);
    font-size: 0.85rem;
    font-weight: 400;
}

.sim-camera-start-btn {
    width: 100%;
    margin-top: var(--sim-space-md);
}

.sim-btn:disabled,
.sim-toggle-input:disabled + .sim-toggle-track {
    cursor: not-allowed;
    opacity: 0.5;
}

.sim-vector-label {
    font-weight: 700;
}

.sim-vector-amber { color: #D97706; }
.sim-vector-cyan { color: #0891B2; }
.sim-vector-pink { color: #DB2777; }

.sim-feedback-message {
    width: 100%;
    color: var(--sim-text-muted);
    line-height: 1.55;
    white-space: normal;
}

.sim-status-stack {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.sim-status-description {
    color: var(--sim-text-muted);
    white-space: normal;
}

.sim-legend-dot-solar {
    background-color: #EAB308;
    box-shadow: 0 0 5px rgb(234 179 8 / 70%);
}

.sim-legend-dot-infrared {
    background-color: #DC2626;
    box-shadow: 0 0 5px rgb(220 38 38 / 60%);
}

.sim-legend-dot-molecule {
    background-color: rgb(255 255 255 / 65%);
    border: 1px solid #CBD5E1;
}

.sim-lotka-chart {
    aspect-ratio: 13 / 6;
    margin-bottom: 5px;
}

.sim-input-invalid {
    border-color: var(--sim-danger-red) !important;
}

.sim-canvas-direct-manipulation {
    touch-action: none;
}

.sim-induction-graph {
    aspect-ratio: 13 / 8;
}

.sim-scroll-list {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    gap: var(--sim-space-md);
    max-height: 25vh;
    padding-right: 4px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 116, 139, 0.35) transparent;
}

.sim-scroll-list::-webkit-scrollbar { width: 4px; }
.sim-scroll-list::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.35);
    border-radius: 4px;
}

.sim-slider-label-group {
    display: flex;
    align-items: center;
    gap: var(--sim-space-sm);
}

.sim-color-dot {
    width: 12px;
    height: 12px;
    flex: 0 0 12px;
    border-radius: 50%;
}

.sim-color-dot-1 { background-color: #3B82F6; }
.sim-color-dot-2 { background-color: #10B981; }
.sim-color-dot-3 { background-color: #F59E0B; }
.sim-color-dot-4 { background-color: #8B5CF6; }
.sim-color-dot-5 { background-color: #EC4899; }
.sim-color-dot-6 { background-color: #06B6D4; }

.sim-text-blue { color: #2563EB; }
.sim-text-red { color: #DC2626; }
.sim-text-green { color: #059669; }
.sim-text-amber { color: #D97706; }

.sim-force-list {
    display: flex;
    flex-direction: column;
    gap: var(--sim-space-sm);
    max-height: 34vh;
    overflow-y: auto;
}

.sim-force-item {
    padding: 12px;
    background: var(--sim-bg-panel);
    border: 1px solid var(--sim-border);
    border-radius: var(--sim-radius-sm);
    transition: box-shadow 0.2s ease;
}

.sim-force-item:hover {
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.08);
}

.sim-force-header,
.sim-force-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--sim-space-sm);
}

.sim-force-header {
    padding-bottom: 6px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--sim-bg-light);
    font-size: 0.875rem;
}

.sim-force-body {
    flex-wrap: wrap;
}

.sim-force-vector,
.sim-force-angle,
.sim-force-result {
    font-weight: 700;
}

.sim-force-vector {
    text-shadow: 0 0 1px rgba(0, 0, 0, 0.2);
}

.sim-force-angle {
    color: #b45309;
    font-weight: 600;
}

.sim-force-equation {
    color: var(--sim-text-muted);
    font-family: "Times New Roman", serif;
    font-size: 0.8rem;
    font-style: italic;
}

.sim-force-result {
    color: var(--sim-text-main);
    font-family: "Courier New", monospace;
    font-size: 1.05rem;
}

.sim-torque-positive { color: #047857; }
.sim-torque-negative { color: #be123c; }

.sim-net-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sim-space-sm);
    padding: var(--sim-space-md);
    text-align: center;
    background: var(--sim-bg-light);
    border: 1px solid var(--sim-border);
    border-radius: var(--sim-radius-md);
}

.sim-net-value {
    color: var(--sim-text-main);
    font-family: "Courier New", monospace;
    font-size: 2.25rem;
    font-weight: 700;
}

.sim-net-unit {
    margin-left: 4px;
    color: var(--sim-text-muted);
    font-size: 0.875rem;
    font-weight: 700;
}

.sim-direction-badge {
    display: inline-block;
    margin-top: 4px;
    padding: 6px 16px;
    color: var(--sim-text-muted);
    background: var(--sim-border);
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 0.875rem;
    font-weight: 700;
    transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.sim-direction-badge.positive {
    color: #047857;
    background: #d1fae5;
    border-color: #6ee7b7;
}

.sim-direction-badge.negative {
    color: #be123c;
    background: #ffe4e6;
    border-color: #fda4af;
}

.sim-vector-symbol {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    margin: 0 0.1em;
    line-height: 1;
    vertical-align: middle;
}

.sim-vector-arrow {
    margin-bottom: -0.2em;
    font-size: 0.6em;
}

.sim-vector-char {
    font-family: serif;
}

.sim-vector-sub {
    font-size: 0.6em;
    vertical-align: sub;
}

.sim-vector-arm { color: #0891b2; }
.sim-vector-force { color: #db2777; }
.sim-text-tension { color: var(--sim-action-blue); }
.sim-text-weight { color: #047857; }
.sim-text-reaction { color: var(--sim-accent-color); }
.sim-text-torque { color: #7c3aed; }

.sim-toggle-sub {
    margin-left: calc(var(--sim-space-lg) + var(--sim-space-xs));
    font-size: 0.9em;
}

.sim-section-divider {
    width: 100%;
    margin: var(--sim-space-sm) 0;
    border: 0;
    border-top: 1px solid var(--sim-border);
}

.sim-graph-card {
    display: flex;
    flex-direction: column;
    gap: var(--sim-space-sm);
    padding: var(--sim-space-md);
    background: var(--sim-bg-panel);
    border: 1px solid var(--sim-border);
    border-radius: var(--sim-radius-md);
}

.sim-graph-title {
    color: var(--sim-text-main);
    font-weight: 700;
}

.sim-graph-frame {
    position: relative;
    flex: none;
    width: 100%;
    min-height: 0;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: var(--sim-bg-panel);
    border: 1px solid var(--sim-border);
    border-radius: var(--sim-radius-sm);
}

.sim-graph-frame canvas {
    width: 100%;
    height: 100%;
}

.sim-canvas-theme-dark {
    background: #111827;
    transition: background-color 0.3s ease;
}

.sim-canvas-theme-dark.is-transparent {
    background-color: transparent;
}

.sim-canvas-bg-media {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.sim-canvas-bg-media.active {
    opacity: 1;
}

.sim-canvas-layer {
    position: absolute;
    inset: 0;
    z-index: 10;
    cursor: grab;
}

.sim-canvas-layer:active {
    cursor: grabbing;
}

.sim-legend-line-cyan { background-color: #22d3ee; }
.sim-legend-line-pink { background-color: #ec4899; }

/* === HTML Maker 專屬輸入元件 === */
.sim-custom-input {
    flex-grow: 1;
    padding: 8px 12px;
    border: 1px solid var(--sim-border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}
.sim-custom-input:focus {
    border-color: var(--sim-brand-primary);
}

.sim-custom-textarea {
    width: 100%;
    height: 300px;
    padding: 12px;
    border: 1px solid var(--sim-border);
    border-radius: 6px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    resize: vertical;
    outline: none;
    background-color: #fafafa;
    white-space: pre;
    overflow-x: auto;
    color: var(--sim-text-main);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}
.sim-custom-textarea:focus {
    border-color: var(--sim-brand-primary);
    background-color: #ffffff;
}
.sim-custom-textarea::-webkit-scrollbar { width: 8px; height: 8px; }
.sim-custom-textarea::-webkit-scrollbar-track { background: var(--sim-bg-light); border-radius: 4px; }
.sim-custom-textarea::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.sim-custom-textarea::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.sim-preview-iframe {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    border: none;
    background-color: #ffffff;
    z-index: 5;
    display: block;
}

/* ==========================================================================
   9. 動力論與特殊元件 (Kinetic Theory Special Components)
   ========================================================================== */

/* 參數鎖定按鈕 */
.sim-lock-btn {
    background: none; 
    border: none; 
    font-size: 1.1rem;
    cursor: pointer; 
    margin-right: 6px; 
    transition: transform 0.2s;
    filter: grayscale(100%); 
    opacity: 0.5;
}
.sim-lock-btn:hover { 
    transform: scale(1.15); 
}
.sim-lock-btn.locked { 
    filter: none; 
    opacity: 1; 
    transform: scale(1.1); 
}

/* 狀態警示框 */
.sim-status-box {
    padding: 10px; 
    border-radius: var(--sim-radius-sm); 
    text-align: center;
    font-weight: 600; 
    font-size: 0.9rem; 
    min-height: 42px;
    display: flex; 
    align-items: center; 
    justify-content: center;
    background-color: var(--sim-bg-light); 
    color: var(--sim-brand-primary);
    border: 1px solid var(--sim-border); 
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}
.sim-status-box.warning { 
    background-color: #FFF7ED; 
    color: #9A3412; 
    border-color: #FFEDD5; 
}
.sim-status-box.danger { 
    background-color: #FEF2F2; 
    color: #B91C1C; 
    border-color: #FECACA; 
}
.sim-status-box.info {
    background-color: #EFF6FF;
    color: #1D4ED8;
    border-color: #BFDBFE;
}
.sim-status-box.success {
    background-color: #F0FDF4;
    color: #166534;
    border-color: #BBF7D0;
}

.sim-teaching-feedback {
    width: 100%;
    min-height: 0;
    height: auto;
    flex-shrink: 0;
    align-items: stretch;
    justify-content: flex-start;
    gap: 6px;
    padding: 14px 16px;
    text-align: left;
    line-height: 1.55;
}

.sim-teaching-feedback > strong,
.sim-teaching-feedback > span {
    display: block;
    max-width: 100%;
}

.sim-teaching-feedback > strong {
    line-height: 1.35;
}

.sim-status-reserved {
    height: 72px;
    flex-shrink: 0;
}

.sim-status-reserved.is-empty {
    visibility: hidden;
}

/* ==========================================================================
   11. 使用者偏好與高對比支援 (Accessibility Preferences)
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .sim-app-shell *,
    .sim-app-shell *::before,
    .sim-app-shell *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .sim-btn:active,
    .sim-slider::-webkit-slider-thumb:active {
        transform: none;
    }
}

@media (prefers-reduced-transparency: reduce) {
    .sim-panel,
    .sim-panel-header,
    .sim-watermark,
    .sim-camera-loading {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    .sim-panel,
    .sim-panel-header,
    .sim-camera-loading {
        background: #ffffff;
    }
}

@media (prefers-contrast: more) {
    .sim-panel,
    .sim-camera-loading {
        background: #ffffff;
        border-color: #64748b;
    }

    .sim-btn,
    .sim-slider,
    .sim-toggle-track,
    .sim-segmented-control {
        forced-color-adjust: auto;
    }
}

/* 動態公式顯示 */
.sim-formula-display {
    font-size: 1.6rem; 
    font-weight: bold; 
    text-align: center; 
    color: var(--sim-brand-primary);
    font-family: 'Times New Roman', Times, serif; 
    font-style: italic; 
    margin: 5px 0 10px 0;
}
.sim-formula-display span { 
    display: inline-block; 
    transition:
        color 150ms ease-out,
        transform 150ms ease-out,
        text-shadow 150ms ease-out;
}
.sim-formula-display span.active {
    color: var(--sim-action-blue); 
    transform: scale(1.35); 
    text-shadow: 0 4px 10px rgba(59, 130, 246, 0.4);
}

/* ==========================================================================
   10. 抽籤與娃娃機專屬元件 (Picker & Claw Machine Components)
   ========================================================================== */

.sim-picker-hidden {
    display: none !important;
}

.sim-picker-bg-primary {
    background-color: var(--sim-brand-primary);
}

.sim-picker-text-primary {
    color: var(--sim-brand-primary);
}

.sim-picker-border-primary {
    border-color: var(--sim-brand-primary);
}

.sim-picker-machine-shape {
    transition: border-radius 0.5s ease-in-out;
}

/* 搖桿動作 */
.sim-joystick-active {
    transform: rotate(-15deg);
}

/* 彈跳出現動畫 */
@keyframes sim-anim-bounce-in {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.05); opacity: 1; }
    70% { transform: scale(0.9); }
    100% { transform: scale(1); opacity: 1; }
}
.sim-anim-bounce-in {
    animation: sim-anim-bounce-in 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* 彈出視窗動畫 */
@keyframes sim-anim-pop-up {
    0% { transform: scale(0.8) translateY(20px); opacity: 0; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}
.sim-anim-pop-up {
    animation: sim-anim-pop-up 0.4s ease-out forwards;
}
