* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    background: #000;
    color: #fff;
    font-family: system-ui, -apple-system, sans-serif;
    overflow: hidden;
    height: 100dvh;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 500px;
    margin: 0 auto;
}

.top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent);
    pointer-events: none;
}

.top-bar * {
    pointer-events: auto;
}

.app-logo {
    font-weight: 700;
    font-size: 1.4rem;
    background: linear-gradient(45deg, #f09433, #e6683c, #dc2743);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 1rem;
    backdrop-filter: blur(5px);
    cursor: pointer;
}

.circle-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
}

.circle-btn:active {
    transform: scale(0.95);
}

/* Search popover */
#search-popover {
    position: absolute;
    top: 60px;
    right: 20px;
    width: 280px;
    max-width: 80vw;
    background: #111;
    border-radius: 12px;
    padding: 10px;
    border: 1px solid #333;
}

#wiki-search {
    width: 100%;
    background: #222;
    border: none;
    color: white;
    padding: 12px;
    border-radius: 8px;
    font-size: 1rem;
}

#search-results {
    margin-top: 8px;
}

.search-result-item {
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    color: white;
}

.search-result-item:hover {
    background: #222;
}

/* Feed */
.feed-container {
    height: calc(100dvh - 60px);
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
    scrollbar-width: none;
}

.feed-container::-webkit-scrollbar {
    display: none;
}

.feed-item {
    height: calc(100dvh - 60px);
    scroll-snap-align: start;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 20px;
    background-color: #111;
    cursor: pointer;
}

.feed-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
}

.feed-item.has-image::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.2) 50%, transparent);
    z-index: 1;
}

.feed-item:not(.has-image) {
    justify-content: center;
    background: linear-gradient(135deg, #1a1a2e, #16213e, #0f3460);
}

.content-overlay {
    position: relative;
    z-index: 2;
}

.content-overlay h2 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 10px;
    line-height: 1.1;
}

.content-overlay p {
    font-size: 1rem;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.85);
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.feed-actions {
    display: flex;
    gap: 15px;
    margin-top: 15px;
}

.feed-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 1rem;
    cursor: pointer;
    backdrop-filter: blur(5px);
    color: white;
}

.feed-btn:active {
    transform: scale(0.95);
}

.like-btn.liked {
    background: rgba(255, 100, 100, 0.3);
}

.read-btn {
    background: rgba(255, 255, 255, 0.9);
    color: #000;
    font-weight: 600;
}

/* Bottom nav */
.bottom-nav {
    height: calc(60px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    flex-shrink: 0;
    background: #000;
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid #222;
    position: sticky;
    bottom: 0;
    z-index: 5;
}

.nav-item {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.nav-icon {
    font-size: 1.2rem;
}

.nav-label {
    font-size: 0.65rem;
}

.nav-item.active {
    color: white;
}

/* Article dialog */
#article-dialog {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    background: #000;
    border: none;
    padding: 0;
    color: white;
    display: flex;
    flex-direction: column;
}

#article-dialog::backdrop {
    background: black;
}

.reading-progress {
    position: absolute;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, #f09433, #dc2743);
    width: 0%;
    z-index: 1;
}

.modal-header {
    padding: 12px 15px;
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.95);
    border-bottom: 1px solid #222;
    gap: 10px;
}

.header-title {
    flex: 1;
    min-width: 0;
}

.header-title h2 {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-actions {
    display: flex;
    gap: 8px;
}

.nav-path {
    font-size: 0.75rem;
    color: #666;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    line-height: 1.7;
    font-size: 1.05rem;
    color: #ddd;
}

.modal-body h2,
.modal-body h3 {
    margin: 25px 0 12px;
    color: white;
}

.modal-body p {
    margin-bottom: 16px;
}

.modal-body a {
    color: #f09433;
    text-decoration: none;
}

.modal-body img {
    max-width: 100%;
    border-radius: 8px;
    margin: 15px 0;
}

/* Overlay dialog */
#overlay-dialog {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    background: #000;
    border: none;
    padding: 0;
    color: white;
    display: flex;
    flex-direction: column;
}

#overlay-dialog::backdrop {
    background: black;
}

.overlay-header {
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #222;
}

.overlay-header h2 {
    font-size: 1.3rem;
    background: linear-gradient(45deg, #f09433, #dc2743);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.overlay-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

/* List items */
.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #111;
    border-radius: 12px;
    margin-bottom: 10px;
    cursor: pointer;
}

.list-item:active {
    background: #222;
}

.item-thumb {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    background-color: #333;
    flex-shrink: 0;
    overflow: hidden;
}

.item-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

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

.item-meta {
    font-size: 0.8rem;
    color: #666;
    margin-top: 2px;
}

/* Empty states */
.empty-state {
    text-align: center;
    padding: 60px 30px;
    color: #666;
}

.empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}

.empty-state h3 {
    color: #fff;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    translate: -50% 0;
    background: #333;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 0.9rem;
    border: none;
    color: white;
}

/* Loading */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #666;
}

.loader {
    width: 30px;
    height: 30px;
    border: 2px solid #333;
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}

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

/* Wiki content fixes */
.mwe-math-fallback-image-inline,
.mwe-math-fallback-image-display {
    filter: invert(1);
}

.sidebar,
.sistersitebox,
.navbox {
    display: none;
}

.infobox {
    border-color: #333 !important;
    background: #111 !important;
    color: #ddd;
}

.infobox td,
.infobox th {
    border-color: #333 !important;
}

.thumbinner {
    background: transparent !important;
    border: none !important;
}

.thumbcaption {
    color: #888;
    font-size: 0.85rem;
}

.modal-body .mw-file-element {
    max-width: 100%;
    height: auto;
}

/* Tree view */
.tree-stats {
    text-align: center;
    padding: 12px;
    color: #888;
    font-size: 0.85rem;
    border-bottom: 1px solid #222;
    margin-bottom: 15px;
}

.tree-session {
    margin-bottom: 24px;
}

.tree-session-header {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 10px;
}

.tree-node {
    position: relative;
    padding: 4px 0;
}

.tree-children {
    padding-left: 24px;
    margin-left: 8px;
    border-left: 1px dashed #333;
}

.tree-children .tree-node::before {
    content: '';
    position: absolute;
    left: -24px;
    top: 16px;
    width: 20px;
    border-bottom: 1px dashed #333;
}

.tree-label {
    display: inline-block;
    padding: 8px 14px;
    background: #111;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid #222;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-label:active {
    background: #222;
}

.tree-root>.tree-label {
    background: linear-gradient(135deg, rgba(240, 148, 51, 0.15), rgba(220, 39, 67, 0.15));
    border-color: rgba(240, 148, 51, 0.3);
}