:root {
    color-scheme: light;
    --bg: #f4f5f8;
    --panel: #ffffff;
    --panel-2: #eceef3;
    --card: #f9fafc;
    --text: #1a1a2e;
    --muted: #444a6a;
    --muted-2: #767e94;
    --line: #d8dae2;
    --accent: #d63856;
    --accent-hover: #b91d3e;
    --accent-2: #ff6b35;
    --danger: #e94560;
    --warn: #ff9800;
    --ok: #4caf50;
    --shadow: 0 14px 36px rgba(26, 26, 46, 0.16);
    --disabled-bg: rgba(236, 238, 243, 0.7);
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0f0f1a;
    --panel: #1a1a2e;
    --panel-2: #16213e;
    --card: #1e2a4a;
    --text: #e0e0e0;
    --muted: #a0a8c0;
    --muted-2: #6b7394;
    --line: #2a2a4a;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --accent-2: #ff6b35;
    --danger: #e94560;
    --warn: #ff9800;
    --ok: #4caf50;
    --shadow: 0 14px 36px rgba(0, 0, 0, 0.36);
    --disabled-bg: rgba(22, 33, 62, 0.72);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

button,
input {
    font: inherit;
}

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 6;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 0 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
}

.brand-mark {
    font-weight: 800;
    letter-spacing: 0;
    font-size: 16px;
    color: var(--accent);
}

.brand-subtitle {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.file-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.button,
.icon-button {
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    min-height: 32px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.button {
    padding: 0 12px;
}

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

.icon-button {
    width: 32px;
    padding: 0;
}

.button:hover,
.icon-button:hover {
    border-color: var(--accent);
    background: var(--card);
}

.button.primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.icon-button.active {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.icon-button.active:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.button:disabled,
.icon-button:disabled {
    color: var(--muted-2);
    background: var(--disabled-bg);
    border-color: var(--line);
    cursor: not-allowed;
}

.button:active,
.icon-button:active {
    transform: translateY(1px);
}

.button svg,
.icon-button svg {
    width: 17px;
    height: 17px;
    stroke-width: 2.2;
}

.button input {
    display: none;
}

.workspace {
    min-height: 0;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 350px;
    grid-template-areas: "controls viewer conversion";
}

.sidebar,
.conversion-sidebar {
    min-height: 0;
    overflow: auto;
    background: var(--panel);
    scrollbar-color: var(--line) var(--panel);
    scrollbar-width: thin;
}

.sidebar {
    grid-area: controls;
    border-right: 1px solid var(--line);
}

.conversion-sidebar {
    grid-area: conversion;
    border-left: 1px solid var(--line);
}

.panel {
    border-bottom: 1px solid var(--line);
    padding: 12px 16px;
}

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

.source-row {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 7px 0;
    border-top: 1px solid var(--line);
}

.source-row:first-of-type {
    border-top: 0;
}

.source-row span {
    color: var(--muted);
    font-size: 13px;
}

.source-row strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border: 1px solid var(--line);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.segmented button {
    min-height: 34px;
    border: 0;
    border-right: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--muted);
    cursor: pointer;
}

.segmented button:last-child {
    border-right: 0;
}

.segmented button.active {
    background: var(--accent);
    color: #fff;
}

.check-row,
.slider-row {
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: var(--text);
    font-size: 13px;
}

.check-row input {
    accent-color: var(--accent);
}

.slider-row {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
}

.slider-row.with-value {
    grid-template-columns: 96px minmax(0, 1fr) 48px;
}

.slider-value-input {
    width: 100%;
    padding: 2px 4px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: var(--panel);
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    text-align: right;
}

.slider-row input {
    width: 100%;
    min-width: 0;
    margin: 0;
    accent-color: var(--accent);
}

.number-row {
    min-height: 34px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
}

.number-input {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--muted);
}

.number-input input {
    width: 76px;
    min-height: 30px;
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 0 7px;
    color: var(--text);
    background: var(--panel-2);
}

.select-input {
    min-height: 30px;
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 0 7px;
    color: var(--text);
    background: var(--panel-2);
}

.mapping-list {
    display: grid;
    gap: 6px;
}

.mapping-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    padding: 7px 0;
    border-top: 1px solid var(--line);
}

.mapping-row:first-child {
    border-top: 0;
    padding-top: 0;
}

.mapping-type {
    min-width: 0;
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.mapping-status {
    display: grid;
    justify-items: end;
    gap: 2px;
    color: var(--muted);
    font-size: 11px;
}

.mapping-status strong {
    color: var(--accent);
    font-size: 12px;
}

.empty-state {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

.metrics {
    margin: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.metrics div {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 9px;
    background: var(--panel-2);
}

.metrics dt {
    color: var(--muted);
    font-size: 12px;
    margin: 0 0 4px;
}

.metrics dd {
    margin: 0;
    font-size: 22px;
    font-weight: 800;
}

.diagnostics-panel {
    min-height: 160px;
}

.diagnostics {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
}

.diagnostics li {
    border-left: 4px solid var(--line);
    background: var(--panel-2);
    padding: 8px 9px;
    border-radius: 4px;
    font-size: 13px;
    line-height: 1.35;
}

.diagnostics li.info {
    border-color: var(--accent);
}

.diagnostics li.warning {
    border-color: var(--warn);
}

.diagnostics li.error {
    border-color: var(--danger);
}

.diagnostics li.success {
    border-color: var(--ok);
}

.diagnostics strong {
    display: block;
    margin-bottom: 2px;
}

.strategy-list {
    margin: 0;
    display: grid;
    gap: 8px;
}

.strategy-list div {
    border-top: 1px solid var(--line);
    padding-top: 8px;
}

.strategy-list div:first-child {
    border-top: 0;
    padding-top: 0;
}

.strategy-list dt {
    margin: 0 0 3px;
    font-weight: 800;
    font-size: 12px;
    color: var(--accent);
}

.strategy-list dd {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.conversion-action {
    width: 100%;
}

.secondary-action {
    margin-top: 8px;
}

.conversion-action.is-busy svg {
    animation: conversion-spin 900ms linear infinite;
}

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

.viewer-area {
    grid-area: viewer;
    min-height: 0;
    position: relative;
    background: var(--bg);
}

.viewer {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 420px;
}

.viewer.is-picking canvas {
    cursor: pointer;
}

.viewer.is-walk-placed::after {
    content: "+";
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 3;
    pointer-events: none;
    transform: translate(-50%, -50%);
    color: var(--accent);
    font-size: 22px;
    font-weight: 800;
    line-height: 1;
}

.viewer.is-walk-awaiting canvas {
    cursor: crosshair;
}

.walk-hud {
    position: absolute;
    left: 50%;
    bottom: 18px;
    z-index: 4;
    transform: translateX(-50%);
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 4px;
    color: var(--text);
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    box-shadow: 0 8px 18px rgba(25, 32, 42, 0.14);
    font-size: 12px;
    font-weight: 700;
    pointer-events: none;
}

.walk-hud[hidden] {
    display: none;
}

.marquee {
    position: absolute;
    z-index: 4;
    pointer-events: none;
    border: 1px dashed var(--accent, #d63856);
    background: rgba(214, 56, 86, 0.12);
    border-radius: 2px;
}

.marquee[hidden] {
    display: none;
}

.clip-panel {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 4;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: color-mix(in srgb, var(--panel) 94%, transparent);
    border: 1px solid var(--line);
    border-radius: 4px;
    box-shadow: 0 6px 14px rgba(25, 32, 42, 0.12);
    color: var(--text);
    font-size: 11px;
}

.clip-panel[hidden] {
    display: none;
}

.clip-panel-title {
    font-weight: 800;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-size: 10px;
}

.clip-axis-label {
    font-weight: 800;
    color: var(--accent);
    margin-left: 4px;
}

.clip-num-wrap {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--line);
    border-radius: 3px;
    overflow: hidden;
}

.clip-step {
    width: 16px;
    padding: 0;
    background: color-mix(in srgb, var(--panel) 70%, var(--line) 30%);
    border: 0;
    color: var(--text);
    font-size: 8px;
    line-height: 1;
    cursor: pointer;
}

.clip-step:hover {
    background: color-mix(in srgb, var(--panel) 40%, var(--line) 60%);
}

.clip-num-input {
    width: 48px;
    padding: 2px 4px;
    border: 0;
    background: var(--panel);
    color: var(--text);
    text-align: right;
    font-family: inherit;
    font-size: 11px;
}

.clip-slider {
    flex: 1 1 0;
    min-width: 40px;
    accent-color: var(--accent);
}

#clip-reset {
    padding: 3px 10px;
    font-size: 11px;
}

.ifc-loading {
    position: absolute;
    left: 50%;
    top: 18px;
    z-index: 6;
    transform: translateX(-50%);
    width: min(640px, calc(100% - 32px));
    padding: 14px 22px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: color-mix(in srgb, var(--panel) 96%, transparent);
    box-shadow: 0 12px 28px rgba(25, 32, 42, 0.18);
    color: var(--text);
    pointer-events: none;
    font-size: 14px;
}

.ifc-loading[hidden] {
    display: none;
}

.ifc-loading-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    font-weight: 800;
    font-size: 14px;
    letter-spacing: 0.02em;
}

#ifc-loading-percent {
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.ifc-loading-bar {
    margin-top: 12px;
    height: 8px;
    background: color-mix(in srgb, var(--text) 12%, transparent);
    border-radius: 5px;
    overflow: hidden;
}

.ifc-loading-fill {
    height: 100%;
    background: var(--accent, #d63856);
    border-radius: 5px;
    width: 0%;
    transition: width 0.15s linear;
}

.ifc-loading-fill.is-indeterminate {
    width: 35%;
    animation: ifc-loading-slide 1.1s ease-in-out infinite;
}

@keyframes ifc-loading-slide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(285%); }
}

.ifc-loading-stage {
    margin-top: 8px;
    color: var(--muted);
    font-size: 13px;
    min-height: 1em;
}

.hover-tooltip {
    position: absolute;
    z-index: 4;
    pointer-events: none;
    max-width: 280px;
    padding: 6px 8px;
    border-radius: 5px;
    background: rgba(26, 26, 46, 0.92);
    color: #fff;
    font-size: 12px;
    line-height: 1.25;
    box-shadow: 0 8px 18px rgba(25, 32, 42, 0.18);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.inspect-card {
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.inspect-title {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    font-weight: 800;
    overflow-wrap: anywhere;
}

.inspect-card pre {
    margin: 0;
    max-height: 52vh;
    overflow: auto;
    padding: 12px 16px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: 12px;
    line-height: 1.45;
}

.footer-bar {
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 16px;
    background: var(--panel);
    border-top: 1px solid var(--line);
}

.footer-credit {
    min-width: 0;
    overflow: hidden;
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.footer-credit em {
    color: var(--muted);
    font-weight: 400;
}

.footer-meta {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
}

.footer-link {
    border: 0;
    padding: 0;
    color: var(--accent);
    background: transparent;
    cursor: pointer;
    font: inherit;
    text-decoration: none;
}

.footer-link:hover {
    text-decoration: underline;
}

.help-modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 24px;
}

.help-modal[hidden] {
    display: none;
}

.help-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 15, 26, 0.58);
}

.help-card {
    position: relative;
    width: min(920px, 100%);
    max-height: min(760px, calc(100vh - 48px));
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.credits-card {
    width: min(420px, 100%);
}

.help-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding: 16px;
    border-bottom: 1px solid var(--line);
}

.help-header h2,
.help-body h3 {
    margin: 0;
    letter-spacing: 0;
}

.help-header h2 {
    color: var(--accent);
    font-size: 18px;
}

.help-header p,
.help-body p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

.help-body {
    overflow: auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    padding: 16px;
}

.help-body section {
    min-width: 0;
}

.help-body h3 {
    margin-bottom: 8px;
    color: var(--text);
    font-size: 13px;
    text-transform: uppercase;
}

.help-body ol {
    margin: 0;
    padding-left: 18px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.55;
}

.help-list {
    margin: 0;
    display: grid;
    grid-template-columns: minmax(112px, 0.7fr) minmax(0, 1.3fr);
    gap: 7px 12px;
    font-size: 12px;
    line-height: 1.4;
}

.help-list dt {
    color: var(--text);
    font-weight: 700;
}

.help-list dd {
    margin: 0;
    color: var(--muted);
}

.help-keys {
    width: 100%;
    border-collapse: collapse;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

.help-keys th,
.help-keys td {
    padding: 6px 0;
    border-top: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.help-keys th {
    width: 118px;
    padding-right: 12px;
    color: var(--text);
}

kbd {
    display: inline-block;
    min-width: 19px;
    margin-right: 2px;
    padding: 1px 4px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-weight: 700;
    text-align: center;
}

@media (max-width: 900px) {
    .topbar {
        height: auto;
        min-height: 64px;
        align-items: flex-start;
        flex-direction: column;
        padding: 12px;
    }

    .workspace {
        grid-template-columns: minmax(0, 1fr) 300px;
        grid-template-areas:
            "controls controls"
            "viewer conversion";
    }

    .sidebar {
        max-height: 34vh;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .conversion-sidebar {
        max-height: 66vh;
        border-left: 1px solid var(--line);
        border-bottom: 0;
    }

    .viewer {
        height: 66vh;
        min-height: 360px;
    }

    .help-body {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .workspace {
        grid-template-columns: 1fr;
        grid-template-areas:
            "controls"
            "viewer"
            "conversion";
    }

    .conversion-sidebar {
        max-height: 46vh;
        border-left: 0;
        border-top: 1px solid var(--line);
    }

    .viewer {
        height: 54vh;
    }

    .footer-bar {
        padding: 0 10px;
    }

    .footer-credit {
        font-size: 10px;
    }

    .footer-credit em {
        display: none;
    }

    .help-modal {
        padding: 12px;
    }

    .help-list {
        grid-template-columns: 1fr;
        gap: 3px;
    }

    .help-list dd {
        margin-bottom: 5px;
    }
}
