/* ==========================================================
 *  Optics Lab - 网页版样式
 *  深色科技风格，对应 Swift 端 Color 扩展
 * ========================================================== */

:root {
    --deep-blue:      rgb(8, 13, 31);       /* 主背景 */
    --dark-blue:      rgb(15, 23, 46);      /* 次级背景 */
    --cyan-highlight: rgb(0, 217, 242);     /* 青色高亮 */
    --purple-accent:  rgb(140, 89, 242);    /* 紫色强调 */
    --glass-bg:       rgba(255,255,255,0.06);
    --glass-border:   rgba(0, 217, 242, 0.15);
    --glass-hover:    rgba(0, 217, 242, 0.12);
    --text-primary:   rgba(255,255,255,0.95);
    --text-secondary: rgba(255,255,255,0.65);
    --text-muted:     rgba(255,255,255,0.4);
    --success:        #34d399;
    --danger:         #ef4444;
    --warning:        #f59e0b;
    --panel-bg:       rgba(15, 23, 46, 0.92);
    --panel-bg-solid: rgba(15, 23, 46, 0.96);
    --border-soft:    rgba(255,255,255,0.05);
    --border-axis:    rgba(255,255,255,0.06);
    --slider-track:   rgba(255,255,255,0.08);
    --thumb-border:   rgb(15, 23, 46);
    --readout-bg:     rgba(255,255,255,0.03);
    --readout-border: rgba(255,255,255,0.06);
    --warn-text:      #ffaa33;
    --low-text:       #ff5555;
    --gray-text:      #9ca3af;
}

/* ============== 浅色主题 ============== */
[data-theme="light"] {
    --deep-blue:      rgb(235, 238, 246);
    --dark-blue:      rgb(255, 255, 255);
    --cyan-highlight: rgb(0, 140, 200);
    --purple-accent:  rgb(115, 65, 210);
    --glass-bg:       rgba(0, 0, 0, 0.04);
    --glass-border:   rgba(0, 100, 150, 0.18);
    --glass-hover:    rgba(0, 140, 200, 0.1);
    --text-primary:   rgba(20, 28, 45, 0.95);
    --text-secondary: rgba(20, 28, 45, 0.6);
    --text-muted:     rgba(20, 28, 45, 0.38);
    --success:        #10b981;
    --danger:         #dc2626;
    --warning:        #d97706;
    --panel-bg:       rgba(255, 255, 255, 0.88);
    --panel-bg-solid: rgba(255, 255, 255, 0.96);
    --border-soft:    rgba(0, 0, 0, 0.06);
    --border-axis:    rgba(0, 0, 0, 0.06);
    --slider-track:   rgba(0, 0, 0, 0.08);
    --thumb-border:   rgb(255, 255, 255);
    --readout-bg:     rgba(0, 0, 0, 0.025);
    --readout-border: rgba(0, 0, 0, 0.06);
    --warn-text:      #c4770a;
    --low-text:       #c0392b;
    --gray-text:      #6b7280;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--deep-blue);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
                 "Helvetica Neue", "Segoe UI", sans-serif;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* ============== 3D 画布 ============== */
#scene-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: grab;
    will-change: transform;
    image-rendering: auto;
    backface-visibility: hidden;
}

#scene-canvas:active {
    cursor: grabbing;
}

/* ============== 通用 UI 元素 ============== */
.panel {
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 18px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    color: var(--text-primary);
}

.section-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--cyan-highlight);
    margin-bottom: 8px;
}

/* ============== 顶部工具栏 ============== */
#top-toolbar {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    z-index: 10;
}

#top-toolbar .title {
    flex: 1;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* FPS 帧率显示 & 滑块调节 */
.fps-wrap {
    position: relative;
}
.fps-counter {
    font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
    font-size: 12px;
    font-weight: 600;
    color: var(--cyan-highlight);
    background: rgba(0, 217, 242, 0.08);
    border: 1px solid rgba(0, 217, 242, 0.2);
    border-radius: 8px;
    padding: 4px 10px;
    min-width: 60px;
    text-align: center;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.2s;
}
.fps-counter:hover {
    background: var(--glass-hover);
    border-color: rgba(0, 217, 242, 0.4);
}
.fps-counter.warn { color: var(--warn-text); border-color: rgba(255,170,51,0.3); background: rgba(255,170,51,0.08); }
.fps-counter.low  { color: var(--low-text); border-color: rgba(255,85,85,0.3);  background: rgba(255,85,85,0.08); }

/* FPS 滑块面板 */
.fps-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 220px;
    background: var(--panel-bg-solid);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    padding: 12px 14px 10px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
    z-index: 100;
    display: none;
    animation: fadeSlide 0.18s ease;
}
.fps-panel.show { display: block; }
.fps-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 12px;
    color: rgba(255,255,255,0.5);
}
.fps-panel-header span:last-child {
    font-family: 'SF Mono', 'Menlo', monospace;
    color: var(--cyan-highlight);
    font-weight: 600;
    font-size: 13px;
}

/* 滑块样式 */
#fps-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right, var(--cyan-highlight) 0%, rgba(255,255,255,0.15) 0%);
    outline: none;
    cursor: pointer;
    margin: 0;
}
#fps-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--cyan-highlight);
    border: 2px solid var(--thumb-border);
    box-shadow: 0 0 8px rgba(0,217,242,0.5);
    cursor: pointer;
    transition: transform 0.1s;
}
#fps-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
#fps-slider::-moz-range-thumb {
    width: 16px; height: 16px; border-radius: 50%;
    background: var(--cyan-highlight); border: 2px solid var(--thumb-border);
    box-shadow: 0 0 8px rgba(0,217,242,0.5); cursor: pointer;
}

/* 刻度 */
.fps-ticks {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 10px;
    font-family: 'SF Mono', 'Menlo', monospace;
    color: rgba(255,255,255,0.3);
}
.fps-ticks span {
    transition: all 0.15s;
    padding: 2px 4px;
    border-radius: 4px;
    cursor: pointer;
}
.fps-ticks span:hover {
    color: var(--cyan-highlight);
    background: rgba(0,217,242,0.1);
}

@keyframes fadeSlide {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    color: var(--cyan-highlight);
    cursor: pointer;
    transition: all 0.18s ease;
}

.icon-btn:hover {
    background: rgba(0, 217, 242, 0.12);
    transform: scale(1.05);
}

.icon-btn.danger {
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.3);
}

.icon-btn.danger:hover {
    background: rgba(239, 68, 68, 0.12);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

/* ============== 底部器械栏 ============== */
#instrument-bar {
    position: absolute;
    bottom: 12px;
    left: 12px;
    right: 12px;
    z-index: 10;
    padding: 8px 12px 10px;
}

#instrument-bar .handle {
    width: 36px;
    height: 4px;
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
    margin: 0 auto 8px;
}

#instrument-bar .scroller {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px;
    scrollbar-width: none;
}

#instrument-bar .scroller::-webkit-scrollbar {
    display: none;
}

.instrument-btn {
    flex: 0 0 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 4px;
    background: var(--glass-bg);
    border: 1px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.18s ease;
}

.instrument-btn:hover {
    background: rgba(255,255,255,0.10);
}

.instrument-btn.selected {
    border-color: var(--cyan-highlight);
    background: linear-gradient(135deg,
        rgba(0,217,242,0.25), rgba(140,89,242,0.25));
    transform: scale(1.05);
    box-shadow: 0 0 12px rgba(0,217,242,0.3);
}

.instrument-btn .icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.instrument-btn .icon svg {
    width: 22px;
    height: 22px;
}

.instrument-btn .name {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.instrument-btn.selected .name {
    color: var(--cyan-highlight);
    font-weight: 600;
}

/* ============== Inspector 属性面板 ============== */
#property-panel {
    position: absolute;
    top: 76px;
    right: 12px;
    bottom: 100px;
    width: 280px;
    z-index: 9;
    display: none;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    animation: slideInRight 0.25s ease;
}

#property-panel.visible {
    display: flex;
}

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

/* Inspector 头部 */
.inspector-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 14px 12px;
    border-bottom: 1px solid var(--glass-border);
    flex-shrink: 0;
}

.inspector-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    flex-shrink: 0;
}

.inspector-title-group {
    flex: 1;
    min-width: 0;
}

.inspector-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.inspector-subtitle {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
    font-family: 'SF Mono', 'Menlo', monospace;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.inspector-close {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s;
    flex-shrink: 0;
}

.inspector-close:hover {
    background: var(--glass-bg);
    color: var(--text-primary);
}

/* Inspector 主体 */
.inspector-body {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border) transparent;
}

.inspector-body::-webkit-scrollbar {
    width: 4px;
}

.inspector-body::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 2px;
}

/* Inspector 可折叠分区 */
.inspector-section {
    border-bottom: 1px solid var(--border-soft);
}

.inspector-section:last-child {
    border-bottom: none;
}

.inspector-section-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px 8px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.inspector-section-header:hover {
    background: var(--glass-hover);
}

.inspector-section-header .chevron {
    width: 10px;
    height: 10px;
    transition: transform 0.2s;
    opacity: 0.5;
    flex-shrink: 0;
}

.inspector-section.collapsed .chevron {
    transform: rotate(-90deg);
}

.inspector-section-header .section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.inspector-section-content {
    padding: 0 14px 12px;
}

.inspector-section.collapsed .inspector-section-content {
    display: none;
}

/* Inspector 属性行（键值对布局） */
.insp-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 28px;
    padding: 3px 0;
}

.insp-row .insp-label {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}

.insp-row .insp-value {
    font-family: 'SF Mono', 'Menlo', monospace;
    font-size: 12px;
    font-weight: 600;
    color: var(--cyan-highlight);
    text-align: right;
}

.insp-row .insp-value.purple { color: var(--purple-accent); }
.insp-row .insp-value.green  { color: var(--success); }
.insp-row .insp-value.orange { color: var(--warning); }
.insp-row .insp-value.gray   { color: #9ca3af; }

/* Inspector 滑块行 */
.insp-slider {
    padding: 4px 0 2px;
}

.insp-slider .insp-slider-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.insp-slider .insp-slider-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.insp-slider .insp-slider-value {
    font-family: 'SF Mono', 'Menlo', monospace;
    font-size: 12px;
    font-weight: 600;
    color: var(--cyan-highlight);
}

.insp-slider.purple .insp-slider-value { color: var(--purple-accent); }
.insp-slider.green  .insp-slider-value { color: var(--success); }
.insp-slider.orange .insp-slider-value { color: var(--warning); }
.insp-slider.gray   .insp-slider-value { color: #9ca3af; }

.insp-slider input[type="range"] {
    width: 100%;
    height: 3px;
    background: var(--slider-track);
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.insp-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--cyan-highlight);
    border-radius: 50%;
    border: 2px solid var(--dark-blue);
    cursor: pointer;
    box-shadow: 0 0 6px rgba(0,217,242,0.4);
}

.insp-slider.purple input[type="range"]::-webkit-slider-thumb {
    background: var(--purple-accent);
    box-shadow: 0 0 6px rgba(140,89,242,0.4);
}
.insp-slider.green input[type="range"]::-webkit-slider-thumb {
    background: var(--success);
    box-shadow: 0 0 6px rgba(52,211,153,0.4);
}
.insp-slider.orange input[type="range"]::-webkit-slider-thumb {
    background: var(--warning);
    box-shadow: 0 0 6px rgba(245,158,11,0.4);
}
.insp-slider.gray input[type="range"]::-webkit-slider-thumb {
    background: #9ca3af;
    box-shadow: 0 0 6px rgba(156,163,175,0.4);
}

.insp-slider input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--cyan-highlight);
    border-radius: 50%;
    border: 2px solid var(--dark-blue);
    cursor: pointer;
}

/* Inspector 位置输入 */
.insp-position {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.insp-axis {
    background: var(--glass-bg);
    border: 1px solid var(--border-axis);
    border-radius: 6px;
    padding: 5px 4px;
    text-align: center;
    cursor: ns-resize;
    transition: all 0.15s;
}

.insp-axis:hover {
    background: rgba(0, 217, 242, 0.08);
    border-color: rgba(0, 217, 242, 0.2);
}

.insp-axis .axis-label {
    font-size: 9px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.insp-axis .axis-val {
    font-size: 11px;
    color: var(--text-primary);
    font-family: 'SF Mono', 'Menlo', monospace;
    font-weight: 600;
    margin-top: 1px;
}

/* Inspector 删除按钮 */
.insp-delete {
    width: 100%;
    height: 34px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.25);
    border-radius: 8px;
    color: var(--danger);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.insp-delete:hover {
    background: rgba(239,68,68,0.2);
    border-color: rgba(239,68,68,0.4);
}

.insp-delete svg {
    width: 14px;
    height: 14px;
}

/* Inspector 传感器读数 */
.insp-readout {
    border-radius: 8px;
    padding: 8px 10px;
    background: var(--readout-bg);
    border: 1px solid var(--readout-border);
}

.insp-readout.hit {
    background: rgba(52,211,153,0.1);
    border-color: rgba(52,211,153,0.25);
}

.insp-readout .ro-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--success);
}

.insp-readout .ro-status.idle {
    color: var(--text-muted);
    font-weight: 500;
}

.insp-readout .ro-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 5px var(--success);
    animation: pulse 1.5s ease-in-out infinite;
}

.insp-readout .ro-dot.idle {
    background: rgba(255,255,255,0.2);
    box-shadow: none;
    animation: none;
}

.insp-readout .ro-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    margin-top: 4px;
}

.insp-readout .ro-row .ro-name {
    color: var(--text-secondary);
}

.insp-readout .ro-row .ro-val {
    font-family: 'SF Mono', 'Menlo', monospace;
    font-weight: 600;
    color: var(--success);
}

/* ============== 提示横幅 ============== */
#hint-banner {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 16px;
    background: rgba(0, 217, 242, 0.15);
    border: 1px solid var(--cyan-highlight);
    border-radius: 18px;
    color: var(--cyan-highlight);
    font-size: 13px;
    font-weight: 500;
    z-index: 8;
    display: none;
    animation: fadeIn 0.3s ease;
}

#hint-banner.visible {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

#hint-banner .dismiss {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    margin-left: 10px;
    font-size: 16px;
    line-height: 1;
}

/* ============== 元件信息气泡 ============== */
.bubble {
    position: absolute;
    pointer-events: none;
    padding: 4px 8px;
    background: var(--panel-bg-solid);
    border: 1px solid var(--cyan-highlight);
    border-radius: 8px;
    color: var(--cyan-highlight);
    font-size: 11px;
    font-weight: 600;
    transform: translate(-50%, -120%);
    white-space: nowrap;
    z-index: 5;
}

/* ============== 响应式 ============== */
@media (max-width: 640px) {
    #top-toolbar { height: 50px; }
    #top-toolbar .title { font-size: 14px; }
    .instrument-btn { flex: 0 0 56px; }
    .instrument-btn .name { font-size: 10px; }
    #property-panel { width: 240px; top: 70px; bottom: 90px; }
}
