*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --blue: #185FA5;
  --blue-light: #E6F1FB;
  --blue-dark: #0C447C;
  --green: #0F6E56;
  --green-light: #E1F5EE;
  --green-dark: #085041;
  --red-light: #FCEBEB;
  --red-dark: #791F1F;
  --amber-light: #FAEEDA;
  --amber-dark: #633806;
  --bg: #ffffff;
  --bg-secondary: #f5f5f3;
  --text: #1a1a18;
  --text-muted: #6b6b68;
  --text-hint: #9b9b97;
  --border: rgba(0, 0, 0, 0.12);
  --border-md: rgba(0, 0, 0, 0.22);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg-secondary);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
}

.app {
  width: 100%;
  max-width: 540px;
}

.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none; }

/* Header */
.header {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  text-align: center;
}

.header-title {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 4px;
}

.header-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* Display box */
.display-box {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  margin-bottom: 1rem;
  overflow: hidden;
}

.placeholder {
  font-size: 14px;
  color: var(--text-hint);
  text-align: center;
  line-height: 1.7;
}

.placeholder strong {
  color: var(--text);
}

/* Digits */
/* Trial table (live accumulating display) */
.display-box--table {
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
  overflow-y: auto;
  max-height: 380px;
}

.trial-table {
  width: 100%;
  border-collapse: collapse;
}

.trial-table td {
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--border);
  vertical-align: middle;
}

.trial-table tr:last-child td {
  border-bottom: none;
}

/* Phase separator title (Endroit / Envers) */
.phase-sep td {
  font-size: 20px;
  font-weight: 700;
  padding: 14px 16px 10px;
  letter-spacing: 0.3px;
  border-bottom: 2px solid currentColor;
}

.phase-sep-end td { color: var(--blue); }
.phase-sep-env td { color: var(--green); }

.phase-sep-env td {
  padding-top: 28px;
}

.cell-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  width: 1%;
}

.cell-seq {
  width: auto;
}

.cell-res {
  text-align: right;
  white-space: nowrap;
  width: 1%;
}

.cell-digit {
  font-size: 30px;
  font-weight: 500;
  line-height: 1;
  color: var(--text);
  margin-right: 10px;
}

.cell-dot {
  font-size: 30px;
  line-height: 1;
  color: var(--text-hint);
  opacity: 0.35;
  margin-right: 10px;
}

/* Current row highlight */
.trial-current.trial-end { background: var(--blue-light); }
.trial-current.trial-env { background: var(--green-light); }

.trial-end .cell-digit-cur {
  color: var(--blue-dark);
  font-weight: 700;
}

.trial-env .cell-digit-cur {
  color: var(--green-dark);
  font-weight: 700;
}

/* Finished rows are dimmed so the current line stands out */
.trial-done .cell-digit { color: var(--text-muted); }

.res-ok { color: var(--green); font-weight: 600; font-size: 13px; }
.res-ko { color: var(--red-dark); font-weight: 600; font-size: 13px; }
.res-pending { color: var(--text-hint); font-size: 16px; }
.res-await { color: var(--blue); font-size: 14px; }
.trial-env .res-await { color: var(--green); }

/* Bottom action bar — Lancer / Réussi / Échoué on one centered line */
.action-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  background: var(--bg-secondary);
  z-index: 5;
}

.action-bar .btn-primary {
  width: auto;
  min-width: 200px;
  margin-bottom: 0;
}

.btn-oui, .btn-non {
  font-size: 15px;
  font-weight: 500;
  padding: 13px 26px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  min-width: 130px;
}

.btn-oui { background: var(--green-light); color: var(--green-dark); }
.btn-non { background: var(--red-light); color: var(--red-dark); }

/* Identity form on result screen */
.identity-box {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.identity-header {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* Patient fields */
.patient-fields {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.field-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.field-row:last-child {
  margin-bottom: 0;
}

.field {
  flex: 1;
}

.field-note {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 8px;
}

.field label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.field input {
  width: 100%;
  font-size: 14px;
  padding: 8px 10px;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.field input:focus {
  outline: none;
  border-color: var(--blue);
}

/* Progress bar */
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 1rem;
  overflow: hidden;
}

.progress-fill {
  height: 4px;
  border-radius: 2px;
  width: 0%;
  transition: width 0.2s;
}

.fill-end { background: var(--blue); }
.fill-env { background: var(--green); }

/* Mode label */
.mode-label {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}

.label-end { background: var(--blue-light); color: var(--blue-dark); }
.label-env { background: var(--green-light); color: var(--green-dark); }

/* Status */
.status-msg {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  min-height: 22px;
  margin-bottom: 0.75rem;
}

.status-hint {
  font-size: 12px;
  color: var(--text-hint);
}

/* Buttons */
.btn-primary {
  width: 100%;
  font-size: 15px;
  font-weight: 500;
  padding: 13px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  margin-bottom: 8px;
}

.btn-end { background: var(--blue); color: #fff; }
.btn-env { background: var(--green); color: #fff; }

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-outline {
  width: 100%;
  font-size: 14px;
  padding: 11px;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-md);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  margin-bottom: 8px;
}

/* Keyboard hint */
.kbd {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  background: var(--bg-secondary);
  border: 0.5px solid var(--border-md);
  border-radius: 4px;
  font-family: monospace;
}

/* Transition screen */
.transition-box {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  text-align: center;
  margin-bottom: 1.5rem;
}

.trans-icon {
  font-size: 36px;
  color: var(--green);
  margin-bottom: 1rem;
}

.trans-title {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.trans-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

/* Consigne / example screens (read to the patient) */
.consigne-box {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  text-align: left;
}

.consigne-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-hint);
  margin-bottom: 10px;
}

.consigne-say {
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  margin: 0 0 12px;
  padding: 4px 0 4px 16px;
  border-left: 3px solid var(--border-md);
  quotes: "« " " »";
}

.consigne-say::before { content: open-quote; color: var(--text-hint); }
.consigne-say::after  { content: close-quote; color: var(--text-hint); }

.consigne-end .consigne-say { border-left-color: var(--blue); }
.consigne-env .consigne-say { border-left-color: var(--green); }

.consigne-hint {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0 0 14px;
}

.consigne-hint:last-child { margin-bottom: 0; }

.consigne-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 2px 7px;
  margin-right: 7px;
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-muted);
  vertical-align: middle;
}

/* Consigne nested inside the pause/transition card: lighter inset */
.transition-box .consigne-box {
  border: none;
  background: var(--bg-secondary);
  padding: 14px 18px;
  margin-bottom: 0;
}

.transition-box .consigne-tag { background: var(--bg); }

/* Result screen */
.result-box {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.res-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border);
}

.res-label {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.res-val {
  font-size: 22px;
  font-weight: 500;
}

.rds-row {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
}

.rds-label {
  font-size: 14px;
  font-weight: 500;
}

.rds-val-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rds-val {
  font-size: 28px;
  font-weight: 500;
}

/* Badges */
.badge {
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 4px;
  font-weight: 500;
}

.badge-end     { background: var(--blue-light);   color: var(--blue-dark); }
.badge-env     { background: var(--green-light);  color: var(--green-dark); }
.badge-ok      { background: var(--green-light);  color: var(--green-dark); }
.badge-warn    { background: var(--amber-light);  color: var(--amber-dark); }
.badge-bad     { background: var(--red-light);    color: var(--red-dark); }
.badge-neutral { background: var(--bg-secondary); color: var(--text-muted); }

/* Detail box */
.detail-box {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 1rem;
  font-size: 12px;
}

.detail-header {
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-size: 13px;
}

.detail-phase {
  font-weight: 500;
  color: var(--text);
  margin-top: 8px;
  margin-bottom: 4px;
  font-size: 13px;
}

.detail-phase-first {
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
  font-size: 13px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 0.5px solid var(--border);
}

.detail-row-ok { color: var(--green); }
.detail-row-ko { color: var(--text-muted); }

/* Interpretation box on result screen */
.interpretation-box {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.interp-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.interp-subtitle {
  font-size: 12px;
  font-weight: 600;
  color: var(--blue-dark);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin: 12px 0 6px;
}

.interp-line {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  margin-bottom: 8px;
}

.interp-line:last-child { margin-bottom: 0; }

.interp-ok   { color: var(--green-dark); }
.interp-warn { color: var(--amber-dark); }
.interp-bad  { color: var(--red-dark); }

.interp-note {
  font-size: 12px;
  color: var(--text-muted);
  border-top: 0.5px solid var(--border);
  padding-top: 8px;
}

.interp-synthese {
  background: #fff;
  border: 0.5px solid var(--border);
  border-left: 3px solid var(--blue-dark);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.interp-synthese .interp-line { margin-bottom: 0; }

.norm-item {
  margin-bottom: 12px;
}

.norm-item .interp-line { margin-bottom: 2px; }

.gauss {
  display: block;
  max-width: 280px;
  margin: 2px auto 0;
}

/* App footer — bibliographic reference */
.app-footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 0.5px solid var(--border);
  font-size: 10px;
  line-height: 1.5;
  color: var(--text-hint);
  text-align: center;
}

.app-footer strong { color: var(--text-muted); }
.app-footer em { font-style: italic; }

/* Report (print) area — hidden on screen, shown when printing */
.report {
  display: none;
}

.btn-report {
  width: 100%;
  font-size: 14px;
  font-weight: 500;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--blue);
  background: var(--blue-light);
  color: var(--blue-dark);
  cursor: pointer;
  margin-bottom: 8px;
}

@media print {
  body {
    background: #fff;
    padding: 0;
    display: block;
  }

  .app {
    display: none;
  }

  .report {
    display: block;
    max-width: 100%;
    padding: 1.5cm;
    color: #000;
    font-size: 12pt;
  }

  .report h1 {
    font-size: 19pt;
    font-weight: 600;
    letter-spacing: -0.2pt;
    margin-bottom: 2px;
    color: #0C447C;
  }

  .report .report-sub {
    font-size: 9.5pt;
    color: #555;
    margin-bottom: 1.6rem;
    border-bottom: 1.5px solid #0C447C;
    padding-bottom: 0.6rem;
  }

  .report .report-section {
    margin-bottom: 1.4rem;
  }

  .report .report-section h2 {
    font-size: 11pt;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5pt;
    color: #0C447C;
    margin-bottom: 8px;
    padding-bottom: 3px;
    border-bottom: 0.5px solid #bbb;
  }

  .report .report-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1cm;
    padding: 5px 0;
    border-bottom: 0.5px solid #ddd;
    font-size: 11pt;
  }

  .report .report-line span:first-child { color: #444; }
  .report .report-line span:last-child { font-weight: 600; color: #000; white-space: nowrap; }

  .report .report-rds {
    font-size: 13pt;
    font-weight: 700;
    margin-top: 12px;
    padding: 10px 14px;
    background: #f0f0ee;
    border-left: 3px solid #0C447C;
    border-radius: 3px;
  }

  .report table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
  }

  .report th, .report td {
    border: 0.5px solid #999;
    padding: 5px 8px;
    font-size: 10pt;
    text-align: center;
  }

  .report th {
    background: #eee;
  }

  .report .report-footer {
    margin-top: 2rem;
    font-size: 9pt;
    color: #666;
    border-top: 1px solid #999;
    padding-top: 0.75rem;
  }

  .report .report-formula {
    font-style: italic;
    color: #333;
    margin-top: 1rem;
    font-size: 10pt;
    line-height: 1.5;
  }

  /* Interpretation block in the printed report */
  .report .report-interp .interp-title { display: none; }

  .report .interp-subtitle {
    font-size: 11pt;
    font-weight: bold;
    color: #000;
    margin: 10px 0 4px;
  }

  .report .interp-line {
    font-size: 10.5pt;
    line-height: 1.5;
    margin-bottom: 5px;
    color: #000;
  }

  .report .interp-note {
    font-size: 9.5pt;
    color: #444;
    border-top: 0.5px solid #ccc;
    padding-top: 5px;
  }

  .report .interp-ok   { color: #0F6E56; }
  .report .interp-warn { color: #633806; }
  .report .interp-bad  { color: #791F1F; }

  .report .norm-item { margin-bottom: 12px; text-align: center; }
  .report .norm-item .interp-line { text-align: left; }
  .report .gauss {
    display: block;
    max-width: 11cm;
    width: 100%;
    margin: 6px auto 10px;
  }

  .report .interp-synthese {
    border: 1px solid #999;
    border-left: 4px solid #1A4E7A;
    padding: 8px 10px;
    margin-bottom: 8px;
  }

  .report .report-norm-note {
    font-size: 9pt;
    color: #555;
    margin-top: 3px;
  }

  .report .report-refs {
    margin-top: 1rem;
    font-size: 8.5pt;
    color: #444;
    line-height: 1.45;
    border-top: 0.5px solid #ccc;
    padding-top: 0.5rem;
  }
}
