:root {
    --bg: #ffffff;
    --bg-rgb: 255, 255, 255;
    --fg: #111111;
    --hint: #707070;
    --accent: #2481cc;
    --bar-bg: rgba(255, 255, 255, 0.92);
    --bar-fg: #111111;
    --sheet-bg: #ffffff;
    --sheet-item-hover: #f2f2f2;
    --sheet-item-active: #e8f3ff;
    --divider: rgba(0, 0, 0, 0.08);
    --bar-height: 50px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    /* ---------- Liquid Glass tokens ---------- */
    --glass-blur: 22px;
    --glass-sat: 180%;
    --glass-bar: rgba(var(--bg-rgb), 0.64);      /* плавающие бары */
    --glass-panel: rgba(var(--bg-rgb), 0.72);    /* шторка (читаемость текста) */
    --glass-chip: rgba(var(--bg-rgb), 0.52);     /* кнопки/строки внутри стекла */
    --glass-sheen: rgba(255, 255, 255, 0.5);     /* верхний внутренний блик */
    --glass-edge: rgba(255, 255, 255, 0.22);     /* волосяная грань */
    --glass-ring: rgba(0, 0, 0, 0.06);           /* тонкий внешний контур (для светлой) */
    --glass-shadow: 0 10px 34px rgba(0, 0, 0, 0.20), 0 2px 8px rgba(0, 0, 0, 0.10);
}

/* Тёмная тема — стекло прозрачнее (светлую не трогаем). */
body[data-theme="dark"] {
    --glass-bar: rgba(var(--bg-rgb), 0.42);
    --glass-panel: rgba(var(--bg-rgb), 0.56);
    --glass-chip: rgba(var(--bg-rgb), 0.38);
    --glass-edge: rgba(255, 255, 255, 0.16);
    --glass-sheen: rgba(255, 255, 255, 0.34);
    --glass-ring: rgba(255, 255, 255, 0.05);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, sans-serif;
    overscroll-behavior-y: contain;
    -webkit-tap-highlight-color: transparent;
}

body {
    min-height: 100vh;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    -webkit-user-select: none;
    user-select: none;
}

button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Базовый стеклянный материал: блюр + насыщенность + блик + контур. */
.glass {
    background: var(--glass-bar);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
    border: 1px solid var(--glass-edge);
    box-shadow:
        var(--glass-shadow),
        inset 0 1px 0 var(--glass-sheen),
        inset 0 0 0 0.5px var(--glass-ring);
}

/* Спекулярный верхний блик-сияние поверх стекла. */
.glass::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.28) 0%,
        rgba(255, 255, 255, 0.04) 42%,
        rgba(255, 255, 255, 0) 100%
    );
}

/* ---------- TOPBAR (floating capsule) ---------- */
#topbar {
    position: fixed;
    top: calc(var(--safe-top) + 8px);
    left: 10px;
    right: 10px;
    height: var(--bar-height);
    border-radius: 24px;
    display: flex;
    align-items: center;
    padding: 0 6px;
    z-index: 20;
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.25s ease;
}

#topbar > * {
    position: relative;
    z-index: 1;
}

#topbar.hidden-bar {
    transform: translateY(calc(-100% - var(--safe-top) - 18px));
    opacity: 0;
}

#back-btn {
    width: 40px;
    height: 40px;
    font-size: 21px;
    color: var(--bar-fg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.14s ease, background 0.14s ease;
}

#back-btn:active {
    background: var(--glass-chip);
    transform: scale(0.9);
}

#chapter-picker-btn {
    flex: 1;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bar-fg);
    border-radius: 16px;
    padding: 4px 10px;
    min-width: 0;
    transition: transform 0.14s ease, background 0.14s ease;
}

#chapter-picker-btn:active {
    background: var(--glass-chip);
    transform: scale(0.97);
}

.picker-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    min-width: 0;
    line-height: 1.15;
}

.manga-title {
    font-size: 11px;
    color: var(--bar-fg);
    opacity: 0.62;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 60vw;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.manga-title:empty {
    display: none;
}

.chapter-row {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
    font-size: 15px;
    min-width: 0;
    letter-spacing: -0.01em;
}

#chapter-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 55vw;
}

.caret {
    font-size: 11px;
    color: var(--hint);
}

#theme-toggle {
    width: 40px;
    height: 40px;
    color: var(--bar-fg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    opacity: 0.9;
    transition: transform 0.14s ease, background 0.14s ease;
}

#theme-toggle:active {
    background: var(--glass-chip);
    transform: scale(0.9);
}

#theme-toggle .icon-moon,
#theme-toggle .icon-sun {
    display: none;
}

body[data-theme="light"] #theme-toggle .icon-moon {
    display: block;
}

body[data-theme="dark"] #theme-toggle .icon-sun {
    display: block;
}

/* ---------- PAGES ---------- */
#pages-container {
    padding-top: calc(var(--bar-height) + var(--safe-top) + 24px);
    padding-bottom: calc(var(--bar-height) + var(--safe-bottom) + 24px);
    min-height: 100vh;
    background: var(--bg);
}

#pages-container img {
    display: block;
    width: 100vw;
    max-width: 100%;
    height: auto;
    margin: 0;
    background: var(--sheet-item-hover);
}

/* ---------- LOADING + ERROR ---------- */
#loading-indicator,
#error-banner {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 12px 22px;
    border-radius: 16px;
    color: var(--fg);
    z-index: 50;
    font-size: 14px;
    font-weight: 500;
    background: var(--glass-panel);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
    border: 1px solid var(--glass-edge);
    box-shadow: var(--glass-shadow), inset 0 1px 0 var(--glass-sheen);
}

#error-banner {
    background: rgba(192, 57, 43, 0.82);
    color: #fff;
    max-width: 80vw;
    text-align: center;
    border-color: rgba(255, 255, 255, 0.25);
}

.hidden {
    display: none !important;
}

/* ---------- BOTTOMBAR (floating capsule) ---------- */
#bottombar {
    position: fixed;
    bottom: calc(var(--safe-bottom) + 8px);
    left: 10px;
    right: 10px;
    height: var(--bar-height);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px;
    z-index: 20;
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.25s ease;
}

#bottombar > * {
    position: relative;
    z-index: 1;
}

#bottombar.hidden-bar {
    transform: translateY(calc(100% + var(--safe-bottom) + 18px));
    opacity: 0;
}

#prev-chapter,
#next-chapter {
    color: var(--bar-fg);
    font-weight: 600;
    font-size: 14px;
    padding: 9px 14px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    box-shadow: none;
    transition: transform 0.14s ease, opacity 0.14s ease;
}

#prev-chapter svg,
#next-chapter svg {
    opacity: 0.85;
}

#prev-chapter:not(:disabled):active,
#next-chapter:not(:disabled):active {
    transform: scale(0.92);
    opacity: 0.6;
}

#page-counter {
    font-size: 13px;
    color: var(--bar-fg);
    opacity: 0.55;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    letter-spacing: 0.03em;
}

/* ---------- CHAPTER SHEET ---------- */
#chapter-sheet {
    position: fixed;
    inset: 0;
    z-index: 100;
}

#chapter-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.38);
    opacity: 0;
    transition: opacity 0.25s ease;
}

#chapter-sheet.visible #chapter-sheet-backdrop {
    opacity: 1;
}

#chapter-sheet-content {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 86vh;
    border-radius: 26px 26px 0 0;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: var(--safe-bottom);
    display: flex;
    flex-direction: column;
    background: var(--glass-panel);
    -webkit-backdrop-filter: blur(40px) saturate(var(--glass-sat));
    backdrop-filter: blur(40px) saturate(var(--glass-sat));
    border-top: 1px solid var(--glass-edge);
    box-shadow:
        0 -12px 48px rgba(0, 0, 0, 0.32),
        inset 0 1px 0 var(--glass-sheen);
}

#chapter-sheet.visible #chapter-sheet-content {
    transform: translateY(0);
}

#chapter-sheet-handle {
    width: 38px;
    height: 5px;
    background: var(--hint);
    opacity: 0.4;
    border-radius: 3px;
    margin: 8px auto 2px;
    flex-shrink: 0;
}

#chapter-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 18px 12px;
    flex-shrink: 0;
}

#chapter-sheet-header h3 {
    margin: 0;
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

#chapter-sheet-close {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--fg);
    opacity: 0.55;
    background: rgba(var(--bg-rgb), 0.0);
    border: none;
    flex-shrink: 0;
    transition: transform 0.14s ease, opacity 0.14s ease;
}

#chapter-sheet-close:active {
    transform: scale(0.85);
    opacity: 0.9;
}

#chapter-search-wrap {
    padding: 0 16px 12px;
    flex-shrink: 0;
}

#chapter-search {
    width: 100%;
    padding: 12px 15px;
    font-size: 15px;
    color: var(--fg);
    background: var(--glass-chip);
    border: 1px solid var(--glass-edge);
    border-radius: 14px;
    outline: none;
    box-shadow: inset 0 1px 0 var(--glass-sheen);
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

#chapter-search::placeholder {
    color: var(--hint);
}

#chapter-search:focus {
    border-color: var(--accent);
    box-shadow: inset 0 1px 0 var(--glass-sheen), 0 0 0 3px rgba(var(--bg-rgb), 0.0), 0 0 0 2px var(--accent);
}

#chapter-list {
    list-style: none;
    margin: 0;
    padding: 2px 12px 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#chapter-list li {
    padding: 15px 16px;
    font-size: 15px;
    font-weight: 500;
    background: var(--glass-chip);
    border: 1px solid var(--glass-edge);
    border-radius: 14px;
    box-shadow: inset 0 1px 0 var(--glass-sheen);
    cursor: pointer;
    transition: transform 0.12s ease, filter 0.12s ease, border-color 0.12s ease;
}

#chapter-list li:active {
    transform: scale(0.985);
    filter: brightness(1.06);
}

#chapter-list li.current {
    border-color: var(--accent);
    font-weight: 700;
    color: var(--accent);
    box-shadow: inset 0 1px 0 var(--glass-sheen), 0 0 0 1px var(--accent);
}

#chapter-list li.sheet-status {
    background: none;
    border: none;
    box-shadow: none;
    color: var(--hint);
    text-align: center;
    cursor: default;
}

#chapter-list-empty {
    padding: 28px 16px;
    text-align: center;
    color: var(--hint);
    font-size: 15px;
}
