:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --text: #1c2321;
  --muted: #5f6b67;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --user: #0f766e;
  --user-text: #ffffff;
  --bot: #ffffff;
  --border: #dfe4e1;
  --warn-bg: #fff6e0;
  --warn-text: #6b4a00;
  --rec: #dc2626;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615;
    --surface: #1b2220;
    --text: #e8edeb;
    --muted: #9aa7a2;
    --accent: #2dd4bf;
    --accent-text: #062b27;
    --user: #14524c;
    --user-text: #e8fffb;
    --bot: #1b2220;
    --border: #2b3532;
    --warn-bg: #3a2f12;
    --warn-text: #f7dc9c;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 1rem 0 0; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
[hidden] { display: none !important; }

.screen { min-height: 100dvh; display: flex; flex-direction: column; max-width: 640px; margin: 0 auto; }
.center { margin: auto; padding: 24px 16px; width: 100%; text-align: center; }
.center .card { text-align: left; margin-top: 16px; }
.content { padding: 8px 16px 32px; }

.bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.bar h1 { flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar h1:first-child { text-align: left; padding-left: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  color: inherit;
  font: inherit;
}
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.95rem; }
input, select {
  font: inherit; font-weight: 400;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
input[type="range"] { padding: 0; accent-color: var(--accent); }

.btn {
  font: inherit; font-weight: 600;
  border-radius: 12px; padding: 12px 16px;
  border: 1px solid transparent; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; color: var(--accent); border-color: var(--border); }
.icon-btn {
  font-size: 1.3rem; line-height: 1;
  width: 44px; height: 44px; border-radius: 50%;
  border: none; background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn:active { background: var(--border); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.mode-card { display: flex; gap: 14px; align-items: center; text-align: left; cursor: pointer; width: 100%; }
.mode-emoji { font-size: 2rem; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.topic {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  cursor: pointer; text-align: left;
}
.topic .emoji { font-size: 1.8rem; }
.topic .progress { font-size: 0.82rem; color: var(--muted); }

/* Conversación */
#screen-chat { height: 100dvh; }
.messages {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 16px 12px 24px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg { max-width: 85%; padding: 10px 14px; border-radius: var(--radius); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-text); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--bot); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg .meta { display: block; font-size: 0.75rem; opacity: 0.7; margin-top: 4px; }
.msg.error { align-self: center; background: var(--warn-bg); color: var(--warn-text); font-size: 0.92rem; }
.correction {
  align-self: flex-end; max-width: 85%;
  background: var(--warn-bg); color: var(--warn-text);
  border-radius: 12px; padding: 8px 12px; font-size: 0.92rem;
}
.correction s { opacity: 0.75; }
.chips { align-self: flex-start; display: flex; flex-wrap: wrap; gap: 6px; max-width: 90%; }
.chip {
  font: inherit; font-size: 0.88rem;
  background: var(--surface); color: var(--accent);
  border: 1px solid var(--accent); border-radius: 999px; padding: 4px 10px; cursor: pointer;
}

.controls {
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 14px);
  background: var(--bg);
  border-top: 1px solid var(--border);
  text-align: center;
}
.status { margin: 0 0 8px; color: var(--muted); font-size: 0.92rem; min-height: 1.3em; }
.controls-row { display: flex; align-items: center; justify-content: center; gap: 28px; }
.mic {
  width: 84px; height: 84px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--accent); color: var(--accent-text);
  font-size: 2.1rem;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.18);
  transition: transform 0.15s, background 0.15s;
}
.mic:active { transform: scale(0.96); }
.mic.recording { background: var(--rec); animation: pulse 1.2s infinite; }
.mic.busy { opacity: 0.6; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgb(220 38 38 / 0.5); }
  70% { box-shadow: 0 0 0 18px rgb(220 38 38 / 0); }
  100% { box-shadow: 0 0 0 0 rgb(220 38 38 / 0); }
}
.type-form { display: flex; gap: 8px; margin-top: 12px; }
.type-form input { flex: 1; min-width: 0; }

/* Hojas */
.sheet {
  border: none; border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 640px; max-height: 85dvh;
  margin: auto auto 0; padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px);
  background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgb(0 0 0 / 0.4); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; }
.vocab-list { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 8px; }
.vocab-list li { border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.vocab-list .ex { color: var(--muted); font-style: italic; font-size: 0.9rem; }
.vocab-list button { margin-left: 4px; font-size: 1rem; width: 32px; height: 32px; }

/* Temas propios */
.custom-label { flex-direction: row; align-items: center; gap: 14px; font-weight: 400; font-size: 1rem; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
.row .btn:disabled { opacity: 0.6; }
.error { color: var(--warn-text); background: var(--warn-bg); padding: 8px 10px; border-radius: 10px; }
.topic-wrap { position: relative; }
.topic-wrap .topic { width: 100%; height: 100%; }
.topic-wrap .remove {
  position: absolute; top: 4px; right: 4px;
  width: 36px; height: 36px; font-size: 0.95rem; color: var(--muted);
}
