:root {
    --bg: #E6E9EC;
    --ink: #18202B;
    --muted: #5B6573;
    --rule: #C4CAD1;
    --hover: #4A6A8C;

    --serif: 'Newsreader', Georgia, serif;
    --sans: 'Geist', system-ui, sans-serif;

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #12161B;
        --ink: #E3E7EB;
        --muted: #8B95A1;
        --rule: #2A313A;
        --hover: #9DB7D3;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #12161B;
    --ink: #E3E7EB;
    --muted: #8B95A1;
    --rule: #2A313A;
    --hover: #9DB7D3;
    color-scheme: dark;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 1rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.25s ease, color 0.25s ease;
}

a {
    color: inherit;
}

a:focus-visible,
button:focus-visible {
    outline: 2px solid var(--hover);
    outline-offset: 4px;
    border-radius: 2px;
}

/* Page frame */

.page {
    width: 100%;
    max-width: 36rem;
    min-height: min(100svh, 54rem);
    margin: 0 auto;
    padding: clamp(1.25rem, 4vh, 2.5rem) 1.75rem 2.75rem;
    display: flex;
    flex-direction: column;
}

.top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 2.75rem;
}

.theme-toggle {
    width: 2.75rem;
    height: 2.75rem;
    margin-right: -0.75rem;
    display: grid;
    place-items: center;
    background: none;
    border: 0;
    color: var(--muted);
    cursor: pointer;
}

.theme-toggle:hover {
    color: var(--ink);
}

.theme-toggle svg {
    width: 1.125rem;
    height: 1.125rem;
}

.theme-toggle .icon-sun {
    display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
    display: none;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .icon-sun {
        display: block;
    }

    :root:not([data-theme="light"]) .theme-toggle .icon-moon {
        display: none;
    }
}

/* Home */

.home {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 3.5rem;
    padding-top: clamp(1.5rem, 6vh, 3.5rem);
}

.name {
    margin: 0;
    font-family: var(--serif);
    font-weight: 300;
    font-size: clamp(3.5rem, 2.4rem + 5vw, 5.25rem);
    line-height: 0.95;
    letter-spacing: -0.025em;
}

.links {
    list-style: none;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--rule);
}

.links a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.125rem 0;
    border-bottom: 1px solid var(--rule);
    text-decoration: none;
    font-family: var(--serif);
    font-size: clamp(1.875rem, 1.6rem + 1vw, 2.25rem);
    line-height: 1;
    transition: color 0.2s ease;
}

.links a:hover {
    color: var(--hover);
}

.links svg {
    width: 1rem;
    height: 1rem;
    color: var(--muted);
    transition: transform 0.2s ease, color 0.2s ease;
}

.links a:hover svg {
    color: var(--hover);
    transform: translate(2px, -2px);
}

.status {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    font-size: 0.8125rem;
    color: var(--muted);
}

.status li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status li[hidden] {
    display: none;
}

.track-ago {
    flex-shrink: 0;
    opacity: 0.7;
}

/* The song line opens Spotify; same tap area as the trophy button */
.status-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    margin: -0.75rem 0;
    color: inherit;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.status-link:hover {
    color: var(--ink);
}

.status-icon {
    width: 0.8125rem;
    height: 0.8125rem;
    flex-shrink: 0;
    color: var(--ink);
}

.eq {
    display: flex;
    align-items: flex-end;
    gap: 2px;
}

.eq span {
    width: 2px;
    height: 100%;
    background: currentColor;
    transform-origin: bottom;
    transform: scaleY(0.4);
}

.eq.is-live span {
    animation: eq 1.1s ease-in-out infinite;
}

.eq.is-live span:nth-child(2) {
    animation-delay: -0.4s;
}

.eq.is-live span:nth-child(3) {
    animation-delay: -0.8s;
}

@keyframes eq {
    0%, 100% { transform: scaleY(0.35); }
    50% { transform: scaleY(1); }
}

/* Writings */

.back {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    font-size: 0.875rem;
    text-decoration: none;
}

.back:hover {
    color: var(--hover);
}

.back svg {
    width: 1rem;
    height: 1rem;
}

.writings-page {
    padding-top: clamp(1.5rem, 5vh, 3rem);
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
}

.title {
    margin: 0;
    font-family: var(--serif);
    font-weight: 300;
    font-size: clamp(3rem, 2.2rem + 3.5vw, 4.25rem);
    line-height: 0.95;
    letter-spacing: -0.025em;
}

.writings {
    list-style: none;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--rule);
}

.writings a {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--rule);
    text-decoration: none;
}

.writings a:hover {
    color: var(--hover);
}

.writings .w-title {
    font-family: var(--serif);
    font-size: 1.5rem;
    line-height: 1.2;
}

.writings time {
    flex-shrink: 0;
    font-size: 0.8125rem;
    color: var(--muted);
}

.empty {
    margin: 0;
    font-family: var(--serif);
    font-style: italic;
    font-weight: 300;
    font-size: 1.3125rem;
    color: var(--muted);
}

.writings:has(li) + .empty {
    display: none;
}

.writings:not(:has(li)) {
    display: none;
}

.writings:not(:has(li)) + .empty {
    padding-top: 1.125rem;
    border-top: 1px solid var(--rule);
}

/* Readings */

.shelf {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.shelf-heading {
    margin: 0;
    font-family: var(--serif);
    font-style: italic;
    font-weight: 300;
    font-size: 1.3125rem;
    color: var(--muted);
}

.books {
    list-style: none;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--rule);
}

.books li,
.films li {
    display: flex;
    gap: 1rem;
    padding: 1.125rem 0;
    border-bottom: 1px solid var(--rule);
}

.book-cover,
.film-poster img {
    flex-shrink: 0;
    width: 4rem;
    height: 6rem;
    object-fit: cover;
    border-radius: 2px;
    background: var(--rule);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.book-body,
.film-body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.book-desc,
.film-review {
    margin: 0.375rem 0 0;
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--muted);
}

.book-source {
    font-size: 0.75rem;
    white-space: nowrap;
    text-underline-offset: 3px;
}

.book-source:hover {
    color: var(--hover);
}

.top-four {
    list-style: none;
    margin: 0;
    padding: 0.75rem 0 0;
    border-top: 1px solid var(--rule);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.625rem;
}

.top-four a {
    display: block;
    border-radius: 3px;
    transition: transform 0.2s ease;
}

.top-four a:hover {
    transform: translateY(-3px);
}

.top-four img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    border-radius: 3px;
    background: var(--rule);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

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

/* Films */

.films {
    list-style: none;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--rule);
}

.films:empty {
    display: none;
}

.film-poster {
    flex-shrink: 0;
    align-self: flex-start;
}

.film-title {
    font-family: var(--serif);
    font-size: 1.5rem;
    line-height: 1.2;
    text-decoration: none;
}

.film-title:hover {
    color: var(--hover);
}

.film-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.125rem 0.75rem;
    font-size: 0.8125rem;
    color: var(--muted);
}

.stars {
    color: var(--ink);
    letter-spacing: 0.05em;
}

.film-review {
    white-space: pre-line;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.films:not(:empty) + .empty {
    display: none;
}

.films:empty + .empty {
    padding-top: 1.125rem;
    border-top: 1px solid var(--rule);
}

.more {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    font-size: 0.875rem;
    text-underline-offset: 4px;
}

.more:hover {
    color: var(--hover);
}

.more svg {
    width: 0.875rem;
    height: 0.875rem;
}

.book-title {
    font-family: var(--serif);
    font-size: 1.5rem;
    line-height: 1.2;
}

.book-author {
    font-size: 0.8125rem;
    color: var(--muted);
}

.progress {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
    font-size: 0.8125rem;
    color: var(--muted);
}

.progress-bar {
    flex: 1;
    height: 2px;
    background: linear-gradient(var(--ink), var(--ink)) no-repeat left / var(--p, 0%) 100%, var(--rule);
}

.progress-value {
    font-variant-numeric: tabular-nums;
}

/* Lately */

.collection {
    list-style: none;
    margin: 0;
    padding: 0.875rem 0 0;
    border-top: 1px solid var(--rule);
}

.collection:not(:has(li)) {
    display: none;
}

.collection:has(li) + .empty {
    display: none;
}

.collection:not(:has(li)) + .empty {
    padding-top: 1.125rem;
    border-top: 1px solid var(--rule);
}

.albums {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.25rem 0.75rem;
}

.albums a {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    text-decoration: none;
}

.album-art {
    position: relative;
    display: grid;
    place-items: center;
    aspect-ratio: 1;
    border-radius: 3px;
    overflow: hidden;
    background: var(--rule);
    margin-bottom: 0.375rem;
}

.album-letter {
    font-family: var(--serif);
    font-weight: 300;
    font-size: 2.5rem;
    line-height: 1;
    color: var(--muted);
}

.album-art img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.album-art img[hidden] {
    display: none;
}

.album-name {
    font-family: var(--serif);
    font-size: 1rem;
    line-height: 1.25;
}

.albums a:hover .album-name {
    color: var(--hover);
}

.album-artist,
.art-meta,
.poem-poet {
    font-size: 0.8125rem;
    color: var(--muted);
}

/* Masonry, so each painting keeps its own shape */
.art {
    columns: 2;
    column-gap: 0.875rem;
}

.art li {
    break-inside: avoid;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    padding-bottom: 1.25rem;
}

.art a {
    display: block;
    margin-bottom: 0.375rem;
}

.art img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 2px;
    background: var(--rule);
}

.art-title {
    font-size: 1rem;
}

a.art-title,
a.poem-title {
    text-decoration: none;
}

a.art-title:hover,
a.poem-title:hover {
    color: var(--hover);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.shelf .credit {
    margin-top: -0.25rem;
}

.art-title,
.poem-title {
    font-family: var(--serif);
    font-size: 1.125rem;
    line-height: 1.25;
}

.poems {
    padding-top: 0;
}

.poems li {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--rule);
}

.poem-title {
    font-size: 1.5rem;
}

.poem-lines {
    margin: 0.5rem 0 0;
    padding-left: 0.875rem;
    border-left: 1px solid var(--rule);
    font-family: var(--serif);
    font-style: italic;
    font-weight: 300;
    font-size: 1.0625rem;
    line-height: 1.6;
    white-space: pre-line;
}

/* Painting viewer */

html:has(.viewer[open]) {
    overflow: hidden;
}

.viewer {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ink);
    overflow: hidden;
}

.viewer[open] {
    display: flex;
    flex-direction: column;
}

.viewer::backdrop {
    background: transparent;
}

/* The scrim fades on its own so the painting can travel above it */
.viewer-scrim {
    position: absolute;
    inset: 0;
    background: var(--bg);
}

.viewer > :not(.viewer-scrim) {
    position: relative;
}

/* Before the opening animation starts, keep everything out of sight */
.viewer[data-state="opening"] .viewer-scrim,
.viewer[data-state="opening"] .viewer-chrome,
.viewer[data-state="opening"] #viewer-img {
    opacity: 0;
}

.viewer-close,
.viewer-nav button {
    width: 2.75rem;
    height: 2.75rem;
    display: grid;
    place-items: center;
    padding: 0;
    background: none;
    border: 0;
    color: var(--muted);
    cursor: pointer;
}

.viewer-close:hover,
.viewer-nav button:hover {
    color: var(--ink);
}

.viewer-close svg,
.viewer-nav svg {
    width: 1.375rem;
    height: 1.375rem;
}

.viewer-close {
    align-self: flex-end;
    margin: 0.75rem 0.75rem 0;
}

.viewer-stage {
    flex: 1;
    min-height: 0;
    margin: 0;
    padding: 0 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    touch-action: pan-y;
}

.viewer-stage img {
    display: block;
    max-width: 100%;
    max-height: calc(100svh - 12rem);
    object-fit: contain;
    border-radius: 2px;
    transform-origin: center;
}

.viewer-caption {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
    text-align: center;
}

.viewer-caption .art-title {
    font-size: 1.375rem;
}

.viewer-caption .book-source {
    margin-top: 0.25rem;
    color: var(--muted);
}

.viewer-nav {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    padding: 0.5rem 0 1.25rem;
}

/* Trophies: tap for the King's laugh */

.trophy-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    margin: -0.75rem 0;
    padding: 0;
    background: none;
    border: 0;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.trophy-button:hover {
    color: var(--ink);
}

.emote {
    position: fixed;
    left: 50%;
    bottom: 9rem;
    z-index: 10;
    width: 10.5rem;
    margin-left: -5.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
}

.emote img {
    display: block;
    width: 100%;
    height: auto;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.25));
}

.emote-note {
    margin: 0;
    font-size: 0.5625rem;
    line-height: 1.35;
    text-align: center;
    color: var(--muted);
}

/* Pops in like the in-game emote, laughs, then floats away */
.emote.is-playing {
    visibility: visible;
    animation: emote-life 1.7s ease both;
}

.emote.is-playing img {
    animation:
        emote-pop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1) both,
        emote-laugh 0.16s ease-in-out 0.42s 6 alternate;
}

@keyframes emote-life {
    0% { opacity: 0; }
    8% { opacity: 1; }
    82% { opacity: 1; transform: none; }
    100% { opacity: 0; transform: translateY(-1rem); }
}

@keyframes emote-pop {
    from { transform: translateY(1.5rem) scale(0.3); }
    to { transform: none; }
}

@keyframes emote-laugh {
    from { transform: rotate(-3deg) scale(1); }
    to { transform: rotate(3deg) scale(1.04); }
}

/* One entrance on load */

.rise {
    animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both;
    animation-delay: calc(var(--i, 0) * 70ms);
}

@keyframes rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .rise,
    .eq.is-live span,
    .emote.is-playing img {
        animation: none;
    }

    .emote.is-playing {
        animation-name: emote-fade;
    }

    @keyframes emote-fade {
        0%, 100% { opacity: 0; }
        10%, 85% { opacity: 1; }
    }

    body,
    .links a,
    .links svg,
    .top-four a {
        transition: none;
    }
}
