/* ═══════════════════════════════════════════════════════════════════════════
   PINGCOIN VISUAL INSPECTOR
   Clean, minimal design matching pingcoin.com aesthetic
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Typography ─────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Cal+Sans&display=swap');

@font-face {
    font-family: 'Cal Sans';
    src: url('https://cal.com/fonts/CalSans-SemiBold.woff2') format('woff2');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

/* ─── CSS Variables ──────────────────────────────────────────────────────── */
:root {
    /* Core palette - light, clean, minimal */
    --bg-primary: #fafafa;
    --bg-white: #ffffff;
    --bg-subtle: #f5f5f5;

    /* Text colors */
    --text-primary: #111111;
    --text-secondary: #374151;
    --text-muted: #6b7280;
    --text-subtle: #9ca3af;

    /* Border colors */
    --border-light: #e5e7eb;
    --border-medium: #d1d5db;
    --border-dark: #9ca3af;

    /* Accent colors */
    --accent-primary: #111111;
    --accent-hover: #374151;
    --success: #059669;
    --success-bg: #ecfdf5;
    --error: #dc2626;
    --error-bg: #fef2f2;
    --info: #2563eb;
    --info-bg: #eff6ff;

    /* Typography */
    --font-display: 'Cal Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, monospace;

    /* Spacing scale */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;
    --space-3xl: 64px;

    /* Border radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Transitions */
    --transition: 0.2s ease;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    min-height: 100vh;
    line-height: 1.6;
}

/* ─── Container ──────────────────────────────────────────────────────────── */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-xl) var(--space-lg);
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
header {
    text-align: center;
    padding: var(--space-2xl) 0 var(--space-3xl);
    border-bottom: 1px solid var(--border-light);
    margin-bottom: var(--space-xl);
}

header h1 {
    font-family: var(--font-display);
    font-size: 2.25rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

/* ─── Sections ───────────────────────────────────────────────────────────── */
.section {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin-bottom: var(--space-lg);
    border: 1px solid var(--border-light);
}

.section h2 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

/* Step number styling */
.section h2::before {
    content: '';
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--text-primary);
    border-radius: 50%;
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--bg-white);
    flex-shrink: 0;
}

#step-1 h2::before { content: '1'; }
#step-2 h2::before { content: '2'; }
#step-3 h2::before { content: '3'; }
#step-4 h2::before { content: '4'; }

.section-desc {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: var(--space-lg);
    margin-left: calc(28px + var(--space-md));
}

/* ─── Image Layout ───────────────────────────────────────────────────────── */
.image-row {
    display: flex;
    gap: var(--space-xl);
    justify-content: center;
    flex-wrap: wrap;
}

.image-row.three-col {
    gap: var(--space-lg);
}

.image-box {
    flex: 1;
    min-width: 280px;
    max-width: 400px;
    text-align: center;
}

.three-col .image-box {
    min-width: 240px;
    max-width: 340px;
}

.image-box h3 {
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

.image-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: var(--bg-subtle);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color var(--transition);
}

.image-container:hover {
    border-color: var(--border-medium);
}

.image-container canvas {
    max-width: 100%;
    max-height: 100%;
    display: none;
}

.image-container canvas.visible {
    display: block;
}

/* ─── Drawing Containers ─────────────────────────────────────────────────── */
.drawing-container {
    cursor: crosshair;
}

.drawing-container:hover {
    border-color: var(--text-primary);
}

/* ─── Circle Containers (Cropped Images) ─────────────────────────────────── */
.circle-container {
    border-radius: 50%;
    border: 2px solid var(--border-light);
}

.circle-container.rotatable {
    cursor: grab;
    border-color: var(--text-primary);
    transition: all var(--transition);
}

.circle-container.rotatable:hover {
    box-shadow: 0 0 0 4px rgba(17, 17, 17, 0.08);
}

.circle-container.rotatable:active {
    cursor: grabbing;
}

/* ─── Placeholder ────────────────────────────────────────────────────────── */
.placeholder {
    font-size: 0.875rem;
    color: var(--text-subtle);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
}

.placeholder::before {
    content: '';
    width: 48px;
    height: 48px;
    border: 2px dashed var(--border-medium);
    border-radius: 50%;
    opacity: 0.5;
}

.placeholder.hidden {
    display: none;
}

/* ─── Button Row ─────────────────────────────────────────────────────────── */
.button-row {
    display: flex;
    gap: var(--space-sm);
    justify-content: center;
    margin-top: var(--space-md);
}

/* ─── File Inputs & Buttons ──────────────────────────────────────────────── */
.file-input {
    display: none;
}

/* Base button styles */
.upload-btn,
.example-btn,
.clear-btn,
.detect-btn {
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 500;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

/* Upload button - primary dark */
.upload-btn {
    background: var(--text-primary);
    color: var(--bg-white);
    border: none;
}

.upload-btn:hover {
    background: var(--accent-hover);
}

/* Example button - outlined */
.example-btn {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-medium);
}

.example-btn:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
}

/* Clear button - subtle danger */
.clear-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-light);
}

.clear-btn:hover {
    color: var(--error);
    border-color: var(--error);
    background: var(--error-bg);
}

/* Detect button - subtle success */
.detect-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-light);
}

.detect-btn:hover {
    color: var(--success);
    border-color: var(--success);
    background: var(--success-bg);
}

/* ─── Action Row & Primary CTA ───────────────────────────────────────────── */
.action-row {
    text-align: center;
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border-light);
}

.action-btn {
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 500;
    padding: var(--space-md) var(--space-2xl);
    background: var(--text-primary);
    color: var(--bg-white);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.action-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

.action-btn:disabled {
    background: var(--border-light);
    color: var(--text-subtle);
    cursor: not-allowed;
}

/* ─── Rotation Info ──────────────────────────────────────────────────────── */
.rotation-info {
    margin-top: var(--space-md);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-muted);
}

#rotation-angle {
    color: var(--text-primary);
    font-weight: 500;
}

/* ─── Opacity Control ────────────────────────────────────────────────────── */
.opacity-control {
    margin-top: var(--space-md);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Custom range slider */
.opacity-control input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    cursor: pointer;
}

.opacity-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--text-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition);
}

.opacity-control input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.opacity-control input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--text-primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

#opacity-value {
    font-family: var(--font-mono);
    color: var(--text-secondary);
    min-width: 36px;
}

/* ─── Alignment Score Panel ──────────────────────────────────────────────── */
.alignment-score-box {
    display: flex;
    flex-direction: column;
}

.alignment-score-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: var(--space-lg);
    background: var(--bg-subtle);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    min-height: 200px;
}

.score-display {
    margin-bottom: var(--space-md);
}

.score-display #alignment-score {
    font-family: var(--font-mono);
    font-size: 2.5rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.score-bar-container {
    width: 100%;
    max-width: 150px;
    height: 8px;
    background: var(--border-light);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: var(--space-lg);
}

.score-bar {
    height: 100%;
    width: 0%;
    background: var(--text-muted);
    border-radius: 4px;
    transition: width 0.15s ease, background 0.15s ease;
}

.score-graph-container {
    width: 100%;
    max-width: 150px;
}

.score-graph-label {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-xs);
    text-align: center;
}

#alignment-graph {
    width: 100%;
    height: 40px;
    display: block;
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    border: 1px solid var(--border-light);
}

/* ─── Loading Overlay ────────────────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.loading-content p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: var(--space-lg);
}

/* Simple spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-light);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

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

/* ─── Status Message ─────────────────────────────────────────────────────── */
.status-message {
    position: fixed;
    bottom: var(--space-xl);
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    font-size: 0.875rem;
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 100;
}

.status-message.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.status-message.error {
    background: var(--error-bg);
    border-color: var(--error);
    color: var(--error);
}

.status-message.success {
    background: var(--success-bg);
    border-color: var(--success);
    color: var(--success);
}

.status-message.info {
    background: var(--info-bg);
    border-color: var(--info);
    color: var(--info);
}

/* ─── Hover Zoom Tooltip ─────────────────────────────────────────────────── */
.zoom-tooltip {
    position: fixed;
    display: none;
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    gap: var(--space-sm);
    z-index: 1000;
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.zoom-tooltip.visible {
    display: flex;
}

.zoom-panel {
    text-align: center;
}

.zoom-label {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-xs);
}

.zoom-panel canvas {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    background: var(--bg-subtle);
}

/* ─── Scrollbar Styling ──────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-subtle);
}

/* ─── Selection ──────────────────────────────────────────────────────────── */
::selection {
    background: var(--text-primary);
    color: var(--bg-white);
}

/* ─── Responsive Design ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .image-row.three-col {
        flex-direction: column;
        align-items: center;
    }

    .three-col .image-box {
        width: 100%;
        max-width: 360px;
    }

    header h1 {
        font-size: 1.75rem;
    }
}

@media (max-width: 768px) {
    .container {
        padding: var(--space-lg) var(--space-md);
    }

    header {
        padding: var(--space-xl) 0 var(--space-2xl);
    }

    header h1 {
        font-size: 1.5rem;
    }

    .section {
        padding: var(--space-lg);
    }

    .section h2 {
        font-size: 1.125rem;
    }

    .section-desc {
        margin-left: 0;
    }

    .image-row {
        flex-direction: column;
        align-items: center;
    }

    .image-box {
        width: 100%;
        max-width: 360px;
    }

    .button-row {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .button-row > * {
        width: 100%;
    }

    .action-btn {
        width: 100%;
        max-width: 280px;
    }
}

/* ─── Reduced Motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ─── Focus States (Accessibility) ───────────────────────────────────────── */
:focus-visible {
    outline: 2px solid var(--text-primary);
    outline-offset: 2px;
}

button:focus-visible,
label:focus-visible,
input:focus-visible {
    outline: 2px solid var(--text-primary);
    outline-offset: 2px;
}

/* ─── Step 4: Analysis Layout ────────────────────────────────────────────── */
.analysis-layout {
    display: flex;
    gap: var(--space-xl);
    justify-content: center;
    flex-wrap: wrap;
}

.analysis-overlay-box {
    flex: 0 0 auto;
    text-align: center;
}

.analysis-overlay-box h3 {
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

.analysis-clickable {
    cursor: crosshair;
    border-color: var(--text-primary);
    transition: all var(--transition);
}

.analysis-clickable:hover {
    box-shadow: 0 0 0 4px rgba(17, 17, 17, 0.08);
}

.click-hint {
    margin-top: var(--space-md);
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ─── Snapshot Matrix ────────────────────────────────────────────────────── */
.snapshot-matrix-box {
    flex: 1;
    min-width: 400px;
    max-width: 600px;
}

.snapshot-matrix-box h3 {
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

#snapshot-count {
    font-weight: 400;
    color: var(--text-muted);
}

.snapshot-matrix {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
    background: var(--bg-subtle);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
}

.snapshot-slot {
    position: relative;
    aspect-ratio: 2 / 1;
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.snapshot-slot:has(.snapshot-comparison) {
    border-color: var(--border-medium);
}

.snapshot-placeholder {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--border-light);
}

.snapshot-comparison {
    display: flex;
    width: 100%;
    height: 100%;
}

.snapshot-comparison img {
    width: 50%;
    height: 100%;
    object-fit: cover;
}

.snapshot-comparison img:first-child {
    border-right: 1px solid var(--border-light);
}

.snapshot-remove-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border: none;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    font-size: 12px;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition);
}

.snapshot-slot:hover .snapshot-remove-btn {
    opacity: 1;
}

.snapshot-remove-btn:hover {
    background: var(--error);
}

/* ─── Matrix Controls ────────────────────────────────────────────────────── */
.matrix-controls {
    display: flex;
    gap: var(--space-sm);
    justify-content: center;
    margin-top: var(--space-md);
    flex-wrap: wrap;
}

.action-btn-small {
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    padding: var(--space-sm) var(--space-md);
    background: var(--text-primary);
    color: var(--bg-white);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.action-btn-small:hover {
    background: var(--accent-hover);
}

/* ─── Responsive: Step 4 ─────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .analysis-layout {
        flex-direction: column;
        align-items: center;
    }

    .snapshot-matrix-box {
        min-width: 100%;
        max-width: 100%;
    }
}

@media (max-width: 400px) {
    .snapshot-matrix {
        grid-template-columns: 1fr;
    }
}
