/* WikiWikiWord – minimal styling, CSS variables for theme */
:root,
.theme-dark {
    --bg: #1a1d24;
    --bg-elevated: #23262e;
    --text: #e8eaed;
    --text-muted: #9aa0a6;
    --card-bg: #23262e;
    --accent: #4a9eff;
    --accent-hover: #6bb3ff;
    --border: #3c4043;
    --danger: #e57373;
}

.theme-light {
    --bg: #f0f2f5;
    --bg-elevated: #fff;
    --text: #202124;
    --text-muted: #5f6368;
    --card-bg: #fff;
    --accent: #2563eb;
    --accent-hover: #3b82f6;
    --border: #dadce0;
    --danger: #c5221f;
}

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

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

#app {
    min-height: 100vh;
}

/* Views */
.view {
    display: none;
    min-height: 100vh;
}

.view.active {
    display: block;
}

.view[aria-hidden="false"] {
    display: block;
}

/* ----- Onboarding ----- */
#onboarding-view.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.onboarding-inner {
    max-width: 520px;
    width: 100%;
    position: relative;
}

.onboarding-close {
    position: absolute;
    top: 0;
    left: 0;
    padding: 0.5rem 0;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--accent);
    background: none;
    border: none;
    cursor: pointer;
}

.onboarding-close:hover {
    text-decoration: underline;
}

.onboarding-close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.onboarding-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.onboarding-logo {
    display: block;
    margin: 0 auto 1rem;
    width: 120px;
    height: 120px;
    object-fit: contain;
}

.onboarding-header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin: 0 0 0.5rem;
}

.tagline {
    color: var(--text-muted);
    margin: 0;
    font-size: 0.95rem;
}

.content-warning {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.content-warning p {
    margin: 0 0 0.75rem;
    font-size: 0.9rem;
}

.content-warning-actions {
    display: flex;
    justify-content: center;
}

.content-warning-actions .btn {
    margin: 0;
}

.onboarding-form h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 0.75rem;
}

.topic-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.topic-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    min-height: 44px;
}

.topic-chip:hover {
    border-color: var(--accent);
    background: var(--bg-elevated);
}

.topic-chip.selected {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.topic-chip .remove {
    margin-left: 0.25rem;
    opacity: 0.8;
}

.add-your-own label {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.custom-topic-row {
    position: relative;
    margin-bottom: 0.5rem;
}

#custom-topic-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    font-size: 1rem;
    min-height: 44px;
}

#custom-topic-input::placeholder {
    color: var(--text-muted);
}

.suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin: 0;
    padding: 0;
    list-style: none;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    max-height: 200px;
    overflow-y: auto;
    z-index: 10;
}

.suggestions li {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
    min-height: 44px;
    display: flex;
    align-items: center;
}

.suggestions li:last-child {
    border-bottom: none;
}

.suggestions li:hover {
    background: var(--bg-elevated);
}

.custom-topics-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.onboarding-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.btn {
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    min-height: 44px;
    transition: background 0.15s, opacity 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

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

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

.btn-secondary:hover {
    background: var(--bg-elevated);
}

/* ----- Feed view ----- */
#feed-view.active {
    display: flex;
    flex-direction: column;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 72px;
    height: 100vh;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 100;
    transition: transform 0.2s;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 0.75rem;
    min-height: 52px;
    width: 100%;
}

.sidebar-logo-img {
    display: block;
    width: 40px;
    height: 40px;
    object-fit: contain;
    margin: 0 auto;
}

.sidebar-close {
    display: none;
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 0;
    width: 100%;
}

.sidebar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem;
    background: none;
    border: none;
    color: var(--text);
    font-size: 0.7rem;
    cursor: pointer;
    width: 100%;
    min-height: 56px;
    transition: background 0.15s;
}

.sidebar-item:hover {
    background: var(--bg);
}

.sidebar-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-icon svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 101;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.25rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    min-height: 44px;
}

.feed-main {
    margin-left: 72px;
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.feed-container {
    flex: 1;
    max-width: 640px;
    margin: 0 auto;
    width: 100%;
    padding: 1rem;
    z-index: 1;
}

.liked-feed-wrap {
    flex: 1;
    max-width: 640px;
    margin: 0 auto;
    width: 100%;
    padding: 1rem;
    z-index: 1;
}

.liked-feed-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.liked-feed-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem 1rem;
    margin: 0;
}

.feed-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem 1rem;
    margin: 0;
}

.feed-cards {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.feed-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.feed-card-image-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10;
    background: var(--bg);
    cursor: pointer;
}

.feed-card-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.feed-card-image-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 2.5rem;
}

.feed-card-body {
    padding: 1rem;
}

.feed-card-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0 0 0.5rem;
    line-height: 1.3;
}

.feed-card-title a {
    color: var(--text);
    text-decoration: none;
}

.feed-card-title a:hover {
    text-decoration: underline;
}

.feed-card-extract-wrap {
    margin-bottom: 0.75rem;
}

.feed-card-extract {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0 0 0.35rem;
    line-height: 1.45;
}

.feed-card-read-more {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.85rem;
    color: var(--accent);
    cursor: pointer;
    font-weight: 500;
}

.feed-card-read-more:hover {
    text-decoration: underline;
}

/* Sub-feed (topic) header and Back */
.sub-feed-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.sub-feed-back {
    flex-shrink: 0;
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--accent);
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 6px;
}

.sub-feed-back:hover {
    text-decoration: underline;
}

.sub-feed-back:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.sub-feed-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.feed-card-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}

.feed-card-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
    border-radius: 999px;
    border: none;
    background: var(--pill-color, var(--accent));
    color: var(--pill-text, #fff);
    opacity: 0.95;
    cursor: pointer;
    font-family: inherit;
}

.feed-card-pill:hover {
    opacity: 1;
}

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

.feed-card-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.feed-card-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.4rem 0.6rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 6px;
    min-height: 44px;
    min-width: 44px;
}

.feed-card-actions button:hover {
    color: var(--text);
    background: var(--bg);
}

.feed-card-actions .like-btn {
    font-size: 1.5rem;
    padding: 0.35rem 0.5rem;
}

.feed-card-actions .like-btn svg {
    width: 28px;
    height: 28px;
}

.feed-card-actions button.liked {
    color: var(--danger);
}

.feed-card-actions button.liked svg {
    fill: var(--danger);
}

.feed-loading {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
}

.load-more {
    margin: 1rem auto;
    display: block;
}

/* Sidebar panel (Profiles / Stats / Settings) */
.sidebar-panel-wrap {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 99;
    pointer-events: none;
}

.sidebar-panel-wrap.open {
    pointer-events: auto;
}

.sidebar-panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    cursor: pointer;
    display: none;
    z-index: 0;
}

.sidebar-panel-wrap.open .sidebar-panel-backdrop {
    display: block;
}

.sidebar-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    max-width: 90vw;
    height: 100vh;
    z-index: 1;
    transition: transform 0.2s;
}

.sidebar-panel.closed {
    transform: translateX(100%);
}

.sidebar-panel.open {
    transform: translateX(0);
}

#panel-content {
    width: 280px;
    max-width: 90vw;
    height: 100%;
    background: var(--bg-elevated);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 12px rgba(0,0,0,0.15);
    overflow-y: auto;
    padding: 1rem;
}

#panel-content h3 {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
}

#install-pwa-btn-panel {
    width: 100%;
    margin-top: 0.25rem;
}

.settings-theme {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.settings-theme button {
    flex: 1;
    padding: 0.5rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
}

.settings-theme button.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.panel-label {
    margin: 0 0 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.panel-credit {
    margin: 1.5rem 0 0;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.panel-credit a {
    color: var(--text-muted);
    text-decoration: none;
}

.panel-credit a:hover {
    color: var(--text);
    text-decoration: underline;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.6rem;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.stat-value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--accent);
}

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

.panel-muted {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0;
}

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

.liked-article-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.liked-article-item:last-child {
    border-bottom: none;
}

.liked-article-item a {
    flex: 1;
    min-width: 0;
    color: var(--text);
    text-decoration: none;
    font-size: 0.9rem;
}

.liked-article-item a:hover {
    text-decoration: underline;
}

.liked-article-remove {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: var(--bg);
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.liked-article-remove:hover {
    color: var(--danger);
    background: rgba(229, 115, 115, 0.15);
}

/* Lightbox */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.lightbox[hidden] {
    display: none !important;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    cursor: pointer;
}

.theme-dark .lightbox-backdrop {
    background: rgba(0,0,0,0.85);
}

.theme-light .lightbox-backdrop {
    background: rgba(0,0,0,0.5);
}

.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 1002;
    background: rgba(255,255,255,0.25);
    border: 1px solid rgba(255,255,255,0.3);
    color: #fff;
    font-size: 1.5rem;
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-close:hover {
    background: rgba(255,255,255,0.35);
}

.lightbox-content {
    position: relative;
    z-index: 1001;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.lightbox-viewport {
    width: 90vw;
    height: 90vh;
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    user-select: none;
}

.lightbox-viewport:active {
    cursor: grabbing;
}

.lightbox-image-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transform-origin: center center;
    will-change: transform;
}

.lightbox-image-wrap img {
    max-width: 90vw;
    max-height: 90vh;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    pointer-events: none;
}

/* Bottom nav (mobile) – hidden on desktop */
.bottom-nav {
    display: none;
}

/* Mobile */
@media (max-width: 768px) {
    .sidebar,
    .sidebar-toggle {
        display: none !important;
    }

    .bottom-nav {
        display: flex;
        align-items: center;
        justify-content: space-around;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 56px;
        padding-bottom: env(safe-area-inset-bottom, 0);
        background: var(--bg-elevated);
        border-top: 1px solid var(--border);
        z-index: 100;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.15);
    }

    .bottom-nav-item {
        flex: 1;
        flex-direction: column;
        gap: 2px;
        padding: 6px 4px;
        font-size: 0.7rem;
        min-width: 0;
        border: none;
        background: none;
        color: var(--text-muted);
        cursor: pointer;
        border-radius: 6px;
    }

    .bottom-nav-item .sidebar-icon {
        width: 24px;
        height: 24px;
        margin: 0;
    }

    .bottom-nav-item .sidebar-icon svg {
        width: 22px;
        height: 22px;
    }

    .bottom-nav-item:hover,
    .bottom-nav-item:focus {
        color: var(--text);
        background: rgba(255, 255, 255, 0.06);
    }

    .theme-light .bottom-nav-item:hover,
    .theme-light .bottom-nav-item:focus {
        background: rgba(0, 0, 0, 0.06);
    }

    .feed-main {
        margin-left: 0;
    }

    .feed-container {
        padding-top: 3.5rem;
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0));
    }
}

/* Profile page: privacy note and reset */
.onboarding-privacy {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 1rem 0 0.5rem;
    text-align: center;
}

.btn-reset-profile {
    display: block;
    width: 100%;
    margin-top: 0.5rem;
}
