/*
 * site.css
 *
 * Minimal, dependency-free styling for a newspaper-style comic site.
 * Organized top-to-bottom as: variables/reset, typography, layout,
 * site header/nav, reader page, archive page, shared components, and
 * responsive/dark-mode overrides.
 */

/* ----------------------------------------------------------------------- */
/* Variables & reset                                                       */
/* ----------------------------------------------------------------------- */

:root {
    --color-bg: #fdfdfb;
    --color-surface: #ffffff;
    --color-text: #1a1a1a;
    --color-text-muted: #5a5a5a;
    --color-border: #e0ddd6;
    --color-accent: #b23a2f;
    --color-accent-text: #ffffff;
    --color-error-bg: #fdecea;
    --color-error-text: #7a1f1f;
    --color-warning-bg: #fff6e0;
    --color-warning-text: #6b5000;
    --color-info-bg: #eef3f8;
    --color-info-text: #2a4a63;

    /* Tooltip stays dark-on-light regardless of page theme, like a native OS tooltip. */
    --tooltip-bg: rgba(20, 20, 24, 0.96);
    --tooltip-text: #f5f5f5;

    --font-serif: Georgia, 'Times New Roman', Times, serif;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

    --max-width: 900px;
    --radius: 6px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #15161a;
        --color-surface: #1e1f24;
        --color-text: #ececec;
        --color-text-muted: #a7a7a7;
        --color-border: #33343a;
        --color-accent: #e0574a;
        --color-accent-text: #15161a;
        --color-error-bg: #3a1f1f;
        --color-error-text: #f6c6c0;
        --color-warning-bg: #3a3010;
        --color-warning-text: #f2dfa0;
        --color-info-bg: #1c2b38;
        --color-info-text: #bcd8ec;
    }
}

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

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

a {
    color: var(--color-accent);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ----------------------------------------------------------------------- */
/* Layout                                                                   */
/* ----------------------------------------------------------------------- */

.page {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 1.5rem 1rem 4rem;
}

/* ----------------------------------------------------------------------- */
/* Site header / navigation                                                */
/* ----------------------------------------------------------------------- */

#site-header {
    border-bottom: 1px solid var(--color-border);
    background-color: var(--color-surface);
}

.site-header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0.85rem 1rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1.25rem;
}

.site-title {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    font-weight: bold;
    text-decoration: none;
    color: var(--color-text);
    margin-right: auto;
}

.site-nav {
    display: flex;
    gap: 1rem;
}

.site-nav a {
    text-decoration: none;
    color: var(--color-text-muted);
    font-size: 0.95rem;
    padding-bottom: 2px;
    border-bottom: 2px solid transparent;
}

.site-nav a:hover {
    color: var(--color-text);
}

.site-nav a.active {
    color: var(--color-text);
    border-bottom-color: var(--color-accent);
}

.site-search {
    display: flex;
    gap: 0.4rem;
    width: 100%;
}

.site-search input[type="search"] {
    flex: 1;
    min-width: 0;
}

@media (min-width: 640px) {
    .site-search {
        width: auto;
    }

    .site-search input[type="search"] {
        width: 14rem;
    }
}

/* ----------------------------------------------------------------------- */
/* Reader page                                                             */
/* ----------------------------------------------------------------------- */

.comic {
    text-align: center;
    margin-bottom: 2rem;
}

.comic-title {
    font-family: var(--font-serif);
    font-size: 1.8rem;
    margin: 1rem 0 0.25rem;
}

.comic-date {
    color: var(--color-text-muted);
    margin: 0 0 1.25rem;
    font-size: 0.95rem;
}

.comic-figure {
    position: relative;
    margin: 0;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.75rem;
}

/*
 * Small "i" badge in the image's corner that reveals a stylized hover popover
 * of the comic's original text. comics.js also sets a native `title`
 * attribute on the <img> itself (accessibility / no-CSS fallback) — but the
 * popover itself is anchored to this small badge rather than the whole
 * figure, because comic images here are tall (portrait) and a popover
 * anchored to the full figure would render far above the viewport instead of
 * near the cursor. Generated content (`attr()`) can only read attributes off
 * the element it's attached to, so the text is duplicated onto this badge's
 * own `data-tooltip` attribute.
 */
.comic-info-badge {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    width: 1.75rem;
    height: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-family: var(--font-serif);
    font-style: italic;
    font-weight: bold;
    font-size: 1rem;
    line-height: 1;
    cursor: help;
    z-index: 4;
}

.comic-info-badge[hidden] {
    display: none;
}

.comic-info-badge:hover,
.comic-info-badge:focus-visible {
    background-color: rgba(0, 0, 0, 0.75);
}

.comic-info-badge::after,
.comic-info-badge::before {
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.comic-info-badge::after {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: max-content;
    max-width: min(320px, 80vw);
    padding: 0.65rem 0.9rem;
    background-color: var(--tooltip-bg);
    color: var(--tooltip-text);
    border-radius: var(--radius);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3);
    font-family: var(--font-sans);
    font-style: normal;
    font-weight: normal;
    font-size: 0.85rem;
    line-height: 1.4;
    text-align: left;
    white-space: normal;
    z-index: 5;
}

.comic-info-badge::before {
    content: '';
    position: absolute;
    top: calc(100% + 2px);
    right: 0.5rem;
    border: 6px solid transparent;
    border-bottom-color: var(--tooltip-bg);
    z-index: 5;
}

.comic-info-badge:hover::after,
.comic-info-badge:hover::before,
.comic-info-badge:focus-visible::after,
.comic-info-badge:focus-visible::before {
    opacity: 1;
    transform: translateY(0);
}

.comic-image {
    margin: 0 auto;
    border-radius: 2px;
    opacity: 1;
    transition: opacity 0.15s ease;
}

.comic-image--loading {
    opacity: 0;
}

.comic-image--broken {
    min-height: 200px;
    background-color: var(--color-error-bg);
}

.comic-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* The [hidden] attribute is normally display:none via the UA stylesheet, but
   author rules always win over the UA stylesheet regardless of specificity —
   so the plain ".comic-loading { display: flex }" rule above would otherwise
   keep the spinner visible forever. This re-asserts display:none whenever the
   attribute is present, so toggling `.hidden` in JS actually hides it. */
.comic-loading[hidden] {
    display: none;
}

.comic-loading-spinner {
    width: 42px;
    height: 42px;
    border: 4px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: comic-spin 0.8s linear infinite;
}

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

.comic-original-text {
    display: block;
    max-width: 640px;
    margin: 1.25rem auto 0;
    padding: 0.75rem 1rem;
    background-color: var(--color-info-bg);
    color: var(--color-info-text);
    border-radius: var(--radius);
    font-size: 0.9rem;
    text-align: left;
}

/* Same [hidden]-vs-author-display fix as .comic-loading above. */
.comic-original-text[hidden] {
    display: none;
}

.comic-notes {
    max-width: 640px;
    margin: 1.25rem auto 0;
    color: var(--color-text-muted);
    font-style: italic;
}

.comic-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.6rem;
    margin: 1.5rem 0 0.75rem;
}

.keyboard-hint {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

.keyboard-hint kbd {
    border: 1px solid var(--color-border);
    border-radius: 3px;
    padding: 0 0.35rem;
    font-family: var(--font-sans);
    background-color: var(--color-surface);
}

/* ----------------------------------------------------------------------- */
/* Tags                                                                     */
/* ----------------------------------------------------------------------- */

.tag-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem;
    margin: 0.75rem 0 0;
    padding: 0;
}

.tag-pill {
    display: inline-block;
    background-color: var(--color-info-bg);
    color: var(--color-info-text);
    border-radius: 999px;
    padding: 0.15rem 0.7rem;
    font-size: 0.8rem;
    text-decoration: none;
}

.tag-pill:hover {
    text-decoration: underline;
}

/* ----------------------------------------------------------------------- */
/* Archive page                                                             */
/* ----------------------------------------------------------------------- */

.archive-search-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.archive-search-form input[type="search"] {
    flex: 1;
}

.archive-filter-info {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin: 0 0 1rem;
}

.archive-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.archive-item {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-surface);
    overflow: hidden;
}

.archive-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem;
    text-decoration: none;
    color: var(--color-text);
}

.archive-thumb {
    width: 90px;
    height: 90px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
    background-color: var(--color-bg);
}

.archive-meta {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.archive-title {
    font-weight: bold;
}

.archive-date {
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

.archive-empty {
    list-style: none;
    color: var(--color-text-muted);
    padding: 1rem 0;
    text-align: center;
}

/* ----------------------------------------------------------------------- */
/* Shared components                                                        */
/* ----------------------------------------------------------------------- */

.button,
button,
input[type="search"],
input[type="text"],
input[type="date"] {
    font-family: inherit;
    font-size: 0.95rem;
}

.button {
    display: inline-block;
    background-color: var(--color-accent);
    color: var(--color-accent-text);
    border: none;
    border-radius: var(--radius);
    padding: 0.55rem 1rem;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
}

.button:hover {
    filter: brightness(1.08);
}

.button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    filter: none;
}

.button--link {
    background-color: transparent;
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.button--link:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

input[type="search"],
input[type="text"],
input[type="date"] {
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-surface);
    color: var(--color-text);
}

.status-message {
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
}

.status-message--error {
    background-color: var(--color-error-bg);
    color: var(--color-error-text);
}

.status-message--warning {
    background-color: var(--color-warning-bg);
    color: var(--color-warning-text);
}

.status-message--info {
    background-color: var(--color-info-bg);
    color: var(--color-info-text);
}

/* ----------------------------------------------------------------------- */
/* About page                                                               */
/* ----------------------------------------------------------------------- */

.page--about p {
    max-width: 640px;
}

/* ----------------------------------------------------------------------- */
/* Responsive tweaks                                                       */
/* ----------------------------------------------------------------------- */

@media (max-width: 480px) {
    .comic-title {
        font-size: 1.4rem;
    }

    .comic-nav {
        gap: 0.4rem;
    }

    .button {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }

    .archive-thumb {
        width: 64px;
        height: 64px;
    }
}

/* ----------------------------------------------------------------------- */
/* Admin / uploader page                                                   */
/* ----------------------------------------------------------------------- */

.uploader-warning {
    background-color: var(--color-warning-bg);
    color: var(--color-warning-text);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
}

.data-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.button--small {
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
}

.status-log {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    max-height: 220px;
    overflow-y: auto;
    font-family: 'Consolas', 'Menlo', monospace;
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

.status-log:empty::before {
    content: 'Log messages will appear here.';
    color: var(--color-text-muted);
    font-style: italic;
}

.status-log p {
    margin: 0 0 0.35rem;
}

.status-log .log-error { color: var(--color-error-text); }
.status-log .log-warning { color: var(--color-warning-text); }
.status-log .log-success { color: #1a7a3c; }

.uploader-fieldset {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem 1.25rem;
    margin-bottom: 1.25rem;
    background-color: var(--color-surface);
}

.uploader-fieldset legend {
    padding: 0 0.4rem;
    font-weight: bold;
}

.field-row {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 0.85rem;
}

.field-row label {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.field-row input,
.field-row textarea {
    width: 100%;
}

.dropzone {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone.dropzone--active {
    border-color: var(--color-accent);
    background-color: var(--color-info-bg);
}

.dropzone p {
    margin: 0 0 0.6rem;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.uploader-actions {
    margin: 1.5rem 0;
}

.preview-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.preview-figure {
    margin: 0;
    max-width: 320px;
}

.preview-figure figcaption {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: 0.35rem;
}

.preview-figure img {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-surface);
    min-height: 40px;
}

.preview-meta {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.3rem 1rem;
    font-size: 0.9rem;
}

.preview-meta dt {
    color: var(--color-text-muted);
}

.preview-meta dd {
    margin: 0;
}
