/* ---- Tokens: bachata night ---- */
:root {
  --noche: #191024;        /* deep plum night background */
  --tarima: #241733;       /* panel / dance floor */
  --linea: #3a2a4d;        /* hairlines */
  --bubble-her: #f4ead9;   /* her message: warm paper */
  --bubble-tinta: #2b1c14; /* text on her bubble */
  --bubble-nico: #35244a;  /* feedback bubble */
  --crema: #efe6f5;        /* light text on dark */
  --apagado: #a893c2;      /* muted text */
  --rosa: #e8556d;         /* bachata rose accent */
  --dorado: #e9b44c;       /* amber: correct */
  --verde: #7fc98a;        /* soft green: correct check */
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--noche);
  color: var(--crema);
  font-family: "Outfit", system-ui, sans-serif;
  font-size: 16px;
}

/* ---- Login gate ---- */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(232, 85, 109, 0.18), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(233, 180, 76, 0.12), transparent 60%),
    var(--noche);
}

.gate-card { max-width: 420px; text-align: center; }

.eyebrow {
  color: var(--rosa);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
  margin: 0 0 14px;
}

.gate-card h1 {
  font-family: "Fraunces", serif;
  font-weight: 900;
  font-size: clamp(40px, 9vw, 58px);
  line-height: 1.02;
  margin: 0 0 16px;
}

.gate-sub { color: var(--apagado); margin: 0 0 28px; line-height: 1.5; }
.gate-status { color: var(--apagado); font-size: 14px; min-height: 20px; margin-top: 16px; }

/* ---- Buttons ---- */
.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 16px;
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:focus-visible { outline: 3px solid var(--dorado); outline-offset: 2px; }
.btn-primary {
  background: var(--rosa);
  color: #fff;
  box-shadow: 0 6px 18px rgba(232, 85, 109, 0.35);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn-ghost {
  background: transparent;
  color: var(--apagado);
  padding: 8px 14px;
  font-size: 14px;
}
.btn-ghost:hover { color: var(--crema); }

/* ---- App layout ---- */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--linea);
}
.topbar-title { display: flex; flex-direction: column; }
.brand { font-family: "Fraunces", serif; font-weight: 700; font-size: 18px; }
.progress-label { color: var(--apagado); font-size: 12.5px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.progress-dots { display: flex; gap: 4px; flex-wrap: wrap; max-width: 180px; justify-content: flex-end; }
.progress-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--linea);
}
.progress-dots span.done-right { background: var(--verde); }
.progress-dots span.done-wrong { background: var(--rosa); }
.progress-dots span.current { background: var(--dorado); }

/* ---- Chat ---- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(800px 400px at 100% 0%, rgba(232, 85, 109, 0.07), transparent 55%),
    var(--tarima);
}

.msg {
  max-width: 86%;
  padding: 12px 15px;
  border-radius: var(--radius);
  line-height: 1.5;
  font-size: 16px;
  animation: pop 0.22s ease;
  white-space: pre-wrap;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .msg { animation: none; } }

.msg-ex {
  align-self: flex-end;
  background: var(--bubble-her);
  color: var(--bubble-tinta);
  border-bottom-right-radius: 5px;
}
.msg-ex .hint {
  display: block;
  margin-top: 6px;
  font-size: 12.5px;
  color: #7a6653;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.msg-ex .blank {
  display: inline-block;
  min-width: 84px;
  border-bottom: 2px solid var(--rosa);
  text-align: center;
  font-weight: 700;
  color: var(--rosa);
}

.msg-nico {
  align-self: flex-start;
  background: var(--bubble-nico);
  color: var(--crema);
  border-bottom-left-radius: 5px;
}
.msg-nico .who {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--dorado);
  margin-bottom: 4px;
  letter-spacing: 0.05em;
}
.msg-nico.right { border-left: 3px solid var(--verde); }
.msg-nico.wrong { border-left: 3px solid var(--rosa); }
.msg-nico .corr {
  font-family: "Fraunces", serif;
  font-weight: 700;
  font-size: 19px;
  color: var(--dorado);
}
.msg-nico .expl { display: block; margin-top: 8px; color: var(--apagado); font-size: 14.5px; }
.msg-nico .topic {
  display: inline-block;
  margin-top: 10px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--rosa);
  background: rgba(232, 85, 109, 0.12);
  padding: 3px 9px;
  border-radius: 999px;
}

.msg-user {
  align-self: flex-end;
  background: var(--rosa);
  color: #fff;
  border-bottom-right-radius: 5px;
  font-weight: 600;
}

/* Final score card */
.score-card {
  align-self: center;
  text-align: center;
  background: var(--bubble-nico);
  border: 1px solid var(--linea);
  border-radius: 22px;
  padding: 26px 30px;
  margin-top: 8px;
}
.score-card h2 { font-family: "Fraunces", serif; font-size: 30px; margin: 0 0 6px; color: var(--dorado); }
.score-card p { color: var(--apagado); margin: 0 0 18px; }

/* ---- Composer ---- */
.composer {
  border-top: 1px solid var(--linea);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--noche);
}
#answerForm { display: flex; gap: 10px; }
#answerInput {
  flex: 1;
  background: var(--tarima);
  border: 1.5px solid var(--linea);
  border-radius: 999px;
  color: var(--crema);
  font-family: inherit;
  font-size: 16px;
  padding: 12px 18px;
}
#answerInput:focus { outline: none; border-color: var(--rosa); }
#answerInput::placeholder { color: var(--apagado); }

.accent-row { display: flex; gap: 8px; margin-top: 10px; }
.accent-row button {
  flex: 1;
  background: var(--tarima);
  border: 1px solid var(--linea);
  border-radius: 10px;
  color: var(--crema);
  font-size: 17px;
  padding: 7px 0;
  cursor: pointer;
}
.accent-row button:active { background: var(--rosa); }

/* ---- Test-Menü ---- */
.menu-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 32px;
  background: var(--tarima);
}
.menu-intro {
  color: var(--apagado);
  font-size: 14.5px;
  line-height: 1.55;
  max-width: 560px;
  margin: 0 auto 18px;
}
.menu-intro strong { color: var(--dorado); }

.test-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 9px;
}
.test-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  background: var(--noche);
  border: 1px solid var(--linea);
  border-radius: 13px;
  padding: 10px 12px;
  color: var(--crema);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.12s ease;
}
.test-chip:hover { border-color: var(--rosa); transform: translateY(-1px); }
.test-chip:focus-visible { outline: 3px solid var(--dorado); outline-offset: 2px; }
.test-chip .chip-n {
  font-family: "Fraunces", serif;
  font-weight: 700;
  font-size: 17px;
  color: var(--rosa);
}
.test-chip .chip-topic {
  font-size: 12px;
  color: var(--apagado);
  line-height: 1.3;
  min-height: 2.6em;
}
.test-chip .chip-state {
  font-size: 12px;
  font-weight: 700;
  color: var(--verde);
  min-height: 1em;
}
.test-chip.done { border-color: rgba(127, 201, 138, 0.45); }
.test-chip.perfect { border-color: var(--dorado); }
.test-chip.perfect .chip-state { color: var(--dorado); }
.test-chip.perfect .chip-n { color: var(--dorado); }

/* Quiz-Topbar-Anpassungen */
.topbar-center { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.brand.small { font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.btn-ghost.back { font-size: 15px; padding: 6px 8px; }
.score-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---- Historial ---- */
.history-stats {
  display: flex;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto 18px;
}
.history-stats .stat {
  flex: 1;
  background: var(--noche);
  border: 1px solid var(--linea);
  border-radius: 13px;
  padding: 12px;
  text-align: center;
  color: var(--apagado);
  font-size: 12.5px;
}
.history-stats .stat span {
  display: block;
  font-family: "Fraunces", serif;
  font-weight: 700;
  font-size: 22px;
  color: var(--dorado);
  margin-bottom: 2px;
}

.history-list { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.history-empty { color: var(--apagado); text-align: center; margin-top: 30px; }

.history-item {
  background: var(--noche);
  border: 1px solid var(--linea);
  border-radius: 13px;
  overflow: hidden;
}
.history-item.perfect { border-color: rgba(233, 180, 76, 0.5); }
.history-item summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
}
.history-item summary::-webkit-details-marker { display: none; }
.history-item summary:focus-visible { outline: 3px solid var(--dorado); outline-offset: -3px; }
.h-date { color: var(--apagado); font-size: 12.5px; white-space: nowrap; }
.h-test { flex: 1; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-score { font-weight: 700; color: var(--verde); font-size: 14px; white-space: nowrap; }
.history-item.perfect .h-score { color: var(--dorado); }

.h-mistakes {
  margin: 0;
  padding: 4px 16px 14px 30px;
  border-top: 1px solid var(--linea);
  color: var(--apagado);
  font-size: 13.5px;
  line-height: 1.6;
}
.h-mistakes.none { padding: 10px 16px 14px; list-style: none; }
.h-mistakes li { margin-top: 6px; }
.wrong-w { color: var(--rosa); text-decoration: line-through; font-weight: 600; }
.right-w { color: var(--dorado); font-weight: 700; }
