/* Periodic Table. Functional layout before the design pass; existing tokens only.
   Mobile: sticky bar (clock, counter, buttons, input, "Last named" line), the table at full width,
   then the list. 900 px and up: the same order, the bar no longer sticky.
   Cell content follows the table's own width (container queries): symbol only on narrow tables,
   number and symbol from 560 px, number, symbol and name from 840 px. */

.q-elements { padding-block: var(--s5) var(--s7); }
.q-elements__intro { display: grid; gap: var(--s2); margin-bottom: var(--s5); max-width: 60ch; }
.q-elements__intro h1 { font-size: 28px; }

.q-elements__game { max-width: none; display: grid; gap: var(--s3); padding: var(--s2); }
.q-elements__game:focus { outline: none; }

/* ---------- control bar ---------- */
.q-elements__bar {
  position: sticky; top: 0; z-index: 4;
  display: grid; gap: var(--s2);
  margin: calc(-1 * var(--s2)) calc(-1 * var(--s2)) 0; padding: var(--s3);
  background: var(--surface); border-radius: var(--r-card) var(--r-card) 0 0;
}
.q-elements__row { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.q-elements__actions { display: flex; gap: var(--s2); margin-left: auto; }
.q-elements__input {
  width: 100%; min-height: 48px; padding: 0 var(--s4);
  font-size: 18px; /* 16 px or more keeps iOS from zooming on focus */
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r-pill);
}
.q-elements__input:disabled { opacity: .5; }
/* "Last named: Iron (Fe, 26)" / "Already named: Iron": one line, reserved so nothing shifts */
.q-elements__feedback {
  min-height: 1.5em; margin-top: var(--s1); padding-inline: var(--s4); font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.q-elements__result { display: grid; gap: var(--s3); padding: var(--s2); }
.q-elements__result .fig dd { font-size: 24px; }

/* ---------- the table (D4): 18 columns; 7 periods, a gap, the two f-block rows ---------- */
.q-elements__board { position: relative; display: grid; gap: var(--s4); min-width: 0; }
.q-elements__table { container-type: inline-size; min-width: 0; }
.q-elements__grid {
  --gap: 1px;
  --cell: calc((100cqi - 17 * var(--gap)) / 18); /* one cell's width */
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(18, minmax(0, 1fr));
  grid-template-rows: repeat(7, auto) calc(var(--cell) / 3) repeat(2, auto);
}
.q-elements__cell {
  aspect-ratio: 1; min-width: 0; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 2px; background: var(--surface-2);
  line-height: 1; text-align: center; font-variant-numeric: tabular-nums;
}
.q-elements__cell.state { background: var(--st); color: #FFFFFF; } /* named (correct) and missed (wrong) fills from quiz.css */
.q-elements__cell.is-missed { box-shadow: inset 0 0 0 2px var(--st), inset 0 0 0 3px rgba(255, 255, 255, .6); } /* non-color cue: inner ring */
.q-elements__range {
  background: none; box-shadow: inset 0 0 0 1px var(--line-strong);
  color: var(--ink-2); padding-inline: 1px;
}
.q-elements__rng { font-size: calc(var(--cell) * .26); font-weight: 600; overflow-wrap: anywhere; }
.q-elements__sym { font-size: calc(var(--cell) * .6); font-weight: 700; }
.q-elements__z, .q-elements__name { display: none; }

@container (min-width: 560px) {
  .q-elements__grid { --gap: 2px; }
  .q-elements__cell { border-radius: 4px; }
  .q-elements__z { display: block; font-size: calc(var(--cell) * .22); }
  .q-elements__sym { font-size: calc(var(--cell) * .4); margin-top: 2px; }
  .q-elements__rng { font-size: calc(var(--cell) * .22); }
}
@container (min-width: 840px) {
  .q-elements__cell { aspect-ratio: 6 / 5; padding-inline: 2px; }
  .q-elements__z { font-size: calc(var(--cell) * .17); }
  .q-elements__sym { font-size: calc(var(--cell) * .3); margin-top: 1px; }
  .q-elements__name {
    display: block; max-width: 100%; margin-top: 2px;
    font-size: calc(var(--cell) * .15); font-stretch: 75%; /* long names: narrow width axis, then ellipsis */
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
}

/* ---------- category tints (§6.4): named cells, while the table is tinted; the legend chips always ---------- */
.q-elements.is-tinted .q-elements__cell.is-guessed.tone-field, .q-elements__chip.tone-field { background: var(--field); color: var(--on); }
.q-elements.is-tinted .q-elements__cell.is-guessed.tone-light, .q-elements__chip.tone-light { background: var(--light); color: var(--deep); }
.q-elements.is-tinted .q-elements__cell.is-guessed.tone-none, .q-elements__chip.tone-none { background: var(--state-absent); color: #FFFFFF; }
.q-elements__legend { display: grid; gap: var(--s2); }
.q-elements__legend ul {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--s1) var(--s4);
  margin: 0; padding: 0; list-style: none; font-size: 14px;
}
.q-elements__legend li { display: flex; align-items: center; gap: var(--s2); }
.q-elements__legend p { font-size: 13px; }
.q-elements__chip { flex: none; width: 16px; height: 16px; border-radius: 3px; }
.q-elements__chip.is-missed { box-shadow: inset 0 0 0 2px var(--st), inset 0 0 0 3px rgba(255, 255, 255, .6); }

/* ---------- after the game: details on hover or tap (§6.3) ---------- */
.q-elements__grid.is-revealed .q-elements__cell { cursor: pointer; }
.q-elements__cell.is-selected { position: relative; z-index: 1; outline: 2px solid var(--ink); outline-offset: 1px; }
.q-elements__caption { min-height: 1.5em; font-size: 15px; }

/* ---------- setting: tints while playing ---------- */
.q-elements__option { display: flex; align-items: center; gap: var(--s3); min-height: 44px; font-size: 15px; cursor: pointer; }
.q-elements__option input { width: 20px; height: 20px; accent-color: var(--ink); margin: 0; }

/* ---------- the list (D7) ---------- */
.q-elements__list { min-width: 0; border-top: 1px solid var(--line); }
.q-elements__listtable { width: 100%; border-collapse: collapse; font-size: 15px; }
.q-elements__listtable thead th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: var(--s2);
}
.q-elements__listtable td { padding: 6px var(--s2); border-bottom: 1px solid var(--line); height: 36px; }
.q-elements__listtable th:first-child, .q-elements__listtable td:first-child { width: 3.5em; color: var(--ink-2); }
.q-elements__listtable th:nth-child(2), .q-elements__listtable td:nth-child(2) { width: 5em; font-weight: 600; }
.q-elements__listtable th[scope="rowgroup"] {
  text-align: left; font-size: 15px; font-weight: 700; padding: var(--s4) var(--s2) var(--s2);
}
.q-elements__missed td { color: var(--state-wrong); font-style: italic; }

/* ---------- pause: cover the table and the list (D9) ---------- */
.q-elements__pause { inset: 0; padding: var(--s4); align-content: center; }
.q-elements__pause p { font-size: 18px; }
.q-elements.is-paused .q-elements__table,
.q-elements.is-paused .q-elements__list { visibility: hidden; }

/* ---------- your stats ---------- */
.q-elements__stats { max-width: none; display: grid; gap: var(--s4); margin-top: var(--s5); padding: var(--s4); }
.q-elements__stats .figs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.q-elements__stats .fig dd { font-size: 24px; }
.q-elements__recent { overflow-x: auto; }
.q-elements__recent caption { text-align: left; padding-bottom: var(--s2); }
.q-elements__recent th:first-child, .q-elements__recent td:first-child { width: auto; color: inherit; }
.q-elements__recent th:nth-child(2), .q-elements__recent td:nth-child(2) { width: auto; font-weight: 400; }

/* ---------- page text below the quiz ---------- */
.q-elements__about { display: grid; gap: var(--s3); max-width: 72ch; margin-top: var(--s7); }
.q-elements__about h2 { margin-top: var(--s4); }
.q-elements__about ol, .q-elements__about ul { margin: 0; padding-left: 1.4em; display: grid; gap: var(--s1); }
.q-elements__about h3 { margin-top: var(--s2); }
.q-elements__more { display: grid; gap: var(--s3); }
.q-elements__more summary { cursor: pointer; font-weight: 600; padding-block: 10px; } /* about 44 px tall */
.q-elements__more[open] summary { margin-bottom: var(--s2); }
.q-elements__about .q-elements__names thead th { position: static; } /* not in a scroll box: don't stick to the viewport */

@media (min-width: 720px) {
  .q-elements__game { padding: var(--s4); gap: var(--s4); }
  .q-elements__bar { margin: calc(-1 * var(--s4)) calc(-1 * var(--s4)) 0; padding: var(--s4); }
}
@media (min-width: 900px) {
  .q-elements__game { padding: var(--s5); }
  .q-elements__bar { margin: 0; padding: 0; position: static; }
  .q-elements__list { max-height: 50vh; overflow-y: auto; overscroll-behavior: contain; }
  .q-elements__listtable thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
}
