:root {
    --bg: var(--tg-theme-bg-color, #fff);
    --text: var(--tg-theme-text-color, #000);
    --hint: var(--tg-theme-hint-color, #999);
    --link: var(--tg-theme-link-color, #2481cc);
    --btn: var(--tg-theme-button-color, #2481cc);
    --btn-text: var(--tg-theme-button-text-color, #fff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
    --section-bg: var(--tg-theme-section-bg-color, #f5f5f5);
    --section-sep: var(--tg-theme-section-separator-color, #e0e0e0);
    --accent: var(--tg-theme-accent-text-color, #2481cc);
    --subtitle: var(--tg-theme-subtitle-text-color, #666);
    --destructive: #e53935;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
}

#app {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 16px 32px;
}

/* ====== HERO ====== */

.hero {
    position: relative;
    margin: 0 -16px 24px;
    padding: 48px 24px 40px;
    text-align: center;
    overflow: hidden;
    background: linear-gradient(135deg, var(--btn) 0%, color-mix(in srgb, var(--btn) 70%, var(--accent)) 100%);
}

.hero-glow {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.15) 0%, transparent 60%);
    pointer-events: none;
}

.hero-content { position: relative; z-index: 1; }

.hero-badge {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 20px;
    background: rgba(255,255,255,0.2);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 12px;
    backdrop-filter: blur(4px);
}

.hero-title {
    font-size: 36px;
    font-weight: 800;
    color: #fff;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
}

.hero-subtitle {
    font-size: 15px;
    color: rgba(255,255,255,0.85);
    margin-bottom: 28px;
    line-height: 1.5;
}

.hero-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.btn-hero {
    padding: 14px 24px;
    font-size: 15px;
    font-weight: 600;
    border-radius: 14px;
}

.btn-glass {
    background: rgba(255,255,255,0.2);
    color: #fff;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.25);
}

.btn-glass:active { background: rgba(255,255,255,0.3); }

/* ====== QUICK SEARCH ====== */

.quick-search {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--secondary-bg);
    border-radius: var(--radius-lg);
    padding: 4px 16px;
    margin-bottom: 24px;
    border: 1px solid var(--section-sep);
}

.search-input {
    border: none !important;
    background: transparent !important;
    padding: 12px 0 !important;
    font-size: 15px !important;
}

/* ====== SECTIONS ====== */

.section {
    margin-bottom: 28px;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.section-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.section-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    background: var(--secondary-bg);
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* ====== CARDS ====== */

.card-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.fanfic-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    background: var(--secondary-bg);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    border: 1px solid transparent;
}

.fanfic-card:active {
    transform: scale(0.98);
    border-color: var(--btn);
}

.fanfic-card-cover {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: var(--section-bg);
    flex-shrink: 0;
}

.fanfic-card-info {
    flex: 1;
    min-width: 0;
}

.fanfic-card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fanfic-card-owner {
    font-size: 12px;
    color: var(--hint);
    margin-top: 1px;
}

.fanfic-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.fanfic-card-tag {
    padding: 2px 8px;
    background: var(--section-bg);
    border-radius: 6px;
    font-size: 10px;
    color: var(--hint);
    font-weight: 500;
}

.fanfic-card-fandoms {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 2px;
}

.fanfic-card-fandom {
    padding: 2px 8px;
    background: var(--btn);
    color: var(--btn-text);
    border-radius: 6px;
    font-size: 10px;
    font-weight: 500;
    opacity: 0.85;
}

.fanfic-card-rating {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--hint);
    margin-top: 4px;
}

.fanfic-card-rating .star-filled { color: #ffb300; }
.fanfic-card-rating .star-empty { opacity: 0.3; }

.fanfic-card-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}

.fanfic-card-date {
    font-size: 11px;
    color: var(--hint);
}

/* ====== SKELETON LOADING ====== */

.skeleton-list { display: flex; flex-direction: column; gap: 10px; }

.skeleton-card {
    height: 72px;
    background: linear-gradient(90deg, var(--section-bg) 25%, var(--secondary-bg) 50%, var(--section-bg) 75%);
    background-size: 200% 100%;
    border-radius: var(--radius-md);
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes skeleton-pulse {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ====== ABOUT ====== */

.about-section {
    margin-top: 8px;
}

.about-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.about-card {
    padding: 18px 14px;
    background: var(--secondary-bg);
    border-radius: var(--radius-md);
    text-align: center;
    border: 1px solid var(--section-sep);
}

.about-icon {
    width: 32px;
    height: 32px;
    margin-bottom: 8px;
}

.about-card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.about-card p {
    font-size: 12px;
    color: var(--hint);
    line-height: 1.4;
}

/* ====== SEARCH OVERLAY ====== */

.search-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s;
}

.search-overlay-content {
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    background: var(--bg);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    overflow-y: auto;
    padding: 20px 16px 24px;
    animation: slideUp 0.25s ease-out;
}

.search-overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.search-overlay-header h3 {
    font-size: 17px;
    font-weight: 700;
}

.btn-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    opacity: 0.5;
}

.btn-close:hover { opacity: 1; }

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

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

/* ====== GENERAL ====== */

.hidden { display: none !important; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.12s, opacity 0.15s;
    text-decoration: none;
}

.btn:active { transform: scale(0.96); }

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

.btn-secondary {
    background: var(--secondary-bg);
    color: var(--text);
    border: 1px solid var(--section-sep);
}

.btn-full { width: 100%; }

.btn-back {
    background: var(--secondary-bg);
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.btn-back:active { opacity: 0.6; }

.btn-sm {
    padding: 8px 12px;
    font-size: 14px;
    border-radius: var(--radius-sm);
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    opacity: 0.5;
    transition: opacity 0.15s;
}

.btn-icon:hover { opacity: 1; }

.icon { width: 24px; height: 24px; flex-shrink: 0; }
.icon-sm { width: 20px; height: 20px; flex-shrink: 0; }
.icon-xs { width: 18px; height: 18px; flex-shrink: 0; }

/* ====== HEADER ====== */

.header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding-top: 8px;
}

.header h2 {
    font-size: 20px;
    font-weight: 700;
    flex: 1;
}

/* ====== FIELDS ====== */

.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--hint);
    margin-top: 18px;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.field-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--section-sep);
    border-radius: var(--radius-md);
    background: var(--secondary-bg);
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.field-input:focus {
    border-color: var(--btn);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--btn) 20%, transparent);
}

.field-textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--section-sep);
    border-radius: var(--radius-md);
    background: var(--secondary-bg);
    color: var(--text);
    font-size: 15px;
    resize: vertical;
    outline: none;
    font-family: inherit;
    min-height: 90px;
    transition: border-color 0.2s;
}

.field-textarea:focus {
    border-color: var(--btn);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--btn) 20%, transparent);
}

/* ====== COVER UPLOAD ====== */

.cover-upload {
    width: 100%;
    min-height: 130px;
    border: 2px dashed var(--section-sep);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--hint);
    font-size: 14px;
    gap: 8px;
    overflow: hidden;
    position: relative;
    transition: border-color 0.2s, background 0.2s;
}

.cover-upload:hover {
    border-color: var(--btn);
    background: color-mix(in srgb, var(--btn) 5%, transparent);
}

.cover-preview {
    max-width: 100%;
    max-height: 220px;
    object-fit: contain;
}

/* ====== AUTOCOMPLETE ====== */

.autocomplete-wrap { position: relative; }

.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg);
    border: 1px solid var(--section-sep);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    z-index: 100;
    display: none;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.autocomplete-list.visible { display: block; }

.autocomplete-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    transition: background 0.12s;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: var(--secondary-bg);
}

/* ====== AUTHORS ====== */

.authors-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.author-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--secondary-bg);
    border-radius: 20px;
    font-size: 13px;
    border: 1px solid var(--section-sep);
}

.author-chip img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}

.author-remove { cursor: pointer; opacity: 0.5; }
.author-remove:hover { opacity: 1; }

.coauthor-add {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

/* ====== DIVIDER ====== */

.divider {
    border: none;
    border-top: 1px solid var(--section-sep);
    margin: 24px 0;
}

/* ====== PARTS LIST ====== */

.parts-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}

.part-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--secondary-bg);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.12s;
    border: 1px solid transparent;
}

.part-item:active {
    transform: scale(0.98);
    border-color: var(--btn);
}

.part-item .part-title {
    font-size: 15px;
    font-weight: 500;
}

.part-delete {
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.4;
    padding: 4px;
    transition: opacity 0.15s;
}

.part-delete:hover { opacity: 1; }

/* ====== STATS ====== */

.stats-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 4px;
}

.stat-card {
    background: var(--secondary-bg);
    border-radius: var(--radius-md);
    padding: 14px 10px;
    text-align: center;
    border: 1px solid var(--section-sep);
}

.stat-value {
    font-size: 26px;
    font-weight: 800;
    color: var(--btn);
}

.stat-label {
    font-size: 11px;
    color: var(--hint);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.progress-bar {
    height: 6px;
    background: var(--section-sep);
    border-radius: 3px;
    margin-top: 6px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--btn);
    border-radius: 3px;
    transition: width 0.3s;
}

/* ====== FANFIC VIEW ====== */

.fanfic-cover {
    width: 100%;
    max-height: 320px;
    object-fit: cover;
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.fanfic-description {
    color: var(--text);
    font-size: 15px;
    line-height: 1.7;
    margin-bottom: 16px;
    white-space: pre-wrap;
}

.fanfic-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.fanfic-tag {
    padding: 4px 12px;
    background: var(--secondary-bg);
    border-radius: 8px;
    font-size: 12px;
    color: var(--hint);
    font-weight: 500;
}

.rating-display {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--hint);
}

/* ====== MODAL ====== */

.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s;
}

.modal-content {
    background: var(--bg);
    border-radius: var(--radius-xl);
    padding: 28px 24px;
    max-width: 90%;
    width: 360px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.25s ease-out;
}

.modal-content h3 {
    margin-bottom: 16px;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
}

.star-rating {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
}

.star {
    cursor: pointer;
    opacity: 0.25;
    transition: opacity 0.15s, transform 0.15s;
}

.star.active { opacity: 1; }
.star:active { transform: scale(1.2); }

/* ====== DRAFT STATUS ====== */

.draft-status {
    text-align: center;
    font-size: 12px;
    color: var(--hint);
    margin-top: 10px;
    opacity: 0;
    transition: opacity 0.3s;
}

.draft-status.visible { opacity: 1; }

/* ====== SEARCH ADVANCED ====== */

.search-advanced { margin-bottom: 20px; }
.search-advanced .btn { margin-top: 16px; }
.search-result-count {
    text-align: center;
    font-size: 14px;
    color: var(--hint);
    margin-bottom: 14px;
}

/* ====== EMPTY / PLACEHOLDER ====== */

.placeholder {
    text-align: center;
    color: var(--hint);
    padding: 48px 20px;
    font-size: 14px;
}

/* ====== RESPONSIVE ====== */

/* ====== PROFILE ====== */

.profile-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--secondary-bg);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    border: 1px solid var(--section-sep);
}

.profile-avatar-img {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--section-bg);
}

.profile-name {
    font-size: 20px;
    font-weight: 700;
}

.profile-username {
    font-size: 14px;
    color: var(--hint);
    margin-top: 2px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 24px;
}

.stat-card-lg {
    background: var(--secondary-bg);
    border-radius: var(--radius-md);
    padding: 16px 8px;
    text-align: center;
    border: 1px solid var(--section-sep);
}

.stat-value-lg {
    font-size: 28px;
    font-weight: 800;
    color: var(--btn);
}

.skeleton-num {
    color: var(--section-sep) !important;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.fanfic-card-bottom {
    display: flex;
    align-items: center;
    gap: 12px;
}

.coauthor-add .btn-sm {
    background: var(--btn);
    color: var(--btn-text);
    border: none;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
}

/* ====== RESPONSIVE ====== */

@media (max-width: 400px) {
    .hero { padding: 36px 16px 32px; }
    .hero-title { font-size: 28px; }
    .hero-actions { flex-direction: column; }
    .about-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}
