/* === Shared base styles === */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: white;
}

/* === Stories Homepage === */

.stories-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 24px;
    gap: 16px;
}

.stories-header h1 {
    font-size: 2rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

/* Tab bar */
.tab-bar {
    display: flex;
    gap: 0;
    background: rgba(255,255,255,0.15);
    border-radius: 16px;
    padding: 4px;
    max-width: 320px;
}

.tab-btn {
    flex: 1;
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    color: rgba(255,255,255,0.7);
    background: transparent;
    transition: background 0.2s, color 0.2s;
}

.tab-btn:hover {
    color: white;
    background: rgba(255,255,255,0.1);
}

.tab-btn.active {
    background: white;
    color: #333;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* New Story Section */
.new-story-section {
    padding: 0 24px 24px;
}

.new-story-section h2 {
    font-size: 1.4rem;
    margin-bottom: 16px;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.15);
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    max-width: 500px;
    margin-bottom: 20px;
}

.theme-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 20px;
    padding: 20px 16px;
    cursor: pointer;
    min-height: 120px;
    min-width: 120px;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}

.theme-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.theme-btn:active {
    transform: translateY(-1px);
}

.theme-penguins {
    background: linear-gradient(135deg, #74b9ff, #0984e3);
    color: white;
}

.theme-pigs {
    background: linear-gradient(135deg, #fab1a0, #e17055);
    color: white;
}

.theme-clocks {
    background: linear-gradient(135deg, #ffeaa7, #fdcb6e);
    color: #333;
}

.theme-bible {
    background: linear-gradient(135deg, #a29bfe, #6c5ce7);
    color: white;
}

.theme-emoji {
    font-size: 3rem;
    margin-bottom: 8px;
    display: block;
}

.theme-label {
    font-size: 1.1rem;
    font-weight: 700;
}

/* Custom prompt */
.custom-prompt-section {
    display: flex;
    gap: 12px;
    max-width: 500px;
    align-items: stretch;
}

.custom-input {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 14px;
    font-size: 1rem;
    background: rgba(255,255,255,0.9);
    color: #333;
    min-height: 48px;
}

.custom-input::placeholder {
    color: #999;
}

.generate-btn {
    background: linear-gradient(135deg, #00b894, #00cec9);
    color: white;
    border: none;
    border-radius: 14px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    min-height: 48px;
    min-width: 48px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

/* Bookshelf */
.bookshelf-section {
    padding: 24px;
}

.bookshelf-section h2 {
    font-size: 1.4rem;
    margin-bottom: 16px;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.15);
}

.bookshelf-row {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 12px;
    -webkit-overflow-scrolling: touch;
}

.bookshelf-row::-webkit-scrollbar {
    height: 6px;
}

.bookshelf-row::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.3);
    border-radius: 3px;
}

.book-card {
    flex-shrink: 0;
    width: 150px;
    text-decoration: none;
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.2s;
}

.book-card:hover {
    transform: translateY(-4px);
}

.book-cover {
    width: 150px;
    height: 200px;
    border-radius: 12px;
    object-fit: cover;
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    background: rgba(255,255,255,0.1);
}

.book-title {
    margin-top: 8px;
    font-size: 0.9rem;
    text-align: center;
    font-weight: 600;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.book-status {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 4px;
}

.empty-shelf {
    font-size: 1rem;
    opacity: 0.7;
}

/* Progress Overlay */
.progress-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.progress-overlay.hidden {
    display: none;
}

.progress-content {
    text-align: center;
    padding: 40px;
}

.progress-animation {
    font-size: 5rem;
    animation: bounce 1.2s ease-in-out infinite;
    margin-bottom: 24px;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

.progress-stage {
    font-size: 1.4rem;
    margin-bottom: 20px;
    color: white;
}

.progress-bar-container {
    width: 280px;
    height: 24px;
    background: rgba(255,255,255,0.2);
    border-radius: 12px;
    overflow: hidden;
    margin: 0 auto 12px;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #00b894, #55efc4);
    border-radius: 12px;
    transition: width 0.5s ease;
}

.progress-percent {
    font-size: 1.2rem;
    color: white;
    font-weight: 700;
}

/* === Story Reader === */

.reader-body {
    background: #1a1a2e;
    min-height: 100vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.exit-btn {
    position: fixed;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.2);
    color: white;
    font-size: 1.4rem;
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.exit-btn:hover {
    background: rgba(255,255,255,0.4);
}

.page-container {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    transition: opacity 0.4s ease;
}

.page-container.fade-out {
    opacity: 0;
}

.page-container.fade-in {
    opacity: 1;
}

.page-image {
    width: 100%;
    max-height: 60vh;
    object-fit: contain;
    border-radius: 16px;
    margin-bottom: 24px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}

.page-text {
    font-size: 22px;
    color: white;
    text-align: center;
    line-height: 1.6;
    max-width: 600px;
    padding: 0 16px;
}

.end-card {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
}

.end-card.visible {
    display: flex;
}

.end-stars {
    font-size: 4rem;
    animation: bounce-star 1.5s ease-in-out infinite;
    margin-bottom: 24px;
}

@keyframes bounce-star {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.end-title {
    font-size: 3rem;
    color: white;
    font-weight: 800;
    text-shadow: 2px 2px 8px rgba(0,0,0,0.3);
}

.end-subtitle {
    font-size: 1.2rem;
    color: rgba(255,255,255,0.7);
    margin-top: 16px;
}

/* Loading state for reader */
.reader-loading {
    color: white;
    font-size: 1.4rem;
    text-align: center;
}

/* Splash screen */
.splash-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
    width: 100%;
    max-width: 800px;
}

.splash-cover {
    width: 100%;
    max-height: 50vh;
    object-fit: contain;
    border-radius: 16px;
    margin-bottom: 24px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}

.splash-title {
    font-size: 2rem;
    color: white;
    font-weight: 800;
    text-shadow: 2px 2px 8px rgba(0,0,0,0.3);
    margin-bottom: 24px;
}

.splash-start-btn {
    background: linear-gradient(135deg, #00b894, #55efc4);
    color: white;
    border: none;
    border-radius: 24px;
    padding: 20px 48px;
    font-size: 1.6rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    transition: transform 0.2s, box-shadow 0.2s;
    min-width: 200px;
    min-height: 64px;
}

.splash-start-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

.splash-start-btn:active {
    transform: translateY(-1px);
}

.splash-screen.hidden,
.page-container.hidden,
.splash-cover.hidden {
    display: none;
}

/* Image shimmer placeholder */
.shimmer-placeholder {
    width: 100%;
    max-height: 60vh;
    min-height: 200px;
    border-radius: 16px;
    margin-bottom: 24px;
    background: linear-gradient(90deg, rgba(255,255,255,0.05) 25%, rgba(255,255,255,0.15) 50%, rgba(255,255,255,0.05) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

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

/* Page progress dots */
.page-dots {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 50;
    padding: 8px 16px;
    background: rgba(0,0,0,0.3);
    border-radius: 20px;
}

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

.page-dot.active {
    background: white;
    transform: scale(1.3);
}

.page-dot.done {
    background: rgba(255,255,255,0.6);
}

/* Tap to continue hint */
.tap-hint {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.7);
    font-size: 1rem;
    z-index: 50;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
    animation: none;
}

.tap-hint.visible {
    opacity: 1;
    animation: pulse-hint 2s ease-in-out infinite;
}

@keyframes pulse-hint {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* Responsive: Tablet */
@media (max-width: 768px) {
    .stories-header { padding: 16px; }
    .stories-header h1 { font-size: 1.6rem; }
    .tab-btn { font-size: 1rem; padding: 10px 18px; }
    .new-story-section { padding: 0 16px 16px; }
    .theme-grid { max-width: 100%; }
    .theme-btn { min-height: 100px; padding: 16px 12px; }
    .theme-emoji { font-size: 2.5rem; }
    .custom-prompt-section { max-width: 100%; }
    .bookshelf-section { padding: 16px; }
    .page-text { font-size: 20px; }
}

/* Responsive: Phone */
@media (max-width: 480px) {
    .stories-header { padding: 12px; gap: 10px; }
    .stories-header h1 { font-size: 1.3rem; }
    .theme-grid { gap: 10px; }
    .theme-btn { min-height: 90px; min-width: unset; padding: 14px 10px; }
    .theme-emoji { font-size: 2rem; }
    .theme-label { font-size: 0.95rem; }
    .custom-prompt-section { flex-direction: column; }
    .book-card { width: 120px; }
    .book-cover { width: 120px; height: 160px; }
    .book-title { max-width: 120px; font-size: 0.8rem; }
    .progress-animation { font-size: 3.5rem; }
    .progress-bar-container { width: 220px; }
    .page-text { font-size: 18px; }
    .end-title { font-size: 2.2rem; }
    .splash-title { font-size: 1.5rem; }
    .splash-start-btn { font-size: 1.3rem; padding: 16px 36px; }
}
