#hemo-calc {
  --hc-line: #2b2b2b;
  --hc-dim: #7a7a7a;
  --hc-border: #e4e2dd;
  border: 1px solid var(--hc-border);
  border-radius: 12px;
  padding: 1.25rem 1.25rem 1rem;
  margin: 1.5rem 0;
  background: #fdfdfc;
  font-variant-numeric: tabular-nums;
}

.hc-body {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  justify-content: center;
}
.hc-col { flex: 1 1 260px; max-width: 340px; }

.hc-grid-wrap { position: relative; aspect-ratio: 1; }
.hc-grid, .hc-dust { position: absolute; inset: 0; width: 100%; height: 100%; }
.hc-grid { cursor: pointer; touch-action: manipulation; }
.hc-lines line { stroke: var(--hc-line); }

.hc-grid rect { transition: fill-opacity 120ms, stroke-opacity 120ms; }
.hc-grid rect { pointer-events: none; }
.hc-sq-sel-fill   { fill-opacity: 0.2; }
.hc-sq-sel-line   { stroke-width: 0.6; }
.hc-sq-hover-fill { fill-opacity: 0.12; }
.hc-sq-hover-line { stroke-width: 0.45; stroke-dasharray: 0.9 0.6; }

.hc-zoom { width: 100%; aspect-ratio: 1; display: block; }
.hc-zoom-wrap { position: relative; align-self: flex-start; }
.hc-reroll, .hc-lens {
  position: absolute; right: 8px; bottom: 8px;
  width: 30px; height: 30px; padding: 2px;
  border: none; background: none; cursor: pointer;
  opacity: 0.8; transition: opacity 120ms, transform 200ms;
}
.hc-lens { right: auto; left: 8px; }
.hc-reroll svg, .hc-lens svg { width: 100%; height: 100%; display: block; }
.hc-reroll:hover, .hc-lens:hover { opacity: 1; }
.hc-lens[aria-pressed="false"] { opacity: 0.45; }
.hc-reroll:active { transform: rotate(90deg); }

.hc-caption {
  min-height: 1.6em;
  margin-top: 0.4rem;
  font-size: 0.9rem;
  text-align: center;
}
.hc-dot {
  display: inline-block; width: 0.6em; height: 0.6em; border-radius: 50%;
  margin-right: 0.4em; vertical-align: 0.05em;
}
.hc-dim { color: var(--hc-dim); margin-left: 0.5em; }

.hc-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 0.5rem 1.25rem;
  margin-top: 1rem;
}
.hc-field {
  display: grid;
  grid-template-columns: auto;
  justify-items: start;
  align-items: baseline;
  column-gap: 0.45rem;
  margin: 0;
}
.hc-label {
  grid-column: 1 / -1;
  font-size: 0.72rem;
  line-height: 1.2;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--hc-dim);
}
.hc-in {
  width: 6.2em;
  font: inherit;
  font-size: 1.45rem;
  line-height: 1.2;
  border: none;
  border-bottom: 2px solid var(--hc-border);
  background: transparent;
  padding: 0.05rem 0;
  outline: none;
  transition: border-color 120ms;
}
.hc-in:focus { border-bottom-color: #3d85c6; }
.hc-in.hc-bad { border-bottom-color: #cc0000; }
.hc-in::placeholder { color: #c8c8c8; }
.hc-unit { font-size: 0.95rem; color: #444; white-space: nowrap; margin-top: 0.2rem; }
.hc-unit-btn {
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  border-bottom: 1px dotted #999;
}
.hc-unit-btn:hover { color: #000; border-bottom-color: #000; }
.hc-note { grid-column: 1 / -1; min-height: 1.2em; font-size: 0.8rem; color: var(--hc-dim); }
/* Centered on the input boxes: label height + half the box, less half the arrow
   (and a little more, since the arrow glyph sits low in its line). */
.hc-eq {
  font-size: 1.75rem;
  line-height: 1;
  color: #aaa;
  margin-top: calc(0.72rem * 1.2 + (1.45rem * 1.2 + 0.1rem + 2px) / 2 - 0.875rem - 0.4rem);
}


.hc-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.6rem 1.4rem;
  margin-bottom: 1.1rem;
}
.hc-cells { display: flex; gap: 0.35rem; }
.hc-cell-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem 0.3rem 0.4rem;
  border: 1px solid var(--hc-border);
  border-radius: 999px;
  background: transparent;
  font: inherit;
  font-size: 0.82rem;
  color: var(--hc-dim);
  cursor: pointer;
  transition: border-color 120ms, background 120ms, color 120ms;
}
.hc-cell-btn svg { width: 22px; height: 22px; opacity: 0.55; transition: opacity 120ms; }
.hc-cell-btn:hover { color: #333; }
.hc-cell-btn:hover svg { opacity: 0.85; }
.hc-cell-btn[aria-pressed="true"] { border-color: #8a8a8a; background: #fff; color: #222; }
.hc-cell-btn[aria-pressed="true"] svg { opacity: 1; }

.hc-size-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex: 0 1 260px;
  margin: 0;
}
.hc-size { flex: 1; min-width: 90px; accent-color: #555; }
.hc-size-val { font-size: 0.85rem; min-width: 3.4em; text-align: right; }

/* Number format switch: three stacked options beside the concentration box,
   a little taller than it and centered on it. */
.hc-in-row { position: relative; }
.hc-notation {
  position: absolute;  /* centered on the box without making its row taller */
  left: calc(100% + 0.5rem);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
}
.hc-notation button {
  border: none;
  border-radius: 999px;
  background: none;
  padding: 0 0.45rem;
  font: inherit;
  font-size: 0.68rem;
  line-height: 1.15rem;
  color: var(--hc-dim);
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.hc-notation button:hover { color: #333; }
.hc-notation button[aria-pressed="true"] { background: #e7e6e2; color: #222; }

/* Shown over the magnified view when a square holds more cells than are drawn. */
.hc-warn {
  position: absolute; left: 6px; top: 6px; max-width: calc(100% - 12px);
  display: flex; align-items: baseline; gap: 6px;
  padding: 2px 8px; border-radius: 4px;
  background: rgba(212, 219, 199, 0.92); /* readable over the eyepiece's dark corner */
  color: #8b0000; font-size: 0.8rem; font-weight: 600; line-height: 1.25;
  pointer-events: none;
}
.hc-warn[hidden] { display: none; }
.hc-warn b { flex: none; font-size: 1.3rem; font-weight: 800; }

/* ---------- tabs ---------- */
.hc-tabs { display: flex; gap: 0.25rem; margin: -0.4rem 0 1rem; border-bottom: 1px solid var(--hc-border); }
.hc-tabs button {
  border: none; background: none; cursor: pointer;
  padding: 0.35rem 0.8rem; margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  font: inherit; color: var(--hc-dim);
}
.hc-tabs button:hover { color: #333; }
.hc-tabs button[aria-selected="true"] { color: #222; border-bottom-color: #555; }

/* ---------- trainer ---------- */
.ht-setup { display: flex; gap: 1.5rem; align-items: flex-start; justify-content: space-between; }
.ht-opts { display: flex; flex-direction: column; gap: 0.8rem; flex: 1 1 auto; min-width: 0; }
.ht-opt { display: flex; align-items: center; gap: 0.7rem; }
.ht-opt .hc-label { flex: none; width: 4.2rem; }
.ht-seg { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.ht-seg button, .ht-go, .ht-again, .ht-review, .ht-answer button {
  display: inline-flex; align-items: center; gap: 0.35rem;
  border: 1px solid var(--hc-border); border-radius: 999px; background: none; cursor: pointer;
  padding: 0.3rem 0.8rem; font: inherit; font-size: 0.9rem; color: #555;
}
.ht-seg button svg { width: 20px; height: 20px; }
.ht-seg button:hover { color: #222; }
.ht-seg button[aria-pressed="true"] { border-color: #8a8a8a; background: #fff; color: #222; }
.ht-go, .ht-again, .ht-review, .ht-answer button { border-color: #555; color: #222; background: #fff; font-weight: 600; }
.ht-go { align-self: flex-start; margin-top: 0.4rem; padding: 0.45rem 1.2rem; }
.ht-go:hover, .ht-again:hover, .ht-review:hover, .ht-answer button:hover { background: #f1f0ec; }
.ht-preview { flex: none; display: block; }
@media (max-width: 640px) {
  .ht-setup { flex-direction: column; align-items: center; }
}

/* The counting view. Its controls sit in the eyepiece's dark corners and at
   the middle of each edge. */
.ht-round { display: flex; justify-content: center; }
.ht-round[hidden], .ht-end[hidden], .ht-hud[hidden], .ht-key[hidden] { display: none; }
.ht-round:fullscreen { background: #0c0c0c; align-items: center; }
.ht-stage { --ht-size: 480px; position: relative; width: var(--ht-size); height: var(--ht-size); }
.ht-view { width: 100%; height: 100%; display: block; touch-action: manipulation; }
.ht-hud {
  position: absolute; left: 12px; top: 10px;
  display: flex; flex-direction: column; gap: 0.1rem;
  color: #fff; font-size: 0.9rem; line-height: 1.3; pointer-events: none;
}
.ht-time { font-size: 1.15rem; font-weight: 700; }
/* Review mode's key, on a light pill so its black ring shows. */
.ht-key {
  position: absolute; left: 10px; top: 10px;
  display: flex; align-items: center; gap: 0.35rem;
  padding: 0.2rem 0.6rem; border-radius: 999px;
  background: #d4dbc7; color: #111; font-size: 0.85rem; pointer-events: none;
}
.ht-key svg { width: 15px; height: 15px; }
.ht-full, .ht-zoom {
  position: absolute; width: 34px; height: 34px; padding: 5px;
  border: none; background: none; cursor: pointer; color: #fff; opacity: 0.85;
}
.ht-full { right: 10px; top: 10px; }
.ht-full svg { width: 100%; height: 100%; display: block; }
.ht-zoom {
  left: 12px; bottom: 12px; border: 1.5px solid #fff; border-radius: 50%;
  padding: 7px;
}
.ht-zoom svg { width: 100%; height: 100%; display: block; }
.ht-full:hover, .ht-zoom:hover { opacity: 1; }
.ht-done {
  position: absolute; right: 12px; bottom: 12px;
  border: 1.5px solid #fff; border-radius: 999px; background: none; cursor: pointer;
  padding: 0.35rem 1rem; font: inherit; font-weight: 700; color: #fff;
}
.ht-done:hover { background: rgba(255, 255, 255, 0.15); }
.ht-arrow {
  position: absolute; width: 34px; height: 34px; border-radius: 50%;
  border: none; cursor: pointer; padding: 0;
  background: rgba(20, 20, 20, 0.45); color: #fff; font-size: 0.85rem; line-height: 1;
}
.ht-arrow:hover:not(:disabled) { background: rgba(20, 20, 20, 0.7); }
.ht-arrow:disabled { opacity: 0.25; cursor: default; }
.ht-arrow[data-d="0,-1"] { top: 6px; left: calc(50% - 17px); }
.ht-arrow[data-d="0,1"]  { bottom: 6px; left: calc(50% - 17px); }
.ht-arrow[data-d="-1,0"] { left: 6px; top: calc(50% - 17px); }
.ht-arrow[data-d="1,0"]  { right: 6px; top: calc(50% - 17px); }

.ht-star {
  position: absolute; z-index: 5; pointer-events: none;
  margin: -0.55em 0 0 -0.45em; line-height: 1;
  color: #2f7fd8; text-shadow: 0 0 2px #fff, 0 0 1px #fff;
}

.ht-end { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 300px); gap: 1rem 1.5rem; align-items: start; }
.ht-results { display: flex; flex-wrap: wrap; gap: 0.6rem 2rem; }
.ht-big span { display: block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--hc-dim); }
.ht-big b { font-size: 1.8rem; }
.ht-tally { width: 100%; font-size: 0.9rem; border-collapse: collapse; }
.ht-tally td { padding: 0.15rem 0; border-top: 1px solid var(--hc-border); }
.ht-tally td:last-child { text-align: right; white-space: nowrap; padding-left: 1rem; }
.ht-mapcol { grid-row: span 2; display: flex; flex-direction: column; align-items: center; gap: 0.7rem; }
.ht-map { width: 100%; max-width: 300px; }
.ht-map .hc-lines line { stroke: var(--hc-line); }
.ht-map-n { fill: #222; font-weight: 700; }
.ht-quiz { position: relative; }
.ht-quiz p { margin: 0 0 0.4rem; }
.ht-answer { display: flex; gap: 0.5rem; margin-top: 0.6rem; }
.ht-answer input { max-width: 14rem; }
.ht-verdict { margin-top: 0.6rem; min-height: 1.5em; }
.ht-verdict.ht-ok { color: #2f7fd8; font-weight: 700; font-size: 1.25rem; }
.ht-verdict.ht-no { color: #d23a2a; }
.ht-again { grid-column: 1 / -1; justify-self: start; }
@media (max-width: 640px) { .ht-end { grid-template-columns: 1fr; } }
