/* CSS Variables */
:root {
    --color-bg: #0f0f0f;
    --color-surface: #1a1a1a;
    --color-surface-hover: #252525;
    --color-border: #333;
    --color-text: #e8e8e8;
    --color-text-muted: #888;
    --color-primary: #ff4444;
    --color-primary-hover: #ff6666;
    --color-star: #ffd700;
    --color-star-empty: #444;
    --color-success: #22c55e;
    --color-error: #ef4444;
    
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.5);
    
    --transition: 150ms ease;
    
    --header-height: 60px;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    color: var(--color-primary-hover);
}

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    height: var(--header-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
}

.logo:hover {
    color: var(--color-primary);
}

.nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-greeting {
    display: none;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

@media (min-width: 640px) {
    .user-greeting {
        display: inline;
        margin-right: 0.5rem;
    }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    color: white;
}

.btn-secondary {
    background: var(--color-surface-hover);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-border);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
}

.btn-ghost:hover {
    color: var(--color-text);
    background: var(--color-surface-hover);
}

.btn-small {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
}

.btn-full {
    width: 100%;
}

/* Main */
.main {
    padding: 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

/* Search */
.search-section {
    margin-bottom: 1rem;
}

.search-input {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    color: var(--color-text);
    outline: none;
    transition: border-color var(--transition);
}

.search-input:focus {
    border-color: var(--color-primary);
}

.search-input::placeholder {
    color: var(--color-text-muted);
}

/* Category Tabs */
.category-tabs {
    display: flex;
    gap: 0.5rem;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
}

.category-tabs::-webkit-scrollbar {
    display: none;
}

.category-tab {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-size: 0.875rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition);
    flex-shrink: 0;
}

.category-tab:hover,
.category-tab.active {
    background: var(--color-surface-hover);
    border-color: var(--color-primary);
    color: var(--color-text);
}

.category-icon {
    font-size: 1rem;
}

/* Channel Grid */
.channel-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

@media (min-width: 640px) {
    .channel-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

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

/* Channel Card */
.channel-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1rem;
    transition: all var(--transition);
}

.channel-card:hover {
    border-color: var(--color-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.channel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.channel-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.3;
}

.channel-name:hover {
    color: var(--color-primary);
}

.channel-category {
    font-size: 1.5rem;
    cursor: default;
}

.channel-description {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.625rem;
}

.channel-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.channel-meta-row {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
}
.channel-added-by {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    font-style: italic;
}
.card-actions {
    display: flex;
    gap: 0.25rem;
}

.rating-display {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.stars, .stars-large {
    color: var(--color-star);
    letter-spacing: -1px;
}

.rating-value {
    font-weight: 600;
    font-size: 0.875rem;
}

.rating-count {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.no-rating {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-style: italic;
}

.rating-input {
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
}

.modal-rating-input {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--color-bg);
    border-radius: var(--radius-md);
}

.modal-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding-right: 2rem;
    margin-bottom: 0.4rem;
}

.modal-header-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    font-size: 0.875rem;
}

.modal-rating-summary {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.added-by {
    color: var(--color-text-muted);
}

.btn-icon {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    opacity: 0.7;
    transition: opacity var(--transition);
}

.btn-icon:hover {
    opacity: 1;
    background: var(--color-surface-hover);
}

.rate-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.star-buttons {
    display: flex;
    gap: 0.125rem;
}
.star-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--color-star-empty);
    cursor: pointer;
    padding: 0.125rem;
    transition: all var(--transition);
    line-height: 1;
}

.star-btn:hover,
.star-btn:hover ~ .star-btn,
.star-btn.active,
.star-btn.active ~ .star-btn {
    color: var(--color-star);
}

/* Empty State */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
}

.empty-state p {
    margin-bottom: 1rem;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 200;
    animation: fadeIn 150ms ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: slideUp 200ms ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 639px) {
    .modal {
        max-height: 100vh;
        height: 100%;
        border-radius: 0;
    }
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--color-text-muted);
    cursor: pointer;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

.modal-close:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
    padding-right: 2rem;
}

.modal-header h2 a {
    color: var(--color-text);
}

.modal-header h2 a:hover {
    color: var(--color-primary);
}

.channel-category-large {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.modal-body {
    padding: 1.5rem;
}

.channel-description-full {
    margin-bottom: 1rem;
    color: var(--color-text-muted);
}

.channel-meta {
    margin-bottom: 1rem;
}

.rating-display-large {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.stars-large {
    font-size: 1.25rem;
}

.rating-value-large {
    font-size: 1.25rem;
    font-weight: 700;
}

.added-by {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 1.5rem 0;
}

/* Comments */
.comments-section h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
}

.comment-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.comment-form textarea {
    width: 100%;
    padding: 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.875rem;
    resize: vertical;
}

.comment-form textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}

.comment-form button {
    align-self: flex-end;
}

.comments-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.comment {
    padding: 0.75rem;
    background: var(--color-bg);
    border-radius: var(--radius-md);
}

.comment-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

.comment-author {
    font-size: 0.875rem;
}

.comment-time {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.comment-content {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.no-comments {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    font-style: italic;
}

.login-prompt {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: 1rem;
}

/* Auth Forms */
.auth-container {
    max-width: 400px;
    margin: 2rem auto;
    padding: 2rem;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
}

.auth-container h1 {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
}

.form-group input,
.form-group textarea {
    padding: 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-size: 1rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}

.form-group small {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.input-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.auth-switch {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--color-error);
    color: var(--color-error);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

/* Channel Form */
.form-container {
    max-width: 600px;
    margin: 2rem auto;
    padding: 2rem;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
}

.form-container h1 {
    margin-bottom: 1.5rem;
}

.channel-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.category-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

@media (min-width: 640px) {
    .category-selector {
        grid-template-columns: repeat(6, 1fr);
    }
}

.category-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 0.5rem;
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
}

.category-option:hover {
    border-color: var(--color-primary);
}

.category-option input {
    display: none;
}

.category-option:has(input:checked) {
    border-color: var(--color-primary);
    background: rgba(255, 68, 68, 0.1);
}

.category-icon-large {
    font-size: 1.5rem;
}

.category-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

/* Own card - subtle tint */
.channel-card-own {
    border-color: #2a2a3a;
    background: #1c1c2a;
}

/* Username of who added the card */
.channel-added-by {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    font-style: italic;
    align-self: center;
}

/* HTMX loading indicator */
.htmx-request {
    opacity: 0.6;
    pointer-events: none;
}

.htmx-request::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1.5rem;
    height: 1.5rem;
    margin: -0.75rem 0 0 -0.75rem;
    border: 2px solid var(--color-text);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
