/* ==========================================================================
   Typed answers (type-answer.js): the answer-mode switch and the type box.

   Built only from shared tokens, so every site theme restyles it through its
   own system sheet (theme-render.ts lists it as unthemed). Loaded by
   MediSim's page and by CardiSim's landing and home.
   ========================================================================== */

/* ── The switch: two latching keys, the one that is in sunk and lit ───── */
.answerMode { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.answerModeLegend {
  font: 600 var(--fs-legend)/1 var(--font-legend, var(--font-mono));
  letter-spacing: var(--tr-legend, .06em); text-transform: uppercase; color: var(--ink-2);
  margin-right: 2px; white-space: nowrap;
}
.answerModeKey { position: relative; gap: 7px; cursor: pointer; white-space: nowrap; }
.answerModeKey input {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0;
  opacity: 0; cursor: pointer; appearance: none; -webkit-appearance: none;
}
.answerModeKey .led:not(.is-blue) { box-shadow: var(--lens-off); background: transparent; }
.answerModeKey.is-on {
  --key-bg: var(--blue-wash); --key-edge: var(--blue-edge);
  --key-shadow: var(--key-shadow-press); --key-shadow-hover: var(--key-shadow-press);
  transform: translateY(2px); box-shadow: var(--key-shadow-press);
}
.answerModeKey:has(input:focus-visible) { box-shadow: var(--key-shadow), var(--focus); }
.answerModeKey.is-on:has(input:focus-visible) { box-shadow: var(--key-shadow-press), var(--focus); }

/* ── The box ───────────────────────────────────────────────────────────── */
.typeAns { position: relative; display: grid; gap: 6px; min-width: 0; }
.typeAnsField { position: relative; display: flex; align-items: center; }
.typeAnsField > .led { position: absolute; left: 14px; top: 50%; margin-top: -4px; pointer-events: none; }
.typeAnsField > .led:not(.is-green, .is-red) { box-shadow: var(--lens-off); background: transparent; }
.typeAns .typeAnsInput {
  min-height: 52px; padding: 0 128px 0 34px;
  /* 16px at least: phones zoom into anything smaller on focus. */
  font: 600 max(16px, var(--fs-body))/1.2 var(--font-ui);
  letter-spacing: .01em;
}
.typeAnsKeys {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  display: flex; gap: 4px; pointer-events: none;
}
.typeAnsKeys kbd {
  min-width: 22px; padding: 2px 6px; text-align: center;
  font: 600 var(--fs-legend)/1.3 var(--font-legend, var(--font-mono)); letter-spacing: var(--tr-legend, .06em);
  text-transform: uppercase; color: var(--ink-2);
  background: var(--chassis-2, var(--chassis)); border: 1px solid var(--rule-2); border-bottom-width: 2px; border-radius: 4px;
}
.typeAns.is-quiet .typeAnsKeys kbd { color: var(--ink-3); border-color: var(--rule); }
.typeAns:is(.is-right, .is-wrong) .typeAnsKeys { display: none; }
@media not ((hover: hover) and (pointer: fine)) {
  .typeAnsKeys { display: none; }
  .typeAns .typeAnsInput { padding-right: 12px; }
}

.typeAnsList {
  list-style: none; margin: 0; padding: 4px;
  max-height: calc(6 * 42px + 8px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--cap); border: 1px solid var(--rule-2); border-radius: var(--r);
  box-shadow: var(--lift-shadow);
}
.typeAnsList[hidden] { display: none; }
.typeAnsOpt {
  display: flex; align-items: center; gap: 10px;
  min-height: 42px; padding: 0 10px; border-radius: var(--r-sm);
  color: var(--ink-2); cursor: pointer; user-select: none;
}
.typeAnsOpt .led:not(.is-blue) { box-shadow: var(--lens-off); background: transparent; }
.typeAnsOpt.is-active { background: var(--blue-wash); color: var(--ink); box-shadow: inset 0 0 0 1px var(--blue-edge); }
.typeAnsName { flex: 1 1 auto; min-width: 0; }
.typeAnsName b { font-weight: 700; color: var(--ink); }
.typeAnsShort {
  flex: none; padding: 1px 6px; border: 1px solid var(--rule-2); border-radius: 4px;
  font: 600 var(--fs-legend)/1.3 var(--font-legend, var(--font-mono)); letter-spacing: var(--tr-legend, .06em);
  text-transform: uppercase; color: var(--ink-3);
}
@media (pointer: coarse) { .typeAnsOpt { min-height: 46px; } }
/* With a mouse the list drops over what is below instead of pushing it
   down at every letter; a phone keeps it in the flow, above the keyboard. */
@media (hover: hover) and (pointer: fine) {
  .typeAnsList { position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0; max-width: 560px; }
}

/* Said to a screen reader; shown only when nothing matches. */
.typeAnsStatus {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  margin: 0; font-size: var(--fs-small); color: var(--red-ink);
}
.typeAns.is-empty .typeAnsStatus { position: static; width: auto; height: auto; clip-path: none; padding-left: 2px; }
.typeAns.is-empty .typeAnsInput { border-color: var(--red-edge); }

/* Answered: the box keeps the name it took, in the verdict's wash. */
.typeAns.is-right .typeAnsInput { background: var(--green-wash); border-color: var(--green-edge); }
.typeAns.is-wrong .typeAnsInput { background: var(--red-wash); border-color: var(--red-edge); }
.typeAns:is(.is-right, .is-wrong) .typeAnsInput { cursor: default; box-shadow: none; }

@media (forced-colors: active) {
  .typeAnsOpt.is-active { outline: 2px solid Highlight; }
  .answerModeKey.is-on { outline: 2px solid Highlight; }
  .answerModeKey .led, .typeAns .led { forced-color-adjust: none; }
}
