/* ================= APP ================= */

#app {

    --app-inline-padding: 18px;
    --bottom-nav-clearance: calc(72px + max(16px, env(safe-area-inset-bottom)) + 28px);

    max-width: 540px;

    margin: 0 auto;

    min-height: 100vh;

    padding: 0 var(--app-inline-padding) var(--bottom-nav-clearance);

}

/* ================= HEADER ================= */

.topbar {
    display: block;
    min-height: 0;
    padding: 0;
    margin: 0 calc(var(--app-inline-padding) * -1) 14px;
    position: relative;
}

html.access-pending #app {
    visibility: hidden;
}

.access-gate {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: grid;
    place-items: center;
    padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
    background: var(--bg);
}

.access-gate.hidden {
    display: none;
}

.splash-screen {
    display: flex;
    width: min(100%, 420px);
    max-width: calc(100vw - 40px);
    justify-self: center;
    flex-direction: column;
    align-items: center;
    text-align: center;
    color: var(--text-secondary);
}

.splash-visual {
    position: relative;
    width: 84px;
    height: 84px;
    margin-bottom: 22px;
    display: grid;
    place-items: center;
}

.splash-logo {
    width: 72px;
    height: 72px;
    border-radius: 18%;
    object-fit: cover;
    opacity: .55;
    filter: blur(3px);
    animation: splash-logo-appear .8s ease forwards;
}

.splash-progress {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.splash-progress rect {
    stroke: currentColor;
    stroke-width: 1.4;
    stroke-linecap: round;
    stroke-dasharray: 18 82;
    animation: splash-progress 1.8s linear infinite;
}

.splash-icon {
    width: 64px;
    height: 64px;
    color: currentColor;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.splash-icon.hidden,
.splash-button.hidden,
.splash-logo.hidden,
.splash-progress.hidden {
    display: none;
}

.splash-title {
    min-height: 2.9em;
    max-width: 330px;
    font: 600 18px/1.45 "Manrope", sans-serif;
    color: var(--text-secondary);
    transition: opacity .2s ease;
    overflow-wrap: anywhere;
}

.splash-message {
    max-width: 330px;
    margin: 0;
    color: var(--text-secondary);
    font-size: 16px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.splash-button {
    min-width: 210px;
    margin-top: 24px;
}

.splash-screen.is-error .splash-logo,
.splash-screen.is-error .splash-progress {
    display: none;
}

@keyframes splash-logo-appear {
    from { opacity: .45; filter: blur(3px); }
    to { opacity: 1; filter: blur(0); }
}

@keyframes splash-progress {
    to { stroke-dashoffset: -100; }
}

#app[data-active-screen="calendarScreen"] .topbar {
    min-height: 0;
    margin-bottom: 71px;
}

#app[data-active-screen="searchScreen"] .topbar,
#app[data-active-screen="favoritesScreen"] .topbar {
    margin-bottom: 9px;
}

.header-actions {
    position: absolute;
    top: calc(50% + 1px);
    right: var(--app-inline-padding);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1;
    transform: translateY(-50%);
}

#app[data-active-screen="searchScreen"] .header-month-card,
#app[data-active-screen="favoritesScreen"] .header-month-card {
    display: none;
}

.app-header-artwork {
    position: relative;
    width: 100%;
    aspect-ratio: 2.5 / 1;
    overflow: hidden;
    line-height: 0;
    -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 72%, transparent 100%);
    mask-image: linear-gradient(to bottom, #000 0%, #000 72%, transparent 100%);
}

.app-header-artwork img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 42%;
}

.title-icon {
    display: none;
}

.icon-button {

    width: 42px;

    height: 42px;

    border: none;

    border-radius: 14px;

    background: var(--surface);

    color: var(--text);

    cursor: pointer;

    font-size: 20px;

    transition: var(--transition);

    box-shadow: var(--shadow);

}

.icon-button:active {
    transform: scale(.96);
}

/* ================= SCREEN ================= */

.screen {

    display: none;

}

.screen.active {

    display: block;

}

/* ================= MONTH ================= */

.month-card {
    background: var(--surface);

    border: 1px solid var(--border);

    border-radius: 999px;

    min-height: 56px;
    padding: 6px 10px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    margin-bottom: 12px;

    box-shadow: var(--shadow);
}

.header-month-card {
    position: absolute;
    right: var(--app-inline-padding);
    bottom: -59px;
    left: var(--app-inline-padding);
    z-index: 2;
    margin: 0;
}

.month-title {
    font-family: "Manrope", sans-serif;
    font-weight: 800;

    font-size: 22px;

    font-weight: 700;

    text-align: center;

}

.month-center {

    flex: 1;

}

.month-arrow {
    width: 42px;
    height: 42px;

    display: flex;
    align-items: center;
    justify-content: center;

    flex-shrink: 0;

    cursor: pointer;
    user-select: none;

    border-radius: 12px;

    background: transparent;

    transition: .2s;
}

.month-arrow:hover {
    background: transparent;
}

.month-arrow:active {
    transform: scale(.95);
}

.month-arrow svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
}

#prevMonth svg,
#nextMonth svg {
    pointer-events: none;
}

/* ================= WEEK ================= */

.weekdays {

    display: grid;

    grid-template-columns: repeat(7, 1fr);

    margin-bottom: 12px;

    text-align: center;

    color: var(--text-secondary);

    font-size: 13px;

    font-weight: 600;

}

/* ================= CALENDAR ================= */

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    justify-content: stretch;
    gap: 8px;
}

.upcoming-events {
    margin-top: var(--space-lg);
}

.upcoming-events-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: var(--space-sm);
}

.upcoming-events-title {
    flex: 1 1 auto;
    min-width: 0;
    box-sizing: border-box;

    margin: 0;
    padding: 0;

    font-family: "Manrope", sans-serif;
    font-size: 20px;
    font-weight: 800;
    text-align: left;
}

.upcoming-events-all {
    border: 0;
    padding: 0;
    background: transparent;
    flex-shrink: 0;
    color: var(--text-secondary);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

.upcoming-events-empty {
    margin: 0;
    padding: 16px 0 8px;
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
}

.support-cta {
    display: grid;
    width: calc(100% - 12px);
    gap: 3px;
    margin: 0 6px;
    padding: 13px 16px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--text);
    text-align: center;
    cursor: pointer;
    background: linear-gradient(135deg, rgba(255, 175, 119, .16), rgba(255, 175, 119, .07)), var(--surface);
}

#upcomingEventsList {
    padding-bottom: 16px;
}

.favorites-empty-state {
    margin-top: 64px;
    padding: 0 18px;
}

.favorites-empty-state p {
    max-width: 230px;
    margin: 0 auto;
}

.support-cta span {
    color: var(--text-secondary);
    font-size: 13px;
}

.support-cta strong {
    font-size: 15px;
}

/* ==========================================================
   BOTTOM NAVIGATION
   ========================================================== */

.bottom-nav {

    position: fixed;

    left: 50%;
    bottom: max(24px, env(safe-area-inset-bottom));
    transform: translateX(-50%);

    width: min(520px, calc(100% - 32px));

    height: 72px;

    display: flex;
    justify-content: space-around;
    align-items: center;

    background: rgba(27, 31, 43, .82);

    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);

    border-radius: 999px;

    padding: 5px 12px;

    box-shadow:
        0 14px 35px rgba(0, 0, 0, .35),
        inset 0 1px 0 rgba(255, 255, 255, .05);

    border: 1px solid var(--border);

    z-index: 500;
}

.bottom-nav.is-keyboard-open {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.nav-btn {

    flex: 1;

    display: flex;
    flex-direction: column;

    justify-content: center;
    align-items: center;

    gap: 4px;

    padding: 6px 8px;

    border: none;
    background: none;

    border-radius: 999px;

    cursor: pointer;

    color: var(--text-secondary);

    transition: .25s ease;

}

.nav-btn svg {

    width: 22px;
    height: 22px;

    stroke-width: 2.2;

    flex-shrink: 0;

}

.nav-btn small {

    font-size: 11px;

    font-weight: 600;

    line-height: 1;

}

.nav-btn.active {

    background: linear-gradient(180deg,
            rgba(255, 175, 119, .26),
            rgba(255, 175, 119, .16));

    color: #fff;

    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08);

}

.nav-btn:hover {

    transform: translateY(-2px);

}

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 22px;
    height: 22px;

    flex-shrink: 0;
}

.nav-icon svg {
    width: 100%;
    height: 100%;
}

/* ==========================================================
   HELPERS
   ========================================================== */

.hidden {

    display: none !important;

}

.fade {

    animation: fadeIn .25s ease;

}

/* ==========================================================
   TELEGRAM SAFE AREA
   ========================================================== */

body {

    padding-top: env(safe-area-inset-top);

    padding-bottom: env(safe-area-inset-bottom);

}

@media (max-width:540px) {

    #app {
        --app-inline-padding: 14px;
    }

    .title-icon {
        width: 48px;
        height: 48px;
        font-size: 22px;
        border-radius: 16px;
    }

}

@media (max-width: 380px) {
    .upcoming-events-header {
        gap: 8px;
    }

    .upcoming-events-title {
        font-size: clamp(16px, 5.1vw, 18px);
        letter-spacing: -.02em;
    }

    .upcoming-events-all {
        font-size: 12px;
    }
}

@media (max-width: 340px) {
    .upcoming-events-header {
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: end;
    }

    .upcoming-events-title {
        grid-column: 1 / -1;
    }

    .upcoming-events-all {
        grid-column: 2;
    }
}

/* ---------- LARGE PHONES ---------- */

@media (min-width:541px) {

    #app {
        --app-inline-padding: clamp(18px, 3vw, 28px);
        max-width: clamp(620px, 86vw, 880px);
    }

    .bottom-nav {
        width: min(calc(100% - 32px), 840px);
    }

    .calendar-grid {
        gap: clamp(8px, 1.5vw, 14px);
    }

    .weekdays {
        font-size: clamp(13px, 1.8vw, 15px);
    }

}

/* Tablet proportions: keep the wider reading column while scaling controls
   and type independently from the viewport width. */
@media (min-width: 600px) {
    #app {
        --bottom-nav-clearance: calc(84px + max(24px, env(safe-area-inset-bottom)) + 32px);
    }

    .header-actions {
        gap: 10px;
    }

    .icon-button {
        width: 48px;
        height: 48px;
        border-radius: 16px;
    }

    .month-card {
        min-height: 64px;
        padding-inline: 12px;
    }

    .month-title {
        font-size: clamp(23px, 3vw, 27px);
    }

    .month-arrow {
        width: 48px;
        height: 48px;
    }

    .month-arrow svg {
        width: 27px;
        height: 27px;
    }

    .weekdays {
        margin-bottom: 14px;
        font-size: clamp(14px, 1.9vw, 16px);
    }

    .upcoming-events {
        margin-top: clamp(24px, 3vw, 32px);
    }

    .upcoming-events-header {
        margin-bottom: 14px;
    }

    .upcoming-events-title {
        font-size: clamp(22px, 2.8vw, 26px);
    }

    .upcoming-events-all {
        font-size: clamp(14px, 1.8vw, 16px);
    }

    .support-cta {
        padding: 15px 18px;
    }

    .support-cta span {
        font-size: 14px;
    }

    .support-cta strong {
        font-size: 17px;
    }

    .bottom-nav {
        width: min(calc(100% - 40px), 780px);
        height: 84px;
        padding: 6px 16px;
    }

    .nav-btn {
        gap: 6px;
        padding: 8px 12px;
    }

    .nav-btn svg,
    .nav-icon {
        width: 28px;
        height: 28px;
    }

    .nav-btn small {
        font-size: 13px;
    }
}
