/*
 * Petrol-blue room, butter-yellow ticket stubs. The stubs (diary, viewings,
 * login) are the one loud element; everything else stays flat and quiet.
 */
:root {
    --bg: #142128;
    --surface: #1c2d36;
    --raised: #243a45;
    --line: #2f4754;
    --text: #ece6d6;
    --dim: #93a6ae;
    --butter: #f1d27a;
    --butter-deep: #d9b75a;
    --ink: #2a2216;
    --mint: #86c5a4;
    --rose: #d9877f;

    --condensed: "Barlow Condensed", "Arial Narrow", sans-serif-condensed, sans-serif;
    --body: "Barlow", system-ui, sans-serif;

    --tabbar-height: 3.5rem;

    color-scheme: dark;
    font-family: var(--body);
    font-size: 100%;
    line-height: 1.5;
    font-variant-numeric: tabular-nums;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

::selection { background: var(--butter); color: var(--ink); }

[hidden] { display: none !important; }

img { display: block; }

h1, h2, h3 {
    font-family: var(--condensed);
    font-weight: 600;
    line-height: 1.1;
    margin: 0;
}

:focus-visible {
    outline: 2px solid var(--butter);
    outline-offset: 2px;
}

/* ---------- Controls ---------- */

button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}

button:disabled { opacity: 0.5; cursor: default; }

.primary,
.secondary {
    font-family: var(--condensed);
    font-weight: 600;
    font-size: 1.0625rem;
    letter-spacing: 0.01em;
    padding: 0.45rem 1rem;
    border-radius: 6px;
}

.primary { background: var(--butter); color: var(--ink); }
.primary:hover:not(:disabled) { background: var(--butter-deep); }

.secondary { background: var(--raised); color: var(--text); }
.secondary:hover:not(:disabled) { background: var(--line); }

.text-danger {
    color: var(--rose);
    font-size: 0.875rem;
    text-decoration: underline;
    text-decoration-color: transparent;
    text-underline-offset: 3px;
}

.text-danger:hover { text-decoration-color: currentColor; }

select,
input[type="date"],
input[type="search"],
input[type="text"],
input[type="password"],
textarea {
    font: inherit;
    font-size: 0.9375rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
}

select {
    appearance: none;
    padding-right: 1.8rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2393a6ae'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
}

select:focus,
input:focus,
textarea:focus {
    outline: none;
    border-color: var(--butter);
}

/* ---------- Masthead & navigation ---------- */

.masthead {
    display: flex;
    align-items: center;
    gap: 2rem;
    max-width: 1120px;
    margin: 0 auto;
    padding: 1.25rem 1.5rem 0;
}

.masthead h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.tabbar {
    display: flex;
    gap: 1.5rem;
    align-self: stretch;
}

.tab {
    font-family: var(--condensed);
    font-size: 1.1875rem;
    font-weight: 500;
    color: var(--dim);
    padding: 0.75rem 0 0.6rem;
    border-bottom: 3px solid transparent;
}

.tab:hover { color: var(--text); }

.tab[aria-current="page"] {
    color: var(--text);
    border-bottom-color: var(--butter);
}

.masthead-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.signout {
    color: var(--dim);
    font-size: 0.875rem;
    text-decoration: none;
}

.signout:hover { color: var(--text); }

#app {
    max-width: 1120px;
    margin: 0 auto;
    padding: 1.5rem 1.5rem 4rem;
}

.toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 0.6rem;
    margin-bottom: 1.75rem;
    color: var(--dim);
    font-size: 0.875rem;
}

#status-filter-wrap {
    display: contents;
}

#status-filter-wrap select { margin-right: 0.75rem; }

.empty {
    color: var(--dim);
    max-width: 34em;
}

.empty .primary { margin-top: 0.75rem; }

/* ---------- Poster grid ---------- */

.shelf + .shelf { margin-top: 2.75rem; }

.shelf-title {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    font-size: 1.5625rem;
    margin-bottom: 1rem;
}

.shelf-title .count {
    font-family: var(--body);
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--dim);
}

.shelf-note {
    color: var(--dim);
    font-size: 0.875rem;
    margin: -0.6rem 0 1rem;
}

.poster-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1.75rem 1.25rem;
}

.film {
    display: flex;
    flex-direction: column;
    text-align: left;
    min-width: 0;
}

.film-poster {
    position: relative;
    display: block;
    aspect-ratio: 2 / 3;
    background: var(--surface);
    border-radius: 3px;
    overflow: hidden;
}

.film-poster img.poster {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.film:hover .film-poster { outline: 2px solid var(--butter); outline-offset: 3px; }

.no-poster {
    display: flex;
    align-items: flex-end;
    height: 100%;
    padding: 0.75rem;
    font-family: var(--condensed);
    font-size: 1.25rem;
    line-height: 1.1;
    color: var(--dim);
}

.provider-badge {
    position: absolute;
    left: 6px;
    bottom: 6px;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    box-shadow: 0 0 0 2px var(--bg);
}

.rating-badge {
    position: absolute;
    right: 6px;
    top: 6px;
    min-width: 1.9rem;
    padding: 0.05rem 0.35rem;
    border-radius: 4px;
    background: var(--butter);
    color: var(--ink);
    font-family: var(--condensed);
    font-weight: 700;
    font-size: 1rem;
    text-align: center;
}

.film-title {
    margin-top: 0.6rem;
    font-weight: 600;
    font-size: 0.9375rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.film-meta {
    font-size: 0.8125rem;
    color: var(--dim);
    margin-top: 0.15rem;
}

.film-meta .soon { color: var(--butter); }

/* ---------- Ticket stubs ---------- */

.month + .month { margin-top: 2.5rem; }

.month-title {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    font-size: 1.5625rem;
    margin-bottom: 1rem;
}

.month-title .count {
    font-family: var(--body);
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--dim);
}

.stubs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 0.75rem;
}

.stub {
    --notch: 9px;
    --stub-end: 4.5rem;
    position: relative;
    display: grid;
    grid-template-columns: var(--stub-end) 1fr auto;
    align-items: stretch;
    background: var(--butter);
    color: var(--ink);
    border-radius: 5px;
    text-align: left;
    min-height: 4.75rem;
}

/* Notches where the stub tears, cut out top and bottom */
.stub::before,
.stub::after {
    content: "";
    position: absolute;
    left: calc(var(--stub-end) - var(--notch));
    width: calc(var(--notch) * 2);
    height: calc(var(--notch) * 2);
    border-radius: 50%;
    background: var(--bg);
}

.stub::before { top: calc(var(--notch) * -1); }
.stub::after { bottom: calc(var(--notch) * -1); }

.stub-date {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: var(--condensed);
    line-height: 1;
}

.stub-day {
    font-size: 2.25rem;
    font-weight: 700;
}

.stub-dow {
    font-size: 0.9375rem;
    font-weight: 500;
    margin-top: 0.15rem;
}

.stub-body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    padding: 0.6rem 0.75rem 0.6rem 1rem;
    border-left: 2px dashed rgba(42, 34, 22, 0.35);
}

.stub-title {
    font-family: var(--condensed);
    font-size: 1.3125rem;
    font-weight: 600;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stub-meta {
    font-size: 0.8125rem;
    opacity: 0.75;
}

.stub-rating {
    display: flex;
    align-items: center;
    padding: 0 1rem 0 0.25rem;
    font-family: var(--condensed);
    font-size: 1.5rem;
    font-weight: 700;
}

.stub-rating small {
    font-size: 0.875rem;
    font-weight: 500;
    opacity: 0.6;
}

button.stub:hover { background: var(--butter-deep); }

/* ---------- Film detail ---------- */

.back {
    color: var(--dim);
    font-size: 0.9375rem;
    margin-bottom: 1.25rem;
}

.back::before { content: "‹ "; }
.back:hover { color: var(--text); }

.detail {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 2.5rem;
}

.detail-poster {
    width: 100%;
    border-radius: 4px;
}

.detail h2 {
    font-size: 2.75rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.facts {
    margin: 0.5rem 0 0;
    color: var(--dim);
}

.facts strong { color: var(--text); font-weight: 500; }

.overview {
    max-width: 36em;
    margin: 1.25rem 0 0;
    line-height: 1.6;
}

.detail-block {
    margin-top: 2rem;
    max-width: 36em;
}

.detail-block h3 {
    font-size: 1.25rem;
    margin-bottom: 0.6rem;
}

.release-line { margin: 0; }

.release-line.soon { color: var(--butter); }
.release-line.cinema { color: var(--mint); }

.providers {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.providers li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.providers img {
    width: 32px;
    height: 32px;
    border-radius: 7px;
}

.providers .kind { color: var(--dim); display: block; font-size: 0.75rem; }

.plex-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1f1f1f;
    color: #e5a00d;
}

.plex-badge svg { width: 62%; height: 62%; }

.plex-row {
    display: flex;
    flex-wrap: wrap;
    width: fit-content;
    align-items: center;
    gap: 0.6rem 0.75rem;
    margin-bottom: 0.9rem;
    padding: 0.45rem;
    border-radius: 9px;
    background: var(--surface);
}

.plex-row .plex-badge {
    width: 36px;
    height: 36px;
    border-radius: 7px;
}

.plex-label {
    font-weight: 600;
    margin-right: 0.25rem;
}

.plex-actions {
    display: flex;
    gap: 0.4rem;
}

.plex-action {
    padding: 0.35rem 0.85rem;
    border-radius: 6px;
    background: var(--raised);
    color: var(--text);
    font-family: var(--condensed);
    font-size: 1.0625rem;
    font-weight: 600;
    text-decoration: none;
}

.plex-action:hover { background: var(--line); }

.rent-buy {
    margin: 0.9rem 0 0;
    font-size: 0.875rem;
    color: var(--dim);
}

.plex-row + .rent-buy { margin-top: 0; }

.credit {
    margin: 0.75rem 0 0;
    font-size: 0.75rem;
    color: var(--dim);
}

.credit a { color: inherit; }

.segmented {
    display: inline-flex;
    background: var(--surface);
    border-radius: 7px;
    padding: 3px;
}

.segmented button {
    padding: 0.35rem 0.9rem;
    border-radius: 5px;
    font-size: 0.9375rem;
    color: var(--dim);
}

.segmented button:hover { color: var(--text); }

.segmented button[aria-pressed="true"] {
    background: var(--raised);
    color: var(--text);
    font-weight: 600;
}

.segmented button[data-status="abandoned"][aria-pressed="true"] { color: var(--rose); }

.rating-scale {
    display: flex;
    gap: 4px;
}

.rating-scale button {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 5px;
    background: var(--surface);
    color: var(--dim);
    font-family: var(--condensed);
    font-size: 1.125rem;
    font-weight: 600;
}

.rating-scale button:hover { color: var(--text); background: var(--raised); }

.rating-scale button.below {
    background: var(--raised);
    color: var(--text);
}

.rating-scale button.chosen {
    background: var(--butter);
    color: var(--ink);
}

.hint {
    font-size: 0.8125rem;
    color: var(--dim);
    margin: 0.4rem 0 0;
}

.notes {
    width: 100%;
    min-height: 5rem;
    resize: vertical;
    line-height: 1.5;
}

.log-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
}

.viewings {
    margin-top: 1rem;
    display: grid;
    gap: 0.9rem;
    max-width: 22rem;
    /* lets a newly logged stub slide out from under the form */
    overflow: hidden;
    padding: 9px 0;
}

.viewing {
    --stub-end: 4rem;
    --notch: 7px;
    min-height: 3.5rem;
    grid-template-columns: var(--stub-end) 1fr auto;
}

.viewing .stub-day { font-size: 1.75rem; }

.viewing .stub-body { padding-top: 0.4rem; padding-bottom: 0.4rem; }

.viewing .stub-title { font-size: 1.0625rem; }

.viewing-remove {
    padding: 0 0.9rem;
    font-size: 0.8125rem;
    color: var(--ink);
    opacity: 0.6;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.viewing-remove:hover { opacity: 1; }

.viewing.printed { animation: print 420ms cubic-bezier(0.2, 0.7, 0.2, 1); }

@keyframes print {
    from { transform: translateY(-110%); }
    to { transform: translateY(0); }
}

.remove-film {
    margin-top: 3rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--line);
    max-width: 36em;
}

/* ---------- Add dialog ---------- */

.add-dialog {
    width: min(32rem, calc(100vw - 2rem));
    max-height: min(40rem, calc(100vh - 4rem));
    margin: 4rem auto auto;
    padding: 1.25rem;
    background: var(--surface);
    color: var(--text);
    border: 0;
    border-radius: 10px;
}

.add-dialog::backdrop { background: rgba(8, 14, 17, 0.75); }

.add-dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 0.9rem;
}

.add-dialog h2 { font-size: 1.5625rem; }

.add-dialog .close {
    font-size: 1.5rem;
    line-height: 1;
    color: var(--dim);
    padding: 0.25rem 0.5rem;
}

.add-dialog .close:hover { color: var(--text); }

#search-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    font-size: 1rem;
    background: var(--bg);
}

.search-results { margin-top: 0.75rem; }

.result {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    width: 100%;
    padding: 0.5rem;
    border-radius: 6px;
    text-align: left;
}

.result:hover:not(:disabled) { background: var(--raised); }

.result img,
.result .result-blank {
    width: 40px;
    height: 60px;
    border-radius: 2px;
    background: var(--raised);
    object-fit: cover;
    flex-shrink: 0;
}

.result-title { font-weight: 600; }

.result-year { color: var(--dim); font-size: 0.875rem; }

.result-state {
    margin-left: auto;
    font-size: 0.8125rem;
    color: var(--mint);
    white-space: nowrap;
}

.search-message { color: var(--dim); font-size: 0.9375rem; padding: 0.5rem; }

/* ---------- Login ---------- */

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.login {
    display: grid;
    grid-template-columns: 4.5rem 1fr;
    width: min(100%, 22rem);
    background: var(--butter);
    color: var(--ink);
    border-radius: 6px;
    position: relative;
}

.login::before,
.login::after {
    content: "";
    position: absolute;
    left: calc(4.5rem - 10px);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg);
}

.login::before { top: -10px; }
.login::after { bottom: -10px; }

.login-stub {
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 2px dashed rgba(42, 34, 22, 0.35);
}

.login-stub-mark {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-family: var(--condensed);
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.login-fields {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    padding: 1.75rem 1.5rem;
}

.login-fields h1 { font-size: 1.75rem; font-weight: 700; }

.login-fields label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.login-fields input {
    background: #fbf1d0;
    color: var(--ink);
    border-color: rgba(42, 34, 22, 0.25);
}

.login-fields input:focus { border-color: var(--ink); }

.login-fields .primary {
    background: var(--ink);
    color: var(--butter);
    margin-top: 0.3rem;
}

.login-fields .primary:hover { background: #3d3222; }

.login-fields :focus-visible { outline-color: var(--ink); }

.login .error {
    margin: 0;
    font-size: 0.875rem;
    color: #8a2a20;
}

/* ---------- Small screens ---------- */

@media (max-width: 720px) {
    .masthead {
        padding: 1rem 1rem 0;
        padding-top: max(1rem, env(safe-area-inset-top));
    }

    .masthead h1 { font-size: 1.5rem; }

    .masthead-actions { gap: 1rem; }

    /* Tabs move to a bar along the bottom edge, within thumb reach */
    .tabbar {
        position: fixed;
        z-index: 10;
        left: 0;
        right: 0;
        bottom: 0;
        gap: 0;
        height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: var(--surface);
        border-top: 1px solid var(--line);
    }

    .tab {
        flex: 1;
        padding: 0;
        border-bottom: 0;
        border-top: 3px solid transparent;
        font-size: 1.0625rem;
    }

    .tab[aria-current="page"] {
        border-top-color: var(--butter);
        background: var(--raised);
    }

    #app {
        padding: 1.25rem 1rem calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 2rem);
    }

    .poster-grid {
        grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
        gap: 1.25rem 0.75rem;
    }

    .film-title { font-size: 0.875rem; }

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

    .detail {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    .detail-poster { width: 140px; }

    .detail h2 { font-size: 2.25rem; }

    .rating-scale { gap: 3px; }

    .rating-scale button {
        flex: 1;
        width: auto;
        height: 2.5rem;
        font-size: 1rem;
    }

    .add-dialog { margin-top: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
    .viewing.printed { animation: none; }
}
