/* ECG-APP — stylesheet */

:root {
  --bg: #0d1117;
  --bg-soft: #131a24;
  --panel: #171f2b;
  --panel-2: #1d2735;
  --border: #26303f;
  --border-soft: #202937;

  --text: #e8edf4;
  --text-dim: #9aa7b8;
  --text-faint: #6b7789;

  --accent: #2dd4a7;
  --accent-dim: #1a9e7c;
  --accent-ink: #06251d;

  --danger: #f0616d;
  --danger-dim: #b8323e;
  --warn: #f5b544;
  --info: #58a6ff;
  --gold: #f2c14e;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; display: flex; flex-direction: column; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8rem; }
ul { margin: 0 0 .8rem; padding-left: 1.15rem; }
li { margin-bottom: .3rem; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* The router moves focus to the view container on navigation so screen readers
 * announce the new screen. That is not a user-visible focus target, so it must
 * not draw a ring around the whole page. */
#view:focus,
#view:focus-visible { outline: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------------ layout */

.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 1rem; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(13, 17, 23, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex; align-items: center; gap: 1rem;
  min-height: 60px; flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: .55rem;
  font-weight: 750; font-size: 1.08rem; letter-spacing: -0.02em;
  color: var(--text); text-decoration: none; flex-shrink: 0;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  display: grid; place-items: center; color: var(--accent-ink);
  font-size: 15px; font-weight: 800;
}

.nav { display: flex; gap: .15rem; flex-wrap: wrap; flex: 1; }
.nav a {
  padding: .42rem .7rem; border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: .9rem; font-weight: 550;
  white-space: nowrap;
}
.nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--panel-2); color: var(--accent); }

/* Language selector in the header */
.lang-select {
  background: var(--panel);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .35rem 1.6rem .35rem .6rem;
  font: inherit;
  font-size: .82rem;
  cursor: pointer;
  margin-left: .5rem;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%),
                    linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
  background-position: right 0.75rem center, right 0.5rem center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.lang-select:hover { color: var(--text); border-color: #37455a; }
.lang-select option { background: var(--panel); color: var(--text); }

/* Notice shown when clinical prose falls back to English */
.fallback-note {
  font-size: .78rem;
  color: var(--text-faint);
  border-left: 2px solid var(--border);
  padding-left: .6rem;
  margin: .5rem 0 .2rem;
}

.userchip {
  display: flex; align-items: center; gap: .6rem;
  padding: .3rem .3rem .3rem .75rem;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 999px; font-size: .85rem;
}
.userchip .lvl { color: var(--text-faint); font-size: .78rem; }
.userchip .xp { color: var(--accent); font-weight: 650; font-variant-numeric: tabular-nums; }

main { flex: 1; padding: 1.6rem 0 3rem; }

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
}
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .7rem; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); font-size: .85rem; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: .75rem; }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .6rem 1.05rem;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: .92rem; font-weight: 600;
  cursor: pointer; transition: background .14s, border-color .14s, transform .06s;
  text-decoration: none;
}
.btn:hover { background: #26313f; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: var(--accent-ink); border-color: transparent; font-weight: 700;
}
.btn-primary:hover { filter: brightness(1.08); background: linear-gradient(135deg, var(--accent), var(--accent-dim)); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--panel-2); }
.btn-danger { border-color: var(--danger-dim); color: var(--danger); }
.btn-danger:hover { background: rgba(240, 97, 109, .1); }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; }
.btn-block { width: 100%; }

/* ----------------------------------------------------------------- inputs */

.field { margin-bottom: .85rem; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; color: var(--text-dim); }
.input, select.input, textarea.input {
  width: 100%; padding: .6rem .75rem;
  background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: .95rem;
}
.input:focus { border-color: var(--accent); outline: none; }

.alert {
  padding: .65rem .85rem; border-radius: var(--radius-sm);
  font-size: .88rem; border: 1px solid transparent; margin-bottom: .8rem;
}
.alert-error { background: rgba(240, 97, 109, .12); border-color: var(--danger-dim); color: #ffc4c9; }
.alert-info { background: rgba(88, 166, 255, .1); border-color: #2b5586; color: #bcd9ff; }
.alert-warn { background: rgba(245, 181, 68, .1); border-color: #7a5f22; color: #ffdfa6; }

/* -------------------------------------------------------------- ECG frame */

.ecg-frame {
  background: #fffafa;
  border: 1px solid #d9c7c7;
  border-radius: 10px;
  overflow: hidden;
  line-height: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.03);
}
.ecg-frame canvas { display: block; width: 100%; }
.ecg-meta {
  display: flex; gap: 1rem; flex-wrap: wrap;
  font-size: .75rem; color: var(--text-faint);
  margin-top: .4rem; font-family: var(--mono);
}

/* ---------------------------------------------------------------- options */

.options { display: grid; gap: .55rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.option {
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .75rem .9rem; text-align: left;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font: inherit; font-size: .93rem; cursor: pointer;
  transition: background .14s, border-color .14s;
}
.option:hover:not(:disabled) { background: #26313f; border-color: #37455a; }
.option:disabled { cursor: default; }
.option .key {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 6px;
  background: var(--bg-soft); border: 1px solid var(--border);
  display: grid; place-items: center;
  font-family: var(--mono); font-size: .72rem; color: var(--text-faint);
}
.option.correct { border-color: var(--accent); background: rgba(45, 212, 167, .12); }
.option.correct .key { border-color: var(--accent); color: var(--accent); }
.option.wrong { border-color: var(--danger-dim); background: rgba(240, 97, 109, .12); }
.option.wrong .key { border-color: var(--danger-dim); color: var(--danger); }
.option.dim { opacity: .5; }

/* ------------------------------------------------------------------ timer */

.timer {
  height: 8px; background: var(--bg-soft); border-radius: 999px;
  overflow: hidden; border: 1px solid var(--border);
}
.timer-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-dim));
  transition: width .1s linear;
}
.timer-fill.warn { background: linear-gradient(90deg, var(--warn), #c98a1c); }
.timer-fill.danger { background: linear-gradient(90deg, var(--danger), var(--danger-dim)); }

.hud { display: flex; gap: 1.1rem; align-items: center; flex-wrap: wrap; margin-bottom: .6rem; }
.hud-item { display: flex; flex-direction: column; }
.hud-item .k { font-size: .68rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); }
.hud-item .v { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud-item .v.accent { color: var(--accent); }
.hud-item .v.danger { color: var(--danger); }

/* --------------------------------------------------------------- feedback */

.verdict {
  display: flex; align-items: center; gap: .6rem;
  padding: .7rem .9rem; border-radius: var(--radius-sm);
  font-weight: 650; margin-bottom: .8rem;
}
.verdict.ok { background: rgba(45, 212, 167, .13); color: var(--accent); border: 1px solid var(--accent-dim); }
.verdict.no { background: rgba(240, 97, 109, .13); color: #ff9aa2; border: 1px solid var(--danger-dim); }

.metrics-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: .5rem; margin: .7rem 0;
}
.metric {
  background: var(--bg-soft); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: .5rem .65rem;
}
.metric .k { font-size: .67rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }
.metric .v { font-size: .9rem; font-weight: 600; font-family: var(--mono); }

.teach { border-left: 3px solid var(--accent-dim); padding-left: .9rem; margin: .8rem 0; }
.teach.pitfall { border-left-color: var(--warn); }
.teach.action { border-left-color: var(--info); }
.teach h4 { font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); margin-bottom: .25rem; }

/* ---------------------------------------------------------------- badges */

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.badge {
  background: var(--bg-soft); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: .7rem; text-align: center;
}
.badge.earned { border-color: var(--accent-dim); background: rgba(45, 212, 167, .07); }
.badge .icon { font-size: 1.6rem; line-height: 1.2; filter: grayscale(1); opacity: .35; }
.badge.earned .icon { filter: none; opacity: 1; }
.badge .name { font-size: .82rem; font-weight: 650; margin-top: .15rem; }
.badge .desc { font-size: .72rem; color: var(--text-faint); margin-top: .15rem; }

.pill {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .15rem .55rem; border-radius: 999px;
  font-size: .74rem; font-weight: 650;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text-dim);
}
.pill.accent { background: rgba(45, 212, 167, .13); border-color: var(--accent-dim); color: var(--accent); }
.pill.warn { background: rgba(245, 181, 68, .12); border-color: #7a5f22; color: var(--warn); }
.pill.danger { background: rgba(240, 97, 109, .12); border-color: var(--danger-dim); color: var(--danger); }
.pill.demo { background: transparent; color: var(--text-faint); }

/* ----------------------------------------------------------------- bars */

.bar { height: 7px; background: var(--bg-soft); border-radius: 999px; overflow: hidden; border: 1px solid var(--border-soft); }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-dim)); transition: width .35s ease; }
.bar-fill.gold { background: linear-gradient(90deg, var(--gold), #b8891f); }

/* ---------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .5rem .6rem; text-align: left; border-bottom: 1px solid var(--border-soft); }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); font-weight: 650; }
tr.me { background: rgba(45, 212, 167, .08); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }

/* ------------------------------------------------------------- tier cards */

.tier-card { position: relative; display: flex; flex-direction: column; }
.tier-card.locked { opacity: .6; }
.tier-card .lock { font-size: .78rem; color: var(--warn); }

/* --------------------------------------------------------------- toasts */

.toasts {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 90;
  display: flex; flex-direction: column; gap: .5rem; max-width: 320px;
}
.toast {
  background: var(--panel-2); border: 1px solid var(--accent-dim);
  border-radius: var(--radius-sm); padding: .65rem .8rem;
  box-shadow: var(--shadow); font-size: .88rem;
  display: flex; gap: .6rem; align-items: center;
  animation: slideIn .25s ease;
}
.toast .icon { font-size: 1.3rem; }
.toast .t { font-weight: 700; }
.toast .d { font-size: .78rem; color: var(--text-dim); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* -------------------------------------------------------------- disclaimer */

.disclaimer {
  background: rgba(245, 181, 68, .08);
  border: 1px solid #6d5520;
  border-radius: var(--radius-sm);
  padding: .6rem .85rem; font-size: .82rem; color: #ffdfa6;
}
footer {
  border-top: 1px solid var(--border);
  padding: 1.2rem 0; font-size: .8rem; color: var(--text-faint);
}
footer .wrap > * + * { margin-top: .5rem; }

/* ------------------------------------------------------------------- hero */

.hero { padding: 2rem 0 1.2rem; }
.hero h1 { font-size: 2.2rem; letter-spacing: -0.03em; }
.hero .lede { font-size: 1.05rem; color: var(--text-dim); max-width: 46rem; }
.feature { display: flex; gap: .7rem; align-items: flex-start; }
.feature .ico {
  width: 34px; height: 34px; flex-shrink: 0; border-radius: 9px;
  background: var(--panel-2); border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 1.05rem;
}
.feature h3 { font-size: .95rem; margin-bottom: .15rem; }
.feature p { font-size: .85rem; color: var(--text-dim); margin: 0; }

/* -------------------------------------------------------------- drill lab */

.drill-canvas-wrap { position: relative; cursor: crosshair; }
.drill-marker {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--info); pointer-events: none;
}
.drill-marker::after {
  content: attr(data-label);
  position: absolute; top: 2px; left: 3px;
  font-size: 10px; font-family: var(--mono); color: #1b4f8a;
  background: rgba(255,255,255,.8); padding: 0 3px; border-radius: 3px;
}
.drill-span {
  position: absolute; top: 0; bottom: 0;
  background: rgba(88, 166, 255, .16); pointer-events: none;
}

/* ------------------------------------------------------------------ steps */

.step-dots { display: flex; gap: .3rem; }
.step-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.step-dot.done { background: var(--accent); }
.step-dot.current { background: var(--text); }

.vignette dt { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); margin-top: .5rem; }
.vignette dd { margin: .1rem 0 0; font-size: .92rem; }

/* ----------------------------------------------------------- responsive */

/* Translated nav labels are longer than the English ones (Portuguese and
 * French especially), so switch to the single-row scrolling strip well before
 * phone widths rather than letting the header wrap onto three lines. */
@media (max-width: 1040px) {
  .topbar-inner { min-height: auto; padding: .6rem 0; }
  /* flex-basis 100% forces a full row of its own; the base rule's `flex: 1`
   * would otherwise keep it on the brand row and overflow to the right. */
  .nav { order: 3; flex: 0 0 100%; overflow-x: auto; padding-bottom: .2rem; flex-wrap: nowrap; }
  .nav a { white-space: nowrap; }
}

@media (max-width: 720px) {
  .nav a { font-size: .85rem; padding: .35rem .55rem; }
  .hero h1 { font-size: 1.7rem; }
  .options { grid-template-columns: 1fr; }
  .hud { gap: .8rem; }
  .card { padding: .9rem; }
  main { padding: 1rem 0 2rem; }
  .toasts { left: 1rem; right: 1rem; max-width: none; }
  /* Keep the calibration caption to one compact line on small screens. */
  .ecg-meta { gap: .6rem; font-size: .68rem; }
  .ecg-meta span:nth-child(3) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
