/* =====================================================================
   DyslexicAid — shared "Try this yourself" pop-up
   Theme with these custom properties (set on :root by the page):
     --try-font-display  --try-font-body
     --try-ink  --try-paper  --try-surface
     --try-read  --try-dictate  --try-flash  --try-highlight
   Trigger buttons: <button type="button" class="try-btn" data-try="read|dictate|flashcards">
   ===================================================================== */

/* ---------- Trigger button (page may restyle; --try-btn sets its colour) ---------- */
.try-btn{
  display:inline-flex;align-items:center;justify-content:center;gap:10px;
  min-height:48px;padding:12px 22px;border:0;border-radius:12px;
  background:var(--try-btn, var(--try-ink, #13294B));color:#fff;
  font-family:var(--try-font-body, "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif);
  font-size:18px;font-weight:700;line-height:1.2;font-style:normal;text-align:left;
  cursor:pointer;text-decoration:none;
}
.try-btn:hover{filter:brightness(1.08)}
.try-btn:focus-visible{outline:3px solid var(--try-ink, #13294B);outline-offset:3px;box-shadow:0 0 0 6px #fff}

/* ---------- Scroll lock ---------- */
html.try-locked, html.try-locked body{overflow:hidden}

/* ---------- Dialog shell ---------- */
.try-dlg{
  --try-accent:var(--try-read, #2563EB);
  --_ink:var(--try-ink, #13294B);
  --_paper:var(--try-paper, #EEF2F6);
  --_surface:var(--try-surface, #FFFFFF);
  --_hl:var(--try-highlight, #FDE68A);
  --_muted:#4A5B74;
  --_line:#D5DDE7;
  --_tint:#EAF0FD;
  --_body:var(--try-font-body, "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif);
  --_display:var(--try-font-display, "Fraunces", Georgia, serif);
  box-sizing:border-box;
  width:min(760px, calc(100% - 32px));max-width:none;
  max-height:calc(100dvh - 48px);
  margin:auto;padding:0;border:0;border-radius:20px;
  background:var(--_surface);color:var(--_ink);
  font-family:var(--_body);font-size:18px;line-height:1.6;font-style:normal;text-align:left;letter-spacing:.01em;
  box-shadow:0 24px 60px rgba(10,22,44,.35);
  overflow:hidden;
}
@supports (color:color-mix(in srgb, red 50%, blue)){
  .try-dlg{
    --_muted:color-mix(in srgb, var(--_ink) 78%, var(--_surface));
    --_line:color-mix(in srgb, var(--_ink) 16%, var(--_surface));
    --_tint:color-mix(in srgb, var(--try-accent) 10%, var(--_surface));
  }
}
.try-dlg[data-kind="read"]{--try-accent:var(--try-read, #2563EB)}
.try-dlg[data-kind="dictate"]{--try-accent:var(--try-dictate, #0F766E)}
.try-dlg[data-kind="flashcards"]{--try-accent:var(--try-flash, #7C3AED)}
.try-dlg[open]{display:flex;flex-direction:column}
.try-dlg::backdrop{background:rgba(10,22,44,.6)}
.try-dlg *, .try-dlg *::before, .try-dlg *::after{box-sizing:border-box}
.try-dlg em, .try-dlg i, .try-dlg cite, .try-dlg ::placeholder{font-style:normal}

@media (prefers-reduced-motion: no-preference){
  .try-dlg[open]{animation:try-in .22s ease-out}
  .try-dlg[open]::backdrop{animation:try-fade .22s ease-out}
}
@keyframes try-in{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:none}}
@keyframes try-fade{from{opacity:0}to{opacity:1}}

/* Header */
.try-head{
  display:flex;align-items:flex-start;gap:16px;
  padding:22px 24px 18px 28px;border-bottom:1px solid var(--_line);
  border-top:6px solid var(--try-accent);background:var(--_surface);flex:none;
}
.try-head-text{flex:1;min-width:0}
.try-week{display:block;margin:0 0 2px;font-size:16px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:var(--try-accent)}
.try-title{margin:0;font-family:var(--_display);font-weight:600;font-style:normal;font-size:30px;line-height:1.2;color:var(--try-accent)}
.try-what{margin:8px 0 0;font-size:18px;line-height:1.5;color:var(--_muted);max-width:56ch}
.try-close{
  flex:none;display:inline-flex;align-items:center;gap:8px;min-height:44px;min-width:44px;padding:8px 14px;
  border:2px solid var(--_line);border-radius:12px;background:var(--_surface);color:var(--_ink);
  font:700 17px/1 var(--_body);cursor:pointer;
}
.try-close:hover{border-color:var(--_ink)}
.try-close svg{width:14px;height:14px;stroke:currentColor;stroke-width:2.4;fill:none}

/* Body + footer */
.try-body{flex:1 1 auto;overflow:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain;padding:24px 28px 28px;background:var(--_paper)}
.try-foot{flex:none;margin:0;padding:14px 28px;border-top:1px solid var(--_line);background:var(--_surface);font-size:16px;line-height:1.5;color:var(--_muted)}

/* Focus ring for everything inside */
.try-dlg button:focus-visible, .try-dlg textarea:focus-visible, .try-dlg [tabindex]:focus-visible{
  outline:3px solid var(--try-accent);outline-offset:3px;
}
.try-dlg [tabindex="-1"]:focus{outline:none}

/* ---------- Shared controls ---------- */
.try-row{display:flex;flex-wrap:wrap;align-items:center;gap:12px}
.try-ctrl{
  display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:48px;padding:10px 18px;
  border:2px solid var(--_ink);border-radius:12px;background:var(--_surface);color:var(--_ink);
  font:700 18px/1.2 var(--_body);cursor:pointer;text-align:left;
}
.try-ctrl svg{width:16px;height:16px;fill:currentColor;flex:none}
.try-ctrl.try-primary{background:var(--try-accent);border-color:var(--try-accent);color:#fff}
.try-ctrl.try-primary:hover{filter:brightness(1.08)}
.try-ctrl:disabled{opacity:.45;cursor:not-allowed}
.try-status{margin:14px 0 0;min-height:1.6em;font-size:17px;line-height:1.5;color:var(--_muted)}
.try-note{margin:14px 0 0;font-size:16px;line-height:1.5;color:var(--_muted)}
.try-panel{background:var(--_surface);border:1px solid var(--_line);border-radius:16px;overflow:hidden}
.try-sr{position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}

/* ---------- 1. Read aloud ---------- */
.try-read-bar{display:flex;flex-wrap:wrap;align-items:center;gap:12px;padding:14px 18px;background:var(--_tint);border-bottom:1px solid var(--_line)}
.try-speed{display:inline-flex;border:2px solid var(--_ink);border-radius:12px;overflow:hidden}
.try-speed button{min-height:44px;padding:8px 16px;border:0;background:var(--_surface);color:var(--_ink);font:700 17px/1 var(--_body);cursor:pointer}
.try-speed button+button{border-left:2px solid var(--_ink)}
.try-speed button[aria-pressed="true"]{background:var(--_ink);color:#fff}
.try-speed button:focus-visible{outline-offset:-5px;outline-color:var(--_hl)}
.try-sheet{padding:24px 26px 28px}
.try-ws-meta{display:flex;justify-content:space-between;gap:12px;font-size:16px;color:var(--_muted);border-bottom:2px dashed var(--_line);padding-bottom:10px;margin-bottom:16px}
.try-sheet h3{margin:0 0 10px;font-family:var(--_display);font-weight:600;font-size:24px;line-height:1.25}
.try-passage{margin:0;font-size:21px;line-height:1.85;max-width:60ch}
.try-passage .s{border-radius:6px;transition:background-color .15s}
.try-passage .s.on{background:var(--_tint)}
.try-passage .w{border-radius:4px;padding:1px 0;transition:background-color .08s}
.try-passage .w.on{background:var(--_hl);box-shadow:0 0 0 3px var(--_hl)}

/* ---------- 2. Dictation ---------- */
.try-q{margin:0 0 18px;font-size:18px}
.try-q b{font-weight:700}
.try-mic-area{display:flex;flex-direction:column;align-items:center;gap:10px;margin:0 0 20px;text-align:center}
.try-mic{
  position:relative;width:104px;height:104px;border-radius:50%;border:0;cursor:pointer;
  background:var(--try-accent);color:#fff;display:grid;place-items:center;
  box-shadow:0 8px 22px rgba(10,22,44,.22);
}
.try-mic svg{width:40px;height:40px;fill:currentColor}
.try-mic:hover{filter:brightness(1.08)}
.try-mic:focus-visible{outline:4px solid var(--_ink);outline-offset:4px}
.try-mic[data-on="true"]{background:#B42318}
.try-mic[data-on="true"]::after{content:"";position:absolute;inset:-8px;border-radius:50%;border:3px solid #B42318;opacity:.5}
@media (prefers-reduced-motion: no-preference){
  .try-mic[data-on="true"]::after{animation:try-pulse 1.4s ease-out infinite}
}
@keyframes try-pulse{from{transform:scale(1);opacity:.55}to{transform:scale(1.3);opacity:0}}
.try-mic-label{margin:0;font-size:19px;font-weight:700}
.try-wave{display:flex;align-items:center;justify-content:center;gap:5px;height:40px;visibility:hidden}
.try-wave.on{visibility:visible}
.try-wave span{display:block;width:6px;height:8px;border-radius:3px;background:var(--try-accent)}
.try-wave.on span{height:var(--h, 18px)}
@media (prefers-reduced-motion: no-preference){
  .try-wave.on span{animation:try-bar .9s ease-in-out infinite alternate;animation-delay:calc(var(--i) * -.13s)}
  .try-wave.on.loud span{animation-duration:.45s}
}
@keyframes try-bar{from{height:6px}to{height:var(--h, 30px)}}
.try-doc-bar{display:flex;align-items:center;gap:10px;padding:10px 16px;border-bottom:1px solid var(--_line);font-size:16px;color:var(--_muted);background:var(--_surface)}
.try-doc-bar i{display:inline-block;width:12px;height:12px;border-radius:50%;background:var(--_line)}
.try-doc{min-height:150px;padding:20px 22px 24px;font-size:21px;line-height:1.75;white-space:pre-wrap;word-wrap:break-word}
.try-doc .ph{color:var(--_muted)}
.try-doc .interim{color:var(--_muted);opacity:.85}
.try-doc .raw{color:var(--_muted)}
.try-doc mark{background:var(--_hl);color:inherit;border-radius:3px;box-shadow:0 0 0 2px var(--_hl);transition:background-color .8s, box-shadow .8s}
.try-doc mark.gone{background:transparent;box-shadow:none}
.try-caret{display:inline-block;width:2px;height:1.1em;margin-left:2px;vertical-align:-.15em;background:var(--try-accent)}
.try-dictate .try-row{margin-top:16px}
.try-dictate .try-status{margin:0 0 14px}

/* ---------- 3. Flashcards ---------- */
.try-mock{margin:0 0 16px;padding:10px 14px;border-radius:10px;background:var(--_surface);border:2px dashed var(--try-accent);font-size:17px;line-height:1.5}
.try-mock b{color:var(--try-accent)}
.try-label{display:block;margin:0 0 8px;font-size:18px;font-weight:700}
.try-notes{
  display:block;width:100%;min-height:200px;padding:14px 16px;border:2px solid var(--_line);border-radius:12px;
  background:var(--_surface);color:var(--_ink);font:400 18px/1.6 var(--_body);resize:vertical;
}
.try-notes:focus{border-color:var(--try-accent)}
.try-flash .try-row{margin-top:16px}
.try-dots::after{content:"";display:inline-block;width:1.2em;text-align:left}
@media (prefers-reduced-motion: no-preference){
  .try-dots::after{animation:try-dots 1s steps(4) infinite}
}
@keyframes try-dots{0%{content:""}25%{content:"."}50%{content:".."}75%{content:"..."}}
.try-h3{margin:0 0 6px;font-family:var(--_display);font-weight:600;font-size:24px;line-height:1.25}
.try-sub{margin:0 0 16px;color:var(--_muted);font-size:17px}
.try-cards{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:repeat(auto-fill, minmax(200px, 1fr));gap:14px}
.try-cards li{perspective:900px;display:grid}
.try-card{
  display:block;width:100%;min-height:170px;padding:0;border:0;background:none;color:var(--_ink);
  font:inherit;text-align:left;cursor:pointer;border-radius:14px;
}
.try-card-in{display:grid;min-height:170px;height:100%;transform-style:preserve-3d;transition:transform .5s cubic-bezier(.2,.7,.2,1)}
.try-card[aria-pressed="true"] .try-card-in{transform:rotateY(180deg)}
.try-face{
  grid-area:1/1;display:flex;flex-direction:column;gap:8px;padding:16px 16px 14px;border-radius:14px;
  backface-visibility:hidden;-webkit-backface-visibility:hidden;
  background:var(--_surface);border:2px solid var(--_line);font-size:18px;line-height:1.5;
}
.try-face.back{transform:rotateY(180deg);background:var(--_tint);border-color:var(--try-accent)}
.try-face small{font-size:15px;font-weight:700;letter-spacing:.05em;text-transform:uppercase;color:var(--try-accent)}
.try-face .q{font-weight:700}
.try-face .hint{margin-top:auto;font-size:15px;color:var(--_muted)}
.try-card:hover .try-face{border-color:var(--try-accent)}
@media (prefers-reduced-motion: reduce){
  .try-card-in{transition:none;transform:none!important}
  .try-face.back{transform:none}
  .try-card[aria-pressed="true"] .front, .try-card[aria-pressed="false"] .back{visibility:hidden}
}
.try-quiz{padding:22px 22px 24px}
.try-progress{margin:0 0 6px;font-size:16px;font-weight:700;color:var(--try-accent)}
.try-quiz .try-qtext{margin:0 0 16px;font-family:var(--_display);font-weight:600;font-size:24px;line-height:1.3}
.try-answer{margin:0 0 18px;padding:14px 16px;border-radius:12px;background:var(--_tint);border-left:5px solid var(--try-accent);font-size:19px}
.try-score{margin:0 0 16px;font-size:20px}
.try-score b{font-family:var(--_display);font-weight:600;font-size:30px;color:var(--try-accent)}

/* ---------- Phone: full-screen sheet ---------- */
@media (max-width:640px){
  .try-dlg{width:100%;height:100%;height:100dvh;max-height:none;max-height:100dvh;border-radius:0;margin:0;inset:0}
  .try-head{padding:16px 16px 14px;gap:12px}
  .try-title{font-size:25px}
  .try-what{font-size:18px}
  .try-close{padding:8px 10px}
  .try-body{padding:18px 16px 22px}
  .try-foot{padding:12px 16px calc(12px + env(safe-area-inset-bottom))}
  .try-read-bar{padding:12px 14px}
  .try-sheet{padding:18px 16px 20px}
  .try-passage{font-size:20px}
  .try-doc{font-size:20px;padding:16px}
  .try-cards{grid-template-columns:1fr}
  .try-card, .try-card-in{min-height:130px}
}
