:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent-primary: #2563eb;
    --accent-secondary: #4f46e5;
    --accent-success: #16a34a;
    --accent-warning: #f59e0b;
    --accent-danger: #dc2626;
    --border-color: #e2e8f0;
    --border-strong: #cbd5e1;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-hover: 0 18px 38px -28px rgba(15, 23, 42, 0.32), 0 10px 18px -18px rgba(15, 23, 42, 0.18);
    --radius: 8px;
}

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

html {
    background: var(--bg-primary);
}

body {
    min-height: 100vh;
    color: var(--text-primary);
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.08), transparent 34rem),
        linear-gradient(180deg, #ffffff 0%, var(--bg-primary) 34rem);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
}

button,
input,
select {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 268px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 28px 22px;
    background: rgba(255, 255, 255, 0.85);
    border-right: 1px solid #e2e8f0;
    backdrop-filter: blur(18px);
    display: flex;
    flex-direction: column;
    gap: 24px;
}

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

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: #fff;
    font-weight: 800;
    box-shadow: 0 12px 30px -20px rgba(37, 99, 235, 0.8);
}

.brand h1 {
    font-size: 1.08rem;
    line-height: 1.2;
}

.brand p,
.panel-header p,
.passport-info,
.topbar-status span {
    color: var(--text-secondary);
    font-size: 0.86rem;
}

.nav {
    display: grid;
    gap: 8px;
}

.nav-item {
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--text-secondary);
    background: transparent;
    cursor: pointer;
    text-align: left;
    font-weight: 700;
    transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.nav-item:hover,
.nav-item.active {
    color: var(--accent-primary);
    border-color: rgba(37, 99, 235, 0.12);
    background: rgba(37, 99, 235, 0.08);
}

.passport-card,
.content-panel,
.exchange-panel {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.passport-card {
    padding: 16px;
    margin-top: auto;
}

.section-label {
    margin-bottom: 10px;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0;
}

.account-select,
.token-bar input {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.account-select:hover,
.token-bar input:hover {
    border-color: var(--border-strong);
}

.account-select:focus,
.token-bar input:focus {
    border-color: rgba(37, 99, 235, 0.62);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.passport-info {
    margin-top: 12px;
    display: grid;
    gap: 6px;
    word-break: break-all;
}

.passport-info span {
    color: var(--text-secondary);
}

.main {
    min-width: 0;
    padding: 28px;
}

.topbar {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(520px, 0.9fr);
    gap: 18px;
    align-items: center;
    margin-bottom: 18px;
}

.topbar-status {
    display: grid;
    gap: 4px;
}

.topbar-status strong {
    font-size: 1rem;
}

.token-bar {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) 150px auto;
    gap: 10px;
}

.btn {
    min-height: 42px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: #fff;
    cursor: pointer;
    font-weight: 800;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
}

.btn-secondary {
    background: #0f172a;
}

.btn-danger {
    background: #ef4444;
}

.btn-outline {
    border-color: var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.btn-outline:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.btn:disabled {
    opacity: 0.58;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.notification-container {
    min-height: 0;
}

.notification {
    margin-bottom: 12px;
    padding: 12px 14px;
    border: 1px solid rgba(37, 99, 235, 0.16);
    border-left: 4px solid var(--accent-primary);
    border-radius: var(--radius);
    background: rgba(37, 99, 235, 0.08);
    color: var(--text-primary);
    box-shadow: var(--shadow);
}

.notification.error {
    border-color: rgba(220, 38, 38, 0.18);
    border-left-color: var(--accent-danger);
    background: rgba(220, 38, 38, 0.08);
}

.notification.success {
    border-color: rgba(22, 163, 74, 0.18);
    border-left-color: var(--accent-success);
    background: rgba(22, 163, 74, 0.08);
}

.page {
    display: none;
}

.page.active {
    display: block;
}

.layout-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 18px;
}

.content-panel,
.exchange-panel {
    padding: 24px;
}

.exchange-panel {
    align-self: start;
    position: sticky;
    top: 24px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 20px;
}

.panel-header.compact {
    margin-bottom: 14px;
}

.panel-header h2 {
    font-size: 1.35rem;
    line-height: 1.2;
}

.stats-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.stat-pill,
.status-badge,
.card-badge,
.shiny-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    white-space: nowrap;
}

.stat-pill {
    padding: 7px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 700;
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 14px;
}

.theme-card {
    min-height: 158px;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(248, 250, 252, 0.9)),
        var(--bg-secondary);
    cursor: pointer;
    text-align: left;
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
    position: relative;
    overflow: hidden;
}

.theme-card::after {
    content: "";
    position: absolute;
    inset: auto 14px 0;
    height: 3px;
    border-radius: 99px 99px 0 0;
    background: linear-gradient(90deg, rgba(37, 99, 235, 0.32), rgba(79, 70, 229, 0.18));
    opacity: 0;
    transition: opacity 0.18s ease;
}

.theme-card:hover {
    transform: translateY(-2px);
    border-color: rgba(37, 99, 235, 0.32);
    box-shadow: var(--shadow-hover);
}

.theme-card:hover::after {
    opacity: 1;
}

.theme-card.complete {
    border-color: rgba(22, 163, 74, 0.32);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(240, 253, 244, 0.84)),
        var(--bg-secondary);
}

.theme-number {
    display: none;
}

.theme-card h3 {
    margin: 0 0 8px;
    font-size: 1.16rem;
    line-height: 1.25;
}

.theme-card p {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.theme-progress {
    margin-top: 18px;
}

.progress-track {
    height: 7px;
    overflow: hidden;
    border-radius: 99px;
    background: #e2e8f0;
}

.progress-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
}

.theme-meta {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 700;
}

.exchange-tabs,
.filter-tabs {
    display: flex;
    gap: 6px;
    padding: 4px;
    border-radius: var(--radius);
    background: var(--bg-tertiary);
}

.segment {
    min-height: 34px;
    padding: 7px 12px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 800;
    transition: color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.segment.active {
    color: #fff;
    background: #0f172a;
    box-shadow: 0 8px 20px -16px rgba(15, 23, 42, 0.7);
}

.exchange-list {
    margin-top: 14px;
    display: grid;
    gap: 10px;
    max-height: calc(100vh - 220px);
    overflow-y: auto;
    padding-right: 4px;
}

.exchange-item,
.account-item {
    padding: 13px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-secondary);
}

.exchange-title {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-weight: 800;
}

.exchange-meta,
.providers {
    margin-top: 6px;
    color: var(--text-secondary);
    font-size: 0.84rem;
}

.provider-chip {
    display: inline-flex;
    margin: 5px 5px 0 0;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.08);
    color: var(--accent-primary);
    font-weight: 700;
}

.card-catalog {
    display: grid;
    gap: 24px;
}

.catalog-group h3 {
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 1.05rem;
}

.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
    gap: 9px;
}

.modal-card-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.postcard {
    position: relative;
    min-height: 0;
    padding: 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.postcard.missing {
    opacity: 0.4;
    filter: grayscale(1) contrast(0.85);
    background: #e2e8f0;
}

.postcard.shiny {
    border-color: transparent;
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.08), 0 14px 34px -26px rgba(79, 70, 229, 0.52);
}

.postcard.shiny::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.58), rgba(129, 140, 248, 0.32), rgba(14, 165, 233, 0.44));
    pointer-events: none;
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
}

.card-art {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    background-image: var(--asset);
    background-size: 300% 300%;
    background-position: var(--pos-x) var(--pos-y);
    background-repeat: no-repeat;
    object-fit: cover;
    background-color: transparent;
    overflow: hidden;
    transform: translateZ(0);
}

.card-name {
    margin-top: 8px;
    padding-right: 34px;
    min-height: 36px;
    line-height: 1.25;
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 700;
}

.catalog-grid .postcard {
    padding: 7px;
    border-radius: 10px;
}

.catalog-grid .card-art {
    border-radius: 7px;
}

.catalog-grid .card-name {
    margin-top: 5px;
    min-height: 0;
    height: calc(1.18em * 2);
    padding-right: 24px;
    font-size: 0.74rem;
    line-height: 1.18;
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.catalog-grid .count-badge {
    right: 5px;
    bottom: 5px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    font-size: 0.68rem;
}

.catalog-grid .shiny-badge {
    left: 5px;
    top: 5px;
    padding: 2px 6px;
    font-size: 0.62rem;
}

.count-badge {
    position: absolute;
    right: 8px;
    bottom: 8px;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: #fff;
    font-size: 0.82rem;
    font-weight: 900;
    box-shadow: 0 10px 20px -14px rgba(37, 99, 235, 0.75);
}

.shiny-badge {
    position: absolute;
    left: 8px;
    top: 8px;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid rgba(37, 99, 235, 0.18);
    color: var(--accent-secondary);
    font-size: 0.72rem;
    font-weight: 900;
    box-shadow: 0 8px 18px -16px rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(8px);
}

.card-badge {
    padding: 4px 8px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 800;
}

.accounts-list {
    display: grid;
    gap: 12px;
}

.account-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: start;
}

.account-item.current {
    border-color: rgba(37, 99, 235, 0.38);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.06);
}

.account-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-weight: 800;
}

.account-meta {
    margin-top: 6px;
    display: grid;
    gap: 3px;
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.account-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.account-source-note {
    grid-column: 1 / -1;
    padding: 9px 10px;
    border-radius: var(--radius);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.account-edit-form {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(180px, 0.45fr) minmax(260px, 1fr);
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.account-edit-field {
    display: grid;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 800;
}

.account-edit-field input,
.account-edit-field textarea {
    width: 100%;
    min-height: 38px;
    padding: 9px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    outline: none;
    resize: vertical;
    font-weight: 500;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.account-edit-field input:focus,
.account-edit-field textarea:focus {
    border-color: rgba(37, 99, 235, 0.62);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.account-edit-token {
    grid-column: span 1;
}

.account-edit-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.status-badge {
    padding: 3px 8px;
    font-size: 0.72rem;
    background: rgba(245, 158, 11, 0.1);
    color: #b45309;
    font-weight: 900;
}

.status-badge.ok {
    background: rgba(22, 163, 74, 0.1);
    color: #15803d;
}

.status-badge.bad {
    background: rgba(220, 38, 38, 0.1);
    color: #b91c1c;
}

.status-badge.source {
    background: rgba(37, 99, 235, 0.08);
    color: var(--accent-primary);
}

.empty {
    padding: 24px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    color: var(--text-secondary);
    background: rgba(248, 250, 252, 0.72);
    text-align: center;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(15, 23, 42, 0.42);
    padding: 16px;
    backdrop-filter: blur(10px);
}

.modal.open {
    display: block;
}

.modal-content {
    width: min(560px, calc(100vw - 32px), calc(100vh - 210px));
    max-height: calc(100vh - 32px);
    margin: 0 auto;
    overflow: hidden;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 28px 72px -42px rgba(15, 23, 42, 0.52);
}

.modal-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.modal-header h3 {
    font-size: 1.08rem;
}

.modal-header p {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.close {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.close:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.modal-card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 12px;
    gap: 8px;
}

.theme-modal-content .postcard {
    padding: 6px;
    border-radius: 10px;
}

.theme-modal-content .card-name {
    margin-top: 5px;
    min-height: 0;
    height: calc(1.18em * 2);
    padding-right: 28px;
    font-size: 0.76rem;
    line-height: 1.18;
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.theme-modal-content .count-badge {
    right: 6px;
    bottom: 6px;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    font-size: 0.72rem;
}

.theme-modal-content .shiny-badge {
    left: 6px;
    top: 6px;
    padding: 2px 6px;
    font-size: 0.64rem;
}

.theme-modal-content .card-art {
    border-radius: 7px;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

@media (max-width: 1120px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .nav {
        grid-template-columns: repeat(3, 1fr);
    }

    .layout-grid,
    .topbar {
        grid-template-columns: 1fr;
    }

    .exchange-panel {
        position: static;
    }
}

@media (max-width: 760px) {
    .main,
    .sidebar {
        padding: 16px;
    }

    .token-bar,
    .account-item,
    .account-edit-form {
        grid-template-columns: 1fr;
    }

    .account-actions,
    .account-edit-actions {
        justify-content: flex-start;
    }

    .sidebar {
        gap: 14px;
    }

    .nav {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 2px;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .nav::-webkit-scrollbar {
        display: none;
    }

    .nav-item {
        flex: 1 0 104px;
        min-height: 40px;
        padding: 9px 10px;
        text-align: center;
        white-space: nowrap;
    }

    .panel-header {
        flex-direction: column;
    }

    .stats-row {
        justify-content: flex-start;
    }

    .modal-card-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    .catalog-grid {
        grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
        gap: 8px;
    }

    .postcard {
        padding: 7px;
    }

    .card-name {
        min-height: 32px;
        font-size: 0.78rem;
    }
}

@media (max-width: 430px) {
    .nav-item {
        flex-basis: 112px;
    }

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

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

    .modal-card-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
