:root {
    --tg-bg: var(--tg-theme-bg-color, #f4f6f8);
    --tg-text: var(--tg-theme-text-color, #17212b);
    --tg-hint: var(--tg-theme-hint-color, #7d8b99);
    --tg-link: var(--tg-theme-link-color, #2481cc);
    --tg-button: var(--tg-theme-button-color, #2481cc);
    --tg-button-text: var(--tg-theme-button-text-color, #ffffff);
    --tg-secondary: var(--tg-theme-secondary-bg-color, #ffffff);
    --accent: #2481cc;
    --accent-soft: rgba(36, 129, 204, 0.12);
    --success: #2ea66b;
    --warning: #ffb020;
    --danger: #e05252;
    --line: rgba(113, 128, 143, 0.18);
    --shadow: 0 16px 46px rgba(20, 45, 70, 0.11);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--tg-text);
    background: var(--tg-bg);
    font-synthesis: none;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--tg-bg);
}

body {
    min-width: 300px;
    min-height: 100vh;
    margin: 0;
    background: var(--tg-bg);
    color: var(--tg-text);
    -webkit-tap-highlight-color: transparent;
}

button,
input {
    font: inherit;
}

button {
    color: inherit;
}

button:focus-visible,
input:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 32%, transparent);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

.app-shell {
    width: min(100%, 720px);
    min-height: 100vh;
    margin: 0 auto;
    padding: 17px 16px calc(24px + env(safe-area-inset-bottom));
}

.app-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    margin: 0 -16px 24px;
    padding: 0 16px 16px;
    border-bottom: 1px solid var(--line);
}

.brand-mark {
    width: 44px;
    height: 44px;
    color: var(--accent);
}

.brand-mark svg { width: 100%; height: 100%; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.brand-copy {
    min-width: 0;
}

.eyebrow {
    margin: 0 0 3px;
    color: var(--tg-hint);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 0.09em;
    line-height: 1.2;
    text-transform: uppercase;
}

.brand-copy h1 {
    overflow: hidden;
    margin: 0;
    font-size: clamp(18px, 5.2vw, 22px);
    letter-spacing: -0.035em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quota-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 34px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: var(--tg-secondary);
    box-shadow: 0 5px 18px rgba(20, 45, 70, 0.06);
    font-size: 12px;
    font-weight: 700;
}

.quota-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 16%, transparent);
}

.quota-badge.is-premium .quota-dot {
    background: var(--warning);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--warning) 18%, transparent);
}

.view {
    display: none;
    animation: view-in 190ms ease both;
}

.view.is-active {
    display: block;
}

@keyframes view-in {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.loading-view {
    padding: 17vh 12px 12vh;
    text-align: center;
}

.loading-view h2,
.empty-state h2 {
    margin: 26px 0 8px;
    font-size: 25px;
    letter-spacing: -0.035em;
}

.loading-view p,
.empty-state p {
    margin: 0;
    color: var(--tg-hint);
    line-height: 1.55;
}

.loading-lock {
    position: relative;
    width: 74px;
    height: 78px;
    margin: 0 auto;
}

.lock-shackle {
    position: absolute;
    top: 0;
    left: 17px;
    width: 40px;
    height: 42px;
    border: 8px solid var(--accent);
    border-bottom: 0;
    border-radius: 22px 22px 0 0;
}

.lock-body {
    position: absolute;
    right: 4px;
    bottom: 0;
    left: 4px;
    height: 53px;
    border-radius: 18px;
    background: linear-gradient(145deg, #38a6ef, #176bb0);
    box-shadow: 0 15px 34px rgba(36, 129, 204, 0.3);
}

.lock-body span {
    position: absolute;
    top: 18px;
    left: 50%;
    width: 7px;
    height: 15px;
    border-radius: 5px;
    background: #fff;
    transform: translateX(-50%);
}

.loading-line {
    overflow: hidden;
    width: 150px;
    height: 4px;
    margin: 28px auto 0;
    border-radius: 9px;
    background: var(--accent-soft);
}

.loading-line span {
    display: block;
    width: 45%;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    animation: loading 1s ease-in-out infinite alternate;
}

@keyframes loading {
    to { transform: translateX(122%); }
}

.location-card,
.paywall-card {
    border: 1px solid color-mix(in srgb, var(--accent) 10%, var(--line));
    border-radius: 24px;
    background: color-mix(in srgb, var(--tg-secondary) 94%, transparent);
    box-shadow: var(--shadow);
}

.hero-card {
    padding: 17px 4px 0;
}

.hero-card h2,
.codes-heading h2,
.paywall-card h2,
.add-dialog h2 {
    margin: 0;
    font-size: clamp(25px, 7vw, 34px);
    letter-spacing: -0.045em;
    line-height: 1.08;
}

.hero-card > p:last-of-type {
    margin: 10px 0 22px;
    color: var(--tg-hint);
    font-size: 14px;
}

.search-box {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    min-height: 62px;
    padding: 0 13px 0 16px;
    border: 1.5px solid color-mix(in srgb, var(--tg-text) 10%, transparent);
    border-radius: 17px;
    background: var(--tg-secondary);
    box-shadow: 0 7px 24px rgba(20, 45, 70, 0.06);
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.search-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.search-box svg {
    width: 21px;
    fill: none;
    stroke: var(--tg-hint);
    stroke-linecap: round;
    stroke-width: 2;
}

.search-box input {
    min-width: 0;
    height: 60px;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--tg-text);
    font-size: 16px;
}

.search-box input::placeholder {
    color: color-mix(in srgb, var(--tg-hint) 80%, transparent);
}

.search-box button {
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: color-mix(in srgb, var(--tg-hint) 14%, transparent);
    color: var(--tg-hint);
    line-height: 1;
}

.search-box button svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2; }

.section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin: 26px 4px 12px;
}

.section-heading h3 {
    margin: 0;
    font-size: 16px;
}

.section-heading span {
    color: var(--tg-hint);
    font-size: 12px;
    text-align: right;
}

.result-list,
.code-list {
    display: grid;
    gap: 0;
}

.result-list:not(:empty) {
    overflow: hidden;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: var(--tg-secondary);
}

.result-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 78px;
    padding: 14px 12px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: var(--tg-secondary);
    text-align: left;
    box-shadow: none;
}

.result-card:last-child { border-bottom: 0; }

.result-card:active,
.entrance-card:active {
    transform: scale(0.985);
}

.location-pin {
    position: relative;
    display: block;
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: var(--accent-soft);
}

.location-pin::before {
    position: absolute;
    top: 9px;
    left: 13px;
    width: 14px;
    height: 18px;
    border: 2px solid var(--accent);
    border-radius: 9px 9px 11px 11px;
    content: "";
}

.location-pin::after {
    position: absolute;
    top: 15px;
    left: 19px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--accent);
    content: "";
}

.result-icon {
    display: grid;
    width: 46px;
    height: 46px;
    place-items: center;
    color: var(--accent);
}

.result-icon svg { width: 39px; height: 39px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.result-copy {
    min-width: 0;
}

.result-copy strong {
    display: block;
    font-size: 14px;
    line-height: 1.35;
}

.result-copy small {
    display: block;
    margin-top: 5px;
    color: var(--tg-hint);
    font-size: 12px;
}

.chevron {
    color: var(--tg-hint);
}

.chevron svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.trust-note {
    display: flex;
    gap: 11px;
    margin-top: 38px;
    padding: 19px 7px 0;
    border-top: 1px solid var(--line);
    color: var(--tg-hint);
}

.trust-note > span {
    display: grid;
    flex: 0 0 25px;
    height: 25px;
    place-items: center;
    border-radius: 50%;
    border: 2px solid var(--success);
    background: transparent;
    color: var(--success);
    font-size: 13px;
    font-weight: 800;
}

.trust-note > span svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.trust-note p {
    margin: 1px 0 0;
    font-size: 12px;
    line-height: 1.5;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 0 0 15px;
    padding: 5px 0;
    border: 0;
    background: transparent;
    color: var(--tg-link);
    font-size: 14px;
    font-weight: 650;
}

.back-link svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.location-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 19px;
}

.location-card h2 {
    margin: 0;
    font-size: 17px;
    line-height: 1.4;
}

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

.entrance-card {
    position: relative;
    display: grid;
    min-height: 132px;
    padding: 17px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--tg-secondary);
    text-align: left;
    box-shadow: 0 8px 25px rgba(20, 45, 70, 0.05);
}

.entrance-number {
    color: var(--accent);
    font-size: 31px;
    font-weight: 800;
    letter-spacing: -0.05em;
    line-height: 1;
}

.entrance-card strong {
    align-self: end;
    font-size: 14px;
}

.entrance-card small {
    margin-top: 3px;
    color: var(--tg-hint);
    font-size: 11px;
}

.entrance-card .chevron {
    position: absolute;
    top: 14px;
    right: 15px;
}

.selected-address {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 68px;
    margin: 3px 0 24px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--tg-secondary);
}

.selected-address p {
    margin: 0;
    font-size: 14px;
    line-height: 1.4;
}

.selected-address-icon {
    display: grid;
    flex: 0 0 42px;
    height: 42px;
    place-items: center;
    border-radius: 12px;
    background: rgba(113, 128, 143, 0.09);
    color: var(--tg-hint);
}

.selected-address-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.codes-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 14px;
    margin: 5px 2px 14px;
}

.codes-caption {
    margin: 0 2px 18px;
    color: var(--tg-hint);
    font-size: 13px;
}

.code-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    min-height: 88px;
    padding: 17px 14px 17px 18px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: var(--tg-secondary);
    box-shadow: none;
}

.code-list:not(:empty) {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 17px;
    background: var(--tg-secondary);
}

.code-card:last-child { border-bottom: 0; }

.code-value {
    overflow-wrap: anywhere;
    font: 750 24px/1.2 ui-monospace, "SFMono-Regular", Menlo, monospace;
    letter-spacing: 0.025em;
}

.rating-controls {
    display: grid;
    grid-template-columns: 42px 36px 42px;
    align-items: center;
    gap: 2px;
    flex: 0 0 auto;
}

.rating-controls button {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: transparent;
    color: var(--tg-hint);
    font-size: 20px;
    font-weight: 700;
}

.rating-controls button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.rating-controls button.is-active[data-vote="like"] {
    background: color-mix(in srgb, var(--success) 15%, transparent);
    border-color: var(--success);
    color: var(--success);
}

.rating-controls button.is-active[data-vote="dislike"] {
    background: color-mix(in srgb, var(--danger) 15%, transparent);
    border-color: var(--danger);
    color: var(--danger);
}

.rating-controls span {
    font-size: 13px;
    font-weight: 750;
    text-align: center;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 50px;
    padding: 0 18px;
    border: 0;
    border-radius: 15px;
    font-weight: 750;
    transition: opacity 140ms ease, transform 140ms ease;
}

.button:active { transform: scale(0.985); }
.button:disabled { opacity: 0.56; }

.button-primary {
    background: var(--tg-button);
    color: var(--tg-button-text);
}

.button-secondary {
    border: 1px solid var(--line);
    background: var(--tg-secondary);
    color: var(--tg-link);
}

.button-small {
    min-height: 38px;
    padding: 0 12px;
    border-radius: 12px;
    font-size: 12px;
}

.button-small svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.paywall-context {
    margin: 4px 2px 14px;
}

.paywall-context p {
    margin: 0 0 7px;
    color: var(--tg-hint);
    font-size: 14px;
    line-height: 1.4;
}

.paywall-context h2 {
    margin: 0;
    font-size: clamp(28px, 8vw, 36px);
    letter-spacing: -0.045em;
}

.paywall-stage {
    position: relative;
    min-height: 760px;
    padding-top: 224px;
}

.teaser-stack {
    position: absolute;
    inset: 0 10px auto;
    display: grid;
    gap: 10px;
    filter: blur(0.7px);
    opacity: 0.68;
    pointer-events: none;
    user-select: none;
}

.teaser-code {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 72px;
    padding: 0 20px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--tg-secondary);
    font: 750 23px ui-monospace, monospace;
}

.paywall-card {
    position: relative;
    z-index: 2;
    width: min(100%, 480px);
    margin: 0 auto;
    padding: 27px 23px 23px;
    border-radius: 24px;
    text-align: center;
    backdrop-filter: blur(18px);
}

.paywall-lock {
    display: grid;
    width: 64px;
    height: 64px;
    margin: 0 auto 18px;
    place-items: center;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
}

.paywall-lock svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.paywall-card > p:not(.eyebrow):not(.renewal-note) {
    margin: 12px auto 20px;
    color: var(--tg-hint);
    font-size: 14px;
    line-height: 1.5;
}

.benefit-list {
    display: grid;
    gap: 0;
    margin: 0 0 22px;
    padding: 0;
    list-style: none;
    text-align: left;
}

.benefit-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 58px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
    font-weight: 650;
}

.benefit-list li:last-child { border-bottom: 0; }

.benefit-list .benefit-icon {
    display: grid;
    flex: 0 0 39px;
    height: 39px;
    place-items: center;
    border-radius: 50%;
    background: color-mix(in srgb, var(--success) 11%, transparent);
    color: var(--success);
}

.benefit-list li:last-child .benefit-icon { background: rgba(122, 92, 230, 0.11); color: #7658dd; }
.benefit-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.button-stars {
    width: 100%;
    min-height: 56px;
    background: linear-gradient(135deg, #1689ea, #0876d5);
    color: #fff;
    box-shadow: 0 12px 25px rgba(36, 129, 204, 0.24);
}

.button-stars svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }

.button-stars + .button-secondary {
    width: 100%;
    margin-top: 10px;
}

.renewal-note {
    margin: 13px 6px 0;
    color: var(--tg-hint);
    font-size: 11px;
    line-height: 1.45;
}

.empty-state {
    padding: 17vh 20px 10vh;
    text-align: center;
}

.empty-state .button {
    margin-top: 24px;
}

.empty-icon {
    display: grid;
    width: 62px;
    height: 62px;
    margin: 0 auto;
    place-items: center;
    border-radius: 20px;
    background: color-mix(in srgb, var(--danger) 13%, transparent);
    color: var(--danger);
    font-size: 30px;
    font-weight: 800;
}

.app-footer {
    margin: 30px 20px 0;
    color: var(--tg-hint);
    font-size: 10px;
    line-height: 1.45;
    text-align: center;
}

.add-dialog {
    width: min(calc(100% - 24px), 500px);
    margin: auto auto 0;
    padding: 0;
    border: 0;
    border-radius: 25px 25px 0 0;
    background: var(--tg-secondary);
    color: var(--tg-text);
    box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.18);
}

.add-dialog::backdrop {
    background: rgba(15, 23, 32, 0.48);
    backdrop-filter: blur(3px);
}

.add-dialog form {
    position: relative;
    padding: 28px 22px calc(22px + env(safe-area-inset-bottom));
}

.dialog-handle {
    width: 42px;
    height: 4px;
    margin: -15px auto 22px;
    border-radius: 5px;
    background: color-mix(in srgb, var(--tg-hint) 34%, transparent);
}

.dialog-close {
    position: absolute;
    top: 17px;
    right: 17px;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: color-mix(in srgb, var(--tg-hint) 12%, transparent);
    color: var(--tg-hint);
    font-size: 23px;
}

.add-dialog p:not(.eyebrow) {
    margin: 10px 0 22px;
    color: var(--tg-hint);
    font-size: 14px;
}

.field-label {
    display: block;
    margin: 0 0 7px;
    font-size: 12px;
    font-weight: 700;
}

.text-field {
    width: 100%;
    height: 55px;
    margin-bottom: 13px;
    padding: 0 15px;
    border: 1.5px solid var(--line);
    border-radius: 15px;
    outline: 0;
    background: var(--tg-bg);
    color: var(--tg-text);
    font-size: 17px;
}

.text-field:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.add-dialog .button {
    width: 100%;
}

.toast {
    position: fixed;
    z-index: 10;
    right: 16px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    left: 16px;
    width: min(calc(100% - 32px), 500px);
    margin: 0 auto;
    padding: 13px 16px;
    border-radius: 14px;
    background: color-mix(in srgb, var(--tg-text) 92%, transparent);
    color: var(--tg-bg);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.22);
    font-size: 13px;
    font-weight: 650;
    text-align: center;
    animation: toast-in 180ms ease both;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
}

.skeleton-card {
    height: 71px;
    border-radius: 18px;
    background: linear-gradient(90deg, var(--tg-secondary), color-mix(in srgb, var(--tg-hint) 9%, var(--tg-secondary)), var(--tg-secondary));
    background-size: 220% 100%;
    animation: shimmer 1.2s linear infinite;
}

@keyframes shimmer { to { background-position: -220% 0; } }

@media (max-width: 480px) and (max-height: 900px) {
    .paywall-stage {
        min-height: 660px;
        padding-top: 184px;
    }

    .teaser-code {
        height: 56px;
        border-radius: 16px;
        font-size: 21px;
    }

    .paywall-card {
        padding: 21px 20px 19px;
    }

    .paywall-lock {
        width: 56px;
        height: 56px;
        margin-bottom: 12px;
    }

    .paywall-lock svg {
        width: 29px;
        height: 29px;
    }

    .paywall-card > p:not(.eyebrow):not(.renewal-note) {
        margin: 8px auto 12px;
    }

    .benefit-list {
        margin-bottom: 14px;
    }

    .benefit-list li {
        min-height: 50px;
    }

    .benefit-list .benefit-icon {
        flex-basis: 36px;
        height: 36px;
    }

    .button-stars {
        min-height: 52px;
    }

    .renewal-note {
        margin-top: 10px;
    }
}

@media (min-width: 560px) {
    .app-shell { padding-top: 28px; }
    .entrance-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .add-dialog { margin-bottom: 24px; border-radius: 25px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
