:root {
  --bg: #fbf6ef;
  --card: #ffffff;
  --ink: #2b2118;
  --muted: #7a6a5c;
  --red: #c0392b;
  --red-2: #e74c3c;
  --green: #1e8449;
  --green-bg: #e3f5e9;
  --orange: #b9770e;
  --orange-bg: #fdf1dc;
  --bad: #b03a2e;
  --bad-bg: #fbe4e1;
  --blue: #1f5f99;
  --blue-bg: #e4eef8;
  --line: #eadfd2;
  --shadow: 0 2px 10px rgba(60, 40, 20, 0.08);
  --radius: 20px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;
  font-size: 19px;
  line-height: 1.4;
  min-height: 100dvh;
}
#app { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.ar { font-family: "Noto Naskh Arabic", "Segoe UI", Tahoma, sans-serif; direction: rtl; unicode-bidi: plaintext; }
h1 { font-size: 1.5rem; margin: 4px 0 12px; }
h2 { font-size: 1.2rem; margin: 18px 0 8px; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
.top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.top .grow { flex: 1; }
.icon-btn { background: var(--card); border-radius: 14px; width: 52px; height: 52px; font-size: 26px; box-shadow: var(--shadow); display: inline-grid; place-items: center; flex: none; }
.big-cards { display: grid; gap: 14px; }
.big-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 16px; padding: 18px; text-align: left; width: 100%;
  border: 3px solid transparent;
}
.big-card:active { transform: scale(0.99); }
.big-card .emoji { font-size: 56px; line-height: 1; flex: none; }
.big-card .txt { flex: 1; }
.big-card .t { font-weight: 700; font-size: 1.25rem; }
.big-card .ar { font-size: 1.2rem; color: var(--muted); }
.big-card.sel { border-color: var(--red); }
.say { background: var(--blue-bg); color: var(--blue); border-radius: 50%; width: 48px; height: 48px; font-size: 22px; flex: none; display: inline-grid; place-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 12px 8px; text-align: center; border: 3px solid transparent; }
.tile .emoji { font-size: 40px; }
.tile .t { font-size: 0.85rem; font-weight: 600; margin-top: 4px; }
.tile .ar { font-size: 0.9rem; color: var(--muted); }
.tile.sel { border-color: var(--red); }
.photo-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border: 4px solid transparent; padding: 0; width: 100%; text-align: left; }
.photo-card img { width: 100%; display: block; aspect-ratio: 4/3; object-fit: cover; background: #ddd; }
.photo-card .cap { padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.photo-card .cap .txt { flex: 1; }
.photo-card.sel { border-color: var(--red); }
.primary { background: var(--red); color: #fff; border-radius: 18px; padding: 16px 20px; font-size: 1.2rem; font-weight: 700; width: 100%; box-shadow: var(--shadow); }
.primary:disabled { opacity: 0.5; }
.secondary { background: var(--card); border-radius: 16px; padding: 12px 16px; font-weight: 600; box-shadow: var(--shadow); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }

/* Sesión */
.phases { display: flex; gap: 6px; }
.phases span { flex: 1; height: 8px; border-radius: 4px; background: var(--line); }
.phases span.done { background: var(--green); }
.phases span.now { background: var(--red); }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; background: var(--card); border-radius: 12px; padding: 6px 10px; box-shadow: var(--shadow); }
.timer.late { color: #fff; background: var(--red); }
.session-photo { width: 100%; border-radius: 16px; display: block; max-height: 38vh; object-fit: contain; background: #222; }
.chat { display: flex; flex-direction: column; gap: 10px; margin: 12px 0 180px; }
.msg { border-radius: 18px; padding: 12px 14px; max-width: 92%; box-shadow: var(--shadow); }
.msg.ex { background: var(--card); align-self: flex-start; border-bottom-left-radius: 6px; }
.msg.me { background: #fde7e3; align-self: flex-end; border-bottom-right-radius: 6px; }
.msg .who { font-size: 0.8rem; color: var(--muted); margin-bottom: 2px; }
.msg .tools { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.msg .tools button { background: var(--bg); border-radius: 12px; padding: 6px 10px; font-size: 0.95rem; }
.msg .trad { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 1.1rem; }
.fix { border-radius: 18px; padding: 12px 14px; align-self: stretch; }
.fix.perfecto { background: var(--green-bg); }
.fix.casi { background: var(--orange-bg); }
.fix.error, .fix.no_entendido { background: var(--bad-bg); }
.fix .head { font-weight: 700; }
.fix .good { font-size: 1.15rem; font-weight: 600; margin: 6px 0; }
.fix .tools button { background: rgba(255,255,255,0.7); border-radius: 12px; padding: 8px 10px; font-size: 0.95rem; }
.fix .tools { display: flex; gap: 8px; flex-wrap: wrap; }
.fix .extra { margin-top: 8px; }
.typing { align-self: flex-start; color: var(--muted); font-style: italic; }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; background: linear-gradient(transparent, var(--bg) 24%);
  padding: 22px 16px calc(14px + env(safe-area-inset-bottom));
}
.dock-inner { max-width: 720px; margin: 0 auto; }
.live { min-height: 1.4em; background: var(--card); border-radius: 14px; padding: 8px 12px; margin-bottom: 10px; box-shadow: var(--shadow); font-size: 1.05rem; }
.live:empty { display: none; }
.dock-row { display: flex; align-items: center; justify-content: center; gap: 14px; }
.mic {
  width: 92px; height: 92px; border-radius: 50%; background: var(--red); color: #fff; font-size: 42px;
  box-shadow: 0 6px 18px rgba(192, 57, 43, 0.4); display: grid; place-items: center; flex: none;
}
.mic.on { background: var(--green); animation: pulse 1.3s infinite; box-shadow: 0 6px 18px rgba(30, 132, 73, 0.4); }
.mic:disabled { opacity: 0.45; animation: none; }
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.07); } 100% { transform: scale(1); } }
.side { width: 60px; height: 60px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); font-size: 26px; display: grid; place-items: center; flex: none; }
.typebox { display: flex; gap: 8px; margin-top: 10px; }
.typebox input { flex: 1; font: inherit; padding: 12px; border-radius: 14px; border: 2px solid var(--line); background: var(--card); }

/* Resultado */
.score { font-size: 3rem; font-weight: 800; text-align: center; }
.badge { display: inline-block; padding: 6px 14px; border-radius: 999px; font-weight: 700; }
.badge.apto { background: var(--green-bg); color: var(--green); }
.badge.justo { background: var(--orange-bg); color: var(--orange); }
.badge.no_apto { background: var(--bad-bg); color: var(--bad); }
.crit { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; align-items: center; }
.bar { height: 12px; border-radius: 6px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--green); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
ul.clean { padding-left: 1.1em; margin: 6px 0; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; background: var(--line); border-radius: 12px; padding: 3px; }
.seg button { background: transparent; padding: 8px 12px; border-radius: 10px; font-size: 0.95rem; }
.seg button.on { background: var(--card); box-shadow: var(--shadow); font-weight: 700; }
input.pin { font-size: 2rem; letter-spacing: 0.4em; text-align: center; width: 100%; padding: 14px; border-radius: 16px; border: 2px solid var(--line); }
#toast { position: fixed; left: 50%; bottom: 130px; transform: translateX(-50%); background: #2b2118; color: #fff; padding: 12px 16px; border-radius: 14px; max-width: 90vw; z-index: 20; }
.big-es { font-size: 1.6rem; font-weight: 700; text-align: center; margin: 8px 0; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--red); border-radius: 50%; animation: spin 0.9s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.credits { font-size: 0.75rem; color: var(--muted); }
.profe-card { background: linear-gradient(135deg, #c0392b, #e67e22); color: #fff; padding: 26px 18px; margin-bottom: 6px; }
.profe-card .ar { color: #fff3e6; }
.profe-card .emoji { font-size: 72px; }
.profe-card .t { font-size: 1.45rem; }
.side.on-ar { background: #1e8449; color: #fff; }

/* Botón grande con estados */
.main-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.main-cap { font-weight: 700; font-size: 0.95rem; text-align: center; max-width: 170px; line-height: 1.25; min-height: 2.5em; }
.side-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 0.75rem; color: var(--muted); }
.side-wrap[hidden] { display: none; }
.mic.st-thinking { background: #9e9e9e; box-shadow: none; animation: none; }
.mic.st-thinking #mainicon { animation: spin 2s linear infinite; display: inline-block; }
.mic.st-speaking { background: var(--blue); box-shadow: 0 6px 18px rgba(31, 95, 153, 0.4); }
.mic.st-ready { background: var(--red); }
.mic.st-listening { background: var(--green); animation: pulse 1.3s infinite; box-shadow: 0 6px 18px rgba(30, 132, 73, 0.45); font-size: 38px; }
.mic.st-ended { background: #e67e22; }
.mic:disabled { opacity: 1; }
body[data-state="thinking"] .msg .tools, body[data-state="thinking"] .fix .tools,
body[data-state="listening"] .msg .tools, body[data-state="listening"] .fix .tools { opacity: 0.35; pointer-events: none; }
#stopfab { position: fixed; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); background: var(--blue); color: #fff; font-weight: 700; padding: 14px 18px; border-radius: 999px; box-shadow: 0 6px 18px rgba(0,0,0,.25); z-index: 30; font-size: 1.05rem; }
#stopfab[hidden] { display: none; }

.big-card.listening { background: var(--green-bg); border-color: var(--green); animation: pulse 1.6s infinite; }
.secondary.listening { background: var(--green); color: #fff; }
#app.is-busy .big-card { opacity: 0.5; pointer-events: none; }

/* Ventana "¿Salir?" */
.dlg-back { position: fixed; inset: 0; background: rgba(30, 20, 10, 0.55); z-index: 50; display: grid; place-items: center; padding: 16px; }
.dlg { background: var(--card); border-radius: 24px; padding: 22px 18px; width: 100%; max-width: 380px; text-align: center; display: grid; gap: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.dlg-t { font-size: 1.35rem; font-weight: 800; }
.dlg-no { padding: 16px; font-size: 1.15rem; }
.icon-btn#salir { width: 56px; height: 56px; font-size: 28px; }
