:root {
    color-scheme: light;
    font-family: Pretendard, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --orange: #f97316;
    --bg: #f5f7fa;
    --card: #ffffff;
    --text: #172033;
    --muted: #667085;
    --line: #e4e7ec;
    --shadow: 0 12px 32px rgba(23, 32, 51, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    margin: 0;
    height: 100vh;
    height: 100dvh;
    overflow-x: hidden;
    overflow-y: hidden;
    min-width: 320px;
    background: var(--bg);
    color: var(--text);
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.app-shell {
    display: grid;
    grid-template-rows: 62px minmax(0, 1fr) auto;
    overflow-x: hidden;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-width: 0;
    max-width: 100%;
    padding: 0 22px;
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(16px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    text-decoration: none;
    font-weight: 800;
    font-size: 17px;
}

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 8px;
}

.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
}

.file-button,
.ghost-button,
.primary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 38px;
    padding: 0 13px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    font-weight: 700;
    font-size: 13px;
    white-space: nowrap;
}

.file-button input {
    display: none;
}

.file-button:hover,
.ghost-button:hover {
    border-color: #c8d2e4;
    background: #f8fafc;
}

.primary-button {
    border-color: var(--blue);
    background: var(--blue);
    color: #fff;
}

.primary-button:hover {
    background: var(--blue-dark);
}

.workspace {
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr);
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.tool-rail {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    padding: 16px 10px;
    background: #fff;
    border-right: 1px solid var(--line);
}

.tool-button {
    display: grid;
    justify-items: center;
    gap: 5px;
    width: 60px;
    min-height: 58px;
    padding: 7px 4px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font-weight: 700;
    font-size: 11px;
}

.tool-button:hover {
    background: #f2f6ff;
    color: var(--blue);
}

.tool-button.active {
    background: var(--blue);
    color: #fff;
    box-shadow: 0 10px 22px rgba(37, 99, 235, 0.22);
}

.compare-grid {
    display: grid;
    grid-template-columns: minmax(280px, 35%) minmax(0, 65%);
    gap: 14px;
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    padding: 14px;
}

.panel {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    box-shadow: var(--shadow);
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
    padding: 13px 15px;
    border-bottom: 1px solid var(--line);
}

.panel-head h1 {
    margin: 2px 0 0;
    font-size: 16px;
    line-height: 1.2;
}

.eyebrow {
    margin: 0;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.pill,
.axis-chip {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    background: #eef4ff;
    color: var(--blue);
    font-size: 12px;
    font-weight: 800;
}

.panel-help {
    display: grid;
    gap: 3px;
    padding: 9px 15px;
    border-bottom: 1px solid var(--line);
    background: #fbfcff;
}

.panel-help strong {
    color: var(--text);
    font-size: 12px;
    line-height: 1.2;
}

.panel-help span {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.calibration-control {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 5px;
}

.calibration-control label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text);
    font-size: 12px;
    font-weight: 800;
}

.calibration-control input {
    width: 72px;
    min-height: 30px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
}

.mini-button {
    min-height: 30px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--blue);
    font-size: 12px;
    font-weight: 800;
}

.calibration-control > span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.photo-stage,
.viewer-wrap {
    position: relative;
    min-height: 0;
    overflow: hidden;
    background:
        linear-gradient(rgba(37, 99, 235, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(37, 99, 235, 0.06) 1px, transparent 1px),
        #f8fafc;
    background-size: 28px 28px;
}

.photo-placeholder {
    position: absolute;
    inset: 18px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 8px;
    border: 1px dashed #cbd5e1;
    border-radius: 12px;
    color: var(--muted);
    text-align: center;
    background: rgba(255, 255, 255, 0.7);
}

.photo-placeholder svg {
    width: 54px;
    height: 54px;
    color: #94a3b8;
}

.photo-placeholder strong {
    color: var(--text);
    font-size: 15px;
}

.photo-placeholder span {
    max-width: 260px;
    font-size: 13px;
    line-height: 1.45;
}

#photoPreview {
    display: none;
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
}

#photoPreview.loaded {
    display: block;
}

.point-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.photo-point {
    position: absolute;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    transform: translate(-50%, -50%);
    border: 3px solid #fff;
    border-radius: 999px;
    color: #fff;
    font-size: 11px;
    font-weight: 900;
    box-shadow: 0 8px 18px rgba(23, 32, 51, 0.2);
}

.photo-point.a {
    background: var(--blue);
}

.photo-point.b {
    background: var(--orange);
}

.photo-point.calibration {
    background: #172033;
}

.photo-line {
    position: absolute;
    height: 3px;
    transform-origin: left center;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--blue), var(--orange));
    box-shadow: 0 4px 10px rgba(23, 32, 51, 0.16);
}

.calibration-line {
    background: #172033;
}

#modelCanvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.distance-badge,
.depth-badge {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    min-width: 86px;
    padding: 7px 11px;
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 999px;
    background: rgba(23, 32, 51, 0.84);
    color: #fff;
    text-align: center;
    font-size: 13px;
    font-weight: 900;
    pointer-events: none;
}

.depth-badge {
    background: rgba(249, 115, 22, 0.92);
}

.hidden {
    display: none;
}

.axis-chip {
    position: absolute;
    right: 14px;
    bottom: 14px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--muted);
}

.view-tabs {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #f8fafc;
}

.app-tabs {
    flex: 0 0 auto;
}

.view-tab {
    min-height: 28px;
    padding: 0 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-weight: 800;
    font-size: 12px;
}

.view-tab.active {
    background: #fff;
    color: var(--blue);
    box-shadow: 0 3px 10px rgba(23, 32, 51, 0.08);
}

.result-bar {
    display: grid;
    grid-template-columns: minmax(210px, 1.35fr) minmax(160px, 1fr) minmax(160px, 1fr) minmax(150px, 0.9fr) minmax(150px, 0.9fr) minmax(190px, 1.35fr);
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    background: #fff;
}

.status-block,
.metric-card,
.history-list {
    min-width: 0;
    min-height: 56px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}

.status-block {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 13px;
}

.status-dot {
    flex: 0 0 auto;
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: var(--blue);
    box-shadow: 0 0 0 5px rgba(37, 99, 235, 0.12);
}

.status-block strong {
    overflow: hidden;
    color: var(--text);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.metric-card {
    display: grid;
    align-content: center;
    gap: 4px;
    padding: 0 13px;
}

.metric-card span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.metric-card strong {
    overflow: hidden;
    color: var(--text);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.distance-card strong {
    color: var(--blue);
    font-size: 22px;
    line-height: 1;
}

.depth-card strong {
    color: var(--orange);
    font-size: 22px;
    line-height: 1;
}

.history-list {
    display: flex;
    align-items: center;
    gap: 7px;
    overflow-x: auto;
    padding: 0 11px;
}

.history-item {
    flex: 0 0 auto;
    padding: 7px 10px;
    border-radius: 9px;
    background: #f8fafc;
    color: var(--text);
    font-size: 12px;
    font-weight: 800;
}

.camera-dialog {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(23, 32, 51, 0.42);
}

.camera-dialog.hidden {
    display: none;
}

.camera-card {
    width: min(720px, 100%);
    overflow: hidden;
    border: 1px solid rgba(228, 231, 236, 0.86);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 24px 70px rgba(23, 32, 51, 0.24);
}

.camera-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
}

.camera-head h2 {
    margin: 2px 0 0;
    font-size: 18px;
    line-height: 1.2;
}

.icon-button {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
}

.icon-button:hover {
    border-color: #c8d2e4;
    background: #f8fafc;
}

.camera-preview {
    position: relative;
    aspect-ratio: 16 / 10;
    background:
        linear-gradient(rgba(37, 99, 235, 0.08) 1px, transparent 1px),
        linear-gradient(90deg, rgba(37, 99, 235, 0.08) 1px, transparent 1px),
        #0f172a;
    background-size: 28px 28px;
}

.camera-preview video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-note {
    margin: 0;
    padding: 12px 18px 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

.camera-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 18px 18px;
}

.primary-button.wide {
    width: auto;
    padding: 0 14px;
}

body.photo-focus .compare-grid,
body.model-focus .compare-grid {
    grid-template-columns: minmax(0, 1fr);
}

body.photo-focus .model-panel {
    display: none;
}

body.model-focus .photo-panel {
    display: none;
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-rows: auto minmax(0, 1fr) auto;
    }

    .app-header {
        flex-wrap: wrap;
        min-height: 62px;
        overflow: hidden;
        padding: 10px 14px;
    }

    .app-tabs {
        order: 2;
        margin-left: auto;
    }

    .header-actions {
        flex: 1 1 100%;
        order: 3;
        width: 100%;
        max-width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .workspace {
        grid-template-columns: 1fr;
        width: 100%;
        max-width: 100%;
    }

    .tool-rail {
        position: sticky;
        top: 0;
        z-index: 4;
        flex-direction: row;
        max-width: 100%;
        overflow-x: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .compare-grid,
    body.photo-focus .compare-grid,
    body.model-focus .compare-grid {
        width: 100%;
        max-width: 100%;
        grid-template-columns: 1fr;
        grid-auto-rows: minmax(300px, 1fr);
        overflow-y: auto;
    }

    .result-bar {
        grid-template-columns: 1fr 1fr;
        max-height: 34vh;
        overflow-y: auto;
    }

    .status-block,
    .history-list {
        grid-column: 1 / -1;
    }
}

@media (max-width: 620px) {
    .file-button,
    .ghost-button,
    .primary-button {
        padding: 0 10px;
        font-size: 12px;
    }

    .primary-button {
        width: 38px;
        padding: 0;
    }

    .primary-button span {
        display: none;
    }

    .primary-button.wide {
        width: auto;
        padding: 0 12px;
    }

    .primary-button.wide span {
        display: inline;
    }

    .camera-dialog {
        padding: 10px;
    }

    .camera-actions {
        flex-direction: column-reverse;
    }

    .camera-actions .ghost-button,
    .camera-actions .primary-button {
        width: 100%;
    }

    .result-bar {
        grid-template-columns: 1fr;
    }

    .distance-card strong {
        font-size: 20px;
    }
}
