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

:root {
    --bg: #111318;
    --text: #e4e4e7;
    --muted: #71717a;
    --surface: #1c1f27;
    --border: #27272a;
    --accent: #67e8d8;
    --primary: #38bdf8;
    --liked: #f43f5e;
    --overlay-bg: rgba(0, 0, 0, 0.15);
    --nav-bg: rgba(28, 31, 39, 0.82);
}

[data-theme="light"] {
    --bg: #f9f9f9;
    --text: #18181b;
    --muted: #71717a;
    --surface: #ffffff;
    --border: #e4e4e7;
    --accent: #0d9488;
    --primary: #0284c7;
    --liked: #e11d48;
    --overlay-bg: rgba(0, 0, 0, 0.10);
    --nav-bg: rgba(255, 255, 255, 0.82);
}

body {
    font-family: -apple-system, "Helvetica Neue", Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    transition: background 0.25s, color 0.25s;
}

main {
    max-width: 660px;
    margin: 0 auto;
    padding: 1.5rem 1rem calc(5rem + env(safe-area-inset-bottom));
}

/* ── HEADER ─────────────────────────────────── */

header {
    text-align: center;
    margin-bottom: 3.5rem;
}

.header-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 2.5rem;
}

header h1 {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.title-svg {
    display: block;
    width: min(360px, 88vw);
    height: auto;
    overflow: visible;
}

.title-text {
    font-family: 'Dancing Script', cursive;
    font-size: 72px;
    font-weight: 700;
    fill: var(--accent);
    fill-opacity: 0;
    stroke: var(--accent);
    stroke-width: 2px;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 10000;
    stroke-dashoffset: 10000;
    animation:
        title-write 5.5s ease-in-out forwards,
        title-fill 1.8s ease-in 4.6s forwards;
}

@keyframes title-write {
    to { stroke-dashoffset: 0; }
}

@keyframes title-fill {
    to { fill-opacity: 1; }
}

header p {
    margin-top: 0.45rem;
    font-size: 0.8rem;
    color: var(--muted);
    letter-spacing: 0.01em;
}

.theme-toggle {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    color: var(--muted);
    transition: border-color 0.2s, color 0.2s;
}

.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-50%) scale(1.08);
}

/* ── NAVIGATION (fixed bottom tab bar) ───────── */

.nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--nav-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 100;
}

.nav-btn {
    flex: 1;
    background: none;
    border: none;
    border-top: 2px solid transparent;
    padding: 0.8rem 0.5rem;
    color: var(--muted);
    font-size: 0.72rem;
    font-family: inherit;
    font-weight: 500;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.nav-btn:hover {
    color: var(--text);
}

.nav-btn.active {
    color: var(--accent);
    border-top-color: var(--accent);
}

/* ── PAGE CONTENT ────────────────────────────── */

.page-content { display: none; }
.page-content.active { display: block; }

/* ── QUOTES ──────────────────────────────────── */

.quotes-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-bottom: 2rem;
}

.quote-card {
    background: var(--surface);
    border-radius: 6px;
    padding: 1.35rem 1.35rem 1rem;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    opacity: 0;
    animation: fadeIn 0.3s ease forwards;
}

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

.quote-content {
    font-size: 1.05rem;
    line-height: 1.75;
    font-style: italic;
    color: var(--text);
    padding-right: 1.75rem;
    margin-bottom: 0.65rem;
}

.quote-author {
    font-size: 0.8rem;
    color: var(--muted);
    letter-spacing: 0.04em;
}

/* ── HEART BUTTON (state indicator) ─────────── */

.heart-btn {
    position: absolute;
    top: 0.8rem;
    right: 0.8rem;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.3;
    padding: 0.2rem;
    line-height: 1;
    transition: opacity 0.2s, text-shadow 0.3s, color 0.3s;
}

.heart-btn:hover { opacity: 0.55; }

.heart-btn.liked {
    opacity: 1;
    color: rgba(255, 250, 240, 0.95);
    text-shadow:
        0 0 6px 2px rgba(255, 250, 240, 0.5),
        0 0 12px 4px rgba(255, 250, 240, 0.25);
    animation: heartPulse 1.8s ease-in-out infinite;
}

.heart-btn::before {
    content: '♥';
    color: var(--muted);
}

.heart-btn.liked::before {
    color: rgba(255, 250, 240, 0.95);
}

@keyframes heartPop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.5); }
    100% { transform: scale(1); }
}

@keyframes heartPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.heart-btn.animate { animation: heartPop 0.3s ease; }

@keyframes heartFloat {
    0%   { opacity: 1; transform: translateY(0) scale(0.8); }
    100% { opacity: 0; transform: translateY(-40px) scale(1.2); }
}

.heart-particle {
    position: absolute;
    top: 0.8rem;
    right: 0.8rem;
    font-size: 0.85rem;
    pointer-events: none;
    animation: heartFloat 0.75s ease-out forwards;
}

/* ── HOVER OVERLAY ───────────────────────────── */

.quote-overlay {
    position: absolute;
    inset: 0;
    background: var(--overlay-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.18s ease;
    border-radius: inherit;
    pointer-events: none;
}

.quote-card:hover .quote-overlay {
    opacity: 1;
}

.overlay-heart {
    font-size: 2rem;
    line-height: 1;
    opacity: 0.6;
    transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.22s ease;
    pointer-events: none;
    user-select: none;
}

.overlay-heart::before {
    content: '♥';
    color: var(--muted);
}

.overlay-heart.liked::before {
    color: rgba(255, 250, 240, 0.9);
    text-shadow:
        0 0 10px 4px rgba(255, 250, 240, 0.5),
        0 0 20px 8px rgba(255, 250, 240, 0.25);
}

.quote-card:hover .overlay-heart {
    opacity: 1;
    transform: scale(1.15);
}

/* Touch: brief flash on tap */
@media (hover: none) {
    .quote-card:active .quote-overlay { opacity: 1; }
    .heart-btn { opacity: 0.6; }
}

/* ── RANK BADGES ─────────────────────────────── */

.rank-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    margin-right: 0.5rem;
    vertical-align: middle;
}

.top-three-rank {
    background: linear-gradient(135deg, #fbbf24, #f97316);
    color: #000;
}

.other-rank {
    background: var(--border);
    color: var(--muted);
}

/* ── LOADING & ERRORS ────────────────────────── */

#loading, #top-quotes-loading, #liked-loading {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
    font-size: 0.875rem;
}

.spinner {
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    animation: spin 0.75s linear infinite;
    margin: 0 auto 0.875rem;
}

.spinner.small {
    width: 16px;
    height: 16px;
    margin: 0;
}

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

.error {
    text-align: center;
    padding: 1.5rem;
    color: #fb7185;
    background: rgba(251, 113, 133, 0.07);
    border: 1px solid rgba(251, 113, 133, 0.18);
    border-radius: 6px;
    font-size: 0.875rem;
}

.liked-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.liked-hint {
    font-size: 0.82rem;
    margin-top: 0.4rem;
    opacity: 0.7;
}

/* ── SCROLL / INFINITE ───────────────────────── */

.scroll-sentinel { height: 20px; width: 100%; }

.scroll-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 1.25rem;
    color: var(--muted);
    font-size: 0.82rem;
}

.scroll-loading.hidden { display: none; }

.scroll-error {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    color: #fb7185;
    font-size: 0.82rem;
}

.scroll-error.hidden { display: none; }

.no-more-quotes {
    text-align: center;
    padding: 1.25rem;
    color: var(--muted);
    font-size: 0.82rem;
}

.no-more-quotes.hidden { display: none; }

/* ── PWA PROMPT ──────────────────────────────── */

.pwa-prompt {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.1rem 1.25rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.28);
    z-index: 1000;
}

.pwa-prompt.hidden { display: none; }

.pwa-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 999;
}

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

.pwa-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.65rem;
}

.pwa-icon {
    width: 38px;
    height: 38px;
    background: var(--primary);
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.pwa-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.pwa-message {
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.5;
    margin-bottom: 0.85rem;
}

.pwa-instructions {
    background: var(--bg);
    border-left: 3px solid var(--primary);
    border-radius: 0 5px 5px 0;
    padding: 0.65rem 0.9rem;
    margin-bottom: 0.85rem;
    font-size: 0.82rem;
    color: var(--text);
}

.pwa-buttons { display: flex; gap: 0.5rem; }

.pwa-btn {
    flex: 1;
    padding: 0.55rem;
    border: none;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.15s;
}

.pwa-btn.primary { background: var(--primary); color: white; }
.pwa-btn.primary:hover { opacity: 0.85; }
.pwa-btn.secondary { background: var(--border); color: var(--muted); }

/* ── FOOTER ──────────────────────────────────── */

.footer-note {
    text-align: center;
    padding: 1.5rem 0;
    font-size: 0.78rem;
    color: var(--muted);
}

/* ── MOBILE ──────────────────────────────────── */

@media (max-width: 600px) {
    main { padding: 1rem 0.75rem calc(5rem + env(safe-area-inset-bottom)); }

    header h1 { font-size: 1.25rem; }

    .header-container { padding: 0 2.25rem; }

    .quote-card { padding: 1.1rem 1.1rem 0.85rem; }

    .quote-content { font-size: 1rem; }

    .overlay-heart { font-size: 2.75rem; }
}

/* ── SHARE BUTTON ──────────────────────────────── */

.share-btn {
    position: absolute;
    top: 0.8rem;
    right: 2.5rem;
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    opacity: 0.3;
    padding: 0.2rem;
    line-height: 1;
    transition: opacity 0.2s;
    color: var(--muted);
}

.share-btn:hover {
    opacity: 0.55;
}

.share-btn::before {
    content: '\2197';
}

/* ── SHARE MODAL ──────────────────────────────── */

.share-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.share-modal.hidden {
    display: none;
}

.share-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.share-modal-content {
    position: relative;
    background: var(--surface);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.share-modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--muted);
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

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

.share-preview {
    margin-bottom: 1.25rem;
}

.share-quote-card {
    padding: 2rem 1.5rem;
    border-radius: 8px;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: background 0.3s, color 0.3s;
}

.share-quote-content {
    font-size: 1.25rem;
    line-height: 1.6;
    font-style: italic;
    margin-bottom: 1rem;
    text-align: center;
}

.share-quote-author {
    font-size: 0.9rem;
    text-align: right;
    opacity: 0.7;
}

.share-quote-card.bg-dark {
    background: linear-gradient(135deg, #1a1a2e, #111318);
    color: #e4e4e7;
}

.share-quote-card.bg-light {
    background: #f9f9f9;
    color: #18181b;
}

.share-quote-card.bg-sunset {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.share-quote-card.bg-ocean {
    background: linear-gradient(135deg, #1e3c72, #2a5298);
    color: white;
}

.share-quote-card.bg-teal {
    background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
    color: #e4e4e7;
}

.share-quote-card.font-sans {
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

.share-quote-card.font-serif {
    font-family: Georgia, serif;
}

.share-quote-card.font-mono {
    font-family: monospace;
}

.share-quote-card.size-small .share-quote-content {
    font-size: 1rem;
}

.share-quote-card.size-medium .share-quote-content {
    font-size: 1.25rem;
}

.share-quote-card.size-large .share-quote-content {
    font-size: 1.5rem;
}

.share-quote-card.size-xlarge .share-quote-content {
    font-size: 1.8rem;
}

.share-options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.share-option-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.share-option-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.share-bg-options,
.share-font-options,
.share-size-options {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.share-bg-btn {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s;
}

.share-bg-btn:hover {
    transform: scale(1.05);
}

.share-bg-btn.active {
    border-color: var(--accent);
}

.share-font-btn,
.share-size-btn {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s, border-color 0.2s;
}

.share-font-btn:hover,
.share-size-btn:hover {
    border-color: var(--accent);
}

.share-font-btn.active,
.share-size-btn.active {
    border-color: var(--accent);
    background: var(--surface);
}

.share-size-btn[data-size="small"] { font-size: 0.8rem; }
.share-size-btn[data-size="medium"] { font-size: 1rem; }
.share-size-btn[data-size="large"] { font-size: 1.2rem; }
.share-size-btn[data-size="xlarge"] { font-size: 1.4rem; }

.share-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.share-action-btn {
    flex: 1;
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.share-action-btn svg {
    flex-shrink: 0;
}

.share-action-btn:hover {
    border-color: var(--accent);
}

.share-action-btn.primary {
    background: var(--accent);
    color: #111318;
    border-color: var(--accent);
}

.share-action-btn.primary:hover {
    opacity: 0.9;
}

.share-social {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
}

.share-social-label {
    font-size: 0.8rem;
    color: var(--muted);
}

.share-social-buttons {
    display: flex;
    gap: 0.5rem;
}

.share-social-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
}

.share-social-btn:hover {
    border-color: var(--accent);
    transform: scale(1.1);
}

.share-social-btn svg {
    transition: opacity 0.2s;
}

/* Share Toast Notification */
.share-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--surface);
    color: var(--text);
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    font-size: 0.9rem;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}

.share-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
