/* --- Reset & Variables --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface2: #eef0f4;
    --border: #d8dce3;
    --text: #2c3e50;
    --text-dim: #8896a7;
    --accent: #3b6cb4;
    --accent-hover: #2d5a9e;
    --accent2: #e8962e;
    --accent2-hover: #d08020;
    --danger: #d94a5d;
    --success: #3a9d6e;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

html { font-size: 15px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-y: auto;
}

/* --- Layout --- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 20px 40px;
}

/* --- Header --- */
.header {
    text-align: center;
    padding: 20px 0 28px;
}
.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.02em;
}
.header p {
    font-size: 0.88rem;
    color: var(--text-dim);
    margin-top: 6px;
}

/* --- Controls --- */
.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.file-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text);
    transition: border-color 0.2s, background 0.2s;
}
.file-label:hover { border-color: var(--accent); background: #e6ecf4; }
.file-label input { display: none; }

#fileName {
    font-size: 0.82rem;
    color: var(--text-dim);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-select {
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
}
.model-select:focus { outline: none; border-color: var(--accent); }

.btn {
    padding: 8px 22px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-download {
    background: var(--accent2);
    color: #fff;
}
.btn-download:hover { background: var(--accent2-hover); }

.btn-sample {
    display: inline-flex;
    align-items: center;
    padding: 8px 18px;
    background: var(--accent2);
    border: none;
    border-radius: var(--radius);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.2s;
}
.btn-sample:hover { background: var(--accent2-hover); }

.point-size-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    font-size: 0.82rem;
    color: var(--text-dim);
}
.point-size-group input[type="range"] {
    width: 90px;
    accent-color: var(--accent);
}

/* --- Viewer panels --- */
.viewers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.viewer-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: #fafbfc;
    font-size: 0.85rem;
    font-weight: 500;
}
.panel-header .dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
}
.dot-input { background: #5b9bd5; }
.dot-result { background: #e8962e; }
.panel-header .point-count {
    font-size: 0.75rem;
    color: var(--text-dim);
}

.viewer-canvas {
    flex: 1;
    min-height: 360px;
    cursor: grab;
    background: #f2f3f5;
}
.viewer-canvas:active { cursor: grabbing; }

/* --- Loading --- */
.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    font-size: 0.85rem;
    color: var(--accent);
}
.loading-overlay.hidden { display: none; }

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Result info --- */
.result-info {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
    gap: 12px;
}
.result-info.hidden { display: none; }

/* --- Example showcase --- */
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 32px 0 28px;
}

#exampleShow {
    text-align: center;
    margin-bottom: 28px;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.section-legend {
    font-size: 0.82rem;
    color: var(--text-dim);
    margin-bottom: 16px;
}

.legend-dot {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    vertical-align: -1px;
}

.slideshow {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    max-width: 900px;
    margin: 0 auto;
}

.slide-viewport {
    flex: 1;
    max-width: 780px;
    height: 350px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    background: var(--surface);
}

.slide-img {
    display: none;
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.slide-img.active { display: block; }

.slide-arrow {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-dim);
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, color 0.2s, box-shadow 0.2s;
    line-height: 1;
    box-shadow: var(--shadow);
}
.slide-arrow:hover {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 2px 6px rgba(59, 108, 180, 0.15);
}

.slide-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 14px;
}

.slide-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--border);
    border: none;
    cursor: pointer;
    padding: 0;
    transition: background 0.2s;
}
.slide-dot.active { background: var(--accent); }

/* --- Help bar --- */
.help-bar {
    text-align: center;
    padding: 8px;
    font-size: 0.78rem;
    color: var(--text-dim);
}
.help-bar kbd {
    display: inline-block;
    padding: 1px 7px;
    border: 1px solid var(--border);
    border-radius: 3px;
    font-family: inherit;
    font-size: 0.72rem;
    background: var(--surface2);
    color: var(--text-dim);
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: #fff;
    max-width: 360px;
    opacity: 0;
    transform: translateX(40px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-error { background: var(--danger); }
.toast-success { background: var(--success); }

/* --- Footer --- */
.footer-beian {
    text-align: center;
    padding: 20px 0 8px;
}
.footer-beian a {
    font-size: 0.72rem;
    color: var(--text-dim);
    text-decoration: none;
    opacity: 0.6;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .viewers {
        grid-template-columns: 1fr;
    }
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    .point-size-group {
        margin-left: 0;
        justify-content: flex-end;
    }
    #fileName { max-width: 100%; }
    .slide-arrow { display: none; }
}
