:root {
    --primary-color: #00796b; /* A more subdued, "natural" green */
    --dark-color: #333333;
    --light-color: #ffffff;
    --background-color: #f5f5f5;
    --accent-color: #a1887f; /* Earthy accent */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--background-color);
    color: var(--dark-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

#app-footer {
    margin-top: 1rem;
    padding: 1rem;
    font-size: 0.85rem;
    color: #777;
}
#app-footer a { color: #777; text-decoration: none; }
#app-footer a:hover { color: var(--primary-color); text-decoration: underline; }
#app-footer .footer-sep { margin: 0 0.5rem; color: #bbb; }

.danger-zone {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid #eee;
}

/* --- Settings screen --- */
.settings-section {
    text-align: left;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
}
.settings-section h3 {
    margin-bottom: 0.4rem;
}
.settings-hint {
    font-size: 0.85rem;
    color: #777;
    margin-top: 0;
}
#display-name-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 1rem;
    box-sizing: border-box;
    margin-bottom: 0.6rem;
}
.settings-status {
    font-size: 0.85rem;
    margin-top: 0.5rem;
    min-height: 1.1em;
}
.settings-status.success { color: #2e7d32; }
.settings-status.error { color: #c62828; }

/* --- Field-guide card extras: hero image + confidence badge --- */
.field-guide-hero {
    display: block;
    width: 100%;
    max-height: 180px;
    object-fit: contain;
    background: #f8f8f8;
    border-radius: 6px;
    margin-bottom: 0.5rem;
}
.confidence-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: white;
    margin-bottom: 0.4rem;
}
.confidence-badge.confidence-high   { background: #2e7d32; }
.confidence-badge.confidence-medium { background: #ed6c02; }
.confidence-badge.confidence-low    { background: #757575; }

/* --- Home-screen public stats line --- */
.home-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin: 0.75rem 0 1rem;
    font-size: 0.85rem;
    color: #666;
    line-height: 1.4;
}
.home-stats strong { color: var(--primary-color); }

/* --- Correction form (manual entry after "None of these are correct") --- */
.correction-form {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    text-align: left;
}
.correction-form label {
    font-size: 0.85rem;
    color: #555;
    margin-top: 0.3rem;
}
.correction-form select,
.correction-form input[type="text"] {
    padding: 0.5rem 0.6rem;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 0.95rem;
}
.correction-form select:disabled {
    background: #f5f5f5;
    color: #aaa;
}
.correction-form button {
    margin-top: 0.6rem;
}

/* --- Field Guide Progress: status badge, progress bar, achievements --- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.9rem;
    border-radius: 24px;
    background: linear-gradient(135deg, var(--primary-color), #4db6ac);
    color: white;
    font-weight: 600;
    margin-bottom: 0.6rem;
}
.status-badge .status-tier {
    background: rgba(255,255,255,0.25);
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
}
.status-badge .status-name { font-size: 0.95rem; }
.status-badge.tier-0 { background: #888; }

.progress-bar {
    background: #eee;
    border-radius: 6px;
    overflow: hidden;
    height: 8px;
    margin: 0.3rem 0;
}
.progress-bar-fill {
    background: var(--primary-color);
    height: 100%;
    transition: width 0.3s;
}
.progress-next {
    font-size: 0.85rem;
    color: #555;
    margin: 0.25rem 0 0;
}
.progress-totals { margin-top: 0.4rem; }

.achievements-header {
    margin: 1.25rem 0 0.5rem;
    font-size: 1rem;
    color: var(--primary-color);
}
.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.6rem;
}
.achievement {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 0.5rem 0.7rem;
    background: #fafafa;
}
.achievement.earned {
    border-color: var(--primary-color);
    background: #f3faf8;
}
.achievement.locked { opacity: 0.55; }
.achievement-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.2rem;
}
.achievement-desc {
    font-size: 0.8rem;
    color: #666;
}

/* --- Choice + picker screens --- */
.choice-preview-img {
    max-width: 220px;
    width: 100%;
    border-radius: 8px;
    margin: 0.5rem auto 1rem;
    display: block;
}
#picker-search {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 1rem;
    box-sizing: border-box;
    margin-bottom: 0.75rem;
}
#picker-list {
    max-height: 55vh;
    overflow-y: auto;
    text-align: left;
    margin-bottom: 1rem;
}
.picker-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.7rem 0.85rem;
    margin: 0;
    border: none;
    border-bottom: 1px solid #eee;
    background: white;
    color: var(--dark-color);
    cursor: pointer;
    font-size: 0.95rem;
}
.picker-item:hover { background: #f0f7f5; color: var(--primary-color); }
.picker-note {
    font-size: 0.8rem;
    color: #888;
    padding: 0.5rem;
    text-align: center;
}
#delete-account-btn {
    background: none;
    border: 1px solid #c62828;
    color: #c62828;
    padding: 0.4rem 0.9rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}
#delete-account-btn:hover { background: #c62828; color: white; }
#delete-account-btn:disabled { opacity: 0.5; cursor: not-allowed; }

#app {
    width: 100%;
    max-width: 500px;
    background-color: var(--light-color);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    overflow: hidden;
    min-height: 80vh;
}

section {
    padding: 2rem;
    text-align: center;
}

.hidden {
    display: none !important;
}

h1, h2, h3, h4 {
    font-family: 'Georgia', 'Times New Roman', serif;
}

button {
    background-color: var(--primary-color);
    color: var(--light-color);
    border: none;
    padding: 12px 24px;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
    margin: 0.5rem;
}

button:hover {
    background-color: #004d40;
}

/* New Field Guide Entry Styles */
.field-guide-entry {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    text-align: left;
    background: #fafafa;
}
.field-guide-entry img {
    max-width: 100%;
    border-radius: 5px;
    margin-bottom: 1rem;
}
.field-guide-entry h3 {
    margin-top: 0;
    font-size: 1.5rem;
}
.field-guide-entry .taxonomy {
    font-style: italic;
    color: #555;
    margin-bottom: 1rem;
}
.field-guide-entry .field-section {
    margin-bottom: 1rem;
}
.field-guide-entry .field-section h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.25rem;
    color: var(--primary-color);
}
.field-guide-entry .field-section p, .field-guide-entry .field-section ul {
    margin: 0;
    padding-left: 0;
    list-style-position: inside;
}

/* Journal Styles */
#journal-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
    min-height: 50vh;
}
.journal-card {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 0.5rem;
    text-align: center;
    background-color: #f9f9f9;
    cursor: pointer;
    transition: box-shadow 0.1s, transform 0.1s;
    position: relative;
}
.journal-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    transform: translateY(-1px);
}
.sighting-count-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    background: var(--primary-color);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
}

/* --- Journal detail modal --- */
.journal-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 1000;
    padding: 1.5rem 1rem;
    overflow-y: auto;
}
.journal-modal {
    background: #fff;
    border-radius: 10px;
    max-width: 460px;
    width: 100%;
    padding: 1.25rem;
    position: relative;
    text-align: center;
}
.journal-modal-close {
    position: absolute;
    top: 0.4rem;
    right: 0.6rem;
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    color: #888;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
}
.journal-modal-close:hover { color: #222; }
.journal-modal-img {
    width: 100%;
    max-height: 260px;
    object-fit: contain;
    border-radius: 6px;
    background: #f3f3f3;
}
.journal-modal h3 { margin: 0.75rem 0 0.25rem; }
.journal-modal-meta {
    font-size: 0.85rem;
    color: #666;
    margin: 0 0 1rem;
}
.journal-modal-guide { text-align: left; }

.journal-history {
    text-align: left;
    margin-bottom: 1rem;
}
.journal-history h4 {
    margin: 0 0 0.4rem;
    font-size: 0.95rem;
    color: var(--primary-color);
}
.journal-history ul {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 160px;
    overflow-y: auto;
}
.journal-history li {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid #eee;
    font-size: 0.85rem;
}
.journal-history li:last-child { border-bottom: none; }
.journal-history .hist-loc { color: #333; }
.journal-history .hist-when { color: #888; white-space: nowrap; }
.journal-card img {
    width: 100%;
    max-width: 120px;
    height: 120px;
    object-fit: contain;
    margin-bottom: 0.5rem;
}
.journal-card h4 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
}
.journal-card .location {
    font-size: 0.75rem;
    color: #666;
    margin-top: 4px;
}


/* Camera View */
#camera-screen { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: #000; padding: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; touch-action: manipulation; }
#camera-view { width: 100%; height: 100%; object-fit: cover; }
.camera-controls { position: absolute; bottom: 20px; width: 100%; text-align: center; }

/* Real-zoom slider — sensor-level zoom via MediaStreamTrack constraints. */
#camera-zoom-overlay {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: rgba(0, 0, 0, 0.55);
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    backdrop-filter: blur(4px);
    width: min(78vw, 360px);
}
#camera-zoom-overlay .camera-zoom-label {
    min-width: 2.6rem;
    text-align: center;
}
#camera-zoom-slider {
    flex: 1;
    accent-color: white;
    height: 4px;
}

/* Analysis Screen Loader */
.loader { border: 8px solid #f3f3f3; border-top: 8px solid var(--primary-color); border-radius: 50%; width: 60px; height: 60px; animation: spin 1s linear infinite; margin: 2rem auto; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Cropper Screen */
.cropper-container { width: 100%; height: 60vh; margin-bottom: 1rem; }
#image-to-crop { display: block; max-width: 100%; }

/* General Layout & Auth */
.user-image-container { margin-bottom: 2rem; border-bottom: 1px solid #eee; padding-bottom: 1rem; }
#user-submitted-image { max-width: 200px; max-height: 200px; border-radius: 8px; border: 1px solid #ddd; }
#app-header { padding: 0.5rem 1rem; background-color: #f5f5f5; border-bottom: 1px solid #ddd; text-align: right; }
#auth-container button { padding: 6px 12px; font-size: 0.8rem; margin: 0 0.25rem; }
#user-details { margin-right: 1rem; font-size: 0.9rem; color: #333; }
#leaderboard-list { list-style: none; padding: 0; margin: 1.5rem 0; }
#leaderboard-list li { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding: 0.75rem; border-bottom: 1px solid #eee; font-size: 1.1rem; }
#leaderboard-list li:first-child { font-weight: bold; font-size: 1.3rem; color: var(--primary-color); }
#leaderboard-list .score { font-weight: bold; white-space: nowrap; }
#leaderboard-list .leaderboard-name {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    min-width: 0;
}

/* Compact tier pill — colored by tier so higher ranks visually stand out. */
.leaderboard-tier {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 600;
    color: white;
    letter-spacing: 0.02em;
    white-space: nowrap;
    text-transform: uppercase;
    background: #9e9e9e;
}
.leaderboard-tier.tier-1 { background: #78909c; }                                /* Beacon Spotter */
.leaderboard-tier.tier-2 { background: #4caf50; }                                /* Signal Apprentice */
.leaderboard-tier.tier-3 { background: #26a69a; }                                /* Spectrum Scout */
.leaderboard-tier.tier-4 { background: var(--primary-color); }                   /* Frequency Naturalist */
.leaderboard-tier.tier-5 { background: #1976d2; }                                /* Senior Site Surveyor */
.leaderboard-tier.tier-6 { background: #6a1b9a; }                                /* RF Curator */
.leaderboard-tier.tier-7 { background: #d84315; }                                /* Wireless Archivist */
.leaderboard-tier.tier-8 { background: linear-gradient(135deg, #b8860b, #ffd700); color: #3a2700; }  /* Grand Curator of the Field Spectrum */

/* --- New Tab and Tech Spec Styles --- */

.view-tabs {
    display: flex;
    border-bottom: 1px solid #ddd;
    margin-bottom: 1rem;
}

.tab-btn {
    padding: 0.5rem 1rem;
    border: none;
    background-color: transparent;
    color: var(--dark-color);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin: 0;
    border-radius: 0;
}

.tab-btn.active {
    border-bottom: 3px solid var(--primary-color);
    font-weight: bold;
    color: var(--primary-color);
}

.tech-specs-view dl {
    text-align: left;
}

.tech-specs-view dt {
    font-weight: bold;
    color: #333;
    width: 150px;
    float: left;
    clear: left;
}

.tech-specs-view dd {
    margin-left: 160px;
    margin-bottom: 0.5rem;
}

.tech-specs-view .spec-section {
    margin-bottom: 1.25rem;
}
.tech-specs-view .spec-section h5 {
    margin: 0 0 0.4rem 0;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--primary-color);
    border-bottom: 1px solid #eee;
    padding-bottom: 0.2rem;
}
.tech-specs-view .spec-section dl {
    margin: 0;
}
.tech-specs-view .muted {
    color: #999;
    font-style: italic;
}

.log-sighting-btn {
    width: 100%;
    margin-top: 1rem;
}

/* Model selector on home screen */
#model-selector-container {
    margin-top: 1.5rem;
    padding: 0.75rem 1rem;
    background-color: #f0f4f3;
    border: 1px solid #c8dbd8;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.85rem;
}

#model-selector-container label {
    font-weight: 600;
    color: var(--primary-color);
    white-space: nowrap;
}

#model-selector {
    border: 1px solid #c8dbd8;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.85rem;
    background-color: #fff;
    color: var(--dark-color);
    cursor: pointer;
}

/* Badge showing which model produced the results */
.model-badge {
    font-size: 0.75rem;
    color: #666;
    font-style: italic;
    text-align: right;
    margin: 0 0 0.75rem 0;
    padding: 3px 8px;
    background-color: #f0f4f3;
    border-radius: 4px;
    border: 1px solid #c8dbd8;
}