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

:root {
    --bg: #0B0E14;
    --bg-alt: #101520;
    --bg-card: #131820;
    --bg-card-hover: #1a2030;
    --border: #1e2530;
    --border-light: #2a3340;
    --text: #E8ECF0;
    --text-muted: #8090a0;
    --text-dim: #4a5568;
    --primary: #5DCAA5;
    --primary-light: #5DCAA5;
    --primary-dark: #0F6E56;
    --accent: #5DCAA5;
    --accent-light: #8EDBC0;
    --success: #5DCAA5;
    --warning: #fdcb6e;
    --danger: #e17055;
    --psa: #e74c3c;
    --beckett: #3498db;
    --cgc: #f39c12;
    --ace: #2ecc71;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 20px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.6);
    --transition: 0.2s ease;
    --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

a {
    color: var(--primary-light);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    color: var(--accent);
}

img {
    max-width: 100%;
    display: block;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ===== Navbar ===== */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.nav-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.nav-logo {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    letter-spacing: -0.5px;
    gap: 6px;
}

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

.logo-icon {
    flex-shrink: 0;
    margin-right: 8px;
    height: 28px;
    width: auto;
}

.logo-wordmark {
    font-weight: 600;
}

.logo-light {
    font-weight: 400;
}

.logo-dot {
    color: var(--primary);
    font-weight: 600;
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 8px;
}

.nav-links a {
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition);
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--text);
    background: var(--bg-card);
}

.nav-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.nav-toggle span {
    width: 24px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: all var(--transition);
}

/* ===== Hero ===== */
.hero {
    position: relative;
    padding: 140px 0 80px;
    overflow: hidden;
    min-height: 80vh;
    display: flex;
    align-items: center;
}

.hero-bg {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 0%, rgba(93, 202, 165, 0.12) 0%, transparent 60%),
                radial-gradient(ellipse at 80% 50%, rgba(15, 110, 86, 0.08) 0%, transparent 40%);
}

.hero-content {
    position: relative;
    text-align: center;
}

.hero h1 {
    font-size: clamp(2.2rem, 6vw, 3.8rem);
    font-weight: 800;
    line-height: 1.15;
    margin-bottom: 20px;
    letter-spacing: -0.02em;
}

.gradient-text {
    background: linear-gradient(135deg, #8EDBC0, #5DCAA5, #0F6E56);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-sub {
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    color: var(--text-muted);
    max-width: 600px;
    margin: 0 auto 36px;
    line-height: 1.7;
}

.hero-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: #04342C;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(93, 202, 165, 0.25);
}

.btn-primary:hover {
    background: var(--primary-dark);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(93, 202, 165, 0.35);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text);
    border-color: var(--border-light);
}

.btn-lg {
    padding: 16px 32px;
    font-size: 1.05rem;
    border-radius: var(--radius);
}

.btn-icon {
    font-size: 1.2em;
}

/* ===== Sections ===== */
.section {
    padding: 80px 0;
}

.section-alt {
    background: var(--bg-alt);
}

.section-title {
    text-align: center;
    font-size: clamp(1.6rem, 4vw, 2.2rem);
    font-weight: 700;
    margin-bottom: 48px;
    letter-spacing: -0.01em;
}

/* ===== Steps Grid ===== */
.steps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
}

.step-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px 28px;
    text-align: center;
    transition: all var(--transition);
}

.step-card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
}

.step-number {
    position: absolute;
    top: -14px;
    left: 24px;
    width: 28px;
    height: 28px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
}

.step-icon {
    font-size: 2.4rem;
    margin-bottom: 16px;
}

.step-card h3 {
    font-size: 1.15rem;
    margin-bottom: 8px;
}

.step-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ===== Companies Grid ===== */
.companies-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}

.company-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    text-align: center;
    transition: all var(--transition);
    color: var(--text);
}

.company-card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
    color: var(--text);
}

.company-logo {
    display: inline-block;
    height: 40px;
    width: auto;
    max-width: 120px;
    object-fit: contain;
    margin-bottom: 8px;
    filter: brightness(0) invert(1);
    transition: filter 0.3s ease;
}

.company-card:hover .company-logo {
    filter: none;
}

.company-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 14px;
    font-weight: 800;
    font-size: 0.85rem;
    color: #fff;
    margin-bottom: 16px;
}

.company-badge.psa { background: var(--psa); }
.company-badge.beckett { background: var(--beckett); }
.company-badge.cgc { background: var(--cgc); }
.company-badge.ace { background: var(--ace); }

.company-card h3 {
    font-size: 1.05rem;
    margin-bottom: 6px;
}

.company-card p {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ===== Info Card ===== */
.info-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    align-items: center;
}

.info-text p {
    color: var(--text-muted);
    margin-bottom: 16px;
    font-size: 0.95rem;
}

.info-text ul {
    list-style: none;
    margin-bottom: 16px;
}

.info-text li {
    padding: 6px 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.info-text li::before {
    content: '→ ';
    color: var(--primary-light);
}

.centering-demo {
    text-align: center;
}

.demo-card {
    position: relative;
    width: 200px;
    height: 280px;
    border: 3px solid var(--primary-light);
    border-radius: var(--radius);
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.demo-inner {
    width: 140px;
    height: 200px;
    border: 2px dashed var(--accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
}

.demo-border {
    position: absolute;
    color: var(--primary-light);
    font-size: 0.7rem;
    font-weight: 700;
}

.demo-top { top: 6px; left: 50%; transform: translateX(-50%); }
.demo-bottom { bottom: 6px; left: 50%; transform: translateX(-50%); }
.demo-left { left: 6px; top: 50%; transform: translateY(-50%); }
.demo-right { right: 6px; top: 50%; transform: translateY(-50%); }

.demo-label {
    color: var(--text-dim);
    font-size: 0.8rem;
}

/* ===== Footer ===== */
.footer {
    border-top: 1px solid var(--border);
    padding: 40px 0 24px;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
}

.footer-brand {
    font-size: 1.1rem;
    font-weight: 700;
}

.footer-brand p {
    color: var(--text-dim);
    font-size: 0.85rem;
    font-weight: 400;
    margin-top: 6px;
}

.footer-links {
    display: flex;
    gap: 24px;
}

.footer-links a {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.footer-bottom {
    border-top: 1px solid var(--border);
    padding-top: 20px;
    text-align: center;
}

.footer-bottom p {
    color: var(--text-dim);
    font-size: 0.8rem;
}

/* ===== Tool Page ===== */
.tool-page {
    padding-top: 84px;
    min-height: 100vh;
}

.tool-header {
    text-align: center;
    padding: 24px 0;
}

.tool-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.tool-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Upload Area */
.upload-area {
    max-width: 600px;
    margin: 0 auto 32px;
}

.upload-zone {
    border: 2px dashed var(--border-light);
    border-radius: var(--radius-lg);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-card);
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--primary-light);
    background: rgba(93, 202, 165, 0.05);
}

.upload-zone-icon {
    margin-bottom: 16px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.upload-zone h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.upload-zone p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 20px;
}

.upload-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.upload-buttons .btn {
    font-size: 0.9rem;
    padding: 10px 20px;
}

#file-input,
#camera-input {
    display: none;
}

/* Centering Workspace */
.workspace {
    display: none;
    max-width: 900px;
    margin: 0 auto;
    padding-bottom: 40px;
}

.workspace.active {
    display: block;
}

.workspace-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 24px;
    align-items: start;
}

.canvas-container {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    touch-action: pan-x pan-y;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.zoom-wrapper {
    position: relative;
    width: 100%;
    transform-origin: 0 0;
    will-change: transform;
    -webkit-touch-callout: none;
    --ruler-scale: 1;
}

.canvas-container img {
    width: 100%;
    display: block;
    -webkit-touch-callout: none;
    -ms-touch-action: none;
    pointer-events: none;
    -webkit-user-drag: none;
    user-drag: none;
}

/* Draggable Marker Lines */
.marker-line {
    position: absolute;
    z-index: 10;
    transition: opacity 0.15s;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.marker-line.horizontal {
    left: 0;
    right: 0;
    height: calc(3px * var(--ruler-scale));
    cursor: ns-resize;
}

.marker-line.vertical {
    top: 0;
    bottom: 0;
    width: calc(3px * var(--ruler-scale));
    cursor: ew-resize;
}

.marker-line .line-visual {
    position: absolute;
}

.marker-line.horizontal .line-visual {
    left: 0;
    right: 0;
    top: 0;
    height: 100%;
}

.marker-line.vertical .line-visual {
    top: 0;
    bottom: 0;
    left: 0;
    width: 100%;
}

/* Hit area for easier touch targeting */
.marker-line .hit-area {
    position: absolute;
    touch-action: none;
}

.marker-line {
    touch-action: none;
}

.marker-line.horizontal .hit-area {
    left: 0;
    right: 0;
    top: calc(-16px * var(--ruler-scale));
    bottom: calc(-16px * var(--ruler-scale));
}

.marker-line.vertical .hit-area {
    top: 0;
    bottom: 0;
    left: calc(-16px * var(--ruler-scale));
    right: calc(-16px * var(--ruler-scale));
}

.marker-line .label {
    position: absolute;
    background: inherit;
    color: #fff;
    font-size: calc(0.65rem * var(--ruler-scale));
    font-weight: 700;
    padding: calc(2px * var(--ruler-scale)) calc(6px * var(--ruler-scale));
    border-radius: calc(4px * var(--ruler-scale));
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: 0.03em;
}

.marker-line.horizontal .label {
    right: calc(8px * var(--ruler-scale));
    top: calc(-20px * var(--ruler-scale));
}

.marker-line.vertical .label {
    top: calc(8px * var(--ruler-scale));
    left: calc(6px * var(--ruler-scale));
}

/* Outer markers (card edges) - blue */
.marker-outer .line-visual {
    background: rgba(52, 152, 219, 0.9);
}

.marker-outer .label {
    background: rgba(52, 152, 219, 0.9);
}

/* Inner markers (design edges) - green/accent */
.marker-inner .line-visual {
    background: rgba(0, 206, 201, 0.9);
}

.marker-inner .label {
    background: rgba(0, 206, 201, 0.9);
}

.marker-line:hover .line-visual,
.marker-line.dragging .line-visual {
    filter: brightness(1.3);
}

.marker-line:hover,
.marker-line.dragging {
    z-index: 20;
}

/* Results Panel */
.results-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.results-panel h3 {
    font-size: 1rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ratio-display {
    text-align: center;
    margin-bottom: 24px;
    padding: 20px;
    background: var(--bg-alt);
    border-radius: var(--radius);
}

.ratio-row {
    margin-bottom: 12px;
}

.ratio-row:last-child {
    margin-bottom: 0;
}

.ratio-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 4px;
}

.ratio-value {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.ratio-value.excellent { color: var(--success); }
.ratio-value.good { color: var(--accent); }
.ratio-value.fair { color: var(--warning); }
.ratio-value.poor { color: var(--danger); }

/* Grade Table */
.grade-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.grade-table th {
    text-align: left;
    padding: 8px 6px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
}

.grade-table td {
    padding: 8px 6px;
    border-bottom: 1px solid rgba(42, 42, 58, 0.5);
    vertical-align: middle;
}

.grade-table tr:last-child td {
    border-bottom: none;
}

.grade-table .company-name {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.grade-logo {
    display: inline-block;
    height: 18px;
    width: auto;
    max-width: 60px;
    object-fit: contain;
    flex-shrink: 0;
    filter: brightness(0) invert(1);
}

.grade-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.grade-dot.psa { background: var(--psa); }
.grade-dot.beckett { background: var(--beckett); }
.grade-dot.cgc { background: var(--cgc); }
.grade-dot.ace { background: var(--ace); }

.grade-value {
    font-weight: 700;
    font-size: 0.9rem;
}

.grade-value.high { color: var(--success); }
.grade-value.mid { color: var(--warning); }
.grade-value.low { color: var(--danger); }

.grade-desc {
    color: var(--text-muted);
    font-size: 0.7rem;
}

.marker-legend {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.marker-legend h4 {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.legend-line {
    width: 24px;
    height: 3px;
    border-radius: 2px;
}

.legend-line.outer { background: rgba(52, 152, 219, 0.9); }
.legend-line.inner { background: rgba(0, 206, 201, 0.9); }

.reset-btn {
    margin-top: 16px;
    width: 100%;
}

/* Instructions banner */
.instructions-banner {
    background: rgba(93, 202, 165, 0.1);
    border: 1px solid rgba(93, 202, 165, 0.2);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.instructions-banner strong {
    color: var(--text);
}

/* ===== Mobile Ratio Bar (floating at top) ===== */
.mobile-ratio-bar {
    display: none; /* shown on mobile only */
}

/* ===== Mobile Bottom Drawer ===== */
.mobile-drawer {
    display: none; /* shown on mobile only */
}

/* ===== Guide Page ===== */
.guide-page {
    padding-top: 84px;
    min-height: 100vh;
}

.guide-header {
    text-align: center;
    padding: 32px 0;
}

.guide-header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.guide-header p {
    color: var(--text-muted);
    font-size: 1rem;
    max-width: 600px;
    margin: 0 auto;
}

/* Tab Navigation */
.guide-tabs {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 40px;
    flex-wrap: wrap;
}

.guide-tab-logo {
    display: inline-block;
    height: 16px;
    width: auto;
    max-width: 50px;
    object-fit: contain;
    filter: brightness(0) invert(0.6);
    transition: filter 0.2s;
}

.guide-tab:hover .guide-tab-logo {
    filter: brightness(0) invert(0.85);
}

.guide-tab.active .guide-tab-logo {
    filter: brightness(0) invert(1);
}

.guide-tab {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all var(--transition);
    font-family: var(--font);
}

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

.guide-tab.active {
    color: #fff;
    border-color: transparent;
}

.guide-tab.active[data-tab="psa"] { background: var(--psa); }
.guide-tab.active[data-tab="beckett"] { background: var(--beckett); }
.guide-tab.active[data-tab="cgc"] { background: var(--cgc); }
.guide-tab.active[data-tab="ace"] { background: var(--ace); }

/* Guide Content */
.guide-content {
    display: none;
    max-width: 800px;
    margin: 0 auto;
    padding-bottom: 60px;
}

.guide-content.active {
    display: block;
}

.guide-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 24px;
}

.guide-section h2 {
    font-size: 1.4rem;
    margin-bottom: 6px;
}

.guide-section .company-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.guide-section h3 {
    font-size: 1.1rem;
    margin: 24px 0 12px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.guide-section h3:first-of-type {
    border-top: none;
    padding-top: 0;
}

.guide-section p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 12px;
    line-height: 1.7;
}

.guide-section ul, .guide-section ol {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 12px;
    padding-left: 20px;
    line-height: 1.8;
}

.guide-section li {
    margin-bottom: 4px;
}

/* Grade scale table in guides */
.grade-scale {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 0.85rem;
}

.grade-scale th {
    text-align: left;
    padding: 10px 12px;
    background: var(--bg-alt);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.grade-scale td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
}

.grade-scale td:first-child {
    font-weight: 700;
    color: var(--text);
}

.grade-scale tr:last-child td {
    border-bottom: none;
}

.grade-scale .highlight-row td {
    background: rgba(93, 202, 165, 0.05);
}

.tip-box {
    background: rgba(0, 206, 201, 0.08);
    border-left: 3px solid var(--accent);
    padding: 14px 18px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin: 16px 0;
}

.tip-box p {
    color: var(--text);
    font-size: 0.85rem;
    margin: 0;
}

.tip-box strong {
    color: var(--accent);
}

/* ===== Live Camera Viewfinder ===== */
.camera-view {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: #000;
    flex-direction: column;
}

.camera-view.active {
    display: flex;
}

.camera-viewfinder {
    position: relative;
    flex: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.camera-viewfinder video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Card alignment guide rectangle */
.camera-card-guide {
    position: absolute;
    width: 65%;
    aspect-ratio: 2.5 / 3.5;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 10px;
    pointer-events: none;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: 70%;
}

/* Camera controls bar */
.camera-controls {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 20px 32px 40px;
    background: rgba(0, 0, 0, 0.85);
    flex-shrink: 0;
}

.camera-ctrl-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.camera-ctrl-close,
.camera-ctrl-flip {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    transition: background 0.15s;
}

.camera-ctrl-close:active,
.camera-ctrl-flip:active {
    background: rgba(255, 255, 255, 0.25);
}

.camera-ctrl-shutter {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: #fff;
    position: relative;
    transition: transform 0.1s;
}

.camera-ctrl-shutter:active {
    transform: scale(0.9);
}

.shutter-ring {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 3px solid #fff;
}

/* ===== Spirit Level HUD ===== */
/* Non-obtrusive bars overlaid on the camera viewfinder */

.level-hud-bar {
    position: absolute;
    z-index: 50;
    pointer-events: none;
}

/* Horizontal bar — top of viewfinder */
.level-hud-h {
    top: 16px;
    left: 10%;
    right: 10%;
    height: 24px;
}

/* Vertical bar — left of viewfinder */
.level-hud-v {
    left: 16px;
    top: 10%;
    bottom: 10%;
    width: 24px;
}

.level-hud-bar .level-hud-track {
    position: relative;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-radius: 12px;
}

/* Center tick mark */
.level-hud-bar .level-hud-center-mark {
    position: absolute;
    background: rgba(255, 255, 255, 0.35);
    z-index: 1;
}

.level-hud-h .level-hud-center-mark {
    left: 50%;
    top: 4px;
    bottom: 4px;
    width: 2px;
    margin-left: -1px;
}

.level-hud-v .level-hud-center-mark {
    top: 50%;
    left: 4px;
    right: 4px;
    height: 2px;
    margin-top: -1px;
}

/* Bubble indicator */
.level-hud-bubble {
    position: absolute;
    border-radius: 50%;
    background: #e8a030;
    box-shadow: 0 0 8px rgba(232, 160, 48, 0.7);
    z-index: 2;
    transition: background 0.25s, box-shadow 0.25s;
    /* NO CSS transition on left/top — JS sets them directly for responsiveness */
}

.level-hud-h .level-hud-bubble {
    width: 20px;
    height: 20px;
    top: 2px;
    /* left is set by JS as pixel value */
}

.level-hud-v .level-hud-bubble {
    width: 20px;
    height: 20px;
    left: 2px;
    /* top is set by JS as pixel value */
}

.level-hud-bubble.on-level {
    background: var(--success);
    box-shadow: 0 0 12px rgba(0, 184, 148, 0.8);
}

/* Subtle glow on bar when level */
.level-hud-bar.on-level .level-hud-track {
    background: rgba(0, 184, 148, 0.2);
}

.level-hud-bar.on-level .level-hud-center-mark {
    background: rgba(0, 184, 148, 0.5);
}

/* Debug overlay for spirit level */
.level-debug {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-family: monospace;
    z-index: 60;
    white-space: pre;
    pointer-events: none;
    text-align: center;
    line-height: 1.6;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    .nav-toggle {
        display: flex;
    }

    .nav-links {
        display: none;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        background: var(--bg);
        border-bottom: 1px solid var(--border);
        flex-direction: column;
        padding: 12px;
    }

    .nav-links.open {
        display: flex;
    }

    .hero {
        padding: 110px 0 60px;
        min-height: auto;
    }

    .hero-actions {
        flex-direction: column;
        align-items: center;
    }

    .btn-lg {
        width: 100%;
        justify-content: center;
    }

    .info-grid {
        grid-template-columns: 1fr;
    }

    .info-card {
        padding: 24px;
    }

    /* --- Mobile workspace layout --- */
    .tool-page {
        padding-top: 64px;
    }

    .tool-header {
        padding: 12px 0 8px;
    }

    .tool-header h1 {
        font-size: 1.3rem;
    }

    .tool-header p {
        font-size: 0.8rem;
    }

    .workspace-layout {
        grid-template-columns: 1fr;
    }

    /* Hide desktop results panel on mobile */
    .results-panel {
        display: none;
    }

    /* Instructions: compact on mobile */
    .instructions-banner {
        padding: 8px 12px;
        margin-bottom: 8px;
        font-size: 0.75rem;
    }

    /* Show mobile ratio bar */
    .mobile-ratio-bar {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 10px 20px;
        margin-bottom: 8px;
    }

    .mobile-ratio-item {
        display: flex;
        align-items: center;
        gap: 8px;
        flex: 1;
        justify-content: center;
    }

    .mobile-ratio-label {
        font-size: 0.65rem;
        font-weight: 600;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.06em;
    }

    .mobile-ratio-value {
        font-size: 1.3rem;
        font-weight: 800;
        letter-spacing: -0.02em;
    }

    .mobile-ratio-value.excellent { color: var(--success); }
    .mobile-ratio-value.good { color: var(--accent); }
    .mobile-ratio-value.fair { color: var(--warning); }
    .mobile-ratio-value.poor { color: var(--danger); }

    .mobile-ratio-divider {
        width: 1px;
        height: 28px;
        background: var(--border);
        margin: 0 12px;
        flex-shrink: 0;
    }

    /* Canvas fills available space */
    .canvas-container {
        border-radius: var(--radius);
    }

    /* Show mobile drawer */
    .mobile-drawer {
        display: block;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        background: var(--bg-card);
        border-top: 1px solid var(--border);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: 0 -4px 24px rgba(0,0,0,0.4);
        transition: transform 0.3s ease;
        transform: translateY(0);
    }

    .mobile-drawer-toggle {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 8px;
        width: 100%;
        padding: 12px 16px;
        background: none;
        border: none;
        cursor: pointer;
        color: var(--text);
        font-family: var(--font);
        -webkit-tap-highlight-color: transparent;
    }

    .drawer-handle {
        width: 36px;
        height: 4px;
        background: var(--border-light);
        border-radius: 2px;
    }

    .drawer-toggle-text {
        font-size: 0.8rem;
        font-weight: 600;
        color: var(--primary-light);
    }

    .mobile-drawer-content {
        display: none;
        padding: 0 16px 24px;
        max-height: 50vh;
        overflow-y: auto;
    }

    .mobile-drawer-content.open {
        display: block;
    }

    .mobile-drawer.expanded .drawer-toggle-text {
        color: var(--text-muted);
    }

    /* Compact grade grid for mobile */
    .mobile-grade-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-bottom: 16px;
    }

    .mobile-grade-card {
        background: var(--bg-alt);
        border-radius: var(--radius-sm);
        padding: 10px 12px;
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .mobile-grade-logo {
        display: inline-block;
        height: 20px;
        width: auto;
        max-width: 50px;
        object-fit: contain;
        flex-shrink: 0;
        filter: brightness(0) invert(1);
    }

    .mobile-grade-dot {
        width: 10px;
        height: 10px;
        border-radius: 50%;
        flex-shrink: 0;
    }

    .mobile-grade-dot.psa { background: var(--psa); }
    .mobile-grade-dot.beckett { background: var(--beckett); }
    .mobile-grade-dot.cgc { background: var(--cgc); }
    .mobile-grade-dot.ace { background: var(--ace); }

    .mobile-grade-info {
        display: flex;
        flex-direction: column;
        min-width: 0;
    }

    .mobile-grade-company {
        font-size: 0.65rem;
        color: var(--text-muted);
        font-weight: 500;
    }

    .mobile-grade-value {
        font-size: 1.1rem;
        font-weight: 800;
    }

    .mobile-grade-value.high { color: var(--success); }
    .mobile-grade-value.mid { color: var(--warning); }
    .mobile-grade-value.low { color: var(--danger); }

    .mobile-grade-label {
        font-size: 0.6rem;
        color: var(--text-dim);
    }

    .mobile-drawer-actions {
        display: flex;
        gap: 8px;
    }

    .mobile-drawer-actions .btn {
        font-size: 0.8rem;
        padding: 10px 12px;
    }

    /* Ensure workspace doesn't get hidden behind drawer */
    .workspace.active {
        padding-bottom: 70px;
    }

    /* Guide page */
    .guide-section {
        padding: 20px;
    }

    .grade-scale {
        font-size: 0.78rem;
    }

    .grade-scale th,
    .grade-scale td {
        padding: 8px;
    }

    .footer-content {
        flex-direction: column;
        gap: 20px;
    }

    .upload-zone {
        padding: 32px 16px;
    }

    .ratio-value {
        font-size: 1.5rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 16px;
    }

    .hero h1 {
        font-size: 1.8rem;
    }

    .section {
        padding: 48px 0;
    }

    .section-title {
        margin-bottom: 32px;
    }

    .companies-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .company-card {
        padding: 20px 16px;
    }
}
