:root {
    color-scheme: dark;

    --bg: #151515;
    --panel: #202020;
    --panel-soft: #292929;
    --border: #3b3b3b;
    --text: #f5f5f5;
    --muted: #c8c8c8;
    --soft: #9ca3af;

    --digital: #16a34a;
    --cinemas: #60a5fa;
    --physical: #9ca3af;
    --downloaded: #22c55e;
    --movie-upcoming: #60a5fa;
    --movie-missing: #ef4444;

    --tv-ready: #16a34a;
    --tv-upcoming: #60a5fa;
    --tv-today: #f59e0b;
    --tv-missing: #ef4444;

    --accent: #fbbf24;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    min-height: 64px;
    background: #242424;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 18px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 205px;
}

.brand-mark {
    color: var(--accent);
    font-size: 1.8rem;
    line-height: 1;
}

.brand h1 {
    margin: 0;
    font-size: 1.35rem;
    color: var(--accent);
    letter-spacing: -0.04em;
    white-space: nowrap;
}

.tabs {
    display: flex;
    gap: 8px;
}

.tab {
    border: 1px solid var(--border);
    background: #111827;
    color: var(--text);
    border-radius: 999px;
    padding: 7px 13px;
    font-weight: 800;
    cursor: pointer;
}

.tab.active {
    background: var(--accent);
    color: #111827;
}

.header-stats {
    color: var(--muted);
    font-size: 0.92rem;
    white-space: nowrap;
    min-width: 260px;
}

.today-button {
    border: 1px solid var(--border);
    background: #111827;
    color: var(--text);
    border-radius: 999px;
    padding: 7px 13px;
    font-weight: 800;
    cursor: pointer;
}

.today-button:hover {
    background: #1f2937;
}

.search-wrap {
    position: relative;
    flex: 1;
    max-width: 460px;
    margin-left: auto;
}

#media-search {
    width: 100%;
    border: 0;
    border-bottom: 1px solid #bdbdbd;
    background: transparent;
    color: var(--text);
    font-size: 1rem;
    padding: 9px 4px;
    outline: none;
}

#media-search::placeholder {
    color: #d1d5db;
}

.search-results {
    position: absolute;
    top: 42px;
    left: 0;
    right: 0;
    background: #111827;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    max-height: 420px;
    overflow-y: auto;
}

.search-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #263241;
}

.search-item:hover {
    background: #1f2937;
}

.search-item img,
.search-placeholder {
    width: 38px;
    height: 56px;
    object-fit: cover;
    border-radius: 6px;
    background: #374151;
    flex: 0 0 auto;
}

.search-item strong {
    display: block;
}

.search-item span {
    color: var(--muted);
    font-size: 0.9rem;
}

.archived-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font-size: 0.9rem;
    white-space: nowrap;
    cursor: pointer;
}

.archived-toggle input {
    accent-color: var(--accent);
}

.legend-bar {
    position: sticky;
    top: 64px;
    z-index: 55;
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: center;
    min-height: 38px;
    background: #1c1c1c;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.92rem;
    padding: 8px 22px;
}

.legend-bar span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.legend-box {
    width: 6px;
    height: 18px;
    display: inline-block;
    border-radius: 3px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    display: inline-block;
}

.event-digital {
    background: var(--digital);
}

.event-cinemas {
    background: var(--cinemas);
}

.event-physical {
    background: var(--physical);
}

.downloaded {
    background: var(--downloaded);
}

.event-tv-ready {
    background: var(--tv-ready);
}

.event-tv-upcoming {
    background: var(--tv-upcoming);
}

.event-tv-today {
    background: var(--tv-today);
}

.event-tv-missing {
    background: var(--tv-missing);
}

.event-tv-archived {
    background: #4b5563;
}

main {
    padding: 16px 22px 40px;
}

.status-bar {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--muted);
    padding: 12px 14px;
    margin-bottom: 12px;
}

.calendar {
    display: grid;
    gap: 30px;
}

.month {
    scroll-margin-top: 116px;
}

.month-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--text);
    margin: 0 0 10px;
    font-size: 1.35rem;
}

.month-title span {
    color: var(--soft);
    font-size: 0.95rem;
    font-weight: 500;
}

.weekdays,
.days {
    display: grid;
    grid-template-columns: repeat(7, minmax(130px, 1fr));
}

.weekdays div {
    color: var(--muted);
    font-weight: 700;
    padding: 8px;
    text-align: right;
    border-bottom: 1px solid var(--border);
}

.day {
    min-height: 126px;
    background: #1c1c1c;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 6px;
    position: relative;
}

.day:nth-child(7n + 1) {
    border-left: 1px solid var(--border);
}

.day.empty {
    background: #171717;
}

.day.today {
    background: #252525;
    outline: 2px solid rgba(251, 191, 36, 0.55);
    z-index: 1;
}

.day-number {
    color: #d1d5db;
    font-size: 0.9rem;
    text-align: right;
    margin-bottom: 5px;
}

.event {
    display: block;
    width: 100%;
    text-align: left;
    color: var(--text);
    background: #242424;
    border: 0;
    border-left: 4px solid var(--cinemas);
    border-radius: 3px;
    padding: 7px 7px 7px 9px;
    margin-bottom: 5px;
    cursor: pointer;
}

.event:hover {
    background: #303030;
}

.event.event-digital {
    border-left-color: var(--digital);
    background: #242424;
}

.event.event-cinemas {
    border-left-color: var(--cinemas);
    background: #242424;
}

.event.event-physical {
    border-left-color: var(--physical);
    background: #242424;
}

.event.event-movie-upcoming {
    border-left-color: var(--movie-upcoming);
    background: #242424;
}

.event.event-movie-missing {
    border-left-color: var(--movie-missing);
    background: #2a1f1f;
}

.event.event-tv-ready {
    border-left-color: var(--tv-ready);
    background: #242424;
}

.event.event-tv-upcoming {
    border-left-color: var(--tv-upcoming);
    background: #242424;
}

.event.event-tv-today {
    border-left-color: var(--tv-today);
    background: #242424;
}

.event.event-tv-missing {
    border-left-color: var(--tv-missing);
    background: #2a1f1f;
}

.event.event-tv-archived {
    border-left-color: #4b5563;
    background: #202020;
    opacity: 0.72;
}

.event-title {
    font-size: 0.92rem;
    font-weight: 750;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.event-meta {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: #e5e7eb;
    font-size: 0.78rem;
    margin-top: 3px;
}

.event-downloaded {
    color: #86efac;
}

.hidden {
    display: none !important;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
}

.modal-card {
    position: relative;
    width: min(980px, calc(100vw - 28px));
    max-height: calc(100vh - 34px);
    overflow-y: auto;
    margin: 17px auto;
    background: #111827;
    border: 1px solid #374151;
    border-radius: 18px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 3;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.68);
    color: white;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
}

.movie-detail,
.tv-detail {
    display: grid;
    grid-template-columns: minmax(220px, 330px) 1fr;
    gap: 0;
}

.detail-poster {
    width: 100%;
    min-height: 500px;
    object-fit: cover;
    background: #1f2937;
}

.detail-body {
    padding: 34px 28px;
}

.detail-body h2 {
    font-size: clamp(2rem, 5vw, 3.4rem);
    margin: 0 0 8px;
    line-height: 1;
}

.detail-status {
    color: #93c5fd;
    font-weight: 700;
    margin-bottom: 18px;
}

.detail-overview {
    line-height: 1.6;
    color: #e5e7eb;
    font-size: 1.05rem;
}

.release-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 18px 0;
}

.release-list span {
    border-radius: 999px;
    padding: 7px 11px;
    background: #bfdbfe;
    color: #0f172a;
    font-weight: 800;
    font-size: 0.9rem;
}

.file-info {
    margin-top: 18px;
    color: var(--muted);
    border-top: 1px solid #374151;
    padding-top: 14px;
    font-size: 0.95rem;
}

.placeholder-poster {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 500px;
    padding: 20px;
    background:
        radial-gradient(circle at top left, #334155, transparent 42%),
        linear-gradient(135deg, #111827, #1e293b);
    text-align: center;
}

.placeholder-poster span {
    font-size: 1.35rem;
    font-weight: 800;
    color: #dbeafe;
    line-height: 1.25;
}

@media (max-width: 1050px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 10px;
    }

    .brand {
        min-width: 0;
    }

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

    .search-wrap {
        max-width: none;
        margin-left: 0;
    }

    .legend-bar {
        top: auto;
        position: static;
    }

    .month {
        scroll-margin-top: 20px;
    }
}

@media (max-width: 900px) {
    .weekdays,
    .days {
        grid-template-columns: repeat(7, minmax(95px, 1fr));
        overflow-x: auto;
    }

    .day {
        min-height: 110px;
    }

    .movie-detail,
    .tv-detail {
        grid-template-columns: 1fr;
    }

    .detail-poster {
        max-height: 560px;
        min-height: 0;
    }
}

@media (max-width: 620px) {
    main {
        padding: 12px;
    }

    .calendar {
        overflow-x: auto;
    }

    .weekdays,
    .days {
        min-width: 760px;
    }
}


.date-nav {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
}

.primary-date-button {
    background: var(--accent);
    color: #111827;
}

.primary-date-button:hover {
    background: #fcd34d;
}

.day.jump-highlight {
    outline: 3px solid rgba(251, 191, 36, 0.95);
    box-shadow: 0 0 0 5px rgba(251, 191, 36, 0.18);
}


.cassette-button {
    min-width: 46px;
    height: 36px;
    border: 1px solid rgba(17, 24, 39, 0.22);
    border-radius: 8px;
    background:
        linear-gradient(180deg, #f8fafc 0%, #d1d5db 48%, #9ca3af 52%, #e5e7eb 100%);
    color: #111827;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.9),
        inset 0 -2px 0 rgba(0, 0, 0, 0.16),
        0 2px 5px rgba(0, 0, 0, 0.16);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.cassette-button:hover {
    filter: brightness(1.04);
    transform: translateY(-1px);
}

.cassette-button:active {
    transform: translateY(1px);
    box-shadow:
        inset 0 2px 3px rgba(0, 0, 0, 0.22),
        0 1px 2px rgba(0, 0, 0, 0.14);
}

.cassette-icon {
    font-size: 0.95rem;
    letter-spacing: -3px;
    font-weight: 900;
    line-height: 1;
    transform: scaleX(1.15);
}

/* ----------------------------------------------------
   Mobile compact header fix
   Keeps controls usable in portrait mode
---------------------------------------------------- */

@media only screen and (max-width: 760px) {
    .topbar {
        display: grid;
        grid-template-columns: auto 1fr auto;
        grid-template-areas:
            "brand tabs nav"
            "stats search search";
        align-items: center;
        gap: 8px;
        padding: 8px 10px;
    }

    .brand {
        grid-area: brand;
        min-width: 0;
    }

    .brand h1 {
        font-size: 1rem;
        white-space: nowrap;
    }

    .brand-mark {
        width: 26px;
        height: 26px;
        font-size: 0.75rem;
    }

    .tabs {
        grid-area: tabs;
        justify-content: center;
        gap: 5px;
    }

    .tab {
        padding: 7px 10px;
        font-size: 0.85rem;
    }

    .date-nav {
        grid-area: nav;
        gap: 5px;
    }

    .cassette-button {
        min-width: 38px;
        height: 32px;
    }

    .today-button {
        height: 32px;
        padding: 0 10px;
        font-size: 0.85rem;
    }

    .header-stats {
        grid-area: stats;
        font-size: 0.75rem;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .search-wrap {
        grid-area: search;
        min-width: 0;
    }

    #media-search {
        height: 34px;
        font-size: 0.9rem;
    }

    .archived-toggle {
        grid-column: 1 / -1;
        justify-self: start;
        font-size: 0.8rem;
    }

    .legend-bar {
        overflow-x: auto;
        white-space: nowrap;
        justify-content: flex-start;
        padding: 7px 10px;
    }

    main {
        padding-top: 8px;
    }
}

@media only screen and (max-width: 430px) {
    .brand h1 {
        display: none;
    }

    .header-stats {
        display: none;
    }

    .topbar {
        grid-template-columns: auto 1fr auto;
        grid-template-areas:
            "brand tabs nav"
            "search search search";
    }

    .tab {
        padding: 6px 8px;
    }

    .cassette-button {
        min-width: 34px;
    }

    .today-button {
        padding: 0 8px;
    }
}

