/* === Shared cross-page styles ==========================================
   Canonical version of rules that were duplicated across index.html (via
   main.css), chart.html, flashcards.html, stories.html, games/index.html,
   and the practice/flashcard pages emitted by the build scripts. Loaded
   AFTER theme.css and BEFORE any page-specific stylesheet so per-page
   blocks can still override on equal specificity.

   What lives here: universal reset, body, page-content, top-section,
   .seo-content + descendants, .site-footer, .family-nav + .family-tab,
   .char-row + .char-mini, .ad-slot, plus the shared mobile reductions
   for the same elements.

   What does NOT live here: page-specific layout (chart-grid, flashcard
   deck, game-card grid), header CSS (still injected by js/header.js).
   ====================================================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-outer);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem 1rem;
    transition: background 0.3s, color 0.3s;
    overflow-x: hidden;
}

.page-content {
    width: 100%;
    max-width: 1400px;
    background: transparent;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0;
}

.top-section {
    width: 100%;
    background: transparent;
    /* Vertical padding only — horizontal padding removed so the
       header content's outer edges line up with the practice
       area's outer edges. Body provides the page-level inset. */
    padding: 0.8rem 0 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* === SEO content ===================================================== */
.seo-content {
    width: 100%;
    max-width: 1400px;
    margin: 1.5rem auto 1rem;
    padding: 1rem 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.7;
}

.seo-content h2 {
    color: var(--heading);
    font-size: 1.3rem;
    margin-bottom: 0.8rem;
}

.seo-content h3 {
    color: var(--text);
    font-size: 1rem;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.seo-content p {
    margin-bottom: 0.8rem;
}

.seo-content a {
    color: var(--accent);
    text-decoration: none;
}

.seo-content ol {
    padding-left: 1.2rem;
    margin-bottom: 0.8rem;
}

.seo-content li {
    margin-bottom: 0.4rem;
}

.seo-content details {
    margin-bottom: 0.5rem;
    border: 1px solid var(--subtle-border);
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
}

.seo-content summary {
    cursor: pointer;
    color: var(--text);
    font-weight: 600;
    font-size: 0.9rem;
}

.seo-content details[open] summary {
    margin-bottom: 0.4rem;
}

.seo-content details p {
    margin-bottom: 0;
}

/* Dark-mode SEO overrides — body text reads as primary and links read as
   near-white (with underline) so the dim --text-muted/--accent defaults
   don't fight the charcoal background. */
body.dark .seo-content {
    color: var(--text);
}

body.dark .seo-content a {
    color: #f5f5f5;
    text-decoration: underline;
}

/* === Site footer ===================================================== */
.site-footer {
    margin-top: 2rem;
    padding: 1rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--footer-color);
}

.site-footer a {
    color: var(--footer-link);
    text-decoration: none;
}

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

/* === Family navigation (horizontal carousel) ========================== */
.family-nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    width: 100%;
    max-width: 1400px;
    margin-bottom: 0;
    padding: 8px 0 8px;
    /* Reserve space for the tabs so the toolbar below doesn't
       jump down when JS finishes populating the carousel. Height
       = tab padding (12px) + line-height (~17px) + border (2px)
       + container padding (16px) ≈ 47px. */
    min-height: 47px;
    border-bottom: none;
    scrollbar-width: none;
    -ms-overflow-style: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: grab;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
}

.family-nav:active {
    cursor: grabbing;
}

.family-nav::-webkit-scrollbar {
    display: none;
}

.family-tab {
    padding: 6px 12px;
    border-radius: 8px;
    background: transparent;
    border: 1px solid var(--container-border);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
    white-space: nowrap;
}

.family-tab:hover {
    background: var(--accent-hover);
    color: var(--text-muted);
}

.family-tab.active {
    background: transparent;
    border-color: var(--accent);
    color: var(--accent);
}

.family-tab.learned {
    color: var(--green);
    border-color: var(--green-border);
}

.family-tab.learned.active {
    background: transparent;
    border-color: var(--green);
    color: var(--green);
}

.family-tab.review {
    color: var(--orange);
    border-color: var(--orange-border);
}

.family-tab.review.active {
    background: transparent;
    border-color: var(--orange);
    color: var(--orange);
}

/* === Character row (small cards) ==================================== */
.char-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 6px;
    margin-bottom: 0.5rem;
    padding-bottom: 0;
    flex-wrap: wrap;
}

.char-mini {
    width: 52px;
    height: 64px;
    border-radius: 12px;
    background: transparent;
    border: 1px solid var(--container-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

@media (hover: hover) {
    .char-mini:hover {
        background: var(--accent-hover);
        border-color: var(--accent-border);
    }
}

.char-mini.active {
    background: transparent;
    border-color: var(--accent);
}

.char-mini .char {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 1.4rem;
    color: var(--text);
    line-height: 1;
    transition: opacity 0.3s, font-size 0.3s;
}

.char-mini.active .char {
    color: var(--heading);
}

.char-mini .romaji {
    font-size: 0.65rem;
    color: var(--text-faint);
    margin-top: 2px;
    transition: opacity 0.3s, font-size 0.3s, color 0.3s;
}

.char-mini.active .romaji {
    color: var(--accent);
}

/* === Ad slot ========================================================= */
.ad-slot {
    width: 100%;
    max-width: 1400px;
    height: 60px;
    max-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--subtle-bg);
    border: 1px solid var(--subtle-border);
    border-radius: 12px;
    margin: 0.5rem 0;
    overflow: hidden;
    position: relative;
}

.ad-slot .ad-placeholder {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-faint);
    letter-spacing: 0.05em;
    opacity: 0.5;
    z-index: 1;
}

.ad-slot .ad-bg-chars {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.ad-slot .ad-bg-char {
    position: absolute;
    font-family: 'Noto Sans JP', sans-serif;
    font-weight: 900;
    color: var(--text);
    opacity: 0.04;
    line-height: 1;
    user-select: none;
    -webkit-user-select: none;
}

@media print {
    .ad-slot { display: none !important; }
}

/* === Mobile portrait reductions ===================================== */
@media (max-width: 600px) {
    body {
        padding: 0.8rem 0.5rem;
    }

    .page-content {
        padding: 0.8rem 0.5rem 0;
    }

    h1 { font-size: 1.2rem; }

    .ad-slot {
        margin: 0.5rem 0;
    }

    .family-nav {
        padding: 4px 0 8px;
        gap: 4px;
        /* Mobile: tab padding 8px + smaller font ≈ 35px */
        min-height: 35px;
    }

    .family-tab {
        padding: 4px 8px;
        font-size: 0.75rem;
    }

    .char-row {
        gap: 4px;
        margin-bottom: 0.6rem;
        padding-bottom: 0.5rem;
    }

    .char-mini {
        width: 42px;
        height: 52px;
    }

    .char-mini .char { font-size: 1.1rem; }
    .char-mini .romaji { font-size: 0.55rem; }
}

@media (max-width: 600px) and (max-height: 700px) {
    .ad-slot { display: none; }
}
