:root {
    --bg: #0d0d12;
    --panel: #14141b;
    --panel2: #191924;
    --line: #262633;
    --text: #e8e8f0;
    --dim: #8a8a9c;
    --purple: #8b5cf6;
    --purple2: #a78bfa;
    --gold: #d4af5f;
    --red: #ef4444;
    --green: #34d399;
}

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

html,
body {
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font: 13px/1.45 'Segoe UI', system-ui, sans-serif;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---------- header ---------- */

#topbar {
    height: 52px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    flex: none;
}

.logo {
    font-weight: 700;
    letter-spacing: 3px;
    font-size: 15px;
    margin-right: 14px;
    white-space: nowrap;
}

.logo span {
    color: var(--purple2);
    font-weight: 300;
}

.logo .m1 {
    font-style: normal;
    font-size: 9px;
    color: var(--dim);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 1px 5px;
    margin-left: 8px;
    vertical-align: middle;
}

.logo.big {
    font-size: 28px;
    letter-spacing: 6px;
}

.spacer {
    flex: 1;
}

/* ---------- buttons ---------- */

.btn {
    background: var(--panel2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 14px;
    cursor: pointer;
    font-size: 12.5px;
    transition: border-color .15s, background .15s;
}

.btn:hover:not(:disabled) {
    border-color: var(--purple);
}

.btn:disabled {
    opacity: .38;
    cursor: default;
}

.btn.primary {
    border-color: var(--purple);
    background: rgba(139, 92, 246, .12);
    color: var(--purple2);
}

.btn.primary:hover:not(:disabled) {
    background: rgba(139, 92, 246, .25);
}

.btn.danger:hover:not(:disabled) {
    border-color: var(--red);
    color: var(--red);
}

.btn.icon {
    padding: 7px 10px;
    font-size: 15px;
    line-height: 1;
}

.btn.sm {
    padding: 6px 8px;
    font-size: 12px;
}

.btn.wide {
    width: 100%;
    margin-top: 6px;
}

.btn.scanholes {
    margin-top: 16px;
    border-color: #7f1d1d;
    background: rgba(239, 68, 68, .08);
}

.btn.scanholes:hover:not(:disabled) {
    border-color: var(--red);
}

.btn.scanholes.on {
    border-color: var(--red);
    background: rgba(239, 68, 68, .2);
}

/* ---------- layout ---------- */

main {
    flex: 1;
    display: flex;
    min-height: 0;
}

#leftPanel,
#rightPanel {
    width: 250px;
    flex: none;
    background: var(--panel);
    padding: 14px;
    overflow-y: auto;
}

#leftPanel {
    border-right: 1px solid var(--line);
}

#rightPanel {
    border-left: 1px solid var(--line);
    width: 290px;
    display: flex;
    flex-direction: column;
}

h3 {
    font-size: 10.5px;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: var(--dim);
    margin: 18px 0 8px;
    font-weight: 600;
}

h3:first-child {
    margin-top: 0;
}

.tool-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tool {
    text-align: left;
    padding: 8px 12px;
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    font-size: 12.5px;
}

.tool:hover {
    border-color: var(--purple);
}

.tool.active {
    border-color: var(--purple);
    background: rgba(139, 92, 246, .14);
    color: var(--purple2);
}

.grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.grid3 {
    display: grid;
    grid-template-columns: repeat(3, 44px);
    gap: 8px;
}

.hint {
    color: var(--dim);
    font-size: 11.5px;
    margin: 8px 0;
}

.hint b {
    color: var(--text);
}

.swatch {
    height: 34px;
    border-radius: 8px;
    border: 2px solid var(--line);
    cursor: pointer;
}

.swatch.gold {
    background: linear-gradient(135deg, #f5d67b, #b8860b);
}

.swatch.rose {
    background: linear-gradient(135deg, #f4b8a0, #b76e5b);
}

.swatch.silver {
    background: linear-gradient(135deg, #eef1f6, #9aa1ad);
}

.swatch.active {
    border-color: var(--purple);
}

/* ---------- sliders ---------- */

.slider-row {
    margin: 10px 0;
    position: relative;
}

.slider-row label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text);
    margin-bottom: 5px;
    gap: 6px;
}

.slider-row label span {
    color: var(--gold);
    font-variant-numeric: tabular-nums;
}

.slider-row .info {
    font-style: normal;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid var(--dim);
    color: var(--dim);
    font-size: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: help;
    flex: none;
}

.slider-row .info:hover {
    border-color: var(--purple2);
    color: var(--purple2);
}

input[type=range] {
    width: 100%;
    accent-color: var(--purple);
    height: 4px;
    cursor: pointer;
}

.check {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 12px;
    color: var(--dim);
    margin: 12px 0 4px;
    cursor: pointer;
}

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

/* ---------- viewport ---------- */

#viewport {
    flex: 1;
    position: relative;
    min-width: 0;
    background: radial-gradient(1200px 700px at 50% 30%, #16161f 0%, var(--bg) 70%);
}

#viewport.dragover {
    outline: 2px dashed var(--purple);
    outline-offset: -8px;
}

#viewport.dragover::after {
    content: 'Drop scan to upload';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--purple2);
    background: rgba(139, 92, 246, .08);
    pointer-events: none;
}

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

#btnResetView {
    position: absolute;
    right: 14px;
    bottom: 14px;
}

#emptyState {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    text-align: center;
    color: var(--dim);
}

#busy {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(13, 13, 18, .72);
    z-index: 30;
}

#busy.on {
    display: flex;
}

#busy .ring {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 3px solid var(--line);
    border-top-color: var(--purple);
    animation: spin 1s linear infinite;
}

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

#toast {
    position: absolute;
    left: 50%;
    top: 18px;
    transform: translateX(-50%);
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toastmsg {
    background: var(--panel2);
    border: 1px solid var(--line);
    border-left: 3px solid var(--purple);
    padding: 9px 16px;
    border-radius: 8px;
    font-size: 12.5px;
    animation: fade .25s;
    max-width: 480px;
}

.toastmsg.err {
    border-left-color: var(--red);
}

.toastmsg.ok {
    border-left-color: var(--green);
}

@keyframes fade {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
}

/* ---------- right panel ---------- */

#tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 12px;
    flex: none;
}

.tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--dim);
    padding: 8px 4px;
    cursor: pointer;
    font-size: 12px;
    border-bottom: 2px solid transparent;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--purple2);
    border-bottom-color: var(--purple);
}

.tabpage {
    display: none;
}

.tabpage.active {
    display: block;
}

.basecard {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;
    cursor: pointer;
    position: relative;
}

.basecard p {
    color: var(--dim);
    font-size: 11.5px;
    margin-top: 3px;
}

.basecard.active {
    border-color: var(--gold);
    background: rgba(212, 175, 95, .07);
}

.basecard.disabled {
    opacity: .5;
    cursor: default;
}

.badge {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 9.5px;
    color: var(--purple2);
    border: 1px solid var(--purple);
    border-radius: 5px;
    padding: 1px 6px;
}

.milestone-note {
    border: 1px dashed var(--line);
    border-radius: 10px;
    padding: 12px 14px;
    color: var(--dim);
    font-size: 12px;
}

.milestone-note b {
    color: var(--purple2);
    display: block;
    margin-bottom: 4px;
}

#summary {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    flex: none;
}

#summary .row {
    display: flex;
    justify-content: space-between;
    padding: 2.5px 0;
    font-size: 11.8px;
}

#summary .row span {
    color: var(--dim);
}

#summary .row b {
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

#s_water.pass {
    color: var(--green);
}

#s_water.fail {
    color: var(--red);
}

/* ---------- M1 completion controls ---------- */

.color-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 7px 0;
    font-size: 12px;
    color: var(--text);
}

.color-row label {
    color: var(--dim);
}

.color-row input[type=color] {
    width: 38px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: none;
    cursor: pointer;
}

.color-row input[type=range] {
    width: 120px;
}

.tmpl-select,
.alloy-select,
.ver-select {
    width: 100%;
    margin-top: 6px;
    background: var(--panel2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 5px 6px;
    font-size: 12px;
    cursor: pointer;
}

.alloy-select {
    width: auto;
    margin: 0;
    padding: 2px 4px;
}

.ver-select {
    width: 130px;
    margin: 0;
}

.row.metal-calc {
    align-items: center;
}

.save-state {
    font-size: 11px;
    color: var(--dim);
    margin-right: 4px;
    min-width: 62px;
    text-align: right;
}

.save-state.saved {
    color: var(--green);
}

.save-state.dirty {
    color: var(--gold);
}

#magnifier {
    position: absolute;
    right: 14px;
    bottom: 56px;
    width: 200px;
    height: 200px;
    border: 2px solid var(--purple);
    border-radius: 12px;
    overflow: hidden;
    display: none;
    background: #000;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
    z-index: 20;
    cursor: move;
}

#magnifier.on {
    display: block;
}

#magnifier canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#magnifier .maglabel {
    position: absolute;
    top: 4px;
    left: 8px;
    font-size: 10px;
    color: var(--purple2);
    letter-spacing: 1px;
    pointer-events: none;
}

#magnifier .magclose {
    position: absolute;
    top: 2px;
    right: 6px;
    color: var(--dim);
    cursor: pointer;
    font-size: 14px;
}

#orbitBox {
    position: absolute;
    left: 14px;
    bottom: 14px;
    width: 92px;
    height: 92px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: rgba(20, 20, 28, .6);
    display: none;
    z-index: 20;
}

#orbitBox.on {
    display: block;
}

/* ---------- M2 diamonds panel ---------- */

.tpl-btn {
    padding: 8px;
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    font-size: 12.5px;
}

.tpl-btn:hover {
    border-color: var(--purple);
}

.tpl-btn.active {
    border-color: var(--purple);
    background: rgba(139, 92, 246, .16);
    color: var(--purple2);
}

.size-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    margin: 8px 0;
}

.size-cell {
    font-size: 10.5px;
    padding: 5px 0;
    text-align: center;
    border: 1px solid var(--line);
    border-radius: 5px;
    cursor: pointer;
    color: var(--dim);
    background: var(--panel2);
    font-variant-numeric: tabular-nums;
}

.size-cell.on {
    color: var(--gold);
    border-color: var(--gold);
    background: rgba(212, 175, 95, .1);
}

.size-cell.active {
    outline: 2px solid var(--purple);
}

.dreport {
    margin-top: 12px;
    font-size: 11.5px;
    color: var(--dim);
}

.dreport .drow {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}

.dreport .drow b {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.dreport .blank {
    color: var(--gold);
}

.dreport .ok {
    color: var(--green);
}

.dreport .fail {
    color: var(--red);
}

/* point-system legend dots (match client diagram colours) */

.dot-red,
.dot-blue,
.dot-purple {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: 4px;
    vertical-align: middle;
}

.dot-red {
    background: #ef4444;
}

.dot-blue {
    background: #38bdf8;    
}

.dot-purple {
    background: #a78bfa;
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 4px;
}