/* YarnToss — Minimal, mobile-first, light/dark */

/* ========= DARK THEME (default) ========= */
:root {
    --bg: #0a0a0a;
    --bg-card: #141414;
    --bg-input: #1a1a1a;
    --bg-hover: #1f1f1f;
    --border: #2a2a2a;
    --text: #e8e8e8;
    --text-muted: #888;
    --text-dim: #555;
    --accent: #9b6dff;
    --accent-dim: rgba(155, 109, 255, 0.12);
    --danger: #ff6b6b;
    --success: #4ecdc4;
    --radius: 12px;
    --radius-sm: 8px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --btn-text: #0a0a0a;
    --modal-overlay: rgba(0,0,0,0.7);
}

/* ========= LIGHT THEME ========= */
[data-theme="light"] {
    --bg: #f5f5f5;
    --bg-card: #ffffff;
    --bg-input: #eaeaea;
    --bg-hover: #e0e0e0;
    --border: #d0d0d0;
    --text: #1a1a1a;
    --text-muted: #666;
    --text-dim: #999;
    --accent: #7c4dff;
    --accent-dim: rgba(124, 77, 255, 0.1);
    --danger: #e53935;
    --success: #00897b;
    --btn-text: #ffffff;
    --modal-overlay: rgba(0,0,0,0.4);
}

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

html, body {
    height: 100%;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}

body { padding-top: var(--safe-top); padding-bottom: var(--safe-bottom); }

#app { height: 100%; position: relative; overflow: hidden; }

/* ========= VIDEO BACKGROUND (shared by landing + auth) ========= */
#bg-video,
#bg-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    display: none;
}
#bg-video {
    object-fit: cover;
}
#bg-overlay {
    background: rgba(0, 0, 0, 0.55);
}
/* Show video bg only when landing or auth is active (pure CSS, no flash) */
#app:has(#screen-landing.active) > #bg-video,
#app:has(#screen-landing.active) > #bg-overlay,
#app:has(#screen-auth.active) > #bg-video,
#app:has(#screen-auth.active) > #bg-overlay {
    display: block;
}
[data-theme="light"] #bg-overlay {
    background: rgba(255, 255, 255, 0.6);
}

/* ========= LANDING PAGE ========= */
.landing {
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

/* Landing nav */
.landing-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    padding-top: calc(16px + var(--safe-top));
    z-index: 20;
}
.landing-logo {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.5px;
}
[data-theme="light"] .landing-logo { color: #1a1a1a; }

/* Hamburger */
.hamburger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    z-index: 30;
}
.hamburger span {
    display: block;
    width: 24px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: all 0.25s ease;
}
[data-theme="light"] .hamburger span { background: #1a1a1a; }
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Mobile menu */
.mobile-menu {
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    height: 100%;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    padding: 80px 24px 24px;
    z-index: 15;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transform: translateX(0);
    transition: transform 0.25s ease;
}
.mobile-menu.hidden { transform: translateX(100%); display: flex; }
.menu-link {
    display: block;
    color: var(--text);
    text-decoration: none;
    font-size: 16px;
    font-weight: 500;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    transition: color 0.15s;
}
.menu-link:hover { color: var(--accent); }
.menu-divider { height: 1px; background: var(--border); margin: 8px 0; }
.menu-theme { padding: 14px 0; }

/* Hero */
.landing-hero {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 100vh;
    padding: 80px 24px;
}
.landing-title {
    font-size: clamp(36px, 8vw, 72px);
    font-weight: 700;
    color: #fff;
    letter-spacing: -2px;
    line-height: 1.1;
    margin-bottom: 20px;
}
[data-theme="light"] .landing-title { color: #1a1a1a; }
.landing-sub {
    font-size: clamp(16px, 3vw, 20px);
    color: rgba(255,255,255,0.75);
    max-width: 520px;
    line-height: 1.6;
    margin-bottom: 36px;
}
[data-theme="light"] .landing-sub { color: rgba(0,0,0,0.6); }
.landing-cta {
    font-size: 17px;
    padding: 16px 40px;
    border-radius: 30px;
    letter-spacing: 0.3px;
}

/* How it works */
.landing-section {
    position: relative;
    z-index: 2;
    padding: 80px 24px;
    background: var(--bg);
}
.section-heading {
    font-size: 28px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 48px;
    letter-spacing: -0.5px;
}
.steps-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    max-width: 800px;
    margin: 0 auto;
}
.step-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 24px;
}
.step-num {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 12px;
}
.step-card h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}
.step-card p {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.6;
}

@media (min-width: 600px) {
    .steps-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Footer */
.landing-footer {
    position: relative;
    z-index: 2;
    background: var(--bg);
    border-top: 1px solid var(--border);
    padding: 32px 24px;
    text-align: center;
}
.footer-socials {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 16px;
}
.social-link {
    color: var(--text-muted);
    transition: color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
}
.social-link:hover { color: var(--accent); border-color: var(--accent); }
.footer-copy {
    font-size: 13px;
    color: var(--text-dim);
}

/* ========= SCREENS ========= */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    transform: translateX(8px);
    overflow: hidden;
}
.screen.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
    z-index: 1;
}

/* Top bar */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
    min-height: 56px;
}
.top-title { font-size: 18px; font-weight: 600; }
.top-actions { display: flex; gap: 8px; }

.back-btn, .icon-btn {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}
.back-btn:hover, .icon-btn:hover { background: var(--bg-hover); }

/* Theme toggle icon visibility */
.icon-sun { display: none; }
.icon-moon { display: block; }
[data-theme="light"] .icon-sun { display: block; }
[data-theme="light"] .icon-moon { display: none; }

/* Content area */
.content-area {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.content-area.pad { padding: 16px; }

/* Auth */
.auth-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 32px 24px;
    background: transparent;
    position: relative;
    z-index: 2;
}
#screen-auth { background: transparent; }
#screen-auth .auth-form input {
    background: rgba(10, 10, 10, 0.6);
    border-color: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
[data-theme="light"] #screen-auth .auth-form input {
    background: rgba(255, 255, 255, 0.6);
    border-color: rgba(0, 0, 0, 0.15);
}
#screen-auth .logo { color: #fff; }
[data-theme="light"] #screen-auth .logo { color: var(--accent); }
#screen-auth .tagline { color: rgba(255,255,255,0.7); }
[data-theme="light"] #screen-auth .tagline { color: rgba(0,0,0,0.5); }
#screen-auth .auth-switch { color: rgba(255,255,255,0.6); }
[data-theme="light"] #screen-auth .auth-switch { color: rgba(0,0,0,0.5); }
#screen-auth .auth-back-link { color: rgba(255,255,255,0.5); }
[data-theme="light"] #screen-auth .auth-back-link { color: rgba(0,0,0,0.4); }
.brand { text-align: center; margin-bottom: 48px; }
.logo {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: -1px;
    color: var(--accent);
}
.tagline {
    font-size: 15px;
    color: var(--text-muted);
    margin-top: 8px;
    font-style: italic;
}
.auth-form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.auth-form.hidden { display: none; }
.auth-switch { font-size: 13px; color: var(--text-muted); text-align: center; }
.auth-switch a { color: var(--accent); text-decoration: none; }
.auth-back-link { margin-top: 20px; color: var(--text-muted); font-size: 13px; }

/* Inputs */
input[type="text"],
input[type="email"],
input[type="password"],
textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    padding: 12px 14px;
    outline: none;
    transition: border-color 0.15s;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: none; }

/* Buttons */
.btn-primary {
    background: var(--accent);
    color: var(--btn-text);
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    padding: 12px 20px;
    cursor: pointer;
    transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary.full { width: 100%; }

.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    padding: 12px 20px;
    cursor: pointer;
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-text {
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    padding: 8px;
}

/* Toggle switch */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    font-size: 14px;
    color: var(--text-muted);
    cursor: pointer;
}
.toggle-row.compact { padding: 4px 0; font-size: 13px; }
.toggle-row input { display: none; }
.toggle-switch {
    width: 40px;
    height: 22px;
    background: var(--border);
    border-radius: 11px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}
.toggle-switch::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text);
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
}
.toggle-row input:checked + .toggle-switch { background: var(--accent); }
.toggle-row input:checked + .toggle-switch::after { transform: translateX(18px); }

/* Cards */
.yarn-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin: 8px 16px;
    cursor: pointer;
    transition: background 0.15s;
}
.yarn-card:hover { background: var(--bg-hover); }
.yarn-card:first-child { margin-top: 12px; }
.yarn-card .card-meta {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.yarn-card .card-preview {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.yarn-card .card-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-dim);
}
.yarn-card.contributed { border-left: 3px solid var(--accent); }

/* Story entries */
.entry {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.entry:last-child { border-bottom: none; }
.entry-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.entry-author {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}
.entry-time { font-size: 11px; color: var(--text-dim); }
.entry-content { font-size: 15px; line-height: 1.6; }
.entry.mine { background: var(--accent-dim); margin: 0 -16px; padding: 12px 16px; border-radius: var(--radius-sm); }
.entry .report-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 6px;
}
.entry .report-btn:hover { color: var(--danger); }

/* Compose area */
.compose-area { margin: 16px 0; }
.compose-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
}
.char-count { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.char-count.warn { color: var(--danger); }

/* Bottom bar */
.bottom-bar {
    border-top: 1px solid var(--border);
    background: var(--bg);
    padding: 12px 16px;
    padding-bottom: calc(12px + var(--safe-bottom));
    flex-shrink: 0;
}
.action-row { display: flex; gap: 10px; margin-top: 10px; }
.action-row .btn-primary { flex: 1; }
.action-row .btn-secondary { flex: 0; white-space: nowrap; }

/* FAB */
.fab {
    position: absolute;
    bottom: calc(20px + var(--safe-bottom));
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--btn-text);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(155, 109, 255, 0.3);
    z-index: 10;
    transition: transform 0.15s;
}
.fab:hover { transform: scale(1.05); }

/* Chips */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0; -webkit-overflow-scrolling: touch; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 13px;
    padding: 6px 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}
.chip.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* Starters list */
.starter-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.starter-item {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 14px;
    line-height: 1.5;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--text-muted);
}
.starter-item:hover, .starter-item.selected { border-color: var(--accent); color: var(--text); background: var(--accent-dim); }
.starter-item .starter-cat {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    margin-bottom: 4px;
}

/* Tabs */
.tab-bar, .profile-tabs, .admin-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}
.tab {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.15s;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Profile */
.profile-header {
    display: flex;
    gap: 20px;
    align-items: center;
    margin-bottom: 24px;
}
.avatar-wrap { position: relative; flex-shrink: 0; }
.avatar-lg {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: var(--bg-input);
    border: 3px solid var(--border);
    background-size: cover;
    background-position: center;
}
.avatar-upload {
    position: absolute;
    bottom: 0;
    right: -2px;
    background: var(--accent);
    color: var(--btn-text);
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 10px;
    cursor: pointer;
}
.profile-info h3 { font-size: 20px; font-weight: 600; }
.muted { font-size: 13px; color: var(--text-muted); }
.badge {
    display: inline-block;
    background: var(--accent-dim);
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 4px;
}
.badge.hidden { display: none; }

/* Admin stats */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    text-align: center;
}
.stat-card .stat-num { font-size: 24px; font-weight: 700; color: var(--accent); }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px;
    padding-bottom: calc(24px + var(--safe-bottom));
    width: 100%;
    max-width: 500px;
}
.modal-content h3 { font-size: 16px; margin-bottom: 16px; }
.pass-reasons { display: flex; flex-direction: column; gap: 8px; }
.pass-reason {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    padding: 12px;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
}
.pass-reason:hover { border-color: var(--accent); background: var(--accent-dim); }

/* Error message */
.error-msg {
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.3);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 13px;
    padding: 10px 14px;
    margin-top: 12px;
    width: 100%;
    max-width: 340px;
    text-align: center;
}
.error-msg.hidden { display: none; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Section label */
.section-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

/* Admin table-like rows */
.admin-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.admin-row-actions { display: flex; gap: 8px; }
.admin-row-actions button {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 12px;
    padding: 4px 10px;
    cursor: pointer;
}
.admin-row-actions button:hover { border-color: var(--accent); color: var(--accent); }
.admin-row-actions button.danger:hover { border-color: var(--danger); color: var(--danger); }

/* Loading */
.loading {
    text-align: center;
    padding: 24px;
    color: var(--text-dim);
    font-size: 13px;
}

/* Utility */
.hidden { display: none; }

/* Toss to friend */
#toss-to-panel {
    margin-top: 10px;
}
#toss-to-panel input {
    margin-bottom: 6px;
}
.toss-to-results {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 160px;
    overflow-y: auto;
}
.toss-to-result {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    padding: 10px 12px;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    width: 100%;
}
.toss-to-result:hover { border-color: var(--accent); background: var(--accent-dim); }

/* Share modal */
.share-link-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.share-link-row input {
    flex: 1;
    font-size: 13px;
}
.share-link-row .btn-primary {
    white-space: nowrap;
    padding: 10px 16px;
}
.share-socials {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}
.share-social-btn {
    display: block;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    padding: 12px;
    text-align: center;
    text-decoration: none;
    transition: all 0.15s;
}
.share-social-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ========= DESKTOP ========= */
@media (min-width: 600px) {
    .auth-container { padding: 48px; }
    .yarn-card { margin: 8px auto; max-width: 560px; width: calc(100% - 32px); }
    .content-area.pad { max-width: 560px; margin: 0 auto; }
    .bottom-bar { max-width: 560px; margin: 0 auto; }
    .modal-content { border-radius: var(--radius); margin-bottom: 20vh; }
    .fab { right: calc(50% - 280px + 20px); }
    .landing-hero { padding: 120px 48px; }
    .landing-section { padding: 100px 48px; }
    .avatar-lg { width: 120px; height: 120px; }
}
