/* ==========================================================================
   NetPack Focus Reader
   Setup screen (inside the normal tool page) + full-screen reading overlay.
   Loaded only on /focus-reader.

   The site ships css/dark.css unconditionally, so the setup screen is styled
   for a dark page. The reading overlay deliberately ignores the site theme:
   its background is the reader's own choice and must stay that way.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Self-hosted fonts. Both are SIL Open Font Licence; see fonts/OFL.txt.
   If the files are missing, the stacks in focus-reader-content.js fall back
   to Verdana and the tool still works.
   -------------------------------------------------------------------------- */

@font-face {
    font-family: 'Atkinson Hyperlegible';
    src: url('../fonts/AtkinsonHyperlegible-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Atkinson Hyperlegible';
    src: url('../fonts/AtkinsonHyperlegible-Bold.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'OpenDyslexic';
    src: url('../fonts/OpenDyslexic-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'OpenDyslexic';
    src: url('../fonts/OpenDyslexic-Bold.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* ==========================================================================
   Setup screen
   ========================================================================== */

.focus-reader-interface {
    --fr-panel: rgba(255, 255, 255, .045);
    --fr-panel-hover: rgba(255, 255, 255, .08);
    --fr-line: rgba(255, 255, 255, .13);
    --fr-text: #e9eaee;
    --fr-muted: #a3abba;
    --fr-accent: #6b8ad6;
}

.fr-setup {
    display: flex;
    flex-direction: column;
    gap: 26px;
    color: var(--fr-text);
}

/* dark.css sets a bare `p { color:#EEE }`; keep our own colours winning. */
.fr-setup p { color: inherit; }

.fr-intro { text-align: center; }

.fr-intro .fr-title {
    margin: 0 0 8px;
    font-size: 28px;
    letter-spacing: .06em;
    color: var(--fr-text);
}

.fr-intro .fr-subtitle {
    margin: 0;
    font-size: 16px;
    color: var(--fr-muted);
}

.fr-block-label,
.fr-field > span,
.fr-field-wide > span {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--fr-muted);
}

/* --- Language picker --- */

.fr-langs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.fr-lang {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 11px 18px;
    border: 1px solid var(--fr-line);
    border-radius: 10px;
    background: var(--fr-panel);
    font-size: 15px;
    color: var(--fr-text);
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.fr-lang:hover { background: var(--fr-panel-hover); border-color: rgba(255, 255, 255, .26); }

.fr-lang.is-active {
    border-color: var(--fr-accent);
    background: rgba(107, 138, 214, .18);
    color: #cfe0ff;
    font-weight: 600;
}

.fr-lang-flag { font-size: 20px; line-height: 1; }

/* --- Mode cards --- */

.fr-modes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.fr-mode-card {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 20px;
    border: 1px solid var(--fr-line);
    border-radius: 12px;
    background: var(--fr-panel);
    color: var(--fr-text);
    text-align: left;
    cursor: pointer;
    transition: border-color .15s, background .15s, transform .15s;
}

.fr-mode-card:hover {
    background: var(--fr-panel-hover);
    border-color: var(--fr-accent);
    transform: translateY(-1px);
}

.fr-mode-card.is-primary {
    border-color: transparent;
    background: linear-gradient(135deg, #4a6bb5, #6b8ad6);
    color: #fff;
}

.fr-mode-card.is-primary:hover {
    box-shadow: 0 6px 20px rgba(74, 107, 181, .35);
    border-color: transparent;
}

.fr-mode-icon {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(107, 138, 214, .2);
    color: var(--fr-accent);
    font-size: 15px;
}

.fr-mode-card.is-primary .fr-mode-icon {
    background: rgba(255, 255, 255, .22);
    color: #fff;
}

.fr-mode-body { display: flex; flex-direction: column; gap: 5px; }

.fr-mode-name { font-size: 17px; font-weight: 700; }

.fr-mode-desc { font-size: 14px; line-height: 1.5; opacity: .82; }

.fr-mode-meta {
    margin-top: 5px;
    font-size: 13px;
    font-weight: 600;
    opacity: .92;
}

/* --- Paste panel --- */

.fr-paste {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 18px;
    border: 1px dashed var(--fr-line);
    border-radius: 12px;
    background: var(--fr-panel);
}

/* A display value in a class rule beats the UA [hidden] rule, so restate it. */
.fr-paste[hidden] { display: none; }

.fr-paste textarea {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--fr-line);
    border-radius: 8px;
    background: rgba(0, 0, 0, .28);
    color: var(--fr-text);
    font-family: Verdana, Geneva, sans-serif;
    font-size: 15px;
    line-height: 1.7;
    resize: vertical;
}

.fr-paste textarea::placeholder { color: var(--fr-muted); opacity: .8; }

.fr-paste-error { margin: 0; color: #ff8f85; font-size: 14px; }
.fr-paste-error[hidden] { display: none; }

.fr-btn {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.fr-btn-primary { background: #4a6bb5; color: #fff; }
.fr-btn-primary:hover { background: #5a7cc9; }

/* --- Settings --- */

.fr-settings {
    border: 1px solid var(--fr-line);
    border-radius: 12px;
    padding: 0 18px;
    background: var(--fr-panel);
    color: var(--fr-text);
}

.fr-settings > summary {
    padding: 16px 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--fr-text);
    cursor: pointer;
    list-style: none;
}

.fr-settings > summary::-webkit-details-marker { display: none; }
.fr-settings > summary::before { content: '\25B8'; display: inline-block; margin-right: 10px; transition: transform .15s; }
.fr-settings[open] > summary::before { transform: rotate(90deg); }

.fr-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 110px;
    margin-bottom: 18px;
    border-radius: 10px;
    overflow: hidden;
}

.fr-preview-word { font-weight: 700; line-height: 1.2; }

.fr-settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    padding-bottom: 18px;
}

.fr-field-wide { grid-column: 1 / -1; }

.fr-field select,
.fr-field input[type="range"] { width: 100%; }

.fr-field select {
    padding: 10px;
    border: 1px solid var(--fr-line);
    border-radius: 8px;
    background: rgba(0, 0, 0, .28);
    color: var(--fr-text);
    font-size: 15px;
}

.fr-field input[type="range"] { accent-color: var(--fr-accent); }

.fr-swatches { display: flex; flex-wrap: wrap; gap: 10px; }

.fr-swatch {
    width: 54px;
    height: 44px;
    border: 2px solid var(--fr-line);
    border-radius: 8px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

.fr-swatch.is-active {
    border-color: var(--fr-accent);
    box-shadow: 0 0 0 3px rgba(107, 138, 214, .3);
}

.fr-check {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    color: var(--fr-text);
    cursor: pointer;
}

.fr-check input { width: 18px; height: 18px; accent-color: var(--fr-accent); }

.fr-link-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 18px;
    padding: 0;
    border: none;
    background: none;
    color: #ff8f85;
    font-size: 14px;
    cursor: pointer;
    text-decoration: underline;
}

.fr-disclaimer {
    margin: 0;
    display: flex;
    align-items: flex-start;
    gap: 9px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--fr-muted);
}

.fr-load-error { color: #ff8f85; }

/* ==========================================================================
   Full-screen reader overlay

   Everything below is deliberately insulated from the site stylesheets: the
   overlay covers the page and its colours come from the reader's setting.
   ========================================================================== */

body.fr-locked { overflow: hidden; }

.fr-overlay {
    --fr-bg: #fdf6e3;
    --fr-fg: #2b2b2b;
    --fr-font: 'Atkinson Hyperlegible', Verdana, sans-serif;
    --fr-size: 60px;
    --fr-spacing: 2px;

    position: fixed;
    inset: 0;
    z-index: 2147483000;      /* above the site header, ads and cookie bar */
    display: flex;
    flex-direction: column;
    background: var(--fr-bg);
    color: var(--fr-fg);
    font-family: var(--fr-font);
    overscroll-behavior: contain;
}

/* dark.css styles bare `p`, `h3`, `dt` and friends. Inside the overlay every
   colour must come from --fr-fg, or the text disappears on a cream page. */
.fr-overlay p,
.fr-overlay h3,
.fr-overlay dl,
.fr-overlay dt,
.fr-overlay dd,
.fr-overlay div,
.fr-overlay span,
.fr-overlay button,
.fr-overlay i {
    color: inherit;
}

.fr-overlay button { font-family: inherit; }

/* --- Top bar --- */

.fr-topbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
}

.fr-progress {
    flex: 1 1 auto;
    height: 4px;
    border-radius: 2px;
    background: currentColor;
    opacity: .16;
    overflow: hidden;
}

.fr-progress-bar {
    height: 100%;
    width: 0;
    border-radius: 2px;
    background: currentColor;
    transition: width .18s ease-out;
}

.fr-icon-btn {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font-size: 18px;
    opacity: .45;
    cursor: pointer;
    transition: opacity .15s, background .15s;
}

.fr-icon-btn:hover { opacity: 1; background: rgba(128, 128, 128, .16); }
.fr-icon-btn[hidden] { display: none; }

/* --- Stage --- */

.fr-stage {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 24px;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.fr-card {
    width: 100%;
    max-width: 900px;
    text-align: center;
}

.fr-card-center { position: relative; }

.fr-word {
    font-size: var(--fr-size);
    letter-spacing: var(--fr-spacing);
    line-height: 1.25;
    font-weight: 700;
    max-width: 100%;

    /* A word must never be split across two lines - that is precisely the
       thing this tool exists to avoid. fitWord() in focus-reader.js shrinks
       the type until a long word fits; multi-word chunks may wrap between
       words, never inside one. */
    overflow-wrap: normal;
    word-break: keep-all;
    hyphens: none;
}

/* Last resort, applied by fitWord() only when a word cannot fit even at the
   minimum size (a pasted URL, say). Breaking beats disappearing. */
.fr-word.fr-word-must-break {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.fr-endstop-dot {
    width: 8px;
    height: 8px;
    margin: 22px auto 0;
    border-radius: 50%;
    background: currentColor;
    opacity: .35;
}

.fr-tap {
    margin: 0;
    font-size: clamp(20px, 4vw, 30px);
    opacity: .6;
    letter-spacing: var(--fr-spacing);
}

/* The optional sentence behind the current word. Fading is applied to the
   individual words, not the paragraph: opacity on the parent would create a
   stacking context and cap the active word below full contrast. */
.fr-context {
    max-width: 720px;
    margin: 40px auto 0;
    font-size: clamp(15px, 2.2vw, 20px);
    line-height: 2;
    letter-spacing: .5px;
}

.fr-context span { opacity: .3; }

.fr-context .fr-context-active {
    opacity: 1;
    font-weight: 700;
    border-bottom: 2px solid currentColor;
}

/* --- Questions, feedback, exit --- */

.fr-card-question { max-width: 640px; margin: 0 auto; }

.fr-question-intro {
    margin: 0 0 14px;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: .1em;
    opacity: .5;
}

.fr-question {
    margin: 0 0 34px;
    font-size: clamp(22px, 3.4vw, 32px);
    line-height: 1.5;
    letter-spacing: 1px;
    font-weight: 700;
}

.fr-answers {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    justify-content: center;
}

.fr-answer {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 160px;
    padding: 18px 28px;
    border: 3px solid currentColor;
    border-radius: 12px;
    background: transparent;
    color: inherit;
    font-size: clamp(17px, 2.4vw, 21px);
    font-weight: 700;
    letter-spacing: .5px;
    cursor: pointer;
    transition: background .15s, transform .1s;
}

.fr-answer:hover { background: rgba(128, 128, 128, .16); }
.fr-answer:active { transform: scale(.98); }

.fr-answer-quiet { border-width: 1px; font-weight: 400; opacity: .7; }

/* --- Level note --- */

.fr-level-note {
    margin: 0 0 22px;
    font-size: clamp(15px, 2vw, 18px);
    line-height: 1.5;
    opacity: .6;
}

.fr-level-note-inline {
    position: absolute;
    top: -70px;
    left: 0;
    right: 0;
    margin: 0;
}

/* --- Summary --- */

.fr-card-summary { max-width: 560px; margin: 0 auto; }

.fr-summary-title {
    margin: 0 0 24px;
    font-size: clamp(22px, 3.2vw, 30px);
    letter-spacing: .5px;
}

.fr-stats {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2px;
    margin: 0 0 28px;
    text-align: left;
}

.fr-stats > div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding: 13px 4px;
    border-bottom: 1px solid rgba(128, 128, 128, .28);
}

.fr-stats dt { font-size: 16px; opacity: .7; }
.fr-stats dd { margin: 0; font-size: 22px; font-weight: 700; }

.fr-summary-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.fr-summary-actions .fr-answer {
    min-width: 0;
    padding: 14px 20px;
    font-size: 16px;
}

/* --- Bottom bar --- */

.fr-bottombar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px 20px;
    min-height: 68px;
}

.fr-hint {
    flex: 1 1 auto;
    text-align: center;
    font-size: 13px;
    letter-spacing: .3px;
    opacity: .4;
}

.fr-hint[hidden] { display: none; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 720px) {
    .fr-modes,
    .fr-settings-grid { grid-template-columns: 1fr; }

    .fr-overlay {
        /* Keep the word clear of iOS Safari's bottom toolbar. */
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    /* Cap the chosen size on narrow screens so long words still fit. */
    .fr-word { font-size: min(var(--fr-size), 13vw); }

    .fr-answer { min-width: 132px; padding: 16px 20px; }

    .fr-hint { font-size: 12px; }

    .fr-level-note-inline { top: -54px; }
}

@media (max-width: 380px) {
    .fr-answers { flex-direction: column; }
    .fr-answer { width: 100%; }
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .fr-progress-bar,
    .fr-mode-card,
    .fr-answer,
    .fr-icon-btn { transition: none; }
}
