/* YarnToss — Dark, minimal, mobile-first */

:root {
    --bg: #0a0a0a;
    --bg-card: #141414;
    --bg-input: #1a1a1a;
    --bg-hover: #1f1f1f;
    --border: #2a2a2a;
    --text: #e8e8e8;
    --text-muted: #888;
    --text-dim: #555;
    --accent: #c8a2ff;
    --accent-dim: rgba(200, 162, 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);
}

* { 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; }

/* 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); }

/* 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;
}
.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; }

/* 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: #0a0a0a;
    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: #0a0a0a;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(200, 162, 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: 16px;
    align-items: center;
    margin-bottom: 20px;
}
.avatar-wrap { position: relative; flex-shrink: 0; }
.avatar-lg {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--bg-input);
    border: 2px solid var(--border);
    background-size: cover;
    background-position: center;
}
.avatar-upload {
    position: absolute;
    bottom: -4px;
    right: -4px;
    background: var(--accent);
    color: #0a0a0a;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 8px;
    cursor: pointer;
}
.profile-info h3 { font-size: 18px; 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: rgba(0,0,0,0.7);
    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;
}

/* 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; }

/* 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); }
}
