:root {
    --bg: #0d1117;
    --panel: #161b22;
    --panel-2: #1c2330;
    --border: #2a3240;
    --text: #e6edf3;
    --muted: #8b949e;
    --accent: #3b82f6;
    --accent-2: #22d3ee;
    --danger: #ef4444;
    --ok: #22c55e;
    --shadow: 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    font-size: 13px;
}
code { background: rgba(255,255,255,.06); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.tag { color: var(--accent-2); font-variant-numeric: tabular-nums; }

.app { display: flex; flex-direction: column; height: 100vh; }

/* Topbar */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
    z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 22px; color: var(--accent-2); }
.brand h1 { font-size: 15px; margin: 0; font-weight: 650; }
.brand .subtitle { font-size: 11px; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
    padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
    transition: background .15s, border-color .15s;
}
.btn:hover { background: #232b3a; border-color: #3a4557; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #2f6fe0; }

/* Workspace */
.workspace { display: flex; flex: 1; min-height: 0; }
.sidebar {
    width: 290px; min-width: 290px; background: var(--panel); border-right: 1px solid var(--border);
    overflow-y: auto; padding: 4px 0;
}
.panel { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.panel h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }

.row { margin-bottom: 10px; }
.row > label { display: block; font-size: 12px; margin-bottom: 4px; color: var(--text); }
.row select, .row input[type="number"] {
    width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
    border-radius: 7px; padding: 6px 8px; font-size: 13px;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
.dual { display: flex; flex-direction: column; gap: 2px; }
.chk { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; cursor: pointer; font-size: 12.5px; }
.chk input { accent-color: var(--accent); }

.cloud-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.cloud-item {
    background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
    display: flex; align-items: center; gap: 8px;
}
.cloud-item .ci-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.cloud-item .ci-badge { font-size: 10px; padding: 1px 6px; border-radius: 999px; background: #24304a; color: var(--accent-2); }
.cloud-item .ci-badge.copc { background: #14342a; color: #34d399; }
.cloud-item button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.cloud-item button:hover { color: var(--danger); }

.class-filter { display: flex; flex-direction: column; gap: 4px; max-height: 180px; overflow-y: auto; }
.class-row { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.class-swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.class-row .cnt { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Viewer */
.viewer-wrap { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; }
.toolbar {
    display: flex; align-items: center; gap: 6px; padding: 7px 10px;
    background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; z-index: 12;
}
.tool-group { display: flex; gap: 4px; align-items: center; }
.tool {
    background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
    padding: 6px 10px; border-radius: 7px; cursor: pointer; font-size: 12.5px; white-space: nowrap;
}
.tool:hover { background: #232b3a; }
.tool.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.tool-status { margin-left: auto; color: var(--accent-2); font-size: 12px; }

.dropdown { position: relative; }
.dropdown-menu {
    display: none; position: absolute; top: 110%; right: 0; background: var(--panel-2);
    border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; z-index: 30; min-width: 210px;
}
.dropdown-menu button {
    display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text);
    padding: 9px 12px; cursor: pointer; font-size: 12.5px;
}
.dropdown-menu button:hover { background: var(--accent); color: #fff; }
.dropdown.open .dropdown-menu { display: block; }

.viewer { position: absolute; inset: 0; top: 43px; }
.viewer canvas { display: block; }

/* Overlays */
.overlay { position: absolute; z-index: 10; pointer-events: none; }
.hud { top: 52px; left: 12px; font-size: 11.5px; color: var(--muted); background: rgba(13,17,23,.6); padding: 6px 9px; border-radius: 7px; line-height: 1.6; }
.readout { bottom: 14px; left: 12px; background: rgba(13,17,23,.85); border: 1px solid var(--border); padding: 8px 11px; border-radius: 8px; font-variant-numeric: tabular-nums; font-size: 12px; line-height: 1.7; max-width: 340px; }
.measure-box { top: 52px; right: 12px; background: rgba(13,17,23,.85); border: 1px solid var(--border); padding: 10px 12px; border-radius: 8px; font-size: 12px; min-width: 200px; }
.measure-box h4 { margin: 0 0 6px; font-size: 12px; }
.measure-box .mrow { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.measure-box .mrow b { font-variant-numeric: tabular-nums; }
.legend { bottom: 14px; right: 12px; background: rgba(13,17,23,.85); border: 1px solid var(--border); padding: 8px 10px; border-radius: 8px; font-size: 11px; }
.legend .bar { width: 150px; height: 12px; border-radius: 3px; margin: 4px 0; }
.legend .ends { display: flex; justify-content: space-between; }

.drop-hint {
    position: absolute; inset: 43px 0 0 0; z-index: 40; display: none;
    align-items: center; justify-content: center;
    background: rgba(59,130,246,.12); border: 2px dashed var(--accent); margin: 10px; border-radius: 12px;
}
.drop-hint.show { display: flex; }
.drop-inner { text-align: center; color: var(--text); }
.drop-icon { font-size: 40px; color: var(--accent); }

.loading {
    position: absolute; inset: 43px 0 0 0; z-index: 45; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 14px; background: rgba(13,17,23,.6); backdrop-filter: blur(2px);
}
.spinner { width: 42px; height: 42px; border: 4px solid rgba(255,255,255,.15); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { width: 260px; height: 6px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .1s; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.5); }
.modal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; width: min(560px, 92vw); max-height: 85vh; overflow: auto; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 16px; line-height: 1.7; }
.modal-body h4 { margin: 14px 0 6px; }
.modal-body ul { margin: 4px 0; padding-left: 20px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2c3543; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
