:root {
    --bg0: #121820;
    --bg1: #1a2430;
    --surface: rgba(200, 220, 240, 0.06);
    --surface-strong: rgba(200, 220, 240, 0.11);
    --line: rgba(160, 190, 220, 0.22);
    --text: #eef3f8;
    --muted: #9aafc4;
    --accent: #4a8fd4;
    --accent-deep: #2d6aa8;
    --danger: #c45a5a;
    --trace: #1a2332;
    --handle: #4a8fd4;
    --bend: #e8a54b;
    --radius: 12px;
    --font: "Segoe UI", "Helvetica Neue", sans-serif;
    --edge-pad: 10px;
    --stage-pad-x: 10px;
    --content-max: 960px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    color: var(--text);
    background:
        radial-gradient(900px 500px at 5% -5%, rgba(74, 143, 212, 0.22), transparent 55%),
        linear-gradient(165deg, var(--bg1), var(--bg0) 60%, #0c1018);
}

body.is-workspace {
    overflow: hidden;
    height: 100dvh;
}

.page {
    padding: var(--edge-pad);
    min-height: calc(100vh - var(--edge-pad) * 2);
}

.page.page-wide {
    height: calc(100dvh - var(--edge-pad) * 2);
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.page-inner {
    width: min(var(--content-max), 100%);
    margin-left: auto;
    margin-right: auto;
}

.page-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 40px;
}

.page-header-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex: 0 0 auto;
    min-width: 0;
}

.page-header-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    flex: 1 1 auto;
    min-width: 0;
    margin-left: auto;
}

.page.page-wide > .page-inner {
    flex-shrink: 0;
}

.page.page-wide .brand-name { display: none; }
.page.page-wide h1 { margin: 0; font-size: 1.1rem; line-height: 1; }

.brand img { border-radius: 50%; box-shadow: 0 0 0 2px rgba(74, 143, 212, 0.45); display: block; }
.brand-home { display: block; line-height: 0; border-radius: 50%; text-decoration: none; }
.brand-name { margin: 0; font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
h1 { margin: 0.1rem 0 0; font-size: clamp(1.4rem, 4vw, 1.9rem); font-weight: 650; line-height: 1.15; }

.dropzone {
    margin-top: 1rem;
    border: 1.5px dashed rgba(74, 143, 212, 0.55);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 2.5rem 1.5rem;
    text-align: center;
    cursor: pointer;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: var(--surface-strong); outline: none; }
.dropzone.is-dragover { border-color: var(--accent); background: rgba(74, 143, 212, 0.12); }
.drop-icon {
    width: 48px; height: 48px; margin: 0 auto 0.75rem; border-radius: 12px;
    border: 1px solid var(--line);
    background: linear-gradient(135deg, transparent 46%, rgba(74, 143, 212, 0.45) 46%, rgba(74, 143, 212, 0.45) 54%, transparent 54%);
}
.drop-title { margin: 0; font-weight: 600; }
.drop-sub { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.9rem; }

.workspace-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 0.4rem;
}

.workspace-below {
    flex-shrink: 0;
    display: grid;
    gap: 0.35rem;
    padding-top: 0.15rem;
}

.meta-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem 1rem;
    font-size: 0.76rem;
    color: var(--muted);
    line-height: 1.3;
}

.file-meta { color: var(--muted); }
.hint { color: var(--muted); }

.settings-bar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.45rem 0.6rem;
    padding: 0.45rem 0.65rem;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.settings-sep {
    width: 1px;
    align-self: stretch;
    min-height: 1.5rem;
    background: var(--line);
    flex-shrink: 0;
}

.field {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.76rem;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.field > span:first-child {
    font-weight: 600;
    color: var(--muted);
}

.field-range {
    min-width: 9rem;
}

.field-range input[type="range"] {
    width: 5rem;
    flex-shrink: 0;
}

.field-angle .angle-val {
    font-size: 0.82rem;
    font-weight: 650;
    color: var(--accent);
    min-width: 2.5rem;
    font-variant-numeric: tabular-nums;
}

.field-check {
    cursor: pointer;
}

.field-check span {
    color: var(--text);
    font-weight: 500;
}

.input-compact {
    width: 3.2rem;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: rgba(0, 0, 0, 0.25);
    color: var(--text);
    padding: 0.2rem 0.35rem;
    font-size: 0.8rem;
}

select.input-compact {
    width: auto;
    min-width: 2.8rem;
    padding-right: 1.2rem;
}

.measure-inline {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.measure-inline.muted {
    font-weight: 500;
    color: var(--muted);
}

.measure-hint {
    margin: 0;
    font-size: 0.74rem;
    color: var(--muted);
}

.rooms-block { margin: 0; }
.rooms-inline {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    max-height: none;
    overflow: visible;
}

.rooms-inline li {
    font-size: 0.76rem;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.15);
    white-space: nowrap;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.35rem 0.5rem;
    padding: 0;
    border: 0;
    background: transparent;
}

.tool-group, .zoom-group { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
.zoom-group span { min-width: 2.6rem; text-align: center; font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.tool-btn {
    border: 1px solid var(--line); background: rgba(0, 0, 0, 0.2); color: var(--text);
    border-radius: 8px; padding: 0.32rem 0.55rem; font-size: 0.8rem; font-weight: 600; cursor: pointer;
    line-height: 1.2;
}
.tool-btn-icon {
    width: 1.9rem; height: 1.9rem; padding: 0; font-size: 1.15rem; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    border-color: var(--accent); background: rgba(74, 143, 212, 0.15);
}
.tool-btn:hover { background: var(--surface-strong); }
.tool-btn-icon:hover { background: rgba(74, 143, 212, 0.28); }
.tool-btn.secondary { font-weight: 500; color: var(--muted); }
.tool-btn-danger:not(:disabled) { border-color: rgba(196, 90, 90, 0.5); color: #f0b0b0; }
.tool-btn-danger:not(:disabled):hover { background: rgba(196, 90, 90, 0.2); }
.tool-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.tool-btn-mini {
    padding: 0.2rem 0.45rem; font-size: 0.74rem; border-radius: 6px;
}

.stage {
    flex: 1;
    min-height: 0;
    width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: #e8edf2;
    overflow: auto;
    position: relative;
    padding: var(--edge-pad) var(--stage-pad-x);
    -webkit-overflow-scrolling: touch;
}

.stage-fit {
    position: relative;
    margin: 0 auto;
}

.stage-scaler {
    transform-origin: 0 0;
    position: absolute;
    left: 0;
    top: 0;
}

.stage-inner {
    position: relative;
    background: #fff;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    cursor: default;
}

.tool-btn.is-active {
    border-color: var(--accent);
    background: rgba(74, 143, 212, 0.28);
    color: var(--text);
}

.mode-toggle {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.mode-toggle .mode-btn {
    border: none;
    border-radius: 0;
    min-width: 3.25rem;
}

.mode-toggle .mode-btn + .mode-btn {
    border-left: 1px solid var(--line);
}

.mode-toggle .mode-btn.is-active {
    background: rgba(74, 143, 212, 0.28);
    color: var(--text);
}

.door-group {
    pointer-events: all;
    cursor: pointer;
}

.door-group path {
    fill: none;
    stroke: #1a1a1a;
    stroke-width: 1;
    pointer-events: stroke;
    stroke-linecap: round;
}

.door-group.is-selected path {
    stroke: var(--accent);
    stroke-width: 1.4;
}

.stage-inner.is-edited .trace-svg .seg-hit,
.stage-inner.is-edited .trace-svg .wall-edge,
.stage-inner.is-edited .trace-svg .wall-select,
.stage-inner.is-edited .trace-svg .handle-end,
.stage-inner.is-edited .trace-svg .handle-bend {
    vector-effect: unset;
}

.trace-bg {
    position: relative;
    z-index: 1;
    display: block; width: 100%; height: auto; pointer-events: none; user-select: none; opacity: 0.35;
}
.trace-svg {
    position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible;
    z-index: 2;
}
.trace-svg .seg {
    fill: none; stroke: var(--trace); stroke-width: 1.6; stroke-linecap: square;
    vector-effect: non-scaling-stroke; pointer-events: stroke; cursor: pointer;
}
.trace-svg .seg-hit {
    fill: none; stroke: transparent; stroke-linecap: square;
    vector-effect: non-scaling-stroke; pointer-events: stroke; cursor: pointer;
}
.trace-svg .wall-group { pointer-events: none; }
.trace-svg .wall-group .seg-hit { pointer-events: stroke; }
.trace-svg .wall-core { stroke: none; pointer-events: none; fill: #1a1a1a; }
.trace-svg .wall-select {
    fill: none; stroke: var(--accent); stroke-width: 1.2; stroke-dasharray: 4 3;
    vector-effect: non-scaling-stroke; pointer-events: none;
}
.trace-svg .seg.is-selected { stroke: var(--accent); stroke-width: 2.2; }
.trace-svg .wall-group.is-selected .wall-core { fill: #333; }
.trace-svg .seg.is-curve { stroke-linecap: round; }
.trace-svg .handle-end {
    fill: #fff; stroke: var(--handle); stroke-width: 2; cursor: grab;
    vector-effect: non-scaling-stroke; pointer-events: all;
    transition: fill 0.08s, stroke-width 0.08s;
}
.trace-svg .handle-end.is-snap-line { stroke-width: 3.5; }
.trace-svg .handle-end.is-snap-point {
    fill: var(--handle); stroke: var(--handle); stroke-width: 2.5;
}
.trace-svg .handle-bend {
    fill: #fff; stroke: var(--bend); stroke-width: 2; cursor: grab;
    vector-effect: non-scaling-stroke; pointer-events: all;
}
.trace-svg .handle-end:active,
.trace-svg .handle-bend:active { cursor: grabbing; }

.btn {
    border: 0; background: var(--accent); color: #fff; border-radius: 8px;
    padding: 0.35rem 0.75rem; font-weight: 600; font-size: 0.8rem; cursor: pointer;
    line-height: 1.2; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--accent-deep); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.secondary { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn-trace { padding: 0.35rem 0.85rem; }

.status { margin: 0; font-size: 0.78rem; color: var(--muted); min-height: 1em; }
.status.is-busy { color: var(--accent); }
.status.is-err { color: #e88; }
.foot { margin-top: 2rem; font-size: 0.82rem; color: var(--muted); }
.foot a { color: var(--accent); }
.page.page-wide .foot { display: none; }
