:root {
    --bg: #0b0b12;
    --surface: rgba(20, 20, 31, 0.88);
    --surface2: rgba(30, 30, 49, 0.9);
    --accent: #e50914;
    --accent2: #ff6b35;
    --accent3: #22c55e;
    --text: #f4f4f7;
    --text-muted: #9b9bb8;
    --border: rgba(255, 255, 255, 0.1);
    --nav-height: 92px;
    --card-radius: 24px;
    --gap: 14px;
    --sai-top: env(safe-area-inset-top);
    --sai-bottom: env(safe-area-inset-bottom);
    --sai-left: env(safe-area-inset-left);
    --sai-right: env(safe-area-inset-right);
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100vh;
    background: var(--bg);
}

body {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
    overflow: hidden;
    position: relative;
    font-family: 'Inter', -apple-system, sans-serif;
    color: var(--text);
}

@supports (-webkit-touch-callout: none) {
    html {
        height: -webkit-fill-available;
    }
    body {
        min-height: -webkit-fill-available;
    }
}

body::before,
body::after {
    content: '';
    position: absolute;
    inset: auto;
    pointer-events: none;
    z-index: 0;
    filter: blur(28px);
    opacity: 0.8;
}

body::before {
    width: 320px;
    height: 320px;
    left: -80px;
    top: 6vh;
    background: radial-gradient(circle, rgba(255, 107, 53, 0.48), transparent 68%);
}

body::after {
    width: 380px;
    height: 380px;
    right: -100px;
    bottom: 8vh;
    background: radial-gradient(circle, rgba(34, 197, 94, 0.25), transparent 66%);
}

body.profile-open {
    overflow: hidden;
}

.hidden {
    display: none !important;
}

#auth-shell,
#app-shell {
    position: fixed;
    inset: 0;
    height: 100vh;
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
    background: var(--bg);
    z-index: 1;
}

#auth-shell {
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    background:
        radial-gradient(ellipse 90% 65% at 10% 95%, rgba(52, 19, 97, 0.95) 0%, transparent 65%),
        radial-gradient(ellipse 75% 70% at 90% 8%, rgba(1, 43, 122, 0.9) 0%, transparent 60%),
        radial-gradient(ellipse 50% 50% at 60% 50%, rgba(20, 6, 55, 0.5) 0%, transparent 75%),
        #040210;
}

#app-shell {
    background:
        radial-gradient(ellipse 90% 65% at 10% 95%, rgba(52, 19, 97, 0.95) 0%, transparent 65%),
        radial-gradient(ellipse 75% 70% at 90% 8%, rgba(1, 43, 122, 0.9) 0%, transparent 60%),
        radial-gradient(ellipse 50% 50% at 60% 50%, rgba(20, 6, 55, 0.5) 0%, transparent 75%),
        #040210;
}

.auth-card {
    width: 100%;
    max-width: 430px;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 0;
    background: transparent;
    position: relative;
    z-index: 3;
}

.auth-hero {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 2px;
    padding: calc(20px + env(safe-area-inset-top)) 20px 0;
    text-align: left;
    margin-bottom: auto;
}

.auth-logo {
    display: none;
}

.auth-hero h1 {
    font-family: "Chango", sans-serif;
    font-weight: 400;
    font-size: clamp(2.4rem, 11vw, 3.5rem);
    color: #fff;
    line-height: 1;
    letter-spacing: -0.5px;
    margin: 0;
    text-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

.auth-subtitle {
    font-family: "Chango", sans-serif;
    font-weight: 400;
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 5px;
    margin-top: 2px;
}

/* ── Auth bucket ── */
.auth-bucket {
    position: absolute;
    bottom: -90px;
    right: -260px;
    width: clamp(280px, 190vw, 680px);
    height: auto;
    object-fit: contain;
    z-index: 2;
    pointer-events: none;
    filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.55));
}

/* ── Floating corn pieces ── */
.corn-float {
    position: absolute;
    pointer-events: none;
    z-index: 2;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.4));
    animation: cornFloat 6s ease-in-out infinite;
}

.corn-1 { width: 72px; top: 22%; left: 10%; animation-duration: 6s; }
.corn-2 { width: 52px; top: 15%; left: 70%; animation-duration: 7s; animation-delay: 1.5s; }
.corn-3 { width: 80px; top: 30%; right: 20%; animation-duration: 5.5s; animation-delay: 0.8s; }
.corn-4 { width: 58px; top: 40%; left: 24%; animation-duration: 6.5s; animation-delay: 2.2s; }

@keyframes cornFloat {
    0%, 100% { transform: translateY(0px) rotate(-3deg); }
    35% { transform: translateY(-14px) rotate(5deg); }
    65% { transform: translateY(-6px) rotate(-5deg); }
}

.auth-copy,
.auth-note {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.auth-note {
    margin-top: 14px;
    font-size: 0.76rem;
    text-align: center;
}

.auth-panel {
    width: calc(100% - 24px);
    margin: 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 28px;
    background: rgba(8, 6, 20, 0.75);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 16px 50px rgba(0, 0, 0, 0.28);
    padding: 14px;
}

.glass-panel {
    position: relative;
}

.auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 0 0 16px;
}

.auth-tab,
.auth-submit,
.profile-btn,
.icon-btn {
    border: none;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
}

.auth-tab {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 14px 16px;
    font-size: 0.86rem;
    font-weight: 700;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.auth-tab.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 10px 24px rgba(229, 9, 20, 0.24);
}

.auth-form {
    display: none;
    gap: 12px;
}

.auth-form.active {
    display: grid;
}

.auth-form label,
.profile-form label {
    display: grid;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.auth-form input,
.profile-input {
    width: 100%;
    min-height: 58px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 20px;
    padding: 16px 18px;
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.auth-form input:focus,
.profile-input:focus {
    border-color: var(--accent);
}

.auth-submit,
.profile-btn {
    background: var(--accent);
    color: #fff;
    border-radius: 999px;
    padding: 14px 16px;
    font-size: 0.9rem;
    font-weight: 700;
}

.auth-actions {
    display: grid;
    grid-template-columns: 1fr;
    padding: 8px 12px calc(20px + env(safe-area-inset-bottom));
}

.auth-submit-single {
    width: 100%;
    min-height: 58px;
    background: linear-gradient(135deg, var(--accent), #ff4b58 55%, #ff6b35);
    box-shadow: 0 12px 28px rgba(229, 9, 20, 0.28);
}

.auth-error {
    margin-top: 14px;
}

/* ── App Shell ── */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 430px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

/* ── Top Header ── */
header {
    padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
    background: linear-gradient(180deg, rgba(10, 10, 15, 0.9) 0%, rgba(10, 10, 15, 0.2) 100%);
    position: relative;
    z-index: 20;
    flex-shrink: 0;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.header-main {
    min-width: 0;
}

header h1 {
    font-family: "Chango", sans-serif;
    font-weight: 400;
    font-size: 1.6rem;
    letter-spacing: -0.5px;
    background: white;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

header p.subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
    font-weight: 400;
}

.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 1rem;
    flex-shrink: 0;
}

.database-pill {
    flex: 1;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.65rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Views ── */
.view {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 10px 16px calc(var(--nav-height) + 36px + var(--sai-bottom));
    -webkit-overflow-scrolling: touch;
}

.view.active {
    display: block;
}

/* ── Movie Grid ── */
.movie-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

/* ── Movie Card ── */
.movie-card {
    border-radius: 28px;
    overflow: hidden;
    background: var(--surface);
    position: relative;
    aspect-ratio: 2/3;
    cursor: pointer;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.movie-card:active {
    transform: scale(0.97);
}

.movie-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.movie-card .no-poster {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--surface2) 0%, #0d0d1a 100%);
    gap: 8px;
    padding: 12px;
    text-align: center;
}

.movie-card .no-poster .icon {
    font-size: 2.5rem;
    opacity: 0.6;
}

.movie-card .no-poster .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.3;
}

/* Card overlay at the bottom */
.card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.94) 0%, rgba(0, 0, 0, 0.56) 56%, transparent 100%);
    padding: 28px 12px 12px;
}

.card-overlay h3 {
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.3;
    color: #fff;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-overlay .year {
    font-size: 0.62rem;
    color: rgba(255, 255, 255, 0.55);
    margin-bottom: 8px;
}

/* Card action buttons */
.card-actions {
    display: flex;
    gap: 6px;
}

.btn-watched,
.btn-add,
.btn-remove {
    flex: 1;
    border: none;
    border-radius: 999px;
    padding: 8px 6px;
    font-size: 0.65rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.15s ease;
    letter-spacing: 0.2px;
}

.btn-watched {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    backdrop-filter: blur(4px);
}

.btn-watched:active {
    background: rgba(255, 255, 255, 0.25);
}

.btn-add {
    background: var(--accent);
    color: #fff;
}

.btn-add:active {
    background: #c0000f;
}

.btn-remove {
    background: rgba(229, 9, 20, 0.25);
    color: var(--accent);
}

.btn-remove:active {
    background: rgba(229, 9, 20, 0.4);
}

/* ── Empty State ── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    gap: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 24px;
}

.empty-state .emoji {
    font-size: 3.5rem;
    opacity: 0.6;
}

.empty-state h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.empty-state p {
    font-size: 0.82rem;
    line-height: 1.5;
}

/* ── Add View ── */
#view-add {
    padding-top: 16px;
}

.search-bar-wrap {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

#search-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 20px;
    padding: 14px 16px;
    color: var(--text);
    font-size: 0.92rem;
    font-family: 'Inter', sans-serif;
    outline: none;
    transition: border-color 0.2s;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

#search-input::placeholder {
    color: var(--text-muted);
}

#search-input:focus {
    border-color: var(--accent);
}

#btn-search {
    background: var(--accent);
    border: none;
    border-radius: 18px;
    padding: 14px 18px;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

#btn-search:active {
    background: #c0000f;
}

.search-status {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.82rem;
    padding: 16px 0;
}

.spinner {
    display: inline-block;
    width: 22px;
    height: 22px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Section label ── */
.section-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

/* ── Toast ── */
#toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 20px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(18, 18, 28, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 10px 20px;
    border-radius: 100px;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    white-space: nowrap;
    max-width: 85vw;
    text-align: center;
}

#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Bottom Nav ── */
.dock-nav {
    position: fixed;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 24px);
    max-width: 430px;
    max-height: 80px;
    background: rgba(15, 15, 24, 0.66);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 34px;
    display: flex;
    align-items: stretch;
    padding: 10px;
    z-index: 100;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.42);
}

.nav-btn {
    flex: 1;
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    border-radius: 23px;
    padding: 14px 8px;
}

.nav-btn .nav-icon {
    font-size: 1.75rem;
    transition: transform 0.2s;
}

.nav-btn .nav-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    transition: color 0.2s;
}

.nav-btn.active .nav-label {
    color: var(--accent);
}

.nav-btn.active .nav-icon {
    transform: scale(1.12);
}

.nav-btn.active {
    background: rgba(255, 255, 255, 0.06);
}

/* Badge */
.nav-badge {
    position: absolute;
    top: 10px;
    right: calc(50% - 25px);
    background: var(--accent);
    color: #fff;
    font-size: 0.55rem;
    font-weight: 800;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.2s, transform 0.2s;
}

.nav-badge.visible {
    opacity: 1;
    transform: scale(1);
}

/* Viewed badge (green) */
#btn-viewed .nav-badge {
    background: #22c55e;
    right: calc(50% - 26px);
}

/* ── Error message ── */
.error-msg {
    background: rgba(229, 9, 20, 0.12);
    border: 1px solid rgba(229, 9, 20, 0.3);
    border-radius: 18px;
    color: #ff6b6b;
    font-size: 0.8rem;
    padding: 10px 14px;
    margin-bottom: 16px;
    text-align: center;
}

#profile-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.52);
    z-index: 140;
}

.profile-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: min(100%, 420px);
    height: 100%;
    background: rgba(12, 12, 20, 0.94);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 150;
    padding: calc(24px + var(--sai-top)) 20px 28px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    box-shadow: -12px 0 50px rgba(0, 0, 0, 0.45);
}

.profile-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.profile-head h2 {
    font-size: 1.3rem;
    margin-bottom: 4px;
}

.profile-head p {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.close-btn {
    background: rgba(255, 255, 255, 0.06);
}

.profile-section {
    display: grid;
    gap: 8px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
}

.profile-form {
    gap: 12px;
}

.profile-label {
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.profile-value {
    font-size: 0.95rem;
    color: var(--text);
}

.monospace {
    font-family: 'SFMono-Regular', Consolas, monospace;
}

.profile-btn.secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}

.profile-btn.danger {
    background: rgba(229, 9, 20, 0.2);
    color: #ff8c8c;
    border: 1px solid rgba(229, 9, 20, 0.28);
    margin-top: auto;
}

@media (max-width: 480px) {
    #auth-shell {
        padding: 0;
    }

    .auth-card {
        height: 100%;
        padding: 0;
    }

    .movie-grid {
        gap: 12px;
    }

    .profile-panel {
        width: 100%;
    }

    .dock-nav {
        width: calc(100% - 16px);
        max-height: 75px;
        border-radius: 35px;
    }
}

/* ── Viewed card style ── */
.movie-card.watched::after {
    content: '✓';
    position: absolute;
    top: 8px;
    right: 8px;
    background: #22c55e;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 800;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Install Banner ── */
.install-banner {
    position: fixed;
    bottom: calc(var(--nav-height) + 14px);
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    width: calc(100% - 24px);
    max-width: 430px;
    background: rgba(14, 12, 28, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 24px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    padding: 14px;
}

.install-banner.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

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

.install-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    object-fit: contain;
    flex-shrink: 0;
}

.install-body {
    flex: 1;
    min-width: 0;
}

.install-title {
    display: block;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text);
}

.install-sub {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.install-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.install-action-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 0.8rem;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    white-space: nowrap;
}

.install-close-btn {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Inter', sans-serif;
    flex-shrink: 0;
}

.install-ios-hint {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.6;
}

.install-ios-hint strong {
    color: var(--text);
}