:root {
  --bg: #f5f6fb;
  --card: #ffffff;
  --text: #171a2b;
  --muted: #646b85;
  --line: #e3e6f0;
  --brand: #4f46e5;
  --brand-2: #6366f1;
  --brand-soft: #eef0ff;
  --good: #15803d;
  --good-bg: #dcfce7;
  --fair: #b45309;
  --fair-bg: #fef3c7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --miss: #6b7280;
  --miss-bg: #eceef3;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 24, 50, .06), 0 4px 16px rgba(20, 24, 50, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1220;
    --card: #181c2e;
    --text: #e9ebf5;
    --muted: #9aa1bd;
    --line: #2a3048;
    --brand: #818cf8;
    --brand-2: #6366f1;
    --brand-soft: #23284a;
    --good: #4ade80;
    --good-bg: #133222;
    --fair: #fbbf24;
    --fair-bg: #3a2c0c;
    --bad: #f87171;
    --bad-bg: #3d1717;
    --miss: #9ca3af;
    --miss-bg: #262a3b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(64px + var(--safe-b));
}
button { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
a { color: var(--brand); }

/* ---------- barra superior / navegación ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; margin: 0 4px; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active { background: var(--line); }
.icon-btn svg circle { fill: currentColor; stroke: none; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + var(--safe-b));
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 12px; padding: 4px 0;
}
.bottomnav a.active { color: var(--brand); font-weight: 600; }
body.recording-mode .bottomnav { display: none; }

main { max-width: 760px; margin: 0 auto; padding: 14px 14px 24px; }

/* ---------- tarjetas ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 11px 16px; cursor: pointer;
  background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: 15px;
  min-height: 44px; text-decoration: none;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.small { min-height: 36px; padding: 7px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.btn svg { width: 18px; height: 18px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- lista de textos ---------- */
.text-item { display: block; color: inherit; text-decoration: none; }
.text-item .t-title { font-weight: 700; margin-bottom: 4px; display: flex; gap: 8px; align-items: center; }
.text-item .t-body { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.text-item .t-meta { margin-top: 8px; font-size: 13px; color: var(--muted); display: flex; gap: 12px; align-items: center; }
.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.score-pill { display: inline-block; min-width: 38px; text-align: center; padding: 2px 8px; border-radius: 999px; font-weight: 700; font-size: 13px; }
.s-good { background: var(--good-bg); color: var(--good); }
.s-fair { background: var(--fair-bg); color: var(--fair); }
.s-bad { background: var(--bad-bg); color: var(--bad); }
.s-missed { background: var(--miss-bg); color: var(--miss); }
.s-none { background: var(--line); color: var(--muted); }

.fab {
  position: fixed; right: 18px; bottom: calc(78px + var(--safe-b)); z-index: 15;
  border-radius: 999px; padding: 14px 20px; box-shadow: 0 6px 20px rgba(79, 70, 229, .35);
}

textarea, input[type=text] {
  width: 100%; font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
}
textarea { min-height: 180px; resize: vertical; }
label { display: block; font-weight: 600; font-size: 14px; margin: 10px 0 6px; }

/* ---------- texto de práctica ---------- */
.reading {
  font-size: 21px; line-height: 2.05; letter-spacing: .005em;
  word-break: break-word; user-select: none; -webkit-user-select: none;
}
.w {
  border-radius: 7px; padding: 2px 3px; margin: 0 -1px; cursor: pointer;
  border-bottom: 3px solid transparent; transition: background .2s;
}
.w:active { filter: brightness(.95); }
.w.good { background: var(--good-bg); border-bottom-color: var(--good); }
.w.fair { background: var(--fair-bg); border-bottom-color: var(--fair); }
.w.bad { background: var(--bad-bg); border-bottom-color: var(--bad); }
.w.missed { background: var(--miss-bg); color: var(--miss); border-bottom: 3px dotted var(--miss); }
.w .l-bad { color: var(--bad); font-weight: 800; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.w .l-fair { color: var(--fair); font-weight: 700; }
.w.sel { outline: 2px solid var(--brand); outline-offset: 1px; }
.reading.pending .w { background: transparent; border-bottom-color: var(--line); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; margin-right: 4px; }
.legend .good i { background: var(--good); }
.legend .fair i { background: var(--fair); }
.legend .bad i { background: var(--bad); }
.legend .missed i { background: var(--miss); }

/* ---------- puntuaciones ---------- */
.scores { display: grid; grid-template-columns: 112px 1fr; gap: 14px; align-items: center; }
.ring { position: relative; width: 112px; height: 112px; }
.ring svg { width: 112px; height: 112px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring .bg { stroke: var(--line); }
.ring .fg { stroke-linecap: round; transition: stroke-dashoffset .8s ease; }
.ring .val { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.ring .val b { font-size: 30px; line-height: 1; display: block; }
.ring .val span { font-size: 11px; color: var(--muted); }
.metric { margin-bottom: 8px; }
.metric .row { font-size: 13px; justify-content: space-between; }
.bar { height: 7px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 3px; }
.bar > div { height: 100%; border-radius: 99px; transition: width .8s ease; }
.counts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.trouble { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.trouble:first-of-type { border-top: 0; }
.ph-big { min-width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; font-weight: 700; background: var(--bad-bg); color: var(--bad); font-family: "Noto Sans", "DejaVu Sans", "Lucida Grande", sans-serif; }

/* ---------- barra de grabación ---------- */
.recbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(70px + var(--safe-b)); z-index: 12;
  max-width: 736px; margin: 0 auto;
  background: var(--card); border-radius: 20px; box-shadow: 0 8px 30px rgba(20, 24, 50, .2);
  padding: 10px 12px; display: flex; align-items: center; gap: 12px;
}
body.recording-mode .recbar { bottom: calc(12px + var(--safe-b)); }
body.has-recbar main { padding-bottom: 110px; }
.mic {
  width: 64px; height: 64px; border-radius: 999px; border: 0; flex: none;
  background: var(--brand); color: #fff; display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 4px 14px rgba(79, 70, 229, .4);
}
.mic svg { width: 28px; height: 28px; }
.mic.rec { background: #dc2626; box-shadow: 0 0 0 0 rgba(220, 38, 38, .6); animation: pulse 1.4s infinite; }
.mic.busy { background: var(--muted); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .55); } 70% { box-shadow: 0 0 0 16px rgba(220, 38, 38, 0); } 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); } }
.recinfo { flex: 1; min-width: 0; }
.recinfo b { display: block; font-size: 15px; }
.recinfo span { font-size: 13px; color: var(--muted); }
.meter { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.meter div { height: 100%; width: 0; background: linear-gradient(90deg, #22c55e, #eab308, #ef4444); transition: width .08s; }
.spinner { width: 26px; height: 26px; border: 3px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- historial ---------- */
.att { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-top: 1px solid var(--line); cursor: pointer; }
.att:first-child { border-top: 0; }
.att.cur { background: var(--brand-soft); border-radius: 10px; }
.att .d { flex: 1; font-size: 14px; }

/* ---------- hoja inferior ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 12, 25, .45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 88vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(20px + var(--safe-b));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .2);
  animation: up .22s ease;
  max-width: 760px; margin: 0 auto;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 42px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 12px; }
.wd-head { display: flex; align-items: flex-start; gap: 12px; }
.wd-word { font-size: 34px; font-weight: 800; letter-spacing: .01em; line-height: 1.15; word-break: break-word; }
.wd-word .l-good { color: var(--good); }
.wd-word .l-fair { color: var(--fair); text-decoration: underline wavy; text-underline-offset: 5px; }
.wd-word .l-bad { color: var(--bad); text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 5px; }
.wd-score { margin-left: auto; text-align: center; flex: none; }
.wd-score b { font-size: 26px; display: block; line-height: 1.1; }
.wd-score span { font-size: 12px; }
.ipa { font-family: "Noto Sans", "DejaVu Sans", "Lucida Grande", "Segoe UI", sans-serif; font-size: 19px; }
.pron { display: grid; gap: 10px; margin: 14px 0; }
.pron .box { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.pron .box .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.pron .box .row { justify-content: space-between; flex-wrap: wrap; }
.phones { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.phone {
  border: 0; border-radius: 10px; padding: 6px 9px; min-width: 42px; text-align: center; cursor: pointer;
  font-family: "Noto Sans", "DejaVu Sans", "Lucida Grande", sans-serif; font-size: 17px; line-height: 1.2;
}
.phone small { display: block; font-size: 11px; font-family: system-ui, sans-serif; opacity: .85; }
.phone.good { background: var(--good-bg); color: var(--good); }
.phone.fair { background: var(--fair-bg); color: var(--fair); }
.phone.bad { background: var(--bad-bg); color: var(--bad); }
.phone.none { background: var(--brand-soft); color: var(--brand); }
.phone-tip { background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-top: 6px; }
.issues { margin: 8px 0 0; padding: 0; list-style: none; }
.issues li { padding: 9px 12px; border-radius: 12px; margin-bottom: 6px; font-size: 14px; background: var(--bad-bg); }
.issues li.fair { background: var(--fair-bg); }
.issues li b { font-family: "Noto Sans", "DejaVu Sans", sans-serif; }
.hist-list .att { cursor: default; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 0 6px; }

/* ---------- palabras ---------- */
.wl { display: flex; align-items: center; gap: 10px; padding: 12px 4px; border-top: 1px solid var(--line); cursor: pointer; }
.wl:first-child { border-top: 0; }
.wl .ww { font-weight: 700; font-size: 17px; flex: 1; }
.wl .wm { font-size: 12px; color: var(--muted); text-align: right; }

.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.empty svg { width: 46px; height: 46px; opacity: .5; }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translateX(-50%); z-index: 60;
  background: #1f2337; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.help h3 { margin: 18px 0 6px; font-size: 16px; }
.help p, .help li { font-size: 15px; }

@media (min-width: 700px) {
  .reading { font-size: 23px; }
  .scores { grid-template-columns: 130px 1fr; }
}
