/* ========================================
   19 UNCLES ROUND PICKER — Styles
   Deep violet + teal accent · modern glass
   Adapted from Curry Tracker
   ======================================== */

/* --- Custom Properties --- */
:root {
    --bg-deep: #0B0A14;
    --bg-dark: #14122A;
    --bg-card: rgba(30, 26, 56, 0.82);
    --bg-card-hover: rgba(38, 32, 68, 0.82);
    --bg-elevated: rgba(44, 38, 80, 0.85);
    --bg-input: #0F0D1E;

    --text-primary: #ECE7FA;
    --text-secondary: #9D95BD;
    --text-muted: #6B6388;

    --accent: #9E7BFF;
    --accent-hover: #B79AFF;
    --accent-dim: rgba(158, 123, 255, 0.14);
    --accent-glow: rgba(158, 123, 255, 0.3);

    --teal: #4FD1C5;
    --teal-dim: rgba(79, 209, 197, 0.14);

    --pink: #F472B6;
    --danger: #F87171;

    --gold: #FFD166;
    --gold-glow: rgba(255, 209, 102, 0.25);
    --silver: #C0C0C0;
    --bronze: #CD7F32;

    --border-subtle: rgba(236, 231, 250, 0.12);
    --border-accent: rgba(158, 123, 255, 0.25);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;

    --transition: 0.2s ease;
    --spring: cubic-bezier(0.22, 1, 0.36, 1);
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background: var(--bg-deep);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; }
ul { list-style: none; }

/* --- Noise Overlay --- */
.noise {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.025;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px;
}

/* --- Top Glow --- */
body::before {
    content: '';
    position: fixed;
    top: -200px;
    left: 50%;
    transform: translateX(-50%);
    width: 800px;
    height: 500px;
    background: radial-gradient(ellipse, rgba(158, 123, 255, 0.12) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

/* --- Mesh Gradient Background --- */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 80%, rgba(79, 209, 197, 0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(158, 123, 255, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 60%, rgba(244, 114, 182, 0.02) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

/* --- Layout --- */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px;
    position: relative;
    z-index: 1;
}

.main {
    padding-top: 32px;
    /* Reserve space for the sticky submit bar. On mobile the bar wraps to 3
       rows (counter / button / help text). The env() call handles iPhone
       safe-area insets (home indicator). */
    padding-bottom: calc(var(--submit-bar-reserve, 120px) + env(safe-area-inset-bottom, 0));
    min-height: calc(100vh - 200px);
}

/* --- Header --- */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(11, 10, 20, 0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-subtle);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    gap: 16px;
}

.logo {
    cursor: pointer;
    user-select: none;
    transition: opacity var(--transition);
}
.logo:hover { opacity: 0.85; }

.logo-text {
    font-family: 'Outfit', sans-serif;
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.1;
    color: var(--text-primary);
}
.logo-text em {
    font-style: italic;
    color: var(--accent);
}

.logo-tagline {
    font-size: 0.72rem;
    color: var(--text-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-top: 2px;
}

/* --- Ornament --- */
.ornament {
    padding: 0 20px;
    height: 1px;
    display: block;
}
.ornament-line, .ornament-diamond { display: none; }
.ornament::after {
    content: '';
    display: block;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent) 30%, var(--teal) 70%, transparent);
    opacity: 0.35;
}

/* --- User Area --- */
.user-area {
    position: relative;
    flex-shrink: 0;
}

.user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-md);
    background: var(--accent-dim);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--accent);
    transition: all var(--transition);
    white-space: nowrap;
}
.user-btn:hover {
    background: rgba(158, 123, 255, 0.22);
    border-color: var(--accent);
}
.user-btn .user-icon {
    font-size: 1rem;
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 220px;
    max-height: 70vh;
    overflow-y: auto;
    background: var(--bg-elevated);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
    overflow-x: hidden;
    animation: dropIn 0.15s ease-out;
    z-index: 200;
}

.user-dropdown-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    text-align: left;
    font-size: 0.85rem;
    color: var(--text-primary);
    transition: background var(--transition);
    border-bottom: 1px solid var(--border-subtle);
}
.user-dropdown-item:last-child { border-bottom: none; }
.user-dropdown-item:hover { background: rgba(158, 123, 255, 0.12); }
.user-dropdown-item.active {
    color: var(--accent);
    font-weight: 700;
}
.user-dropdown-item.sign-out {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* --- View Header --- */
.view-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.view-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.view-subtitle {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-deep);
}
.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-ghost {
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}
.btn-ghost:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.btn-danger {
    color: var(--danger);
    border: 1px solid rgba(248, 113, 113, 0.25);
}
.btn-danger:hover {
    background: rgba(248, 113, 113, 0.1);
}

.btn-teal {
    background: var(--teal);
    color: var(--bg-deep);
}
.btn-teal:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(79, 209, 197, 0.3);
}

/* --- Phase banner --- */
.phase-banner {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 16px;
}
.phase-banner.setup    { background: rgba(158, 123, 255, 0.14); color: var(--accent); }
.phase-banner.voting   { background: rgba(79, 209, 197, 0.14);  color: var(--teal); }
.phase-banner.closed   { background: rgba(255, 209, 102, 0.14); color: var(--gold); }
.phase-banner::before {
    content: '●';
    font-size: 0.9em;
}

/* --- Suggestion card grid --- */
.suggestion-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.suggestion-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    transition: all var(--transition);
    animation: cardIn 0.35s var(--spring) both;
}
.suggestion-card.readonly { opacity: 0.95; }
.suggestion-card.selectable { cursor: pointer; }
.suggestion-card.selectable:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-accent);
    transform: translateY(-1px);
}
.suggestion-card.selected {
    background: rgba(158, 123, 255, 0.14);
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-glow);
}
.suggestion-card.cap-reached:not(.selected) {
    opacity: 0.55;
    cursor: not-allowed;
}

.suggestion-check {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 1.5px solid var(--border-accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--bg-deep);
    transition: all var(--transition);
}
.suggestion-card.selected .suggestion-check {
    background: var(--accent);
    border-color: var(--accent);
}
.suggestion-card.selected .suggestion-check::before { content: '✓'; }

.suggestion-body {
    flex: 1;
    min-width: 0;
}
.suggestion-text {
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.35;
}
.suggestion-submitter {
    font-size: 0.74rem;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    margin-top: 2px;
}
.suggestion-submitter em {
    font-style: normal;
    color: var(--text-secondary);
    font-weight: 600;
}

/* --- Tally (results view) --- */
.tally-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    animation: cardIn 0.35s var(--spring) both;
    position: relative;
    overflow: hidden;
}
.tally-card.top-10 {
    border-color: var(--border-accent);
    background: rgba(158, 123, 255, 0.08);
}
.tally-card.tied-boundary {
    border-color: rgba(255, 209, 102, 0.35);
    background: rgba(255, 209, 102, 0.05);
}
.tally-card.mine::after {
    content: 'YOUR PICK';
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 0.62rem;
    letter-spacing: 0.1em;
    color: var(--teal);
    font-weight: 700;
}

.tally-rank {
    flex-shrink: 0;
    width: 32px;
    text-align: center;
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-muted);
}
.tally-card.top-10 .tally-rank { color: var(--accent); }
.tally-card.rank-1 .tally-rank { color: var(--gold); }
.tally-card.rank-2 .tally-rank { color: var(--silver); }
.tally-card.rank-3 .tally-rank { color: var(--bronze); }

.tally-body {
    flex: 1;
    min-width: 0;
}
.tally-text {
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}
.tally-meta {
    font-size: 0.74rem;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    margin-top: 3px;
}

.tally-count {
    flex-shrink: 0;
    min-width: 44px;
    text-align: right;
    font-family: 'Outfit', sans-serif;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--accent);
}
.tally-card.top-10 .tally-count { color: var(--accent); }
.tally-card:not(.top-10) .tally-count { color: var(--text-secondary); }

.tied-badge {
    display: inline-block;
    font-size: 0.64rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--gold);
    background: rgba(255, 209, 102, 0.12);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    vertical-align: middle;
}

/* --- Sticky submit bar --- */
.submit-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px 20px calc(16px + env(safe-area-inset-bottom, 0));
    /* Fully opaque — some mobile browsers (notably Samsung Internet)
       don't honour backdrop-filter reliably. A near-opaque rgba would let
       the footer bleed through. */
    background: var(--bg-deep);
    border-top: 1px solid var(--border-subtle);
    /* Above header (100) and modal backdrop (500) is fine — we only need
       to beat the footer and content flow. */
    z-index: 400;
}
.submit-bar-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.submit-counter {
    font-family: 'Outfit', sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
}
.submit-counter em {
    font-style: normal;
    color: var(--accent);
}
.submit-counter.cap-reached em { color: var(--teal); }
.submit-help {
    font-size: 0.82rem;
    color: var(--text-muted);
    flex: 1;
    min-width: 0;
}
.submit-bar .btn { margin-left: auto; }

/* --- Admin panel --- */
.admin-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 28px;
}
.admin-panel h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--accent);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.admin-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.admin-row:last-child { margin-bottom: 0; }
.admin-row label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.admin-textarea {
    width: 100%;
    min-height: 180px;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.88rem;
    font-family: 'Plus Jakarta Sans', sans-serif;
    line-height: 1.55;
    outline: none;
    resize: vertical;
    transition: border-color var(--transition);
}
.admin-textarea:focus {
    border-color: var(--accent);
}
.admin-select {
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
}
.admin-hint {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-top: 6px;
    line-height: 1.5;
}

/* --- Empty state --- */
.empty-state {
    background: var(--bg-card);
    border: 1px dashed var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 48px 24px;
    text-align: center;
    color: var(--text-muted);
}
.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: 0.7;
}
.empty-state p { margin-bottom: 8px; }

/* --- Pill list (submitted picks) --- */
.pill-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 24px;
}
.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--teal-dim);
    border: 1px solid rgba(79, 209, 197, 0.3);
    border-radius: 999px;
    color: var(--teal);
    font-size: 0.82rem;
    font-weight: 600;
}

/* --- Section headers --- */
.section-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    margin: 28px 0 12px;
    display: flex;
    align-items: baseline;
    gap: 10px;
}
.section-title .subtle {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    text-transform: none;
}

/* --- Modal (reused) --- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(4px);
    z-index: 500;
    animation: fadeIn 0.15s ease;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-elevated);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 92%;
    max-width: 440px;
    z-index: 501;
    animation: modalIn 0.2s ease-out;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.modal h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 12px;
}
.modal p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.55;
}
.modal-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border-color var(--transition);
}
.modal-input:focus { border-color: var(--accent); }

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* --- Setup message (Firebase) --- */
.setup-message {
    max-width: 600px;
    margin: 40px auto;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-lg);
    padding: 32px;
}
.setup-message h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    margin-bottom: 12px;
}
.setup-message p {
    color: var(--text-secondary);
    margin-bottom: 16px;
    font-size: 0.9rem;
}
.setup-message ol {
    list-style: decimal;
    padding-left: 20px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 2;
}
.setup-message code {
    background: var(--bg-elevated);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.85em;
    color: var(--accent);
}
.setup-message a {
    color: var(--accent);
    text-decoration: underline;
}

/* --- Demo mode banner --- */
.demo-banner {
    padding: 10px 14px;
    margin-bottom: 20px;
    background: var(--teal-dim);
    border: 1px solid rgba(79, 209, 197, 0.25);
    border-radius: var(--radius-sm);
    color: var(--teal);
    font-size: 0.82rem;
    line-height: 1.5;
}
.demo-banner strong { color: var(--text-primary); }

/* --- Loading --- */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 80px 20px;
    color: var(--text-muted);
}
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-subtle);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* --- Footer --- */
.footer {
    border-top: 1px solid var(--border-subtle);
    padding: 20px 0;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.footer-emoji { font-size: 1rem; }

/* --- Utilities --- */
.hidden { display: none !important; }

/* --- Animations --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes dropIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes modalIn { from { opacity: 0; transform: translate(-50%, -48%); } to { opacity: 1; transform: translate(-50%, -50%); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
/* Opacity only — no transform. A transform (even translateY(0)) on .animate-in
   would create a containing block and break `position: fixed` on the
   submit-bar nested inside it. */
@keyframes slideUp { from { opacity: 0; } to { opacity: 1; } }

.animate-in { animation: slideUp 0.3s ease-out both; }

/* Staggered suggestion/tally card animation */
.suggestion-card:nth-child(n)  { animation-delay: calc(0.02s * var(--i, 0)); }
.tally-card:nth-child(n)       { animation-delay: calc(0.02s * var(--i, 0)); }

/* --- Responsive --- */
@media (max-width: 700px) {
    .header-inner { padding: 12px 16px; }
    .logo-text { font-size: 1.25rem; }
    .logo-tagline { display: none; }
    .view-header { flex-direction: column; align-items: flex-start; }
    .view-title { font-size: 1.4rem; }
    .submit-bar-inner { gap: 10px; }
    .submit-help { width: 100%; order: 3; font-size: 0.78rem; }
    .submit-bar .btn { margin-left: 0; flex: 1; justify-content: center; }
    .admin-panel { padding: 16px; }
}
