:root {
    --bg: #f4efe6;
    --surface: rgba(255, 250, 243, 0.88);
    --surface-strong: #fffaf3;
    --text: #1f2933;
    --muted: #5c6b73;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --border: rgba(31, 41, 51, 0.12);
    --error-bg: #fff1f2;
    --error-border: #fecdd3;
    --shadow: 0 24px 60px rgba(31, 41, 51, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Georgia, "Times New Roman", serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(15, 118, 110, 0.18), transparent 30%),
        radial-gradient(circle at bottom right, rgba(180, 83, 9, 0.14), transparent 28%),
        linear-gradient(135deg, #f7f2ea, #e7efe8);
}

body.is-loading {
    overflow: hidden;
}

body.is-modal-open {
    overflow: hidden;
}

.page {
    width: min(960px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 3rem 0 4rem;
}

.auth-page {
    display: grid;
    align-items: center;
    min-height: 100vh;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: rgba(24, 32, 38, 0.34);
    backdrop-filter: blur(8px);
}

.loading-overlay[hidden] {
    display: none;
}

.tips-modal {
    position: fixed;
    inset: 0;
    z-index: 950;
    display: grid;
    place-items: center;
    padding: 1.25rem;
}

.tips-modal[hidden] {
    display: none;
}

.tips-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(24, 32, 38, 0.42);
    backdrop-filter: blur(8px);
}

.tips-dialog {
    position: relative;
    z-index: 1;
    width: min(760px, 100%);
    padding: 1.6rem;
}

.tips-eyebrow {
    margin: 0;
    color: var(--accent-dark);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.tips-dialog h2 {
    margin: 0.35rem 0 0;
}

.tips-subtitle {
    margin: 0.7rem 0 0;
    color: var(--muted);
}

.tips-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem;
    margin-top: 1.25rem;
}

.tip-card {
    display: grid;
    gap: 0.65rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.56);
}

.tip-card i {
    font-size: 1.35rem;
    color: var(--accent-dark);
}

.tip-card p {
    margin: 0;
    font-weight: 700;
}

.tips-confirm-button {
    margin-top: 1.25rem;
}

.loading-card {
    width: min(420px, 100%);
    padding: 1.5rem;
    text-align: center;
    border-radius: 24px;
    background: rgba(255, 250, 243, 0.96);
    border: 1px solid rgba(31, 41, 51, 0.1);
    box-shadow: var(--shadow);
}

.spinner {
    width: 3rem;
    height: 3rem;
    margin: 0 auto 1rem;
    border-radius: 50%;
    border: 4px solid rgba(15, 118, 110, 0.16);
    border-top-color: var(--accent);
    animation: spin 0.9s linear infinite;
}

.loading-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
}

.loading-text {
    margin: 0.6rem 0 0;
    color: var(--muted);
}

.hero {
    padding: 2rem;
}

.auth-shell {
    padding: 2rem;
}

.auth-intro h1 {
    margin: 0.25rem 0 0;
    font-size: clamp(2rem, 4vw, 3rem);
}

.auth-eyebrow {
    margin: 0;
    color: var(--accent-dark);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.auth-subtitle {
    max-width: 42rem;
    margin: 0.75rem 0 0;
    color: var(--muted);
}

.auth-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.auth-panel {
    padding: 1.25rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.46);
}

.auth-panel-active {
    border-color: rgba(15, 118, 110, 0.28);
    box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.08);
}

.auth-form {
    display: grid;
    gap: 0.85rem;
}

.auth-form label {
    font-weight: 700;
}

.auth-form input {
    width: 100%;
    padding: 0.85rem 1rem;
    border-radius: 16px;
    border: 1px solid rgba(31, 41, 51, 0.14);
    background: rgba(255, 255, 255, 0.96);
    font: inherit;
    color: var(--text);
}

.auth-form input:focus {
    outline: 2px solid rgba(15, 118, 110, 0.18);
    border-color: rgba(15, 118, 110, 0.34);
}

h2 {
    margin-top: 0;
    font-weight: 700;
}

.result-label {
    color: var(--muted);
}

.upload-form {
    display: grid;
    gap: 0.9rem;
    margin: 0;
}

.upload-heading {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    justify-content: center;
}

.tips-trigger-button {
    width: 2.2rem;
    min-width: 2.2rem;
    height: 2.2rem;
    padding: 0;
    border-radius: 50%;
    background: rgba(17, 94, 89, 0.08);
    color: var(--accent-dark);
    box-shadow: none;
}

.tips-trigger-button:hover {
    box-shadow: none;
    background: rgba(17, 94, 89, 0.15);
}

.tips-trigger-button i {
    font-size: 1rem;
}

.app-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: nowrap;
}

.current-user {
    margin: 0;
    margin-right: auto;
    color: var(--muted);
    font-weight: 700;
    word-break: break-word;
    min-width: 0;
}

.logout-button {
    width: auto;
    min-width: fit-content;
    white-space: nowrap;
    padding-inline: 1.15rem;
    background: rgba(17, 94, 89, 0.1);
    color: var(--accent-dark);
    box-shadow: none;
}

.logout-button:hover {
    box-shadow: none;
    background: rgba(17, 94, 89, 0.16);
}

.upload-label {
    font-weight: 700;
}

.centered {
    text-align: center;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.upload-icon-button {
    display: grid;
    place-items: center;
    width: 5rem;
    height: 5rem;
    margin: 0 auto;
    border-radius: 50%;
    color: white;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    cursor: pointer;
    box-shadow: 0 18px 32px rgba(15, 118, 110, 0.24);
    transition: transform 160ms ease, box-shadow 160ms ease;
}

.upload-icon-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 22px 34px rgba(15, 118, 110, 0.3);
}

.upload-icon-button svg {
    width: 2rem;
    height: 2rem;
    fill: currentColor;
}

.upload-preview {
    display: grid;
    justify-items: center;
    gap: 0.65rem;
    min-height: 13rem;
    padding: 1.1rem;
    border: 2px dashed rgba(15, 118, 110, 0.28);
    border-radius: 22px;
    background: rgba(225, 231, 222, 0.92);
    overflow: hidden;
}

.preview-image {
    width: calc(100% + 2.2rem);
    height: 13rem;
    margin: -1.1rem -1.1rem 0;
    object-fit: cover;
    border-radius: 18px;
    border: 0;
    box-shadow: none;
}

.camera-preview {
    width: calc(100% + 2.2rem);
    height: 13rem;
    margin: -1.1rem -1.1rem 0;
    object-fit: cover;
    border-radius: 18px;
    border: 0;
    background: #0f1720;
    box-shadow: none;
}

.preview-image[hidden] {
    display: none;
}

.camera-preview[hidden] {
    display: none;
}

.preview-placeholder {
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 8rem;
    color: rgba(17, 94, 89, 0.42);
}

.preview-placeholder[hidden] {
    display: none;
}

.preview-placeholder svg {
    width: 3.2rem;
    height: 3.2rem;
    fill: currentColor;
}

.preview-filename {
    margin: 0;
    color: var(--muted);
    text-align: center;
    word-break: break-word;
}

button {
    width: fit-content;
    justify-self: center;
    border: 0;
    border-radius: 999px;
    padding: 0.9rem 1.4rem;
    font: inherit;
    font-weight: 700;
    color: white;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    cursor: pointer;
    transition: transform 160ms ease, box-shadow 160ms ease;
}

button:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 28px rgba(15, 118, 110, 0.24);
}

.messages,
.result {
    margin-top: 1.5rem;
}

.message {
    padding: 1rem 1.25rem;
}

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

.message.success {
    background: rgba(236, 253, 245, 0.95);
    border-color: rgba(16, 185, 129, 0.2);
}

.dominant-material-result {
    margin-top: 1rem;
    font-size: clamp(1.8rem, 4vw, 2.8rem);
    font-weight: 700;
    color: var(--accent-dark);
    text-align: center;
}

.material-stage {
    display: grid;
    justify-items: center;
    gap: 0.9rem;
    margin-top: 1.5rem;
    padding-top: 0.5rem;
}

.material-icon {
    display: grid;
    place-items: center;
    width: clamp(120px, 28vw, 180px);
    height: clamp(120px, 28vw, 180px);
    border-radius: 50%;
    background: radial-gradient(circle at top, rgba(15, 118, 110, 0.12), rgba(15, 118, 110, 0.02));
    border: 1px solid rgba(15, 118, 110, 0.15);
}

.material-icon svg {
    width: 58%;
    height: 58%;
    fill: var(--accent-dark);
}

.material-icon i {
    font-size: clamp(3rem, 8vw, 5rem);
    color: var(--accent-dark);
}

.material-stage-label {
    margin: 0;
    min-height: 2.2rem;
    font-size: clamp(1.15rem, 3vw, 1.75rem);
    font-weight: 700;
    color: var(--accent-dark);
    text-align: center;
}

.material-stage-label:empty {
    min-height: 0;
}

.feedback-panel {
    display: grid;
    justify-items: center;
    gap: 0.8rem;
    margin-top: 1.75rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(31, 41, 51, 0.1);
}

.feedback-panel[hidden] {
    display: none;
}

.feedback-text {
    margin: 0;
    color: var(--muted);
    font-weight: 700;
    text-align: center;
}

.feedback-button {
    background: transparent;
    color: var(--accent-dark);
    border: 1px solid rgba(15, 118, 110, 0.28);
    box-shadow: none;
}

.feedback-button:hover {
    box-shadow: none;
    background: rgba(15, 118, 110, 0.06);
}

.feedback-button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.success-text {
    color: var(--accent-dark);
    font-weight: 700;
}

.error-text {
    color: #b42318;
    font-weight: 700;
}

pre {
    margin: 0;
    overflow-x: auto;
    padding: 1.25rem;
    border-radius: 18px;
    background: #172026;
    color: #ecfdf5;
    font-family: "Courier New", monospace;
    font-size: 0.95rem;
}

.result {
    padding: 1.5rem;
}

.result-grid {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 1.25rem;
    margin-top: 1rem;
}

.result-panel {
    margin-top: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.52);
}

.result-panel h3 {
    margin-top: 0;
    margin-bottom: 0.85rem;
}

.annotated-image {
    display: block;
    width: 100%;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: #dfe8e5;
}

.image-meta {
    margin: 0.75rem 0 0;
    color: var(--muted);
}

.summary-list p {
    margin: 0.35rem 0;
}

.percentage-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.85rem;
    margin-top: 1rem;
}

.percentage-card {
    padding: 0.9rem;
    border-radius: 16px;
    background: var(--surface-strong);
    border: 1px solid var(--border);
}

.percentage-material,
.percentage-value {
    margin: 0;
}

.percentage-material {
    color: var(--muted);
}

.percentage-value {
    margin-top: 0.35rem;
    font-size: 1.35rem;
    font-weight: 700;
}

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

@media (max-width: 640px) {
    .page {
        width: min(100% - 1rem, 960px);
        padding-top: 1rem;
    }

    .hero,
    .result {
        padding: 1.25rem;
    }

    button {
        width: 100%;
    }

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

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

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