/* Base reset and typography */
:root {
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);

    /* Color palette */
    --bg: #FFFFFF;
    --text-primary: #111111;
    --text-secondary: #6B6B6B;
    --text-tertiary: #9E9E9E;
    --accent: #3A3A3A;
    --divider: #E5E5E5;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: #f5f5f5;
}

/* Container */
.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 1rem;
    padding-top: calc(1rem + var(--safe-t));
    min-height: 100vh;
    min-height: 100dvh;
}

/* App bar */
.app-bar {
    position: sticky;
    top: calc(-1rem - var(--safe-t));
    margin: calc(-1rem - var(--safe-t)) -1rem 1rem;
    padding: 1rem;
    padding-top: calc(1rem + var(--safe-t));
    background: #f5f5f5;
    z-index: 10;
    transition: box-shadow 0.2s;
}

.app-bar.scrolled {
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.app-bar-main {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 40px;
    position: relative;
}

.about-icon {
    position: absolute;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    color: var(--text-secondary);
    text-decoration: none;
}

.about-icon:active {
    background: #F2F2F2;
    border-radius: 50%;
}

.about-icon-bottom {
    position: fixed;
    bottom: 16px;
    right: 16px;
}

.app-bar-icon {
    width: 28px;
    height: 28px;
}

.app-bar-title {
    margin: 0;
    font-family: 'Inter', sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
}

.app-bar-tagline {
    margin: 0.25rem 0 0;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    max-height: 1.5em;
    overflow: hidden;
    transition: max-height 0.2s, margin 0.2s, opacity 0.2s;
}

.app-bar.scrolled .app-bar-tagline {
    max-height: 0;
    margin: 0;
    opacity: 0;
}

/* Subject sections (home) */
.subject-section {
    margin-bottom: 1.5rem;
}

.subject-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.5rem;
}

.subject-heading {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

.subject-heading a {
    color: inherit;
    text-decoration: none;
}

.view-all-link {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-decoration: none;
}

.view-all-link:hover {
    color: var(--accent);
}

.subject-page-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 0.5rem;
}

/* Collection list (home) */
.collection-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.collection-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--bg);
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: box-shadow 0.2s, transform 0.2s;
}

.collection-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transform: translateY(-1px);
}

.collection-card:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.collection-thumb {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.collection-monogram {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F2F2F2;
    color: var(--text-tertiary);
    font-weight: 500;
    font-size: 0.85rem;
}

.collection-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.collection-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.collection-chevron {
    flex-shrink: 0;
    color: var(--text-tertiary);
}

/* Collection detail page */
.coll-header {
    margin-bottom: 1.5rem;
}

.coll-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.coll-topbar-brand {
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-decoration: none;
}

.coll-topbar-link {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-decoration: none;
}

.coll-topbar-link:hover {
    color: var(--accent);
}

.back-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin: 1.5rem auto 0;
    color: var(--text-tertiary);
}

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

.coll-hero {
    display: flex;
    align-items: flex-start;
    gap: 0.875rem;
    margin-bottom: 0.75rem;
}

.coll-thumb {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.coll-monogram {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F2F2F2;
    color: var(--text-tertiary);
    font-weight: 500;
    font-size: 1rem;
}

.author-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.author-avatar.author-monogram {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #E0E0E0;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 1.1rem;
}

.coll-hero-text {
    flex: 1;
    min-width: 0;
}

.coll-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0 0 0.125rem;
    line-height: 1.3;
}

.coll-meta {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    margin: 0;
}

.coll-meta a {
    color: inherit;
}

.coll-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
}

.coll-desc span {
    display: inline;
}

.coll-desc-clamped {
    display: -webkit-inline-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.coll-desc-toggle {
    display: inline;
    background: none;
    border: none;
    padding: 0;
    margin-left: 0.4em;
    font-size: 0.9rem;
    color: var(--text-tertiary);
    cursor: pointer;
}

.coll-desc-toggle:hover {
    color: var(--text-secondary);
}

.coll-order-label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 0.5rem;
}

.coll-pod-list {
    list-style: none;
    padding: 0;
    margin: 0;
    border-top: 1px solid var(--divider);
}

.coll-pod-list li {
    border-bottom: 1px solid var(--divider);
}

.coll-pod-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 0;
    text-decoration: none;
    color: inherit;
}

.coll-pod-row:hover .coll-pod-title {
    color: var(--accent);
}

.coll-pod-info {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    min-width: 0;
    flex: 1;
}

.coll-pod-num {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    min-width: 1.25rem;
}

.coll-pod-check {
    color: #6b9080;
    min-width: 1.25rem;
    flex-shrink: 0;
}

.coll-pod-text {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 0;
}

.coll-pod-title {
    font-weight: 500;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.coll-pod-meta {
    font-size: 0.8rem;
    color: var(--text-tertiary);
}

.coll-pod-chevron {
    flex-shrink: 0;
    color: var(--text-tertiary);
}

.pod-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.pod-list li {
    margin-bottom: 0.5rem;
}

.pod-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1rem;
    background: var(--bg);
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: box-shadow 0.2s, transform 0.2s;
}

.pod-link:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transform: translateY(-1px);
}

.pod-title {
    font-weight: 600;
    line-height: 1.4;
}

.pod-meta {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    white-space: nowrap;
}

.empty-state {
    text-align: center;
    color: var(--text-tertiary);
    padding: 3rem 1rem;
}

/* Reader */
.reader {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

.reader-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.back-home {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-decoration: none;
    min-width: 48px;
    min-height: 48px;
    display: flex;
    align-items: center;
}

.back-home:hover {
    color: var(--accent);
}

.pod-title-small {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Progress bar */
.progress-bar {
    height: 4px;
    background: var(--divider);
    overflow: hidden;
    margin: -1rem -1rem 0 -1rem;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s ease;
}

/* Message card */
.message-card {
    flex: 1 1 auto;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    animation: card-enter-fwd 0.3s ease-out;
    position: relative;
    margin: 0 -1rem;
    padding: 0;
    overflow: auto;
    padding-bottom: 72px; /* space for fixed nav */
}

/* Image + text as a single grouped flow */
.message-layer {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-block: auto; /* center when short, collapse to top when long */
    justify-content: flex-start;
}

/* Reader menu (three-dots) */
.reader-menu {
    position: absolute;
    top: 12px;
    right: 16px;
    z-index: 10;
}

.menu-trigger {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    color: #fff;
    opacity: 1;
}

.menu-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    min-width: 120px;
    overflow: hidden;
}

.menu-dropdown button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
}

.menu-dropdown button:hover {
    background: var(--divider);
}

.nav-back .message-card {
    animation: card-enter-back 0.3s ease-out;
}

@keyframes card-enter-fwd {
    from {
        opacity: 0;
        transform: translateX(30px) rotateY(-15deg);
    }
}

@keyframes card-enter-back {
    from {
        opacity: 0;
        transform: translateX(-30px) rotateY(15deg);
    }
}

.message-image {
    position: relative;
    width: 100%;
}

.message-image img {
    width: 100%;
    height: auto;
    max-height: 50dvh;
    display: block;
    object-fit: contain;
}

.image-placeholder {
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #F2F2F2;
}

.message-body {
    position: static;
    z-index: 1;
    font-size: 1.1rem;
    line-height: 1.9;
    background: var(--bg);
    padding: 1.5rem;
    margin-top: 0;
    margin-bottom: 0;
}

.message-body p {
    margin: 0 0 1rem;
}

.message-body p:last-child {
    margin-bottom: 0;
}

/* Navigation */
.reader-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    padding-bottom: calc(0.75rem + var(--safe-b));
    background: var(--bg);
    z-index: 20;
}

.nav-btn {
    padding: 0.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    background: transparent;
    color: var(--text-primary);
}

.nav-btn:hover:not(.nav-disabled) {
    background: var(--divider);
    color: var(--accent);
}

.nav-disabled {
    visibility: hidden;
}

/* Empty pod */
.empty-pod {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-secondary);
}

.empty-pod .nav-btn {
    padding: 0.875rem 2rem;
    margin-top: 1rem;
    background: var(--accent);
    color: var(--bg);
}

/* View Transitions - flip effect */
@view-transition {
  navigation: auto;
}

::view-transition-group(root) {
  animation-duration: 0.4s;
}

::view-transition-old(root) {
  animation: flip-out 0.4s ease-in-out forwards;
  transform-origin: center center;
}

::view-transition-new(root) {
  animation: flip-in 0.4s ease-in-out forwards;
  transform-origin: center center;
}

@keyframes flip-out {
  0% { transform: rotateY(0deg); opacity: 1; }
  100% { transform: rotateY(90deg); opacity: 0; }
}

@keyframes flip-in {
  0% { transform: rotateY(-90deg); opacity: 0; }
  100% { transform: rotateY(0deg); opacity: 1; }
}

/* Chunk fade effect */
.chunk {
    transition: opacity 0.3s ease;
}

.chunk-old {
    opacity: 0.5;
}

.chunk-current {
    animation: chunk-enter 0.3s ease-out;
}

.chunk-future {
    visibility: hidden;
    pointer-events: none;
}

@keyframes chunk-enter {
    from {
        opacity: 0;
        transform: translateY(1rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Alpine cloak */
[x-cloak] {
    display: none !important;
}

/* Offline indicator */
.offline-icon {
    position: fixed;
    top: calc(0.75rem + var(--safe-t));
    right: 0.75rem;
    font-size: 1rem;
    color: var(--text-tertiary);
    cursor: help;
    z-index: 10;
}

/* Loading state */
.message-card.loading {
    pointer-events: none;
}
.message-card.loading .message-body {
    opacity: 0.6;
}

/* Chrome visibility transitions */
.progress-bar,
.reader-menu,
.reader-nav {
    transition: opacity 0.2s ease;
}

/* Message label (verse numbers, etc.) */
.msg-label {
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 0.5rem;
}

/* Bilingual two-column layout */
.bilingual-row {
    display: flex;
    gap: 1rem;
}

.col-left,
.col-right {
    flex: 1;
    min-width: 0;
}

.col-left {
    padding-right: 1rem;
    border-right: 2px solid var(--text-tertiary);
}

.col-right {
    padding-left: 0.5rem;
}

/* Progressive bilingual reveal */
.bilingual-row.bilingual-row-hidden {
    visibility: hidden;
}

.bilingual-row.col-right-hidden .col-right {
    visibility: hidden;
}

/* Stack columns on narrow screens */
@media (max-width: 400px) {
    .bilingual-row {
        flex-direction: column;
        gap: 0.25rem;
    }

    .col-left {
        padding-right: 0;
        border-right: none;
        padding-bottom: 0.25rem;
    }

    .col-right {
        padding-left: 0;
        color: var(--text-secondary);
    }
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: calc(60px + var(--safe-b));
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 30;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.toast.show {
    opacity: 1;
}

/* Markdown styles in message body */
.message-body blockquote {
    margin: 1rem 0;
    padding: 0.5rem 1rem;
    border-left: 3px solid var(--text-tertiary);
    color: var(--text-secondary);
    font-style: italic;
}

.message-body blockquote p {
    margin: 0;
}

.message-body code {
    background: var(--divider);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
    font-size: 0.9em;
}

.message-body pre {
    background: var(--divider);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
}

.message-body pre code {
    background: none;
    padding: 0;
}

.message-body ul,
.message-body ol {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.message-body li {
    margin-bottom: 0.5rem;
}

.message-body a {
    color: var(--accent);
    text-decoration: underline;
}

.message-body a:hover {
    color: var(--text-primary);
}

/* Inline markdown in bilingual columns */
.bilingual-row code {
    background: var(--divider);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
    font-size: 0.9em;
}

.bilingual-row a {
    color: var(--accent);
    text-decoration: underline;
}

/* About page */
.about-page {
    background: var(--bg);
    min-height: calc(100vh - 2rem - var(--safe-t));
    min-height: calc(100dvh - 2rem - var(--safe-t));
    margin: 0 -1rem;
    padding: 1rem;
    padding-top: calc(1rem + var(--safe-t));
}

.about-back {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 2rem;
}

.about-back:active {
    background: #F2F2F2;
    border-radius: 4px;
}

.about-title {
    font-family: 'Inter', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 1rem;
}

.about-tagline {
    font-size: 1rem;
    color: var(--text-secondary);
    margin: 0 0 2rem;
}

.about-body {
    font-size: 1rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0 0 1rem;
    max-width: 320px;
}

.about-body strong {
    color: var(--accent);
    font-weight: 600;
}

.about-contact {
    font-size: 1rem;
    color: var(--text-secondary);
    margin: 2rem 0 0;
    padding-top: 1rem;
    border-top: 1px solid var(--divider);
}

.about-contact a {
    color: var(--accent);
    text-decoration: none;
}

.about-note {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0.25rem 0 0;
}

.about-privacy {
    font-size: 0.85rem;
    color: #9E9E9E;
    margin: 1.5rem 0 0;
}

/* Responsive adjustments */
@media (min-width: 481px) {
    .container {
        padding: 2rem;
    }
}

/* Desktop: constrain reader width */
@media (min-width: 720px) {
    .message-layer {
        max-width: 640px;
        margin-left: auto;
        margin-right: auto;
    }
}
