* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-dark: #0a0a0a;
    --bg-panel: #1a1a1a;
    --accent: #ff4757;
    --accent-hover: #ff6b7a;
    --text: #ffffff;
    --text-muted: #888;
    --border: #333;
    --recording: #ff0000;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-dark);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    touch-action: none;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

#logo-link {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 100;
    text-decoration: none;
}

#logo {
    height: 32px;
    width: auto;
    opacity: 0.9;
    transition: opacity 0.2s;
}

#logo:hover {
    opacity: 1;
}

#fps-overlay {
    position: fixed;
    top: 52px;
    left: 16px;
    z-index: 100;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 8px;
    border-radius: 4px;
    font-variant-numeric: tabular-nums;
}

#video-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #000;
}

#camera {
    display: none;
}

#output {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

#recording-indicator {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    padding: 8px 16px;
    border-radius: 20px;
    z-index: 100;
}

#recording-indicator.hidden {
    display: none;
}

.rec-dot {
    width: 12px;
    height: 12px;
    background: var(--recording);
    border-radius: 50%;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

#rec-timer {
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

#controls {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    z-index: 100;
}

.control-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid var(--text);
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text);
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

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

.control-btn svg {
    width: 24px;
    height: 24px;
}

.control-btn.small {
    width: 44px;
    height: 44px;
}

.control-btn.small svg {
    width: 20px;
    height: 20px;
}

#record-btn .record-icon {
    width: 24px;
    height: 24px;
    background: var(--text);
    border-radius: 50%;
    transition: all 0.2s;
}

#record-btn.recording {
    border-color: var(--recording);
    animation: pulse 1s infinite;
}

#record-btn.recording .record-icon {
    background: var(--recording);
    border-radius: 4px;
    width: 20px;
    height: 20px;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.4); }
    50% { box-shadow: 0 0 0 10px rgba(255, 0, 0, 0); }
}

.panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-panel);
    border-radius: 20px 20px 0 0;
    padding: 20px;
    padding-top: 12px;
    z-index: 200;
    max-height: 70vh;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.panel::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 16px;
}

.panel.hidden {
    transform: translateY(100%);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.panel-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--border);
    color: var(--text);
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-section {
    margin-bottom: 20px;
}

.gallery-section h3 {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.gallery-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.colors-row .gallery-item {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
}

.colors-row .gallery-item span {
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    color: white;
}

.colors-row .gallery-item[data-color="#ffffff"] span {
    color: #333;
    text-shadow: none;
}

.gradient-bg span {
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
    color: white;
    font-weight: 500;
}

#gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 12px;
}

.gallery-item {
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--border);
    position: relative;
}

.gallery-item:hover {
    border-color: var(--text-muted);
}

.gallery-item.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(255, 71, 87, 0.3);
}

.gallery-item.none-bg {
    background: linear-gradient(135deg, var(--border) 0%, #252525 100%);
}

.gallery-item.none-bg span {
    color: var(--text);
    font-weight: 500;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item span {
    font-size: 12px;
    color: var(--text-muted);
}

.gallery-item svg {
    width: 24px;
    height: 24px;
    margin-bottom: 4px;
}

.gallery-item.add-new {
    background: transparent;
    border: 2px dashed var(--border);
}

.gallery-item.add-new:hover {
    border-color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
}

.gallery-item .delete-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    color: white;
    font-size: 14px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
}

.gallery-item:hover .delete-btn {
    display: flex;
}

.blur-bg {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    filter: blur(2px);
}

.blur-bg span {
    filter: blur(0);
    color: white;
}

.top-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
}

.top-btn-left {
    position: fixed;
    top: 20px;
    right: 72px;
    z-index: 100;
}

.top-btn-left.active {
    background: rgba(255, 71, 87, 0.3);
    border-color: var(--accent);
}

.settings-section {
    margin-bottom: 24px;
}

.settings-section h3 {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.setting-row span {
    font-size: 15px;
}

.setting-row select {
    background: var(--border);
    color: var(--text);
    border: none;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
}

.setting-row input[type="range"] {
    width: 120px;
    accent-color: var(--accent);
}

.setting-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
}

.info-row {
    font-size: 14px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

#loading-overlay,
#error-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 1000;
}

#loading-overlay.hidden,
#error-overlay.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#error-overlay p {
    color: var(--accent);
    text-align: center;
    padding: 0 20px;
}

#retry-btn {
    padding: 12px 24px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
}

#retry-btn:hover {
    background: var(--accent-hover);
}

/* Landscape orientation */
@media (orientation: landscape) and (max-height: 500px) {
    #controls {
        bottom: 15px;
    }

    .control-btn {
        width: 50px;
        height: 50px;
    }

    .panel {
        max-height: 80vh;
    }
}

/* Landscape mode */
#app.landscape-mode {
    transform: rotate(90deg);
    transform-origin: center center;
    width: 100vh;
    height: 100vw;
    position: fixed;
    top: 50%;
    left: 50%;
    margin-top: -50vw;
    margin-left: -50vh;
}

#app.landscape-mode #video-container {
    width: 100%;
    height: 100%;
}

#app.landscape-mode #controls {
    bottom: 20px;
}

#app.landscape-mode .top-btn {
    top: 20px;
    right: 20px;
}

#app.landscape-mode .top-btn-left {
    right: 72px;
}

#app.landscape-mode #logo-link {
    top: 16px;
    left: 16px;
}

/* Model loading indicator */
#model-loading {
    color: var(--accent);
    animation: pulse-text 1s infinite;
}

#model-loading.hidden {
    display: none;
}

@keyframes pulse-text {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Large screens */
@media (min-width: 768px) {
    #controls {
        bottom: 40px;
    }

    .control-btn {
        width: 70px;
        height: 70px;
    }

    .control-btn svg {
        width: 28px;
        height: 28px;
    }

    #record-btn .record-icon {
        width: 28px;
        height: 28px;
    }

    #gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}
