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

.button,
button,
input[type="search"],
input[type="text"],
input[type="email"],
input[type="password"],
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);
}

.button--small {
    padding: 0.35rem 0.65rem;
    font-size: 0.85rem;
}

.button--full {
    width: 100%;
}

.btn-favorite--active {
    color: #e0245e;
    border-color: #e0245e;
    background-color: transparent;
}

input[type="search"],
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"] {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-surface);
    color: var(--color-text);
    width: 100%;
}

.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);
}

/*
 * 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,
 * auth dialog, 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 {
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 1px solid var(--color-border);
    background-color: var(--color-surface);
    width: 100%;
    overflow-x: clip; /* Prevents sub-pixel calculation overflow from breaking page body width */
}

.site-header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: relative;
    box-sizing: border-box;
}

.site-title {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    font-weight: bold;
    text-decoration: none;
    color: var(--color-text);
    white-space: nowrap;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

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

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

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

.site-search {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

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

.auth-nav-host {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
    min-width: 120px;
    justify-content: flex-end;
}

/* Hide hamburger by default in standard desktop mode */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: 1px solid var(--color-border);
    color: var(--color-text);
    font-size: 1.2rem;
    line-height: 1;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
}

/* Dynamic State: Applied whenever elements overflow available width */
.is-mobile .site-header-inner .mobile-menu-toggle {
    display: block;
}

.is-mobile .site-header-inner #nav-desktop-links,
.is-mobile .site-header-inner #nav-desktop-search {
    display: none !important;
}

.is-mobile .site-header-inner {
    justify-content: flex-start;
}

.is-mobile .site-header-inner .auth-nav-host {
    margin-left: auto;
}

.mobile-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 1rem;
    flex-direction: column;
    gap: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.mobile-dropdown--open {
    display: flex;
}

.mobile-nav {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.mobile-nav .nav-link {
    text-decoration: none;
    color: var(--color-text);
    font-size: 1rem;
}

/* ----------------------------------------------------------------------- */
/* Dynamic Body-Level Mobile Reader Rules                                  */
/* ----------------------------------------------------------------------- */

/* Hide keyboard hint on mobile view */
body.is-mobile .keyboard-hint {
    display: none !important;
}

/* Transform navigation into a sticky bottom toolbar on mobile */
body.is-mobile .comic-nav {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 900;
    margin: 0 -1rem -1.5rem -1rem; /* Stretch full-width past main container padding */
    padding: 0.65rem 0.75rem;
    background-color: var(--color-surface);
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.25);
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 0.5rem;
}

/* Hide desktop text labels on mobile */
body.is-mobile .comic-nav .nav-text {
    display: none !important;
}

/* Format mobile icon buttons for comfortable touch targets */
body.is-mobile .comic-nav .button {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.6rem 0;
    font-size: 1.25rem;
    line-height: 1;
    min-height: 44px; /* Standard accessible touch-target size */
    border-radius: var(--radius);
}

body.is-mobile .comic-nav .nav-symbol {
    font-size: 1.3rem;
    font-weight: bold;
}

/* Update mobile reader body text mask */
body.is-mobile .fact-body {
    /* Fades the bottom 3rem of text to transparent */
    -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 3rem), transparent 100%);
    mask-image: linear-gradient(to bottom, black calc(100% - 3rem), transparent 100%);
    padding-bottom: 1.5rem; /* Prevents last sentence cutoff */
}

/* Add a subtle top shadow to the sticky bar to accentuate scrollable overlap */
body.is-mobile .comic-nav {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 900;
    margin: 0 -1rem -1.5rem -1rem;
    padding: 0.65rem 0.75rem;
    background-color: var(--color-surface);
    border-top: 1px solid var(--color-border);
    /* Soft top gradient glow over underlying text */
    box-shadow: 0 -12px 20px rgba(0, 0, 0, 0.4);
}
/* User Dropdown Classes */
.user-dropdown {
    position: relative;
    display: inline-block;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.user-menu-list {
    display: none;
    position: absolute;
    right: 0;
    top: 110%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    min-width: 170px;
    z-index: 1000;
    padding: 0.5rem 0;
}

.user-menu-list--open {
    display: block;
}

.user-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.5rem 1rem;
    color: var(--color-text);
    text-decoration: none;
    font-size: 0.9rem;
    cursor: pointer;
}

.user-menu-item--bordered {
    border-top: 1px dashed var(--color-border);
}

.user-menu-item--danger {
    color: #e53935;
    border-top: 1px solid var(--color-border);
}

/* Skeleton Loading Animation Rules */
@keyframes skeleton-pulse {
    0% { opacity: 0.6; }
    50% { opacity: 0.3; }
    100% { opacity: 0.6; }
}

.auth-skeleton-btn {
    display: inline-block;
    width: 80px;
    height: 32px;
    background: var(--color-border);
    border-radius: var(--radius);
    animation: skeleton-pulse 1.5s infinite;
}

.skeleton-box {
    background-color: var(--color-border);
    border-radius: var(--radius);
    animation: skeleton-pulse 1.5s infinite;
}

.skeleton-title {
    width: 250px;
    height: 2rem;
    margin: 1rem auto 0.5rem;
}

.skeleton-date {
    width: 140px;
    height: 1rem;
    margin: 0 auto 1.25rem;
}

/* ----------------------------------------------------------------------- */
/* 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;
}

.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;
}

.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;
}

.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;
}

/* ----------------------------------------------------------------------- */
/* Form Rows & Layouts                                                     */
/* ----------------------------------------------------------------------- */

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

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

/* ----------------------------------------------------------------------- */
/* Unified Auth Dialog Modal                                               */
/* ----------------------------------------------------------------------- */

.auth-dialog {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-surface);
    color: var(--color-text);
    padding: 0;
    width: min(380px, 90vw);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.auth-dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

.auth-dialog-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    margin-left: auto;
}

.auth-popover-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1.25rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 1.25rem;
}

.auth-control-btn {
    flex: 1;
    padding: 0.6rem;
    border-radius: calc(var(--radius) / 2);
    font-weight: bold;
    font-size: 0.9rem;
    cursor: pointer;
    text-align: center;
}

.auth-control-btn--login {
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text);
}

.auth-control-btn--signup {
    background-color: var(--color-accent);
    border: none;
    color: var(--color-accent-text);
}

.auth-popover-content {
    padding: 0 1.5rem;
}

.auth-popover-title {
    margin: 0 0 0.3rem;
    font-family: var(--font-serif);
    font-size: 1.4rem;
    font-weight: bold;
}

.auth-popover-subtitle {
    margin: 0 0 1.25rem;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.auth-form-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    font-size: 0.85rem;
}

.remember-me-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--color-text-muted);
}

.forgot-password-btn {
    background: none;
    border: none;
    color: var(--color-accent);
    cursor: pointer;
    font-size: inherit;
    text-decoration: none;
    padding: 0;
}

.auth-view--hidden {
    display: none !important;
}

.auth-status-box {
    display: none;
    margin: 0 1.5rem 1.25rem;
}

.auth-status-box--visible {
    display: block;
}

.auth-submit-wrapper {
    margin-top: 1rem;
}

.auth-submit-wrapper--spaced {
    margin-top: 1.5rem;
}

.auth-dialog-switch {
    margin-top: 1rem;
}

/* SSO Footer & Separator Updates */
.auth-sso-footer {
    /* Removed border-top and reduced top padding */
    padding-top: 0;
    padding-bottom: 1.25rem;
    margin-top: 0;
}

.sso-separator {
    position: relative;
    text-align: center;
    /* Reduced top and bottom margins for tighter, balanced spacing */
    margin: 0.75rem 0;
}

.sso-separator::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--color-border);
    z-index: 1;
}

.sso-separator span {
    position: relative;
    background-color: var(--color-surface);
    padding: 0 0.6rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    z-index: 2;
}

/* Ensure form submit button wrappers don't force unnecessary bottom margins */
.auth-submit-wrapper {
    margin-top: 1rem;
}

.auth-submit-wrapper--spaced {
    margin-top: 1rem; /* Aligned with standard form wrapper spacing */
}

.btn-google-sso {
    width: 100%;
    background-color: transparent;
    color: var(--color-text);
    border: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
}

.btn-google-sso:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}
