* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Lock the layout to the viewport width so mobile can't pinch/scroll sideways.
   `clip` (not `hidden`) avoids turning the page into a scroll container, which
   would otherwise break the sticky sidebar/top bar. `hidden` is the fallback. */
html, body {
    max-width: 100%;
    overflow-x: hidden;
    overflow-x: clip;
}

html {
    /* Stop iOS from auto-resizing text on orientation change */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
    color: #1f2937;
    background: #f9fafb;
    line-height: 1.6;
}

/* Media never spills past its container (fixed-size thumbnails use classes,
   whose higher specificity keeps their explicit width/height) */
img, video, canvas, svg {
    max-width: 100%;
    height: auto;
}

.container {
    width: 80%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* On narrow screens use the full width instead of shrinking to 80% */
@media (max-width: 900px) {
    .container {
        width: 100%;
    }
}

/* ---- Layout: left sidebar (desktop) / slide-in drawer (mobile) ---- */
.layout {
    display: flex;
    align-items: stretch;
    min-height: 100vh;
}

.sidebar {
    flex: 0 0 220px;
    width: 220px;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    padding: 1.5rem 0;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-logo {
    display: block;
    font-size: 1.4rem;
    font-weight: 700;
    color: #111827;
    text-decoration: none;
    padding: 0 1.5rem 1.25rem;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
}

.sidebar nav a {
    padding: 0.7rem 1.5rem;
    color: #374151;
    text-decoration: none;
    border-left: 3px solid transparent;
}

.sidebar nav a:hover {
    background: #f3f4f6;
    color: #2563eb;
    border-left-color: #2563eb;
}

.sidebar .nav-user {
    margin: 0.25rem 0;
    border-top: 1px solid #f3f4f6;
}

.sidebar nav .nav-group {
    display: flex;
    flex-direction: column;
    margin-top: 0.5rem;
    border-top: 1px solid #f3f4f6;
    padding-top: 0.5rem;
}

.sidebar nav .nav-group-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.4rem 1.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.sidebar nav .nav-group-caret {
    transition: transform 0.2s ease;
    font-size: 0.7rem;
}

.sidebar nav .nav-group.open .nav-group-caret {
    transform: rotate(180deg);
}

/* Sub-links collapsed by default; revealed when the group is open. */
.sidebar nav .nav-sub-list {
    display: none;
    flex-direction: column;
}

.sidebar nav .nav-group.open .nav-sub-list {
    display: flex;
}

.sidebar nav a.nav-sub {
    padding-left: 2.5rem;
    font-size: 0.95rem;
    color: #4b5563;
}

.main-area {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.main-area > main.container {
    flex: 1 0 auto;
}

/* Mobile top bar + backdrop are hidden on desktop */
.mobile-bar { display: none; }
.sidebar-backdrop { display: none; }

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: #111827;
    text-decoration: none;
}

main.container {
    padding-top: 3rem;
    padding-bottom: 3rem;
}

/* ---- Mobile: hamburger toggles a slide-in vertical menu ---- */
@media (max-width: 900px) {
    .layout {
        display: block;
        min-height: 0;
    }

    .mobile-bar {
        display: flex;
        align-items: center;
        gap: 0.85rem;
        background: #fff;
        border-bottom: 1px solid #e5e7eb;
        padding: 0.75rem 1rem;
        position: sticky;
        top: 0;
        z-index: 40;
    }

    .nav-toggle {
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        width: 42px;
        height: 42px;
        padding: 9px;
        background: transparent;
        border: 1px solid #e5e7eb;
        border-radius: 0.5rem;
        cursor: pointer;
    }

    .nav-toggle span {
        display: block;
        height: 2px;
        width: 100%;
        background: #374151;
        border-radius: 2px;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100%;
        width: 260px;
        max-width: 80vw;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 60;
        box-shadow: 2px 0 16px rgba(0, 0, 0, 0.15);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease;
        z-index: 50;
    }

    .sidebar-backdrop.show {
        opacity: 1;
        visibility: visible;
    }

    main.container {
        padding-top: 2rem;
    }
}

.hero {
    text-align: center;
    padding: 3rem 0;
}

.hero h1 {
    font-size: 2.25rem;
    margin-bottom: 1rem;
    color: #111827;
}

.hero .lead {
    font-size: 1.125rem;
    color: #4b5563;
    margin-bottom: 2rem;
}

.btn {
    display: inline-block;
    background: #2563eb;
    color: #fff;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    text-decoration: none;
    font-weight: 600;
}

.btn:hover {
    background: #1d4ed8;
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-top: 3rem;
}

.feature {
    background: #fff;
    padding: 1.5rem;
    border-radius: 0.75rem;
    border: 1px solid #e5e7eb;
}

.feature h3 {
    margin-bottom: 0.5rem;
    color: #111827;
}

.about h1 {
    margin-bottom: 1rem;
}

.about p {
    margin-bottom: 1rem;
    color: #374151;
}

.legal {
    text-align: left;
    line-height: 1.6;
}

.legal h2 {
    margin: 1.6rem 0 0.5rem;
    font-size: 1.05rem;
    color: #111827;
}

.legal p {
    font-size: 0.92rem;
}

.legal-updated {
    color: #6b7280;
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

.legal-foot {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid #e5e7eb;
    color: #6b7280;
    font-size: 0.85rem;
}

.nav-user {
    margin-left: 1.25rem;
    color: #111827;
    font-weight: 600;
}

.nav-chat {
    position: relative;
}

.nav-badge {
    display: inline-block;
    min-width: 1.1rem;
    margin-left: 0.2rem;
    padding: 0 0.35rem;
    background: #ef4444;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.1rem;
    text-align: center;
    border-radius: 999px;
    vertical-align: top;
}

.nav-badge[hidden] {
    display: none;
}

.login {
    max-width: 420px;
    margin: 2rem auto;
    text-align: center;
    background: #fff;
    padding: 2.5rem 2rem;
    border-radius: 0.75rem;
    border: 1px solid #e5e7eb;
}

.login h1 {
    margin-bottom: 0.5rem;
    color: #111827;
}

.login-sub {
    color: #4b5563;
    margin-bottom: 1.75rem;
}

.login .g_id_signin {
    display: inline-block;
}

.login-warning {
    color: #b45309;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 0.5rem;
    padding: 0.875rem 1rem;
    font-size: 0.9rem;
}

.login-warning code {
    background: #fef3c7;
    padding: 0.1rem 0.35rem;
    border-radius: 0.25rem;
}

.login-error {
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
}

.auth-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.auth-tab {
    flex: 1;
    padding: 0.6rem 0;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    color: #6b7280;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}

.auth-tab.active {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    text-align: left;
}

.auth-form input:not([type="checkbox"]) {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    font-size: 0.95rem;
}

.auth-form input:not([type="checkbox"]):focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.auth-consent {
    display: flex;
    flex-direction: column;
    margin: 0.25rem 0;
    border: 1px solid #e5e7eb;
    border-radius: 0.65rem;
    background: #fff;
    overflow: hidden;
}

.consent-row {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    font-size: 0.85rem;
    color: #4b5563;
    cursor: pointer;
    line-height: 1.45;
    padding: 0.6rem 0.85rem;
    user-select: none;
}

.consent-row input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 1.2rem;
    height: 1.2rem;
    flex: none;
    margin: 0;
    padding: 0;
    border: 1.5px solid #cbd5e1;
    border-radius: 0.35rem;
    background: #fff;
    cursor: pointer;
    position: relative;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.consent-row input[type="checkbox"]:checked {
    background: #2563eb;
    border-color: #2563eb;
}

.consent-row input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    left: 0.4rem;
    top: 0.18rem;
    width: 0.3rem;
    height: 0.58rem;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.consent-row input[type="checkbox"]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.22);
}

.consent-all {
    font-weight: 700;
    font-size: 0.93rem;
    color: #111827;
    background: #f9fafb;
    border-bottom: 1px solid #eef0f3;
}

.consent-req {
    display: inline-block;
    margin-right: 0.35rem;
    padding: 0.05rem 0.4rem;
    border-radius: 0.3rem;
    background: rgba(37, 99, 235, 0.1);
    color: #2563eb;
    font-size: 0.72rem;
    font-weight: 700;
    font-style: normal;
    vertical-align: 0.05rem;
}

.consent-row a {
    color: #2563eb;
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px solid rgba(37, 99, 235, 0.35);
}

.consent-row a:hover {
    border-bottom-color: #2563eb;
}

.btn-block {
    width: 100%;
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

.auth-divider {
    display: flex;
    align-items: center;
    text-align: center;
    color: #9ca3af;
    font-size: 0.85rem;
    margin: 1.5rem 0 1rem;
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    border-top: 1px solid #e5e7eb;
}

.auth-divider span {
    padding: 0 0.75rem;
}

.hidden {
    display: none !important;
}

/* --- Face score page ---------------------------------------------------- */
.score-hero {
    text-align: center;
    padding: 1.5rem 0 2rem;
}

.score-hero h1 {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    color: #111827;
}

.score-hero .lead {
    font-size: 1.05rem;
    color: #4b5563;
}

.uploader {
    max-width: 560px;
    margin: 0 auto;
}

.dropzone {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 260px;
    border: 2px dashed #cbd5e1;
    border-radius: 1rem;
    background: #fff;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone.dragging {
    border-color: #2563eb;
    background: #eff6ff;
}

.dropzone-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: #6b7280;
    padding: 2rem;
    text-align: center;
}

.dropzone-icon {
    font-size: 2.5rem;
}

.dropzone-text {
    font-weight: 600;
    color: #374151;
}

.dropzone-hint {
    font-size: 0.85rem;
    color: #9ca3af;
}

.preview {
    max-width: 100%;
    max-height: 360px;
    object-fit: contain;
    border-radius: 0.75rem;
}

#score-form .btn-block {
    margin-top: 1rem;
}

.btn-block:disabled {
    background: #93c5fd;
    cursor: not-allowed;
}

.score-error {
    margin-top: 1rem;
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    font-size: 0.92rem;
}

.loading {
    margin-top: 1.5rem;
    text-align: center;
    color: #4b5563;
    font-weight: 600;
}

.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid #c7d2fe;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: -2px;
    margin-right: 0.4rem;
}

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

.result-card {
    margin-top: 1.75rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 1rem;
    padding: 1.75rem;
}

.result-top {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 1rem;
}

.tier-badge {
    width: 72px;
    height: 72px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.25rem;
    font-weight: 800;
    color: #fff;
    border-radius: 1rem;
    background: #6b7280;
}

.tier-badge[data-tier="S"] { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.tier-badge[data-tier="A"] { background: linear-gradient(135deg, #8b5cf6, #6366f1); }
.tier-badge[data-tier="B"] { background: linear-gradient(135deg, #3b82f6, #06b6d4); }
.tier-badge[data-tier="C"] { background: linear-gradient(135deg, #10b981, #22c55e); }
.tier-badge[data-tier="D"] { background: #64748b; }
.tier-badge[data-tier="F"] { background: #94a3b8; }

.score-number {
    font-size: 2.5rem;
    font-weight: 800;
    color: #111827;
    line-height: 1;
}

.score-max {
    font-size: 1.1rem;
    font-weight: 600;
    color: #9ca3af;
    margin-left: 0.35rem;
}

.score-label {
    color: #6b7280;
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.result-rank {
    display: inline-block;
    align-self: center;
    margin: 0 auto 1rem;
    padding: 0.45rem 0.9rem;
    border-radius: 16px;
    background: #f1f5f9;
    color: #0f172a;
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.5;
}

.result-comment {
    color: #374151;
    font-size: 1.05rem;
    margin-bottom: 1.25rem;
}

.result-lists {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.result-list {
    background: #f9fafb;
    border: 1px solid #f3f4f6;
    border-radius: 0.75rem;
    padding: 1rem 1.1rem;
}

.result-list h4 {
    margin-bottom: 0.5rem;
    color: #111827;
    font-size: 0.95rem;
}

.result-list ul {
    margin: 0;
    padding-left: 1.1rem;
    color: #4b5563;
    font-size: 0.92rem;
}

.result-list li {
    margin-bottom: 0.3rem;
}

.btn-secondary {
    display: inline-block;
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #e5e7eb;
    padding: 0.6rem 1.25rem;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.92rem;
    cursor: pointer;
}

.btn-secondary:hover {
    background: #e5e7eb;
}

.disclaimer {
    margin-top: 1.5rem;
    text-align: center;
    color: #9ca3af;
    font-size: 0.82rem;
}

/* --- History page ------------------------------------------------------- */
.history {
    max-width: 640px;
    margin: 0 auto;
}

.history h1 {
    color: #111827;
    margin-bottom: 0.35rem;
}

.history-sub {
    color: #4b5563;
    margin-bottom: 1.5rem;
}

.history-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.summary-stat {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    padding: 1.1rem 0.75rem;
    text-align: center;
}

.summary-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 800;
    color: #4f46e5;
    line-height: 1.1;
}

.summary-label {
    display: block;
    margin-top: 0.3rem;
    color: #6b7280;
    font-size: 0.85rem;
}

.history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.history-item {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    overflow: hidden;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.history-item:hover {
    border-color: #c7d2fe;
    box-shadow: 0 2px 10px rgba(79, 70, 229, 0.08);
}

.history-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1.1rem;
    text-decoration: none;
    color: inherit;
}

.history-thumb {
    width: 72px;
    height: 72px;
    flex: none;
    border-radius: 0.75rem;
    object-fit: cover;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
}

.history-item .tier-badge {
    width: 72px;
    height: 72px;
    font-size: 1.9rem;
    border-radius: 0.75rem;
}

.history-info {
    flex: 1;
    min-width: 0;
}

.history-score {
    font-size: 1.5rem;
    font-weight: 800;
    color: #111827;
    line-height: 1.1;
}

.history-score .score-max {
    font-size: 0.85rem;
}

.history-tier {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    color: #fff;
    vertical-align: middle;
    background: #6b7280;
}

.history-tier[data-tier="S"] { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.history-tier[data-tier="A"] { background: linear-gradient(135deg, #8b5cf6, #6366f1); }
.history-tier[data-tier="B"] { background: linear-gradient(135deg, #3b82f6, #06b6d4); }
.history-tier[data-tier="C"] { background: linear-gradient(135deg, #10b981, #22c55e); }
.history-tier[data-tier="D"] { background: #64748b; }
.history-tier[data-tier="F"] { background: #94a3b8; }

.history-meta {
    color: #6b7280;
    font-size: 0.88rem;
    margin-top: 0.15rem;
}

.history-arrow {
    flex: none;
    color: #cbd5e1;
    font-size: 1.6rem;
    line-height: 1;
}

/* --- Single-score detail page --- */
.history-detail {
    max-width: 640px;
    margin: 0 auto;
}

.detail-back {
    display: inline-block;
    margin-bottom: 1rem;
    color: #4f46e5;
    font-size: 0.92rem;
    font-weight: 600;
    text-decoration: none;
}

.detail-back:hover {
    text-decoration: underline;
}

.detail-photo {
    display: block;
    width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 0.75rem;
    margin-bottom: 1.25rem;
    background: #f3f4f6;
    cursor: zoom-in;
}

/* Fullscreen zoom overlay for the evaluated photo */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.9);
    cursor: zoom-out;
}

.lightbox.open {
    display: flex;
}

.lightbox img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 0.5rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1.25rem;
    font-size: 2.2rem;
    line-height: 1;
    color: #fff;
    background: none;
    border: none;
    cursor: pointer;
}

.history-note {
    margin-top: 1.5rem;
    text-align: center;
    color: #9ca3af;
    font-size: 0.82rem;
}

.history-empty {
    text-align: center;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    padding: 2.5rem 1.5rem;
}

.history-empty p {
    color: #4b5563;
    margin-bottom: 1.25rem;
}

.site-footer {
    background: #fff;
    border-top: 1px solid #e5e7eb;
    padding: 1.5rem 0;
    text-align: center;
    color: #6b7280;
    font-size: 0.875rem;
}

.footer-count {
    margin: 0 0 0.4rem;
    color: #374151;
}

.footer-count strong {
    color: #4f46e5;
    font-weight: 700;
}

.footer-cost {
    margin: 0 0 0.6rem;
    color: #6b7280;
    font-size: 0.8rem;
}

.footer-cost strong {
    color: #374151;
    font-weight: 600;
}

.footer-cost-usd {
    color: #9ca3af;
}
