/* FriendlyReader: calm, book-like, grown-up. */
:root {
    --font-ui: "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-read: Charter, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
    --radius: 10px;
}

.theme-light {
    --bg: #f7f7f5; --surface: #ffffff; --text: #1f2328; --muted: #6a737d; --line: #e3e3df;
    --accent: #2f6f6a; --accent-text: #ffffff; --current: #fff1b8; --current-line: #d99a00;
    --read: #57606a; --skipped: #b26b00; --misread: #b3261e; --mispronounced: #b3261e; --helped: #2f6f6a;
}

.theme-sepia {
    --bg: #f1e7d0; --surface: #f8f0dc; --text: #3b2f22; --muted: #7a6a55; --line: #e0d2b4;
    --accent: #7a4f1d; --accent-text: #fff8ea; --current: #f6d98b; --current-line: #a0661c;
    --read: #6b5a45; --skipped: #a35a00; --misread: #a12a1a; --mispronounced: #a12a1a; --helped: #2f6f6a;
}

.theme-dark {
    --bg: #15181c; --surface: #1d2126; --text: #e6e6e3; --muted: #9aa3ad; --line: #2e343b;
    --accent: #6cc3b9; --accent-text: #10201e; --current: #4a3d12; --current-line: #f2c14e;
    --read: #a8b0b8; --skipped: #f2a54a; --misread: #ff8a80; --mispronounced: #ff8a80; --helped: #6cc3b9;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body { font-family: var(--font-ui); }

.app { min-height: 100vh; background: var(--bg); color: var(--text); transition: background .2s, color .2s; }

a { color: var(--accent); }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: .75rem 1.5rem; border-bottom: 1px solid var(--line); background: var(--surface);
}

.brand { font-weight: 650; letter-spacing: .01em; text-decoration: none; color: var(--text); font-size: 1.1rem; }

.topbar nav a { margin-left: 1.25rem; text-decoration: none; color: var(--muted); font-weight: 500; }
.topbar nav a.active { color: var(--text); border-bottom: 2px solid var(--accent); padding-bottom: 2px; }

main { padding: 0 1.5rem 8rem; }

h1 { font-weight: 600; font-size: 1.8rem; margin: 2rem 0 .5rem; }
h2 { font-weight: 600; font-size: 1.25rem; margin: 0; }

.muted { color: var(--muted); }

.btn {
    display: inline-flex; align-items: center; gap: .4rem; cursor: pointer;
    border: 1px solid var(--line); background: var(--surface); color: var(--text);
    padding: .5rem .95rem; border-radius: var(--radius); font: inherit; font-weight: 500;
}
.btn:hover:not([disabled]) { border-color: var(--accent); }
.btn[disabled] { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin: .75rem 0; }

.hidden-file { display: none; }

/* Start screen */
.start { max-width: 760px; margin: 0 auto; }
.paste {
    width: 100%; margin-top: 1rem; padding: 1rem; border-radius: var(--radius); border: 1px solid var(--line);
    background: var(--surface); color: var(--text); font: 1.05rem/1.6 var(--font-read); resize: vertical;
}
.note { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: .75rem 1rem; border-radius: var(--radius); }

/* Toolbar */
.toolbar {
    position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; justify-content: space-between; gap: .75rem;
    align-items: center; max-width: 900px; margin: 0 auto; padding: .9rem 0; background: var(--bg); border-bottom: 1px solid var(--line);
}
.toolbar .title { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.doc-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 22rem; }
.controls { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

.pill { font-size: .78rem; padding: .15rem .6rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.pill.state-listening { color: var(--accent); border-color: var(--accent); }
.pill.state-speakinghelp { color: var(--current-line); border-color: var(--current-line); }
.pill.state-finished { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.meter { width: 70px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; display: inline-block; }
.meter span { display: block; height: 100%; background: var(--accent); transition: width .1s linear; }

/* Reading page */
.page {
    max-width: 900px; margin: 1.5rem auto 0; padding: 2.5rem 3rem; background: var(--surface);
    border: 1px solid var(--line); border-radius: 14px; font-family: var(--font-read);
}
.para { margin: 0 0 1.1em; max-width: 68ch; }
.hint { font-family: var(--font-ui); font-size: .85rem; margin-top: 2rem; }

.w { cursor: pointer; border-radius: 4px; padding: 0 .05em; transition: background-color .15s, color .15s; }
.w:hover { text-decoration: underline dotted var(--muted); }
.w.read { color: var(--read); }
.w.current { background: var(--current); box-shadow: inset 0 -3px 0 var(--current-line); color: var(--text); }
.w.current.idle { box-shadow: inset 0 -2px 0 var(--muted); background: transparent; }
.w.skipped { color: var(--text); text-decoration: underline dashed var(--skipped) 2px; text-underline-offset: .2em; }
.w.misread, .w.mispronounced { color: var(--text); text-decoration: underline wavy var(--mispronounced) 1.5px; text-underline-offset: .22em; }
.w.helped:not(.current) { color: var(--text); box-shadow: inset 0 -2px 0 var(--helped); }

/* Help bubble */
.help-bubble {
    position: fixed; left: 50%; bottom: 6.5rem; transform: translateX(-50%); z-index: 10;
    display: flex; align-items: center; gap: .7rem; padding: .7rem 1.3rem; border-radius: 999px;
    background: var(--text); color: var(--bg); box-shadow: 0 8px 30px rgba(0,0,0,.18); animation: rise .2s ease-out;
}
.help-bubble .label { opacity: .75; }
.help-bubble .word { font-family: var(--font-read); font-size: 1.35rem; font-weight: 600; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Practice mode and heard line */
.practice-bar, .heard {
    position: fixed; left: 0; right: 0; bottom: 0; padding: .9rem 1.5rem; background: var(--surface);
    border-top: 1px solid var(--line); z-index: 8;
}
.practice-bar label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .35rem; }
.practice-bar input { width: 100%; padding: .65rem .8rem; font: 1.05rem var(--font-read); border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.heard { font-size: .9rem; }

/* Banner */
.banner { max-width: 900px; margin: 1rem auto 0; padding: .7rem 1rem; border-radius: var(--radius); display: flex; justify-content: space-between; gap: 1rem; }
.banner.error { background: color-mix(in srgb, var(--misread) 12%, var(--surface)); border: 1px solid var(--misread); }

/* Summary */
.summary-overlay { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.summary { width: min(900px, 100%); max-height: 85vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); padding: 1.5rem 2rem; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.summary header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
.stats div { display: flex; flex-direction: column; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: var(--radius); }
.stats strong { font-size: 1.5rem; font-weight: 600; }
.stats span { font-size: .8rem; color: var(--muted); }
.tricky { width: 100%; border-collapse: collapse; }
.tricky th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 500; padding: .4rem .5rem; border-bottom: 1px solid var(--line); }
.tricky td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); }
.tricky td.tw { font-family: var(--font-read); font-size: 1.15rem; font-weight: 600; }
.tricky td:last-child { text-align: right; }

/* Settings */
.settings { max-width: 720px; margin: 0 auto; }
fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 1.1rem 1.4rem 1.3rem; margin: 1.25rem 0; background: var(--surface); }
legend { font-weight: 600; padding: 0 .4rem; }
.field { display: flex; flex-direction: column; gap: .35rem; margin: .9rem 0; }
.field small { color: var(--muted); }
.field input[type=range] { accent-color: var(--accent); width: 100%; }
.field input:not([type=range]), .field select { padding: .5rem .65rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
.mic-test audio { display: block; width: min(100%, 28rem); margin-top: .75rem; }
.radio { display: flex; gap: .5rem; align-items: center; margin: .3rem 0; }
.sample { font-family: var(--font-read); background: var(--bg); padding: .75rem 1rem; border-radius: var(--radius); }

@media (max-width: 700px) {
    .page { padding: 1.5rem 1.25rem; }
    .stats { grid-template-columns: repeat(2, 1fr); }
}

/* Blazor error UI */
#blazor-error-ui {
    background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); display: none;
    left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000; color: #222;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
