#ui-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
}

#ui-overlay > * {
    pointer-events: auto;
}

/* Top bar */
#top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top, 0px));
    background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
    z-index: 20;
}

#top-bar .left,
#top-bar .right {
    display: flex;
    align-items: center;
    gap: 6px;
}

#app-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

/* Bottom sheet */
#bottom-sheet {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: min(55vh, 380px);
    background: var(--surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow);
    transform: translateY(calc(100% - 60px));
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 30;
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

#bottom-sheet.expanded {
    transform: translateY(0);
}

#sheet-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 4px;
    padding: 10px 0 6px;
    min-height: 48px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

#sheet-handle::after {
    content: '';
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--text2);
    opacity: 0.5;
}

.sheet-handle-label {
    font-size: 10px;
    color: var(--text2);
    opacity: 0.5;
    letter-spacing: 0.3px;
}

#bottom-sheet.expanded .sheet-handle-label {
    display: none;
}

#sheet-content {
    padding: 0 14px 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    max-height: calc(min(55vh, 380px) - 30px - env(safe-area-inset-bottom, 0px));
}

#sheet-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 12px;
    background: var(--surface2);
    border-radius: var(--radius-sm);
    padding: 3px;
}

.sheet-tab {
    flex: 1;
    padding: 8px 6px;
    text-align: center;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text2);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.sheet-tab.active {
    background: var(--accent);
    color: #fff;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* Control groups */
.ctrl-group {
    margin-bottom: 12px;
}

.ctrl-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 600;
    color: var(--text2);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ctrl-value {
    color: var(--text);
    font-weight: 400;
}

.ctrl-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Camera selector */
.camera-selector {
    display: flex;
    gap: 6px;
}

.camera-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface2);
    color: var(--text2);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 11px;
}

.camera-btn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(124,107,245,0.15);
}

/* Gallery grid */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-top: 6px;
    max-height: 180px;
    overflow-y: auto;
}

.gallery-item {
    aspect-ratio: 1;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid transparent;
    cursor: pointer;
    position: relative;
    background: var(--surface2);
}

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

.gallery-item.active {
    border-color: var(--accent);
}

.gallery-item .del-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    display: none;
}

.gallery-item:hover .del-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Blend mode grid */
.blend-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}

.blend-btn {
    padding: 6px 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface2);
    color: var(--text2);
    font-size: 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
}

.blend-btn.active {
    border-color: var(--accent);
    background: rgba(124,107,245,0.2);
    color: var(--accent);
}

/* Layer list */
.layer-list {
    max-height: 150px;
    overflow-y: auto;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    background: var(--surface2);
    margin-bottom: 4px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 13px;
}

.layer-item.active {
    border: 1px solid var(--accent);
    background: rgba(124,107,245,0.12);
}

.layer-item .thumb {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: cover;
    background: #333;
}

.layer-item .name {
    flex: 1;
}

.layer-item .vis-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    font-size: 14px;
}

.layer-item .vis-btn.off {
    opacity: 0.3;
}

/* Transform controls */
.transform-sliders {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.transform-sliders .ctrl-group {
    margin-bottom: 0;
}

/* Grid toggle grid */
.grid-toggle-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}

.grid-toggle-btn {
    padding: 8px 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface2);
    color: var(--text2);
    font-size: 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
}

.grid-toggle-btn.active {
    border-color: var(--accent);
    background: rgba(124,107,245,0.2);
    color: var(--accent);
}

/* Ruler/guide list */
.guide-list {
    max-height: 100px;
    overflow-y: auto;
}

.guide-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 4px;
    background: var(--surface2);
    margin-bottom: 2px;
    font-size: 12px;
}

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

.guide-item .del-btn {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 14px;
}

/* Measurement overlay */
#measure-overlay {
    position: absolute;
    inset: 0;
    z-index: 6;
    pointer-events: none;
}

/* Sheet toggle button */
.btn-sheet-toggle {
    position: fixed;
    bottom: 16px;
    left: 16px;
    z-index: 35;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 20px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    transition: transform 0.2s, opacity 0.2s;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
}

.btn-sheet-toggle:active {
    transform: scale(0.92);
}

.btn-sheet-toggle.hidden-btn {
    opacity: 0;
    pointer-events: none;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    backdrop-filter: blur(10px);
    color: var(--text);
    font-size: 13px;
    box-shadow: var(--shadow);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
}

/* Color picker row */
.color-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.color-row input[type=color] {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    padding: 0;
    cursor: pointer;
    background: none;
}

.color-row input[type=color]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-row input[type=color]::-webkit-color-swatch {
    border: 2px solid var(--border);
    border-radius: 50%;
}

/* Grid size presets */
.preset-btns {
    display: flex;
    gap: 4px;
}

.preset-btn {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface2);
    color: var(--text2);
    font-size: 10px;
    cursor: pointer;
}

.preset-btn.active {
    border-color: var(--accent);
    background: rgba(124,107,245,0.2);
    color: var(--accent);
}

/* Welcome Splash */
.splash-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0,0,0,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: splashFadeIn 0.3s ease;
}

.splash-overlay.hidden {
    display: none;
}

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

.splash-card {
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 16px 64px rgba(0,0,0,0.6);
    max-width: 420px;
    width: 90vw;
    overflow: hidden;
    position: relative;
    animation: splashSlideUp 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes splashSlideUp {
    from { transform: translateY(40px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.splash-close-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.5);
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.splash-close-btn:hover {
    background: rgba(0,0,0,0.75);
}

.splash-image {
    width: 100%;
    height: auto;
    display: block;
    max-height: 55vh;
    object-fit: contain;
    background: var(--bg);
}

.splash-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    gap: 12px;
}

.splash-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text2);
    cursor: pointer;
    user-select: none;
}

.splash-checkbox input[type=checkbox] {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
}
