:root {
    --bg: #0f0f12;
    --surface: #17171c;
    --surface-2: #1f1f27;
    --text: #f4f4f6;
    --muted: #a7a7b4;
    --accent: #c9a24b;
    --accent-hover: #ddb860;
    --danger: #e5484d;
    --success: #46a758;
    --border: #2a2a33;
    --radius: 14px;
    --max: 1100px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

.container { max-width: var(--max); margin: 0 auto; padding: 0 20px; }

/* Header */
.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: rgba(15,15,18,0.9);
    backdrop-filter: blur(8px);
    z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { height: 80px; width: auto; display: block; }
.brand span { font-weight: 600; letter-spacing: 0.3px; }

/* Hamburger toggle (shown only on mobile) */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 46px;
    height: 42px;
    padding: 0 10px;
    background: transparent;
    border: 1px solid var(--accent);
    border-radius: 10px;
    cursor: pointer;
}
.nav-toggle span {
    display: block;
    height: 2px;
    width: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Buttons */
.btn {
    display: inline-block;
    border: none;
    border-radius: 999px;
    padding: 11px 22px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #1a1200; }
.btn-primary:hover { background: var(--accent-hover); color: #1a1200; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-ghost:hover { background: rgba(201,162,75,0.12); color: var(--accent-hover); border-color: var(--accent-hover); }
/* Active / selected nav button: gold filled */
.btn-ghost.active,
.btn.active { background: var(--accent); color: #1a1200; border-color: var(--accent); }
.btn-ghost.active:hover,
.btn.active:hover { background: var(--accent-hover); color: #1a1200; }
.btn-block { width: 100%; }

/* Hero */
.hero {
    padding: 90px 0 70px;
    text-align: center;
}
.hero h1 {
    font-size: clamp(2rem, 5vw, 3.4rem);
    margin: 0 0 16px;
    line-height: 1.1;
}
.hero p {
    color: var(--muted);
    font-size: 1.15rem;
    max-width: 620px;
    margin: 0 auto 30px;
}

/* Feature cards */
.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    padding: 20px 0 80px;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 26px;
}
.card h3 { margin: 0 0 10px; }
.card p { color: var(--muted); margin: 0; }

/* Footer */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 28px 0;
    color: var(--muted);
    text-align: center;
    font-size: 0.9rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 420px;
    padding: 30px;
    position: relative;
}
.modal h2 { margin: 0 0 6px; }
.modal .subtitle { color: var(--muted); margin: 0 0 22px; font-size: 0.95rem; }
.modal-close {
    position: absolute;
    top: 14px; right: 16px;
    background: none; border: none;
    color: var(--muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* Forms */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.field input {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 13px;
    color: var(--text);
    font-size: 15px;
}
.field input:focus { outline: none; border-color: var(--accent); }

.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px;
    text-align: center;
    cursor: pointer;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.9rem;
}
.tab.active { background: var(--accent); color: #1a1200; border-color: var(--accent); }

.alert { border-radius: 10px; padding: 11px 14px; margin-bottom: 16px; font-size: 0.9rem; }
.alert-error { background: rgba(229,72,77,0.12); border: 1px solid var(--danger); color: #ff9ea1; }
.alert-success { background: rgba(70,167,88,0.12); border: 1px solid var(--success); color: #9fe0ab; }

.form-hidden { display: none; }

/* Admin + account layout */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 26px;
    margin-bottom: 24px;
}
.panel h2 { margin-top: 0; }
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    padding: 34px;
}
.auth-card .brand { justify-content: center; margin-bottom: 24px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
th { color: var(--muted); font-weight: 600; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 28px;
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(15,15,18,0.92);
    backdrop-filter: blur(8px);
}
/* Topbar nav links styled as gold outline buttons (match .btn-ghost) */
.topbar .nav a {
    margin-left: 10px;
    font-weight: 600;
    display: inline-block;
    padding: 9px 18px;
    border-radius: 999px;
    border: 1px solid var(--accent);
    color: var(--accent);
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.topbar .nav a:hover {
    background: rgba(201,162,75,0.12);
    color: var(--accent-hover);
    border-color: var(--accent-hover);
}
/* Current page: gold filled */
.topbar .nav a.active {
    background: var(--accent);
    color: #1a1200;
    border-color: var(--accent);
}
.topbar .nav a.active:hover { background: var(--accent-hover); color: #1a1200; }

/* Select inputs (match text inputs) */
.select-input {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 13px;
    color: var(--text);
    font-size: 15px;
}
.select-input:focus { outline: none; border-color: var(--accent); }

/* Multi-column form rows */
.field-row {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}
.field-row .field { flex: 1; min-width: 120px; }

/* Product grid + cards (My Picks) */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 20px;
    margin-top: 20px;
}
.product-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.product-image {
    aspect-ratio: 3 / 4;
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.product-image img { width: 100%; height: 100%; object-fit: cover; }
.product-noimage { color: var(--muted); font-size: 0.85rem; }
.product-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.product-brand { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }
.product-title { margin: 0; font-size: 1.02rem; }
.product-price { font-weight: 600; color: var(--accent); }
.product-reasons {
    list-style: none;
    padding: 0;
    margin: 4px 0 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.product-reasons li {
    font-size: 0.82rem;
    color: var(--muted);
    padding-left: 18px;
    position: relative;
}
.product-reasons li::before {
    content: "\2713";
    position: absolute;
    left: 0;
    color: var(--success);
    font-weight: 700;
}
.product-card .btn { margin-top: auto; }

/* Profile two-column layout: mannequin left, form right */
.profile-layout {
    display: grid;
    grid-template-columns: 512px 1fr; /* mannequin column +60% (320 -> 512) */
    gap: 150px;                        /* spacing between mannequin and form */
    align-items: start;
    max-width: 1280px;
}
/* The pane is the grid item; it spans the full layout height so the
   sticky child has room to stay pinned while the form scrolls. */
.mannequin-pane { position: relative; height: 100%; }
.mannequin-sticky {
    position: sticky;
    position: -webkit-sticky; /* Safari */
    top: 120px; /* clears the frozen topbar */
    max-height: calc(100vh - 140px);
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
}
.mannequin-canvas {
    width: 100%;
    height: 560px;
    cursor: grab;
    touch-action: none; /* let OrbitControls handle touch drags */
}
.mannequin-canvas:active { cursor: grabbing; }
.mannequin-canvas canvas { display: block; border-radius: 10px; }
.mannequin-caption { margin-top: 14px; }
.mannequin-shape {
    display: block;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent);
}
.mannequin-note {
    display: block;
    font-size: 0.82rem;
    color: var(--muted);
    margin-top: 2px;
}
.profile-form { min-width: 0; }

/* Medium screens: keep two columns but ease the width + gap */
@media (max-width: 1200px) {
    .profile-layout {
        grid-template-columns: 400px 1fr;
        gap: 80px;
    }
    .mannequin-canvas { height: 480px; }
}

/* Stack on narrow screens: mannequin on top */
@media (max-width: 760px) {
    .profile-layout {
        grid-template-columns: 1fr;
        gap: 24px;
    }
    .mannequin-sticky { position: static; }
    .mannequin-canvas { height: 340px; }
}

/* ============================================================
   Mobile-friendly refinements
   ============================================================ */

/* Avoid horizontal scroll from any wide child */
html, body { max-width: 100%; overflow-x: hidden; }
img, svg, canvas { max-width: 100%; }

/* Comfortable tap targets on touch devices */
@media (hover: none) and (pointer: coarse) {
    .btn { padding: 13px 22px; }
    .topbar .nav a, .site-header nav a { padding: 6px 2px; }
}

/* Tablet and below */
@media (max-width: 860px) {
    .container { padding: 0 16px; }

    /* Headers: allow the brand + nav to wrap instead of overflowing */
    .site-header,
    .topbar {
        flex-wrap: wrap;
        gap: 10px 14px;
        padding: 12px 16px;
    }
    .topbar .nav {
        display: flex;
        flex-wrap: wrap;
        gap: 8px 14px;
        width: 100%;
        justify-content: flex-start;
    }
    .topbar .nav a { margin-left: 0; }

    /* Index page: show the hamburger, collapse nav into a dropdown */
    .site-header { position: relative; }
    .nav-toggle { display: flex; }
    .site-header nav {
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        width: 100%;
        order: 3;              /* drop below the brand + toggle row */
        padding-top: 6px;
    }
    .site-header nav.open { display: flex; }
    .site-header nav .btn { width: 100%; text-align: center; }

    /* Smaller logo so the header doesn't dominate the screen */
    .brand img { height: 48px; }
    .brand span { font-size: 1rem; }

    /* Tighten the hero */
    .hero { padding: 48px 0 36px; }
    .hero p { font-size: 1.02rem; }

    /* Features stack to one or two columns naturally via auto-fit already */
    .features { padding: 10px 0 48px; gap: 14px; }
    .card { padding: 20px; }

    /* Panels + tables */
    .panel { padding: 20px; }
}

/* Phones */
@media (max-width: 560px) {
    .brand img { height: 40px; }

    /* Full-width primary actions read better on phones */
    .hero .btn { width: 100%; max-width: 320px; }

    /* Buttons in headers shouldn't be full width, keep them inline */
    .site-header nav .btn,
    .topbar .nav .btn { width: auto; }

    /* Modal fills more of the screen and sits a touch higher */
    .modal { max-width: 100%; padding: 24px 20px; border-radius: 16px; }
    .modal-overlay { align-items: flex-start; padding: 14px; }
    .modal h2 { font-size: 1.3rem; }

    /* Product grid: 2 columns on small phones, 1 on very small */
    .product-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
    .product-body { padding: 12px; }
    .product-title { font-size: 0.95rem; }

    /* Measurement/size rows stack vertically for easier input */
    .field-row { flex-direction: column; gap: 0; }
    .field-row .field { min-width: 0; }

    /* Tables scroll horizontally rather than squashing */
    .panel table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* On touch the 3D mannequin can trap vertical scroll; keep it usable.
   When stacked (<=760px) it is static; make sure it is not too tall.
   Allow vertical page scrolling to pass through the canvas so users
   don't get stuck rotating the model when they mean to scroll. */
@media (max-width: 760px) {
    .mannequin-canvas { height: 320px; touch-action: pan-y; }
}
@media (max-width: 560px) {
    .mannequin-canvas { height: 300px; }
}
