:root {
    --bg: #0b0e14; --bg-card: #151a24; --bg-elevated: #1c2230; --fg: #e4e8f1; --fg-muted: #7a8499;
    --accent: #00e6a7; --accent-dim: rgba(0,230,167,0.12); --danger: #ff4d6a; --danger-dim: rgba(255,77,106,0.12);
    --border: #232a38; --radius: 12px; --radius-sm: 8px; --font: 'DM Sans', system-ui, sans-serif;
    --shadow: 0 8px 32px rgba(0,0,0,0.45); --panel-width: 360px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--fg); overflow: hidden; }
.hidden { display: none !important; }

#join-screen { display: flex; align-items: center; justify-content: center; height: 100vh; background: radial-gradient(ellipse 60% 50% at 50% 0%, rgba(0,230,167,0.06) 0%, transparent 70%), var(--bg); }
.join-card { width: 100%; max-width: 420px; padding: 48px 36px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); text-align: center; }
.join-icon { width: 64px; height: 64px; margin: 0 auto 20px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--accent-dim); color: var(--accent); font-size: 24px; }
.join-card h1 { font-size: 28px; font-weight: 700; margin-bottom: 6px; }
.join-subtitle { color: var(--fg-muted); font-size: 14px; margin-bottom: 32px; }

.form-group { text-align: left; margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--fg-muted); margin-bottom: 6px; }
.form-group input { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-elevated); color: var(--fg); font-size: 15px; font-family: var(--font); outline: none; transition: border-color .2s; }
.form-group input:focus { border-color: var(--accent); }

.btn-secondary { width: 100%; margin-top: 10px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-elevated); color: var(--fg); font-size: 16px; font-weight: 600; font-family: var(--font); cursor: pointer; transition: all .2s; display: flex; align-items: center; justify-content: center; gap: 10px; }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
#join-btn { width: 100%; margin-top: 12px; padding: 14px; border: none; border-radius: var(--radius-sm); background: var(--accent); color: #0b0e14; font-size: 16px; font-weight: 700; font-family: var(--font); cursor: pointer; transition: opacity .2s; display: flex; align-items: center; justify-content: center; gap: 10px; }
#join-btn:hover { opacity: .9; }

#call-screen { display: flex; flex-direction: column; height: 100vh; }
#call-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; background: var(--bg-card); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.header-left { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.badge { background: var(--accent-dim); color: var(--accent); font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.header-right { display: flex; align-items: center; gap: 8px; }

.btn-icon { background: transparent; border: 1px solid var(--border); color: var(--fg-muted); width: 36px; height: 36px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; transition: all .2s; }
.btn-icon:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }

#video-area { flex: 1; position: relative; overflow: hidden; background: var(--bg); }
#remote-videos { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 6px; padding: 6px; width: 100%; height: 100%; align-content: start; }
#remote-videos:has(.participant-tile:only-child) { grid-template-columns: 1fr; }

.participant-tile { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--bg-elevated); min-height: 200px; }
.participant-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.participant-name { position: absolute; bottom: 10px; left: 10px; background: rgba(0,0,0,0.65); backdrop-filter: blur(6px); color: #fff; font-size: 13px; font-weight: 500; padding: 4px 10px; border-radius: 6px; pointer-events: none; }
.no-remote { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--fg-muted); font-size: 15px; grid-column: 1 / -1; }

#local-video-container { position: absolute; bottom: 80px; right: 16px; width: 320px; height: 220px; border-radius: var(--radius); overflow: hidden; background: var(--bg-elevated); border: 2px solid var(--border); box-shadow: var(--shadow); z-index: 10; display: flex; align-items: center; justify-content: center; transition: right .3s ease; }
#local-video-container.panel-open { right: calc(var(--panel-width) + 16px); }
#output-canvas { width: 100%; height: 100%; object-fit: cover; display: block; transform: scaleX(-1); }
#cam-off-icon { font-size: 32px; color: var(--fg-muted); }
#local-name { position: absolute; bottom: 6px; left: 8px; background: rgba(0,0,0,0.6); color: #fff; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 4px; pointer-events: none; }

/* Transcript Container */
#transcript-container { position: absolute; bottom: 20px; left: 20px; max-width: 500px; max-height: 200px; background: rgba(0,0,0,0.7); backdrop-filter: blur(8px); border-radius: var(--radius); padding: 16px; overflow-y: auto; z-index: 20; border: 1px solid var(--border); }
#transcript-text p { margin-bottom: 8px; line-height: 1.4; font-size: 14px; color: #fff; }
#transcript-text p:last-child { margin-bottom: 0; }
.transcript-processing { color: var(--fg-muted) !important; font-style: italic; }
.transcript-listening { color: var(--fg-muted); font-style: italic; margin-bottom: 8px; line-height: 1.4; font-size: 14px; color: #fff; display: flex; align-items: center; gap: 8px; }
.listening-dot { width: 8px; height: 8px; background-color: var(--accent); border-radius: 50%; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { opacity: 1; transform: scale(1); } 50% { opacity: 0.4; transform: scale(0.85); } 100% { opacity: 1; transform: scale(1); } }

#controls { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 16px; background: var(--bg-card); border-top: 1px solid var(--border); flex-shrink: 0; }
.ctrl-btn { width: 52px; height: 52px; border: none; border-radius: 50%; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all .2s; background: var(--bg-elevated); color: var(--fg); border: 1px solid var(--border); }
.ctrl-btn.active { background: var(--accent-dim); color: var(--accent); border-color: transparent; }
.ctrl-btn.off { background: var(--danger-dim); color: var(--danger); border-color: transparent; }
.ctrl-btn.danger { background: var(--danger); color: #fff; border-color: transparent; width: 60px; border-radius: 30px; }

#settings-panel { position: fixed; top: 0; right: 0; bottom: 0; width: var(--panel-width); background: var(--bg-card); border-left: 1px solid var(--border); z-index: 50; box-shadow: -4px 0 20px rgba(0,0,0,0.3); display: flex; flex-direction: column; transform: translateX(100%); transition: transform .3s ease; }
#settings-panel.open { transform: translateX(0); }
#settings-panel.hidden { display: flex; transform: translateX(100%); }

.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.panel-header h2 { font-size: 18px; font-weight: 600; margin: 0; }
.panel-body { padding: 20px; overflow-y: auto; flex: 1; }

.settings-section { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.settings-section:last-child { border-bottom: none; }
.settings-section h3 { font-size: 15px; color: var(--accent); margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }

.setting-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.setting-row label { font-size: 13px; color: var(--fg-muted); flex-shrink: 0; margin-right: 12px; max-width: 140px; }
.setting-row input[type="range"] { width: 100%; max-width: 160px; accent-color: var(--accent); cursor: pointer; }
.setting-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }
.settings-select { background: var(--bg-elevated); color: var(--fg); border: 1px solid var(--border); padding: 6px 8px; border-radius: 6px; font-size: 13px; width: 150px; cursor: pointer; }

.btn-sm { padding: 8px 14px; font-size: 13px; font-weight: 600; background: var(--bg-elevated); color: var(--fg-muted); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; transition: all .2s; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn-sm:hover { color: var(--accent); border-color: var(--accent); }

.bg-presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 20px; max-height: 300px; overflow-y: auto; }
.bg-preset { aspect-ratio: 4/3; border-radius: var(--radius-sm); overflow: hidden; cursor: pointer; border: 2px solid var(--border); transition: all .2s; position: relative; display: flex; align-items: center; justify-content: center; background: var(--bg-elevated); }
.bg-preset img { width: 100%; height: 100%; object-fit: cover; }
.bg-preset i { color: var(--fg-muted); font-size: 20px; position: absolute; }
.bg-preset:hover { border-color: var(--accent); }
.bg-preset.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }

.upload-group { margin-bottom: 14px; }
.upload-group label { display: block; font-size: 13px; color: var(--fg-muted); margin-bottom: 6px; }
.file-input { font-size: 12px; color: var(--fg-muted); width: 100%; }
.file-input::file-selector-button { background: var(--bg-elevated); color: var(--fg-muted); border: 1px solid var(--border); padding: 4px 8px; border-radius: 4px; font-size: 12px; cursor: pointer; margin-right: 8px; }

.toast { position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%); background: var(--bg-elevated); color: var(--fg); border: 1px solid var(--border); padding: 10px 20px; border-radius: var(--radius-sm); font-size: 14px; box-shadow: var(--shadow); z-index: 999; animation: toast-in .3s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(12px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

@media (max-width: 600px) {
    #local-video-container { width: 140px; height: 100px; bottom: 74px; right: 8px; }
    .ctrl-btn { width: 46px; height: 46px; }
    #settings-panel { width: 100%; }
    #local-video-container.panel-open { right: 8px; bottom: 50%; transform: translateY(50%); }
    #transcript-container { max-width: calc(100% - 40px); left: 20px; right: 20px; bottom: 80px; }
}