:root {
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --surface-light: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --accent-color: #ec4899;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --border-color: #334155;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* iOS Safari fix */
    width: 100vw;
}

/* iOS Safari form element appearance fix */
input, button, select, textarea {
    -webkit-appearance: none;
    appearance: none;
}

/* Glassmorphism utils */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

/* Auth */
.auth-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
}

.auth-logo {
    text-align: center;
    margin-bottom: 3rem;
}

.logo-circle {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    box-shadow: 0 10px 25px -5px rgba(99, 102, 241, 0.5);
}

.logo-number {
    font-size: 3rem;
    font-weight: 900;
    color: white;
}

.auth-title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-form {
    width: 100%;
    max-width: 350px;
    background: var(--surface-color);
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

.form-group {
    margin-bottom: 1.5rem;
}

input {
    width: 100%;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
}

input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.btn {
    padding: 1rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

.btn-full {
    width: 100%;
}

.auth-switch {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.auth-switch a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.hidden {
    display: none !important;
}

/* App Header */
#app-header {
    padding: 1.5rem 1.5rem 1rem;
    background: var(--bg-color);
    z-index: 10;
}

.header-content {
    display: flex;
    align-items: center;
    margin-bottom: 1.5rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-logo {
    width: 45px;
    height: 45px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-logo-num {
    font-size: 1.5rem;
    font-weight: 800;
}

.header-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.header-quote {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
}

.category-chips {
    display: flex;
    overflow-x: auto;
    gap: 0.75rem;
    padding-bottom: 0.5rem;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

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

.chip {
    padding: 0.5rem 1rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
}

.chip.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Main Content */
#app-main {
    flex: 1;
    overflow-y: auto;
    position: relative;
    padding-bottom: 80px; /* footer space */
}

.page {
    display: none;
}

.page.active {
    display: block;
}

.feed-container {
    padding: 1rem;
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 1.25rem;
}

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

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

/* Post Cards */
.post-card {
    background: var(--surface-color);
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.2s;
}

.post-card:active {
    transform: scale(0.98);
}

.post-card-img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: var(--surface-light);
}

.post-card-content {
    padding: 1.25rem;
}

.post-category-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.post-title {
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

.post-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-badge {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(34, 197, 94, 0.2);
    color: var(--success-color);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    backdrop-filter: blur(4px);
}

/* Post Viewer */
.post-viewer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-color);
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.post-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    z-index: 2;
}

.btn-icon {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
}

#post-viewer-title {
    font-weight: 600;
    font-size: 1.1rem;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0 1rem;
}

#post-viewer-pages {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

.post-viewer-layout {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    gap: 1.5rem;
}

.post-main-content {
    flex: 1;
    width: 100%;
}

.post-sidebar {
    width: 100%;
}

@media (min-width: 1024px) {
    .post-viewer-layout {
        flex-direction: row;
        align-items: stretch;
        padding: 2rem 1rem 2rem 2rem; /* less padding on right for sidebar scrollbar */
        overflow: hidden;
    }
    
    .post-main-content {
        height: 100%;
        overflow-y: auto;
        padding-right: 1rem;
    }
    
    .post-sidebar {
        width: 350px;
        flex-shrink: 0;
        height: 100%;
        overflow-y: auto;
        padding-right: 1rem;
    }
}

.post-viewer-content {
    flex: 1;
}

.post-slides {
    display: flex;
    flex-direction: row;
    width: 100%;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    gap: 0;
}

.post-slide {
    flex: 0 0 100%;
    scroll-snap-align: start;
    width: 100%;
    padding-bottom: 2rem;
}

@media (min-width: 1024px) {
    .post-slides {
        flex-direction: column;
        overflow-x: visible;
        scroll-snap-type: none;
        gap: 2rem;
    }
    .post-slide {
        flex: none;
        border-bottom: 1px solid var(--border-color);
    }
    .post-slide:last-child {
        border-bottom: none;
    }
}

.slide-image {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    background: #000;
    border-radius: 12px;
}

.slide-text {
    width: 100%;
    padding: 1.5rem;
    font-size: 1.1rem;
    line-height: 1.6;
}

.post-main-title {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 1.5rem;
    color: var(--text-color, #fff);
}

.slide-text p {
    margin-bottom: 1rem;
}

.slide-text h2 {
    font-size: 1.5rem;
    margin: 1.5rem 0 1rem;
    color: var(--primary-color);
}

.slide-text ul {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

/* Dots */
.post-viewer-dots {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--surface-color);
}

@media (min-width: 1024px) {
    .post-viewer-dots {
        display: none;
    }
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transition: all 0.2s;
}

.dot.active {
    background: var(--primary-color);
    width: 24px;
    border-radius: 4px;
}

/* Footer Nav */
#app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 50;
}

.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    transition: color 0.2s;
    width: 25%;
}

.nav-btn.active {
    color: var(--primary-color);
}

.nav-icon {
    font-size: 1.5rem;
}

.nav-label {
    font-size: 0.7rem;
    font-weight: 500;
}

/* Toast */
#toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 90%;
    max-width: 400px;
}

.toast {
    background: var(--surface-color);
    color: white;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: slideDown 0.3s forwards;
    border-left: 4px solid var(--primary-color);
}

.toast.error {
    border-color: var(--danger-color);
}

.toast.success {
    border-color: var(--success-color);
}

@keyframes slideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Page headers */
.page-header-inner {
    padding: 1.5rem;
    background: var(--surface-color);
    margin-bottom: 1rem;
}

.page-header-inner h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.page-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Ranking */
.rank-period-tabs {
    display: flex;
    background: var(--bg-color);
    border-radius: 8px;
    padding: 4px;
    margin-top: 1rem;
}

.rank-tab {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
}

.rank-tab.active {
    background: var(--surface-light);
    color: white;
}

.ranking-list {
    padding: 1rem;
}

.rank-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    background: var(--surface-color);
    border-radius: 12px;
    margin-bottom: 0.75rem;
}

.rank-pos {
    font-size: 1.25rem;
    font-weight: 800;
    width: 30px;
    color: var(--text-secondary);
}

.rank-pos.gold { color: #fbbf24; }
.rank-pos.silver { color: #94a3b8; }
.rank-pos.bronze { color: #b45309; }

.rank-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface-light);
    margin-right: 1rem;
    object-fit: cover;
}

.rank-info {
    flex: 1;
}

.rank-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.rank-score {
    font-size: 0.8rem;
    color: var(--success-color);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1rem;
}

.modal-content {
    background: var(--surface-color);
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.test-questions {
    padding: 1.5rem;
}

.test-item {
    margin-bottom: 2rem;
}

.test-q {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.test-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.test-opt {
    padding: 1rem;
    background: var(--surface-light);
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.test-opt:hover {
    background: rgba(99, 102, 241, 0.1);
}

.test-opt.selected {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.test-opt.correct {
    border-color: var(--success-color);
    background: rgba(34, 197, 94, 0.1);
}

.test-opt.wrong {
    border-color: var(--danger-color);
    background: rgba(239, 68, 68, 0.1);
}

.btn-test-submit {
    margin-top: 1rem;
}

.test-result {
    padding: 2rem;
    text-align: center;
}

.result-circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 8px solid var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    font-size: 2rem;
    font-weight: 800;
}

/* Review Post Card */
.review-card {
    background: var(--surface-color);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.review-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

.review-info {
    flex: 1;
}

.review-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.review-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.review-action button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
}

/* Loading */
.loading-spinner {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 1s linear infinite;
}

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

/* Profile */
.profile-header {
    text-align: center;
    padding: 2rem;
    background: var(--surface-color);
    margin-bottom: 1rem;
}

.profile-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--surface-light);
    margin: 0 auto 1rem;
    object-fit: cover;
    border: 4px solid var(--primary-color);
}

.profile-name {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.profile-title {
    display: inline-block;
    background: rgba(236, 72, 153, 0.2);
    color: var(--accent-color);
    padding: 0.25rem 1rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.stats-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 1rem;
}

.stat-box {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: 12px;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.profile-actions {
    padding: 1rem;
}

/* Recommendation Cards */
.rec-card {
    display: flex;
    flex-direction: column;
    margin-bottom: 1.5rem;
    cursor: pointer;
    background: var(--surface-color);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.rec-card-img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: var(--surface-light);
}

.rec-card-info {
    padding: 1rem;
    flex: 1;
}

.rec-card-title {
    font-size: 1rem;
    margin: 0 0 0.5rem 0;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rec-card-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

