/* =========================================================================
   MY SAVED WORDS — FULL PAGE
   Dedicated review grid + printable flashcards.
   Fleet-styled on screen; clean cut-out cards in print. No !important.
   ========================================================================= */

.saved-words-page-root {
    --swp-red: #ef4444;
    --swp-red-deep: #dc2626;
    font-family: var(--as-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
    color: var(--as-text, #1f2937);
    max-width: 1040px;
    /* Grouped section: a top hairline + breathing room sets this block apart
       from the "My Words" section above so the two read as distinct cards. */
    margin: 28px auto 0;
    padding: 24px 0 32px;
    border-top: 1px solid var(--as-border, #e5e7eb);
}

/* --- Kit-proof the type ---
   The Elementor kit styles bare h1/h2/p (e.g. `.elementor-kit-XXXX h1`,
   specificity 0,1,1) — it was blowing the unscoped .swp-title-text up to hero
   size and capitalizing it. Re-declare the fleet type scoped under the root
   (0,2,0) so headings stay calm and match the "My Words" section. */
.saved-words-page-root .swp-title-text {
    font-size: var(--as-text-2xl, 1.5rem);
    font-weight: var(--as-weight-bold, 700);
    color: var(--as-text, #1f2937);
    text-transform: none;
    line-height: 1.2;
}

.saved-words-page-root .swp-empty-title,
.saved-words-page-root .swp-modal-title {
    font-size: var(--as-text-xl, 1.25rem);
    font-weight: var(--as-weight-bold, 700);
    color: var(--as-text, #1f2937);
    text-transform: none;
}

.saved-words-page-root .swp-card-word {
    font-size: var(--as-text-base, 1rem);
    font-weight: var(--as-weight-semibold, 600);
    text-transform: none;
}

/* ---- Boot / loading / error / empty states ---- */
.swp-boot,
.swp-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
    padding: 56px 20px;
    color: var(--as-text-muted, #64748b);
}

.swp-empty {
    border: 1px dashed var(--as-border, #e5e7eb);
    border-radius: 16px;
    background: var(--as-surface-soft, #f8fafc);
}

.swp-empty-icon {
    font-size: 3rem;
    line-height: 1;
    color: var(--swp-red);
}

.swp-empty-title {
    margin: 0;
    font-size: var(--as-text-xl, 1.25rem);
    font-weight: var(--as-weight-bold, 700);
    color: var(--as-text, #1f2937);
}

.swp-state-msg {
    margin: 0;
    max-width: 460px;
    font-size: var(--as-text-base, 1rem);
    line-height: var(--as-leading-relaxed, 1.6);
}

.swp-boot-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--as-border, #e5e7eb);
    border-top-color: var(--swp-red);
    border-radius: 50%;
    animation: swp-spin 0.8s linear infinite;
}

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

/* ---- Toolbar ---- */
.swp-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--as-border, #e5e7eb);
}

.swp-toolbar-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.swp-title-heart {
    color: var(--swp-red);
    font-size: 22px;
    line-height: 1;
}

.swp-title-text {
    margin: 0;
    font-size: var(--as-text-2xl, 1.5rem);
    font-weight: var(--as-weight-bold, 700);
    color: var(--as-text, #1f2937);
}

.swp-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 9px;
    border-radius: 999px;
    background: #fee2e2;
    color: var(--swp-red-deep);
    font-size: 14px;
    font-weight: 700;
}

.swp-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* ---- Sort ---- */
.swp-sort {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.swp-sort-label {
    font-size: var(--as-text-sm, 0.875rem);
    color: var(--as-text-muted, #64748b);
    font-weight: var(--as-weight-medium, 500);
}

.swp-sort-select {
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid var(--as-border, #e5e7eb);
    border-radius: 10px;
    background: var(--as-surface, #fff);
    color: var(--as-text, #1f2937);
    font-size: var(--as-text-base, 1rem);
    font-family: inherit;
    cursor: pointer;
}

.swp-sort-select:focus-visible {
    outline: 2px solid var(--as-read-accent, #2563eb);
    outline-offset: 2px;
}

/* ---- Buttons ---- */
.swp-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 44px;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: var(--as-text-base, 1rem);
    font-weight: var(--as-weight-semibold, 600);
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}

.swp-btn:active { transform: scale(0.97); }

.swp-btn:focus-visible {
    outline: 2px solid var(--as-read-accent, #2563eb);
    outline-offset: 2px;
}

.swp-btn-primary {
    background: var(--swp-red);
    color: #fff;
}

.swp-btn-primary:hover { background: var(--swp-red-deep); }

.swp-btn-print {
    background: var(--as-surface, #fff);
    color: var(--as-text, #1f2937);
    border-color: var(--as-border, #e5e7eb);
}

.swp-btn-print:hover { border-color: #cbd5e1; background: var(--as-surface-soft, #f8fafc); }

.swp-print-ico { font-size: 17px; line-height: 1; }

.swp-btn-ghost {
    background: transparent;
    color: var(--as-text-muted, #64748b);
    border-color: var(--as-border, #e5e7eb);
}

.swp-btn-ghost:hover { background: var(--as-surface-soft, #f8fafc); color: var(--as-text, #1f2937); }

/* --- Beat the Elementor kit ---
   The kit's `button` rule (.elementor-kit-XXXX button, specificity 0,1,1) sets
   white bg / black border / 15px 50px padding / capitalize and outranks every
   single-class .swp-btn* (0,1,0) — clobbering the toolbar buttons into heavy,
   off-fleet blocks. Re-declare the fleet button treatment scoped under the page
   root (0,2,0) so it wins WITHOUT !important. Primary CTA = GREEN pill (fleet
   "click / do"); blue stays for read/selected/links. */
.saved-words-page-root .swp-btn {
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 11px 22px;
    font-size: var(--as-text-base, 1rem);
    font-weight: var(--as-weight-semibold, 600);
    text-transform: none;
}

.saved-words-page-root .swp-btn-primary {
    background: var(--as-primary-bg, #15803d);
    color: #fff;
}

.saved-words-page-root .swp-btn-primary:hover { background: #166534; }

.saved-words-page-root .swp-btn-print {
    background: var(--as-surface, #fff);
    color: var(--as-text, #1f2937);
    border-color: var(--as-border, #e5e7eb);
}

.saved-words-page-root .swp-btn-print:hover { border-color: #cbd5e1; background: var(--as-surface-soft, #f8fafc); }

.saved-words-page-root .swp-btn-ghost {
    background: transparent;
    color: var(--as-text-muted, #64748b);
    border-color: var(--as-border, #e5e7eb);
}

.saved-words-page-root .swp-btn-ghost:hover { background: var(--as-surface-soft, #f8fafc); color: var(--as-text, #1f2937); }

/* ---- Grid ---- */
.swp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
}

.swp-card {
    border: 1px solid var(--as-border, #e5e7eb);
    border-radius: 14px;
    background: var(--as-surface, #fff);
    overflow: hidden;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.swp-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

.swp-card-imgwrap {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: var(--as-surface-soft, #f8fafc);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.swp-card-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.swp-card-noimg {
    font-size: 2.6rem;
    color: #cbd5e1;
}

.swp-card-heart {
    position: absolute;
    top: 6px;
    right: 6px;
}

/* The save-heart (FavoritesService.createHeartButton) renders the bare
   single-class .fav-heart-btn from shared-components.css (specificity 0,1,0).
   The Elementor kit's `button` rule (≥0,1,1) outranks it, which strips the
   circular fleet treatment and leaves a stretched, full-width blue button.
   Re-assert the fleet heart here, scoped under the page root (0,3,0), so it
   wins WITHOUT !important — the same trick sibling widgets use (e.g.
   `.listening-practice-container .fav-heart-btn`). Matches the canonical
   --sm heart in shared-components.css. */
.saved-words-page-root .swp-card-heart .fav-heart-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    min-width: 0;
    min-height: 0;
    max-width: 38px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    color: #ff4d4d;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.22);
    font-size: 19px;
    line-height: 1;
    text-transform: none;
}

.saved-words-page-root .swp-card-heart .fav-heart-btn.saved {
    color: #ff2424;
}

.swp-card-body {
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.swp-card-word {
    font-size: var(--as-text-lg, 1.125rem);
    font-weight: var(--as-weight-semibold, 600);
    text-align: center;
    color: var(--as-text, #1f2937);
    line-height: 1.2;
}

.swp-card-topic {
    display: inline-block;
    max-width: 100%;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--as-read-bg, #eff6ff);
    color: var(--as-read-text, #1e40af);
    font-size: var(--as-text-xs, 0.75rem);
    font-weight: var(--as-weight-medium, 500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- Logged-out gate ---- */
.swp-gate {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 14px;
    max-width: 480px;
    margin: 0 auto;
    padding: 48px 24px;
    border: 1px dashed var(--as-border, #e5e7eb);
    border-radius: 16px;
    background: var(--as-surface-soft, #f8fafc);
}

.swp-gate-icon { font-size: 3rem; line-height: 1; color: var(--swp-red); }
.swp-gate-title { margin: 0; font-size: var(--as-text-xl, 1.25rem); font-weight: 700; color: var(--as-text, #1f2937); }
.swp-gate-msg { margin: 0; color: var(--as-text-muted, #64748b); line-height: 1.6; }

.swp-gate-btn {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 11px 28px;
    border-radius: 10px;
    background: var(--swp-red);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}

.swp-gate-btn:hover { background: var(--swp-red-deep); }

/* ---- Print size modal ---- */
.swp-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.55);
}

.swp-modal {
    width: 100%;
    max-width: 520px;
    background: var(--as-surface, #fff);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.swp-modal-title {
    margin: 0 0 4px;
    font-size: var(--as-text-xl, 1.25rem);
    font-weight: 700;
    color: var(--as-text, #1f2937);
}

.swp-modal-sub {
    margin: 0 0 18px;
    font-size: var(--as-text-sm, 0.875rem);
    color: var(--as-text-muted, #64748b);
    line-height: 1.5;
}

/* Format selector (Flashcards vs Communication Board) */
.swp-format-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.swp-format-tab {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 12px 14px;
    border: 2px solid var(--as-border, #e5e7eb);
    border-radius: 12px;
    background: var(--as-surface, #fff);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.swp-format-tab:hover { border-color: #cbd5e1; }

.swp-format-tab.is-selected {
    border-color: var(--swp-red);
    background: #fef2f2;
}

.swp-format-tab:focus-visible {
    outline: 2px solid var(--as-read-accent, #2563eb);
    outline-offset: 2px;
}

.swp-format-tab-label {
    font-size: var(--as-text-base, 1rem);
    font-weight: 700;
    color: var(--as-text, #1f2937);
}

.swp-format-tab-desc {
    font-size: var(--as-text-xs, 0.75rem);
    color: var(--as-text-muted, #64748b);
}

.swp-size-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 22px;
}

.swp-size-grid--2 { grid-template-columns: repeat(2, 1fr); }
.swp-size-grid--4 { grid-template-columns: repeat(4, 1fr); }

.swp-size-opt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 8px 12px;
    border: 2px solid var(--as-border, #e5e7eb);
    border-radius: 12px;
    background: var(--as-surface, #fff);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.swp-size-opt:hover { border-color: #cbd5e1; }

.swp-size-opt.is-selected {
    border-color: var(--swp-red);
    background: #fef2f2;
}

.swp-size-opt:focus-visible {
    outline: 2px solid var(--as-read-accent, #2563eb);
    outline-offset: 2px;
}

/* mini grid preview of card layout */
.swp-size-preview {
    display: grid;
    gap: 2px;
    width: 38px;
    height: 50px;
    padding: 3px;
    border: 1px solid #cbd5e1;
    border-radius: 3px;
    background: #fff;
}

.swp-size-cell { background: #dbe3ee; border-radius: 1px; }

.swp-size-preview-small     { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(4, 1fr); }
.swp-size-preview-medium    { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(3, 1fr); }
.swp-size-preview-large     { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }
.swp-size-preview-xl        { grid-template-columns: 1fr;            grid-template-rows: repeat(2, 1fr); }
.swp-size-preview-grid      { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(4, 1fr); }
.swp-size-preview-largegrid { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); }

.swp-size-name { font-size: var(--as-text-sm, 0.875rem); font-weight: 700; color: var(--as-text, #1f2937); }
.swp-size-hint { font-size: var(--as-text-xs, 0.75rem); color: var(--as-text-muted, #64748b); }

.swp-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* The print portal is always present in the DOM (createPortal → body);
   hide it on screen, reveal it only in print. */
.swp-print-portal { display: none; }

/* ---- Mobile ---- */
@media (max-width: 600px) {
    .swp-toolbar { align-items: flex-start; }
    .swp-toolbar-actions { width: 100%; }
    .swp-btn-primary, .swp-btn-print { flex: 1 1 auto; justify-content: center; }
    .swp-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
    .swp-size-grid { grid-template-columns: repeat(2, 1fr); }
    .swp-title-text { font-size: var(--as-text-xl, 1.25rem); }
}

@media (prefers-reduced-motion: reduce) {
    .swp-card, .swp-btn, .swp-boot-spinner, .swp-size-opt { transition: none; animation: none; }
}

/* =========================================================================
   §PRINT — printable flashcards
   Hide every other body child and show only the portal. visibility/display
   override works WITHOUT !important because nothing else styles these exact
   targets (a direct body child + the portal class).
   ========================================================================= */
@media print {
    @page { size: letter portrait; margin: 0.5in; }

    /* Hide the whole live page; show only the flashcard portal. */
    body > *:not(.swp-print-portal) { display: none; }

    html, body {
        background: #fff;
        margin: 0;
        padding: 0;
    }

    .swp-print-portal {
        display: block;
        color: #000;
        font-family: Georgia, 'Times New Roman', serif;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* One Letter page of cards (7.5in x 10in printable area). */
    .swp-page {
        display: grid;
        width: 7.5in;
        height: 10in;
        page-break-after: always;
        break-after: page;
    }

    .swp-page:last-child {
        page-break-after: auto;
        break-after: auto;
    }

    .swp-size-small  .swp-page { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(4, 1fr); }
    .swp-size-medium .swp-page { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(3, 1fr); }
    .swp-size-large  .swp-page { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }
    .swp-size-xl     .swp-page { grid-template-columns: 1fr;            grid-template-rows: repeat(2, 1fr); }

    /* Each flashcard: image fills most of the card, word below. Dashed cut line. */
    .swp-flashcard {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.12in;
        padding: 0.18in;
        border: 1px dashed #999;
        box-sizing: border-box;
        overflow: hidden;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .swp-flashcard-imgwrap {
        flex: 1 1 auto;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-height: 0;
    }

    .swp-flashcard-img {
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
    }

    .swp-flashcard-word {
        flex: 0 0 auto;
        font-weight: 700;
        text-align: center;
        color: #000;
        line-height: 1.15;
        word-break: break-word;
    }

    /* Word size scales with card size. */
    .swp-size-small  .swp-flashcard-word { font-size: 16pt; }
    .swp-size-medium .swp-flashcard-word { font-size: 22pt; }
    .swp-size-large  .swp-flashcard-word { font-size: 30pt; }
    .swp-size-xl     .swp-flashcard-word { font-size: 40pt; }

    /* ---------------------------------------------------------------------
       COMMUNICATION BOARD — a pointing grid (3 columns) grouped by topic.
       Solid borders between cells (not cut lines); fits one Letter page.
       --------------------------------------------------------------------- */
    .swp-format-board .swp-board-page {
        width: 7.5in;
        height: 10in;
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        page-break-after: always;
        break-after: page;
        overflow: hidden;
    }

    .swp-format-board .swp-board-page:last-child {
        page-break-after: auto;
        break-after: auto;
    }

    .swp-board-title {
        flex: 0 0 auto;
        text-align: center;
        font-size: 20pt;
        font-weight: 700;
        color: #000;
        padding-bottom: 0.12in;
    }

    .swp-board-sections {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        border-top: 2px solid #222;
        min-height: 0;
    }

    /* One topic group: left category label + its 3-column cell grid. */
    .swp-board-section {
        display: flex;
        align-items: stretch;
        border-bottom: 2px solid #222;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .swp-board-cat {
        flex: 0 0 1.3in;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        padding: 0.08in;
        font-size: 13pt;
        font-weight: 700;
        color: #000;
        border-right: 2px solid #222;
        box-sizing: border-box;
    }

    .swp-board-cells {
        flex: 1 1 auto;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    /* No category column — full-width 3-up grid (single / untagged topic). */
    .swp-board-cells--full {
        flex: 1 1 auto;
        border-top: 2px solid #222;
    }

    /* Each pointing cell: prominent image, label below, clean cell border. */
    .swp-board-cell {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.06in;
        padding: 0.1in;
        border: 1px solid #222;
        box-sizing: border-box;
        overflow: hidden;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .swp-board-cell-imgwrap {
        flex: 1 1 auto;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-height: 0;
    }

    .swp-board-cell-img {
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
    }

    .swp-board-cell-word {
        flex: 0 0 auto;
        text-align: center;
        font-weight: 700;
        color: #000;
        line-height: 1.1;
        word-break: break-word;
    }

    /* Cell height + label size scale with the chosen board density. */
    .swp-size-grid      .swp-board-cells { grid-auto-rows: 2.15in; }
    .swp-size-largegrid .swp-board-cells { grid-auto-rows: 4.3in; }

    .swp-size-grid      .swp-board-cell-word { font-size: 13pt; }
    .swp-size-largegrid .swp-board-cell-word { font-size: 22pt; }
}
