:root {
    --bg: #0b0d12;
    --bg-card: #131722;
    --bg-elev: #1a1f2e;
    --border: #2a3142;
    --text: #e6e8ee;
    --text-muted: #9aa3b2;
    --accent: #8b6dff;
    --accent-glow: rgba(139, 109, 255, 0.18);
    --mystic: #c9a8ff;
    --gold: #d4af37;
    --high: #4ade80;
    --mid: #facc15;
    --low: #f87171;
    --radius: 16px;
    --radius-sm: 10px;
}

* {
    box-sizing: border-box;
}

html, body {
    background: radial-gradient(ellipse at top, #1a1339 0%, var(--bg) 60%) fixed;
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    min-height: 100%;
    -webkit-font-smoothing: antialiased;
}

body {
    margin: 0;
    padding: 0;
}

h1, h2, h3, h4, .crystal-name {
    font-family: 'Cormorant Garamond', Georgia, serif;
    letter-spacing: 0.01em;
    font-weight: 700;
}

.page {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px 16px 80px;
}

.page.admin {
    max-width: 1200px;
}

.page-header {
    text-align: center;
    padding: 16px 4px 24px;
}

.page-header h1 {
    font-size: clamp(1.8rem, 5vw, 2.6rem);
    margin: 0 0 8px;
    background: linear-gradient(120deg, #fff, var(--mystic));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tagline {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin: 0;
}

.show-on-mobile { display: none; }
.hide-on-mobile { display: inline; }

@media (max-width: 600px) {
    .show-on-mobile { display: inline; }
    .hide-on-mobile { display: none; }
    .page { padding: 16px 12px 64px; }
}

/* ---------- Drop zone ---------- */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.1s;
    outline: none;
}
.drop-zone:hover, .drop-zone:focus-visible {
    border-color: var(--accent);
    background: var(--bg-elev);
}
.drop-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-glow);
    transform: scale(1.01);
}
.drop-zone.is-loading {
    opacity: 0.5;
    pointer-events: none;
}
.upload-icon {
    font-size: 2.4rem;
    color: var(--mystic);
    margin-bottom: 8px;
    display: block;
}
.drop-zone-title {
    margin: 4px 0 6px;
    font-size: 1.1rem;
}
.hidden-input {
    display: none;
}

/* ---------- Previews ---------- */
.previews {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-top: 14px;
}
.preview {
    position: relative;
    width: 84px;
    height: 84px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-card);
}
.preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.preview-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: rgba(0,0,0,0.75);
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
}
@media (min-width: 600px) {
    .preview { width: 120px; height: 120px; }
    .preview-remove { width: 32px; height: 32px; }
}

.identify-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 16px;
    padding: 14px 18px;
    font-size: 1rem;
    font-weight: 600;
    background: linear-gradient(120deg, var(--accent), #b48aff);
    border: none;
}
.identify-btn:hover {
    filter: brightness(1.1);
}

/* ---------- Loading ---------- */
.loading-container {
    text-align: center;
    padding: 28px 16px;
}
.loading-text { color: var(--mystic); margin-bottom: 4px; }
.loading-subtext { color: var(--text-muted); font-size: 0.9rem; }

/* ---------- Result card ---------- */
.result-card {
    margin-top: 24px;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px -20px rgba(139, 109, 255, 0.25);
}
@media (min-width: 600px) {
    .result-card { padding: 28px; }
}
.result-header {
    text-align: center;
    margin-bottom: 18px;
}
.crystal-name {
    font-size: clamp(1.8rem, 6vw, 2.4rem);
    margin: 0 0 12px;
    color: #fff;
}
.model-chip {
    display: inline-block;
    margin-top: 10px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.chip-flash {
    background: rgba(139, 109, 255, 0.18);
    color: var(--mystic);
}
.chip-pro {
    background: rgba(74, 222, 128, 0.18);
    color: var(--high);
}

/* ---------- Confidence bar ---------- */
.confidence-bar {
    position: relative;
    height: 24px;
    background: var(--bg-elev);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.confidence-bar.large {
    height: 30px;
    max-width: 360px;
    margin: 0 auto;
}
.confidence-fill {
    position: absolute;
    inset: 0 auto 0 0;
    border-radius: 999px;
}
.conf-high { background: linear-gradient(90deg, #22c55e, #4ade80); }
.conf-mid  { background: linear-gradient(90deg, #ca8a04, #facc15); }
.conf-low  { background: linear-gradient(90deg, #dc2626, #f87171); }
.confidence-text {
    position: relative;
    z-index: 1;
    display: block;
    height: 100%;
    line-height: 24px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.confidence-bar.large .confidence-text { line-height: 30px; }

/* ---------- Card sections ---------- */
.card-section {
    margin-top: 22px;
}
.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.15rem;
    color: var(--mystic);
    margin: 0 0 12px;
}
.section-title i {
    color: var(--gold);
    font-size: 1rem;
}
.mystical-text {
    line-height: 1.65;
    color: #d6dae5;
    margin: 0;
}

/* ---------- 6-dim grid ---------- */
.dim-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}
@media (min-width: 480px) {
    .dim-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 720px) {
    .dim-grid { grid-template-columns: repeat(3, 1fr); }
}
.dim {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}
.dim-label {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
}
.dim-value {
    font-size: 0.95rem;
    line-height: 1.4;
    color: var(--text);
}

/* ---------- Expander ---------- */
.expander {
    margin-top: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elev);
    overflow: hidden;
}
.expander > summary {
    list-style: none;
    cursor: pointer;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 48px;
    font-weight: 600;
    color: var(--mystic);
    user-select: none;
}
.expander > summary::-webkit-details-marker { display: none; }
.expander > summary i.chev {
    transition: transform 0.2s;
}
.expander[open] > summary i.chev {
    transform: rotate(180deg);
}
.expander-body {
    padding: 0 16px 16px;
    color: #d6dae5;
    line-height: 1.6;
}
.ext-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: 1fr;
}
@media (min-width: 600px) {
    .ext-grid { grid-template-columns: repeat(2, 1fr); }
}
.ext-grid h6 {
    color: var(--gold);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0 0 4px;
}
.ext-grid p {
    margin: 0;
}
.affirmation {
    grid-column: 1 / -1;
    background: linear-gradient(120deg, rgba(212, 175, 55, 0.08), rgba(139, 109, 255, 0.08));
    border: 1px solid rgba(212, 175, 55, 0.2);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}
.affirmation p {
    font-size: 1.05rem;
    color: #fff;
}

/* ---------- Alternatives ---------- */
.alts {
    display: grid;
    gap: 12px;
    grid-template-columns: 1fr;
}
@media (min-width: 600px) {
    .alts { grid-template-columns: repeat(2, 1fr); }
}
.alt-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
}
.alt-name {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 8px;
}
.alt-diff {
    margin: 8px 0 0;
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ---------- Grounding sources ---------- */
.grounding-note {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0 0 10px;
    line-height: 1.5;
}
.grounding-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.grounding-list li {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 0.85rem;
}
.grounding-list a {
    color: var(--mystic);
    text-decoration: none;
    word-break: break-all;
}
.grounding-list a:hover { text-decoration: underline; }

/* ---------- Uploaded thumbnails (shown on the result card) ---------- */
.uploaded-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 18px;
}
.uploaded-thumbs img {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elev);
}
@media (min-width: 600px) {
    .uploaded-thumbs img { width: 96px; height: 96px; }
}

/* ---------- Similar images ---------- */
.similar-images {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.similar-images img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--bg-elev);
    border: 1px solid var(--border);
}

/* ---------- Message cards (limit / disabled) ---------- */
.message-card {
    margin: 60px auto;
    max-width: 480px;
    text-align: center;
    padding: 32px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.message-card h2 {
    margin: 12px 0 8px;
    color: #fff;
}
.message-card p {
    color: var(--text-muted);
    line-height: 1.6;
}
.big-icon {
    font-size: 3rem;
    color: var(--mystic);
}

/* ---------- Admin ---------- */
.admin-header {
    text-align: left;
}
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 20px;
}
.filter-bar input,
.filter-bar select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 0.9rem;
    min-height: 40px;
}
.filter-bar input[type="search"] {
    flex: 1 1 200px;
}
.admin-count {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 12px;
}
.admin-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 600px) { .admin-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .admin-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1200px) { .admin-grid { grid-template-columns: repeat(5, 1fr); } }

.admin-tile {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s, border-color 0.15s;
}
.admin-tile:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}
.admin-tile img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    display: block;
}
.admin-tile-empty {
    aspect-ratio: 1 / 1;
    display: grid;
    place-items: center;
    background: var(--bg-elev);
    color: var(--text-muted);
    font-size: 1.6rem;
}
.admin-tile-body {
    padding: 10px 12px;
}
.admin-tile-name {
    font-weight: 600;
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.admin-tile-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-top: 24px;
    color: var(--text-muted);
}
.pagination a {
    color: var(--mystic);
    text-decoration: none;
}

/* ---------- Admin detail ---------- */
.back-link {
    color: var(--mystic);
    text-decoration: none;
    font-size: 0.9rem;
}
.detail-images {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    margin-bottom: 24px;
}
.detail-images figure {
    margin: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.detail-images img {
    width: 100%;
    display: block;
}
.detail-images figcaption {
    padding: 8px 12px;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.detail-section {
    margin-bottom: 24px;
}
.detail-section h3 {
    color: var(--mystic);
    font-size: 1.2rem;
    margin-bottom: 8px;
}
.detail-section pre {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-size: 0.82rem;
    overflow-x: auto;
    color: #cdd3e0;
}
.error-banner {
    background: rgba(248, 113, 113, 0.12);
    border: 1px solid rgba(248, 113, 113, 0.35);
    color: #fecaca;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-top: 12px;
}

/* ---------- Touch device tweaks ---------- */
@media (hover: none) {
    .admin-tile:hover { transform: none; }
}
