/* ── Reset & Base ─────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ── Theme Transition ─────────────────────────── */
/* Smooth fade between Morning and Evening editions */
body,
.paper-sheet,
.masthead,
.masthead-meta,
.masthead-nav,
.sidebar,
.sidebar-header,
.sidebar-search,
.sidebar-footer,
.main-content,
.collection-detail-header,
.variant-chips,
.drawer,
.drawer-preview,
.drawer-preview-label,
.drawer-detail-header,
.letter-title,
.letter-separator,
.section-header,
.icon-card,
.card-preview,
.card-badge,
.card-footer,
.icon-preview-box,
.search-input,
.sidebar-search-input {
    transition:
        background-color 0.35s ease,
        color 0.35s ease,
        border-color 0.35s ease,
        box-shadow 0.35s ease;
}

body {
    background-color: var(--paper-bg);
    color: var(--ink-black);
    font-family: var(--font-serif);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ── Typography ──────────────────────────────── */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 700;
    line-height: 1.1;
}

.font-sans {
    font-family: var(--font-sans);
}

.font-serif {
    font-family: var(--font-serif);
}

.uppercase {
    text-transform: uppercase;
}

.tracking-widest {
    letter-spacing: 0.1em;
    font-size: 10px;
}

/* ── Layout ──────────────────────────────────── */
.page-container {
    min-height: 100vh;
    padding: 0.75rem 2rem;
    display: flex;
    justify-content: center;
}

@media (max-width: 768px) {
    .page-container {
        padding: 0.5rem;
    }
}

.paper-sheet {
    max-width: var(--container-max);
    margin: 0 auto;
    background-color: var(--newsprint-bg);
    box-shadow: var(--shadow-paper);
    min-height: 100vh;
    border-left: 1px solid var(--border-muted);
    border-right: 1px solid var(--border-muted);
    position: relative;
    width: 100%;
}

/* ── Header / Masthead ───────────────────────── */
.masthead {
    border-bottom: 4px solid var(--stroke-black);
    padding: 1rem 2rem;
    text-align: center;
    background: var(--surface-white);
    position: sticky;
    top: 0;
    z-index: 100;
}

.masthead-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--stroke-black);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.masthead-meta > span {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.masthead-meta > span:nth-child(2) {
    justify-content: center;
}

.masthead-meta > span:nth-child(3) {
    justify-content: end;
}

.masthead-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--subtext);
    cursor: pointer;
    border-radius: 4px;
    transition: color 0.2s, background-color 0.2s;
    text-decoration: none;
}

/* Theme toggle rotation on the SVG icon */
.action-btn svg {
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.action-btn:active svg {
    transform: rotate(45deg) scale(0.85);
}

.action-btn:hover {
    color: var(--stroke-black);
    background: var(--gray-accent);
}
.masthead-title {
    font-size: 3.5rem;
    font-weight: 900;
    letter-spacing: -0.05em;
    line-height: 1;
}

.masthead-nav {
    border-top: 2px solid var(--stroke-black);
    border-bottom: 2px solid var(--stroke-black);
    padding: 0.5rem 0;
    display: flex;
    justify-content: center;
    gap: 2rem;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    overflow-x: auto;
}

.nav-item {
    cursor: pointer;
    white-space: nowrap;
    border: none;
    background: none;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    padding: 0.25rem 0.5rem;
    border-radius: 2px;
}

.nav-item:hover {
    text-decoration: underline;
}

.nav-item.active {
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 4px;
}

/* ── Search Bar ──────────────────────────────── */
.search-wrapper {
    position: relative;
    margin-bottom: 1.5rem;
}

.search-input {
    width: 100%;
    background: transparent;
    border: 2px solid var(--stroke-black);
    padding: 0.75rem 1rem;
    font-family: var(--font-serif);
    font-size: 1.125rem;
    font-style: italic;
    outline: none;
}

.search-input:focus {
    box-shadow: 0 0 0 1px var(--stroke-black);
}

.search-icon {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

/* ── Content Sections ────────────────────────── */
.content-wrapper {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.section-header {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--stroke-black);
    padding-bottom: 0.5rem;
}

.section-title {
    font-size: 1.875rem;
    font-weight: 900;
    letter-spacing: -0.025em;
}

.section-meta {
    font-family: var(--font-sans);
    font-size: 0.875rem;
    color: var(--subtext);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* ── Grid & Cards ────────────────────────────── */
.cards-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 768px) {
    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .cards-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.icon-card {
    border: 1px solid var(--border-light);
    background: var(--surface-white);
    padding: 1rem;
    transition:
        background-color 0.35s ease,
        color 0.35s ease,
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.2s ease;
    display: block;
}

.icon-card:hover {
    box-shadow: 4px 4px 0px 0px var(--stroke-black);
    border-color: var(--stroke-black);
    transform: translate(-1px, -1px);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1.25;
    transition: color 0.2s;
}

.icon-card:hover .card-title {
    color: var(--interaction);
}

.card-badge {
    font-family: var(--font-sans);
    font-size: 0.625rem;
    background: var(--surface-muted);
    padding: 0 0.25rem;
    border: 1px solid var(--border-muted);
}

.card-preview {
    aspect-ratio: 16 / 9;
    background-color: var(--surface-light);
    border: 1px solid var(--surface-muted);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.preview-pattern {
    position: absolute;
    inset: 0;
    opacity: 0.1;
    background-image: radial-gradient(#000 1px, transparent 1px);
    background-size: 10px 10px;
}

.preview-samples {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    z-index: 1;
}

.preview-samples img {
    width: 32px;
    height: 32px;
    transition: filter 0.35s ease;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    color: var(--subtext);
    border-top: 1px solid var(--surface-muted);
    padding-top: 0.5rem;
}

/* ── Collection Detail Layout ────────────────── */
.collection-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 16rem; /* 64 */
    border-right: 2px solid var(--stroke-black);
    background: var(--newsprint-bg);
    display: none;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

@media (min-width: 768px) {
    .sidebar {
        display: flex;
    }
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--stroke-black);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-back-btn {
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    transition:
        background-color 0.2s,
        color 0.2s;
}

.sidebar-back-btn:hover {
    background: var(--stroke-black);
    color: var(--text-inverted);
}

.sidebar-title {
    font-family: var(--font-serif);
    font-weight: 700;
    font-size: 1.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-search {
    padding: 1rem;
    border-bottom: 1px solid var(--stroke-black);
    background: var(--surface-white);
}

.sidebar-search-inner {
    position: relative;
}

.sidebar-search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.sidebar-search-input {
    width: 100%;
    background: var(--surface-light);
    border: 1px solid var(--border-muted);
    padding: 0.5rem 0.5rem 0.5rem 2.25rem;
    font-size: 0.875rem;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.2s;
}

.sidebar-search-input:focus {
    border-color: var(--stroke-black);
}

.sidebar-link.active {
    font-weight: 700;
    background: var(--stroke-black);
    color: var(--text-inverted);
}

.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--stroke-black);
    font-size: 0.75rem;
    font-family: var(--font-sans);
    text-align: center;
    color: var(--subtext);
}

.sidebar-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    cursor: pointer;
    border: none;
    background: none;
    text-align: left;
    color: inherit;
    border-radius: 4px;
    transition:
        background-color 0.15s ease,
        color 0.15s ease;
}

.sidebar-link:hover {
    background: var(--gray-accent);
}

.sidebar-link-count {
    font-size: 0.75rem;
    color: var(--subtext);
    font-variant-numeric: tabular-nums;
}

.sidebar-link.active .sidebar-link-count {
    color: rgba(255, 255, 255, 0.6);
}

.main-content {
    flex: 1;
    background: var(--surface-white);
    position: relative;
    /* overflow-y: auto; handled by body/window */
}

.collection-detail-header {
    position: sticky;
    top: 0;
    background: color-mix(in srgb, var(--surface-white) 95%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--stroke-black);
    z-index: 10;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.collection-title-group {
    display: flex;
    flex-direction: column;
}

.collection-title {
    font-size: 1.5rem;
    font-weight: 900;
    font-family: var(--font-serif);
}

.collection-subtitle {
    font-size: 0.75rem;
    color: var(--subtext);
    font-family: var(--font-sans);
    margin-top: 0.25rem;
}

.collection-search-wrapper {
    width: 16rem;
}

.variant-chips {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-muted);
    background: var(--newsprint-bg);
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    flex-wrap: wrap;
}

.variant-chip {
    padding: 0.25rem 1rem;
    border: 1px solid var(--border-light);
    border-radius: 9999px;
    font-size: 0.75rem;
    font-family: var(--font-sans);
    cursor: pointer;
    white-space: nowrap;
    background: var(--surface-white);
    color: var(--ink-black);
    transition:
        background-color 0.2s ease,
        color 0.2s ease,
        border-color 0.2s ease;
}

.variant-chip:hover {
    background: var(--stroke-black);
    color: var(--text-inverted);
    border-color: var(--stroke-black);
}

.variant-chip.active {
    background: var(--stroke-black);
    color: var(--text-inverted);
    border-color: var(--stroke-black);
}

.icons-grid-section {
    padding: 1.5rem;
}

.letter-group {
    margin-bottom: 2rem;
}

.letter-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--stroke-black);
    padding-bottom: 0.5rem;
}

.letter-title {
    font-size: 2.25rem;
    font-weight: 900;
    font-family: var(--font-serif);
    color: var(--border-muted);
}

.letter-separator {
    height: 1px;
    flex: 1;
    background: var(--border-muted);
}

.letter-count {
    font-size: 0.75rem;
    font-family: var(--font-sans);
    color: var(--text-muted);
    font-weight: 700;
}

.icons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem 2rem;
}

.icon-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: 0.25rem;
    cursor: pointer;
    background: transparent;
    border: none;
    text-align: left;
    color: var(--ink-black);
    transition:
        background-color 0.15s ease,
        color 0.35s ease;
}

.icon-item:hover {
    background: var(--hover-bg);
}

.icon-preview-box {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-muted);
    background: var(--surface-white);
    transition:
        background-color 0.2s ease,
        border-color 0.2s ease;
}

.icon-preview-box img {
    transition: filter 0.25s ease;
}

.icon-item:hover .icon-preview-box {
    background: var(--hover-dark-bg);
    border-color: var(--hover-dark-border);
    color: var(--text-inverted);
}

.icon-item:hover .icon-preview-box img {
    filter: invert(1);
}

.icon-info {
    width: 100%;
    text-align: left;
}

.icon-name {
    font-family: var(--font-serif);
    font-weight: 700;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.icon-meta {
    font-family: var(--font-sans);
    font-size: 0.625rem;
    color: var(--subtext);
}

/* ── Drawer ──────────────────────────────────── */
.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    z-index: 40;
    pointer-events: none;
    transition: background 0.3s;
}

.drawer-overlay.open {
    background: rgba(0, 0, 0, 0.15);
    pointer-events: auto;
    cursor: pointer;
}

.drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface-white);
    border-top: 4px solid var(--stroke-black);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.1);
    z-index: 50;
    height: 460px;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 768px) {
    .drawer {
        left: 16rem; /* sidebar width */
    }
}

.drawer.open {
    transform: translateY(0);
}

.drawer-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    height: 100%;
}

.drawer-preview {
    width: 33%;
    min-width: 200px;
    background: var(--paper-bg);
    border-right: 1px solid var(--border-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 2rem;
}

.drawer-preview svg,
.drawer-preview img {
    width: 180px;
    height: 180px;
    transition: filter 0.35s ease;
}

.drawer-preview-label {
    position: absolute;
    top: 1rem;
    left: 1rem;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--surface-white);
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--stroke-black);
}

.drawer-preview-svg {
    transform: scale(2);
}

.drawer-preview-svg svg {
    width: 48px;
    height: 48px;
}

.drawer-details {
    flex: 1;
    padding: 1.5rem 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.drawer-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-muted);
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
}

.drawer-icon-name {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: "Courier New", Courier, monospace;
    letter-spacing: -0.025em;
}

.drawer-close-btn {
    padding: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--ink-black);
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.drawer-close-btn:hover {
    background: var(--border-muted);
}

.drawer-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--stroke-black);
    margin-bottom: 1.25rem;
}

.drawer-tab {
    padding: 0.5rem 1.25rem;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.8125rem;
    background: none;
    border: 1px solid transparent;
    border-bottom: none;
    cursor: pointer;
    color: var(--ink-black);
    transition:
        background-color 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease;
    position: relative;
    top: 2px;
}

.drawer-tab:hover {
    background: var(--surface-muted);
}

.drawer-tab.active {
    background: var(--stroke-black);
    color: var(--text-inverted);
    border-color: var(--stroke-black);
}

.drawer-tab-content {
    margin-bottom: 1.25rem;
}

.drawer-pills {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.drawer-pill {
    padding: 0.375rem 1rem;
    border: 1px solid var(--border-light);
    border-radius: 9999px;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    background: var(--surface-white);
    color: var(--ink-black);
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition:
        background-color 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease;
}

.drawer-pill:hover {
    background: var(--stroke-black);
    color: var(--text-inverted);
    border-color: var(--stroke-black);
}

.drawer-persistent-section {
    margin-bottom: 1rem;
}

.drawer-section-title {
    font-family: var(--font-sans);
    font-weight: 400;
    font-size: 0.8125rem;
    color: var(--subtext);
    margin-bottom: 0.5rem;
}

/* ── Utilities ───────────────────────────────── */
.loading,
.empty-state {
    text-align: center;
    padding: 3rem;
    font-family: var(--font-serif);
    font-style: italic;
    color: var(--subtext);
}

/* ── Generic Search Bar Component ────────────────── */
.search-bar {
    position: relative;
    width: 100%;
}

.search-bar input {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--border-muted);
    padding: 0.5rem 0;
    font-family: var(--font-serif);
    font-size: 1.125rem;
    outline: none;
    transition: border-color 0.2s;
    border-radius: 0;
}

.search-bar input:focus {
    border-color: var(--stroke-black);
}

.search-bar .clear-btn {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--subtext);
}

/* ── Dark Mode Overrides ────────────────────── */

/* Invert dark SVG images from Iconify so they're visible on dark backgrounds */
html.dark .preview-samples img {
    filter: invert(1) brightness(0.85);
}

html.dark .icon-preview-box img {
    filter: invert(1) brightness(0.85);
}

/* In dark mode, hover makes preview box lighter (inverse of light mode behavior) */
html.dark .icon-item:hover .icon-preview-box {
    background: var(--surface-muted);
    border-color: var(--border-light);
}

html.dark .icon-item:hover .icon-preview-box img {
    filter: invert(1) brightness(0.9);
}

/* Drawer preview icon inversion */
html.dark .drawer-preview img,
html.dark .drawer-preview svg {
    filter: invert(1) brightness(0.85);
}

/* Dot pattern visibility in dark mode */
html.dark .preview-pattern {
    background-image: radial-gradient(rgba(255, 255, 255, 0.5) 1px, transparent 1px);
}

/* Drawer overlay darker in dark mode */
html.dark .drawer-overlay.open {
    background: rgba(0, 0, 0, 0.4);
}

/* Search input text color inheritance */
html.dark .search-input,
html.dark .sidebar-search-input,
html.dark .search-bar input {
    color: var(--ink-black);
}

html.dark .search-input::placeholder,
html.dark .sidebar-search-input::placeholder,
html.dark .search-bar input::placeholder {
    color: var(--subtext);
}

/* ── Active States (need high contrast in dark mode) ── */

/* Variant chips: active and hover use cream-on-dark for clear selection */
html.dark .variant-chip.active {
    background: var(--ink-black);
    color: var(--paper-bg);
    border-color: var(--ink-black);
}

html.dark .variant-chip:hover {
    background: var(--ink-black);
    color: var(--paper-bg);
    border-color: var(--ink-black);
}

/* Sidebar active link */
html.dark .sidebar-link.active {
    background: var(--ink-black);
    color: var(--paper-bg);
}

html.dark .sidebar-link.active .sidebar-link-count {
    color: rgba(15, 15, 18, 0.5);
}

/* Sidebar back button hover */
html.dark .sidebar-back-btn:hover {
    background: var(--ink-black);
    color: var(--paper-bg);
}

/* Drawer tab active state */
html.dark .drawer-tab.active {
    background: var(--ink-black);
    color: var(--paper-bg);
    border-color: var(--ink-black);
}

/* Drawer pill hover */
html.dark .drawer-pill:hover {
    background: var(--ink-black);
    color: var(--paper-bg);
    border-color: var(--ink-black);
}

/* ── Tags & Badges ───────────────────────────── */

/* Card badges (license tags) — need visible border + contrast */
html.dark .card-badge {
    background: transparent;
    border-color: var(--border-light);
    color: var(--subtext);
}

/* ── Letter Headers ──────────────────────────── */

/* Letter titles ("A", "B", ...) — decorative but visible */
html.dark .letter-title {
    color: var(--border-light);
}

html.dark .letter-separator {
    background: var(--border-light);
}

/* ── Card & Box Polish ───────────────────────── */

/* Card hover shadow — use glow instead of offset box in dark mode */
html.dark .icon-card:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    border-color: var(--border-light);
}

/* Dot pattern — reduce intensity */
html.dark .preview-pattern {
    opacity: 0.05;
}

/* Masthead search input — subtle border */
html.dark .search-input {
    border-color: var(--border-light);
}

html.dark .search-input:focus {
    box-shadow: 0 0 0 1px var(--border-light);
}
