:root {
    --bg: var(--tg-theme-bg-color, #f5f7fb);
    --panel: var(--tg-theme-secondary-bg-color, #ffffff);
    --panel-2: color-mix(in srgb, var(--panel) 88%, #dde5f3);
    --text: var(--tg-theme-text-color, #172033);
    --muted: var(--tg-theme-hint-color, #6b7280);
    --line: color-mix(in srgb, var(--muted) 22%, transparent);
    --primary: var(--tg-theme-button-color, #2481cc);
    --primary-text: var(--tg-theme-button-text-color, #ffffff);
    --success: #16a34a;
    --danger: #dc2626;
    --warn: #d97706;
    --radius: 8px;
    --sidebar-width: 292px;
    --topbar-height: 76px;
    --shadow: 0 12px 34px rgba(15, 23, 42, .12);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    min-height: 100%;
    min-height: 100dvh;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    scrollbar-gutter: stable;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    touch-action: pan-y;
}

body {
    margin: 0;
    color: var(--text);
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--primary) 6%, var(--bg)) 0%, var(--bg) 260px),
        var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    line-height: 1.45;
    overscroll-behavior-x: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

img,
video,
canvas,
svg {
    max-width: 100%;
}

button,
input,
textarea,
select {
    font: inherit;
    max-width: 100%;
}

input,
textarea,
select {
    font-size: 16px !important;
    line-height: 1.35;
    -webkit-text-size-adjust: 100%;
    transform: translateZ(0);
    touch-action: manipulation;
}

button {
    cursor: pointer;
}

.outside {
    min-height: 100vh;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 14px;
    padding: 24px;
    text-align: center;
}

.outside-logo {
    width: 92px;
    height: 92px;
    border-radius: 999px;
}

.outside h1 {
    margin: 0;
    font-size: 28px;
}

.outside p {
    max-width: 360px;
    margin: 0;
    color: var(--muted);
}

.primary-link,
.button.primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    border: 0;
    border-radius: var(--radius);
    padding: 10px 14px;
    color: var(--primary-text);
    background: var(--primary);
    text-decoration: none;
    font-weight: 700;
}

.app-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    max-width: 100vw;
    overflow-x: clip;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    border-inline-end: 1px solid var(--line);
    background: var(--panel);
    padding: 14px;
    z-index: 20;
}

.brand,
.profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand {
    padding: 8px 8px 16px;
}

.brand-logo,
.profile-photo {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    object-fit: cover;
    background: #111827;
}

.brand strong,
.profile-name {
    display: block;
    font-weight: 800;
}

.brand span,
.profile-plan {
    color: var(--muted);
    font-size: 13px;
}

.profile {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px;
    background: linear-gradient(135deg, var(--panel-2), color-mix(in srgb, var(--primary) 7%, var(--panel)));
}

.profile-plan.pro {
    color: var(--success);
    font-weight: 800;
}

.language-button,
.nav button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 42px;
    margin-top: 8px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 10px 11px;
    color: var(--text);
    background: transparent;
    text-align: start;
}

.language-button {
    border-color: var(--line);
    background: var(--panel-2);
}

.nav button.active,
.nav button:hover,
.language-button:hover {
    background: color-mix(in srgb, var(--primary) 12%, transparent);
    border-color: color-mix(in srgb, var(--primary) 26%, transparent);
}

.main {
    min-width: 0;
    max-width: 100%;
    overflow-x: clip;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    padding: calc(var(--topbar-height) + env(safe-area-inset-top)) 14px calc(22px + env(safe-area-inset-bottom));
}

.topbar {
    position: fixed;
    top: 0;
    inset-inline-start: var(--sidebar-width);
    inset-inline-end: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: calc(var(--topbar-height) + env(safe-area-inset-top));
    margin: 0;
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(12px);
    max-width: 100vw;
    box-shadow: 0 10px 28px rgba(15, 23, 42, .08);
}

.topbar h1 {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
}

.topbar p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.icon-button {
    width: 40px;
    height: 40px;
    flex: none;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
    background: var(--panel);
}

#refreshButton {
    margin-inline-start: auto;
}

.notice {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px;
    background: var(--panel);
}

.notice.error {
    border-color: color-mix(in srgb, var(--danger) 42%, var(--line));
    color: var(--danger);
}

.content {
    display: grid;
    gap: 12px;
    min-width: 0;
}

.grid {
    display: grid;
    gap: 12px;
}

.grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    padding: 14px;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.card + .card {
    margin-top: 2px;
}

.card h2,
.card h3 {
    margin: 0 0 10px;
    font-size: 17px;
}

.card p {
    margin: 6px 0;
    color: var(--muted);
}

.stat {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
    min-width: 0;
}

.stat:last-child {
    border-bottom: 0;
}

.stat strong {
    font-size: 14px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border-radius: 999px;
    padding: 4px 9px;
    background: color-mix(in srgb, var(--muted) 14%, transparent);
    font-size: 12px;
    font-weight: 800;
}

.badge.pro {
    color: #065f46;
    background: #bbf7d0;
}

.badge.free {
    color: #7c2d12;
    background: #fed7aa;
}

.form {
    display: grid;
    gap: 10px;
    min-width: 0;
    max-width: 100%;
}

label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
    min-width: 0;
    max-width: 100%;
}

input:not([type="checkbox"]),
textarea,
select {
    width: 100%;
    min-width: 0;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 11px;
    color: var(--text);
    background: var(--bg);
    outline: none;
    appearance: none;
}

input[type="checkbox"] {
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--bg);
    appearance: none;
    display: inline-grid;
    place-items: center;
    flex: none;
}

input[type="checkbox"]:checked {
    border-color: var(--primary);
    background: var(--primary);
}

input[type="checkbox"]:checked::after {
    content: "";
    width: 9px;
    height: 5px;
    border: solid var(--primary-text);
    border-width: 0 0 2px 2px;
    transform: rotate(-45deg) translate(1px, -1px);
}

.settings-section {
    display: grid;
    gap: 12px;
}

.settings-grid {
    display: grid;
    gap: 10px;
}

.settings-grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.check-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.check-option {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 9px 10px;
    background: var(--panel-2);
    font-size: 13px;
    font-weight: 700;
}

.hint {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 12px;
}

textarea {
    min-height: 92px;
    resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

.row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
}

.row > * {
    min-width: 0;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 9px 12px;
    color: var(--text);
    background: var(--panel-2);
    font-weight: 700;
    max-width: 100%;
}

.button.success {
    color: white;
    background: var(--success);
    border-color: var(--success);
}

.button.danger {
    color: white;
    background: var(--danger);
    border-color: var(--danger);
}

.button.warning {
    color: #111827;
    background: #fbbf24;
    border-color: #fbbf24;
}

.list {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.item {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px;
    background: var(--panel-2);
    min-width: 0;
    overflow-wrap: anywhere;
}

.item-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-weight: 800;
    min-width: 0;
    overflow-wrap: anywhere;
}

.muted {
    color: var(--muted);
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.progress {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: color-mix(in srgb, var(--muted) 18%, transparent);
}

.progress span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--primary);
    transition: width .25s ease;
}

.empty {
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    padding: 14px;
    color: var(--muted);
    text-align: center;
}

@media (max-width: 760px) {
    :root {
        --sidebar-width: 0px;
        --topbar-height: 72px;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(86vw, 320px);
        max-width: 86vw;
        transform: translateX(-102%);
        transition: transform .2s ease;
        box-shadow: var(--shadow);
        -webkit-overflow-scrolling: touch;
    }

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

    body.sidebar-open::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, .32);
        z-index: 15;
    }

    .grid.two {
        grid-template-columns: 1fr;
    }

    .main {
        padding-inline: 10px;
        width: 100vw;
        max-width: 100vw;
        overflow-x: clip;
    }

    .topbar {
        inset-inline-start: 0;
        width: 100vw;
        padding-inline: 10px;
    }

    .topbar > div {
        min-width: 0;
    }

    .topbar h1,
    .topbar p {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .button {
        min-width: 0;
    }

    .row .button {
        flex: 1 1 auto;
    }

    .settings-grid.two,
    .check-grid {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 761px) {
    #menuButton {
        display: none;
    }
}
