/* Engagement Pad: live results.
   Surfaces, text and borders use the site tokens from ../../style.css and the
   [data-theme] overrides in ../../curriculum/themes.css, so every theme still
   works. Two things are the pad's own: the five answer colours, and the dark
   "stage" at the top, which stays dark in every theme so it reads on a
   projector. */

@font-face {
  font-family: 'Fredoka';
  src: url('../../Fonts/Fredoka/fredoka-latin-wght-normal.woff2') format('woff2');
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

/* ------------------------------------------------------------ tokens --- */
/* A diverging scale: red for 1, grey for the neutral 3, blue for 5. Checked
   for colour-blind separation between neighbours on white and on a dark
   surface. Every segment also carries its number, so colour is never the
   only cue. */
:root {
  --pad-1: #c8372f;
  --pad-2: #ee8466;
  --pad-3: #d9d5cd;
  --pad-4: #79aee8;
  --pad-5: #2160c4;
  --pad-ink-1: #fff;
  --pad-ink-2: #3a1408;
  --pad-ink-3: #3a3833;
  --pad-ink-4: #0b2440;
  --pad-ink-5: #fff;

  --pad-stage: #0e1322;
  --pad-stage-2: #182036;
  --pad-stage-line: #2a3452;
  --pad-stage-text: #eef1f8;
  --pad-stage-muted: #9aa5c0;
  --pad-live: #3ddc84;

  --pad-font-fun: 'Fredoka', var(--font-display);
  --pad-gap: 2px;   /* surface gap between stacked segments */
}

[data-theme="dark"], [data-theme="dos"], [data-theme="dos-amber"],
[data-theme="xbox"], [data-theme="blueprint"], [data-theme="gamer"],
.pad-hero {
  --pad-1: #d4433a;
  --pad-2: #f2a084;
  --pad-3: #55524c;
  --pad-4: #86b6ee;
  --pad-5: #3b7be0;
  --pad-ink-1: #fff;
  --pad-ink-2: #3a1408;
  --pad-ink-3: #f0eee9;
  --pad-ink-4: #0b2440;
  --pad-ink-5: #fff;
}

/* ------------------------------------------------------------ stage --- */
.pad-hero {
  background:
    radial-gradient(60rem 22rem at 85% -10%, rgba(59, 123, 224, 0.35), transparent 70%),
    radial-gradient(40rem 18rem at 0% 110%, rgba(212, 67, 58, 0.22), transparent 70%),
    var(--pad-stage);
  color: var(--pad-stage-text);
  padding: 2.5rem 2rem 2rem;
}

.pad-hero-inner { max-width: var(--max-w); margin: 0 auto; }

.pad-hero-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem 2rem;
  flex-wrap: wrap;
  margin-bottom: 1.75rem;
}

.pad-eyebrow {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--pad-stage-muted);
}

.pad-live {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--pad-stage-line);
  border-radius: 999px;
  color: var(--pad-stage-text);
}
.pad-live-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--pad-stage-muted);
}
.pad-live.is-on .pad-live-dot {
  background: var(--pad-live);
  box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.6);
  animation: pad-pulse 2s infinite;
}
.pad-live.is-off .pad-live-dot { background: #f2a084; }

@keyframes pad-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.6); }
  70%  { box-shadow: 0 0 0 0.6rem rgba(61, 220, 132, 0); }
  100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); }
}

.pad-hero h1 {
  font-family: var(--pad-font-fun);
  font-weight: 600;
  font-size: clamp(1.7rem, 4.6vw, 3rem);
  line-height: 1.08;
  letter-spacing: -0.01em;
  margin: 0;
  max-width: 20ch;
  color: var(--pad-stage-text);
}

.pad-today-big { text-align: right; }
.pad-today-n {
  display: block;
  font-family: var(--pad-font-fun);
  font-weight: 600;
  font-size: clamp(3rem, 9vw, 5.5rem);
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}
.pad-today-label {
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--pad-stage-muted);
}

/* Five tiles, one per physical button. A tile lights up when its button is
   pressed. */
.pad-buttons {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
}

.pad-button {
  position: relative;
  padding: 1rem 1rem 0.9rem;
  border-radius: 18px;
  background: var(--pad-stage-2);
  border: 1px solid var(--pad-stage-line);
  overflow: hidden;
  min-width: 0;
}
.pad-button::before {   /* the coloured cap, like the key on the pad */
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 6px;
  background: var(--c);
}
.pad-button-key {
  display: inline-grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 12px;
  background: var(--c);
  color: var(--ink);
  font-family: var(--pad-font-fun);
  font-weight: 700;
  font-size: 1.35rem;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}
.pad-button-title {
  display: block;
  margin-top: 0.6rem;
  font-size: 0.82rem;
  line-height: 1.25;
  color: var(--pad-stage-muted);
  min-height: 2.05em;
}
.pad-button-n {
  display: block;
  margin-top: 0.35rem;
  font-family: var(--pad-font-fun);
  font-weight: 600;
  font-size: 2rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.pad-button-n small {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--pad-stage-muted);
  margin-left: 0.35rem;
}
.pad-button-bar {
  height: 4px;
  margin-top: 0.7rem;
  border-radius: 2px;
  background: var(--pad-stage-line);
  overflow: hidden;
}
.pad-button-bar span {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--c);
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.pad-button.is-hit { animation: pad-hit 1.4s ease-out; }
.pad-button.is-hit .pad-button-key { animation: pad-key 0.5s ease-out; }
@keyframes pad-hit {
  0%   { box-shadow: 0 0 0 2px var(--c), 0 0 2.5rem var(--c); }
  100% { box-shadow: 0 0 0 0 transparent, 0 0 0 transparent; }
}
@keyframes pad-key {
  0%   { transform: translateY(0); }
  30%  { transform: translateY(4px); box-shadow: 0 0 0 rgba(0, 0, 0, 0.35); }
  100% { transform: translateY(0); }
}

.pad-ticker {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  min-height: 2rem;
}
.pad-ticker-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--pad-stage-muted);
  flex: none;
}
.pad-ticker-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 0.4rem;
  overflow: hidden;
  mask-image: linear-gradient(90deg, #000 80%, transparent);
}
.pad-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex: none;
  padding: 0.2rem 0.55rem 0.2rem 0.2rem;
  border-radius: 999px;
  background: var(--pad-stage-2);
  border: 1px solid var(--pad-stage-line);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--pad-stage-muted);
  white-space: nowrap;
}
.pad-chip b {
  display: inline-grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: var(--c);
  color: var(--ink);
  font-family: var(--pad-font-fun);
  font-size: 0.8rem;
}
.pad-chip.is-new { animation: pad-in 0.5s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes pad-in {
  from { transform: translateX(-1rem) scale(0.8); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* The answer colour for anything carrying data-v. */
[data-v="1"] { --c: var(--pad-1); --ink: var(--pad-ink-1); }
[data-v="2"] { --c: var(--pad-2); --ink: var(--pad-ink-2); }
[data-v="3"] { --c: var(--pad-3); --ink: var(--pad-ink-3); }
[data-v="4"] { --c: var(--pad-4); --ink: var(--pad-ink-4); }
[data-v="5"] { --c: var(--pad-5); --ink: var(--pad-ink-5); }

/* ------------------------------------------------------------ page --- */
.pad-main {
  /* body is a column flex container, so `margin: 0 auto` alone would shrink
     the page to its content; width: 100% keeps the full measure. */
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 2rem 4rem;
}

.pad-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0 -0.5rem 1.25rem;
  padding: 0.85rem 0.5rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

/* Segmented control: a row of toggle buttons, one pressed. */
.pad-seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.pad-seg button,
.pad-btn {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.45rem 0.95rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.pad-seg button:hover { color: var(--text); }
.pad-seg button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--border);
}
.pad-seg-sm button { font-size: 0.75rem; padding: 0.3rem 0.65rem; }

.pad-btn {
  background: var(--text);
  color: var(--bg);
}
.pad-btn:hover { opacity: 0.88; }

.pad-seg button:focus-visible,
.pad-btn:focus-visible,
.pad-table th button:focus-visible,
[data-tip]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------------------------------------- cards --- */
.pad-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.pad-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 1.1rem 1.35rem 0;
}
.pad-card-head h2 {
  font-family: var(--pad-font-fun);
  font-size: 1.3rem;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}
.pad-card-tools { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.pad-hint {
  font-size: 0.78rem;
  color: var(--muted);
}

.pad-body { padding: 1.1rem 1.35rem 1.35rem; }
.pad-body-flush { padding: 0.75rem 0 0; }

/* -------------------------------------------- the range in one bar --- */
.pad-stack {
  display: flex;
  gap: var(--pad-gap);
  height: 3rem;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
}
.pad-stack-seg {
  display: grid;
  place-items: center;
  min-width: 0;
  background: var(--c);
  color: var(--ink);
  font-family: var(--pad-font-fun);
  font-weight: 600;
  font-size: 0.95rem;
  transition: flex-grow 0.5s cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
  white-space: nowrap;
}

.pad-stats {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1rem;
  margin: 1.25rem 0 0;
}
.pad-stats > div {
  padding: 0.85rem 0.9rem;
  border-radius: 14px;
  background: var(--surface-2);
  min-width: 0;
}
.pad-stats dt {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.pad-stats dd { margin: 0; }
.pad-stat-v {
  display: block;
  margin-top: 0.2rem;
  font-family: var(--pad-font-fun);
  font-weight: 600;
  font-size: 1.9rem;
  line-height: 1.1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.pad-stat-d {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.74rem;
  line-height: 1.35;
  color: var(--muted);
}

/* ------------------------------------------------------- the charts --- */
.pad-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.pad-legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.pad-legend i {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 3px;
  background: var(--c);
}

.pad-chart { position: relative; min-height: 14rem; }
.pad-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.pad-chart .grid line { stroke: var(--border); }
.pad-chart .axis text {
  fill: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
}
.pad-chart .col rect.seg { fill: var(--c); }
.pad-chart .col rect.hit { fill: transparent; }
.pad-chart .col:hover rect.hit,
.pad-chart .col:focus rect.hit { fill: var(--text); fill-opacity: 0.06; }
.pad-chart .col { outline: none; }

.pad-empty {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 2.5rem 1rem;
}

/* Heat map: a CSS grid, weekdays down and hours across. */
.pad-heat-wrap { overflow-x: auto; }
.pad-heat {
  display: grid;
  gap: 4px;
  min-width: max-content;
}
.pad-heat-h,
.pad-heat-d {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
  display: grid;
  align-items: center;
}
.pad-heat-h { justify-items: center; padding-bottom: 0.15rem; }
.pad-heat-d { padding-right: 0.4rem; }
.pad-heat-c {
  display: grid;
  place-items: center;
  min-width: 2.6rem;
  height: 2.6rem;
  border-radius: 8px;
  background: var(--surface-2);
  font-family: var(--pad-font-fun);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
}
.pad-heat-c.has { background: var(--heat); color: var(--heat-ink); }

.pad-heat-key {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
}
.pad-heat-ramp {
  width: 9rem;
  height: 0.6rem;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--pad-1), var(--pad-2), var(--pad-3), var(--pad-4), var(--pad-5));
}

/* ------------------------------------------------------------ tables --- */
.pad-table-wrap { overflow-x: auto; }
.pad-log-wrap { max-height: 28rem; overflow-y: auto; }

.pad-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}
.pad-table th,
.pad-table td {
  padding: 0.55rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pad-table th:first-child,
.pad-table td:first-child { text-align: left; padding-left: 1.35rem; }
.pad-table th:last-child,
.pad-table td:last-child { padding-right: 1.35rem; }
.pad-table tbody tr:last-child td { border-bottom: 0; }
.pad-table tbody tr:hover { background: var(--surface-2); }

.pad-table th {
  position: sticky;
  top: 0;
  background: var(--surface);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom-color: var(--border-strong);
  vertical-align: bottom;
}
.pad-th-sub {
  display: block;
  font-size: 0.66rem;
  letter-spacing: 0;
  text-transform: none;
  opacity: 0.8;
}
.pad-table th button {
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.pad-table th button::after { content: ' ↕'; opacity: 0.35; }
.pad-table th[aria-sort="ascending"] button::after { content: ' ↑'; opacity: 1; }
.pad-table th[aria-sort="descending"] button::after { content: ' ↓'; opacity: 1; }
.pad-table th[aria-sort] { color: var(--text); }

.pad-table .pad-col-div { text-align: center; width: 45%; }
.pad-table td.pad-today { font-weight: 600; color: var(--text); }
.pad-table td .pad-wd { color: var(--muted); margin-right: 0.35rem; }

/* A diverging bar per day: 1 and 2 to the left of the centre line, 4 and 5
   to the right, and the neutral 3 split across it. */
.pad-div {
  position: relative;
  display: flex;
  height: 1.5rem;
  min-width: 12rem;
}
.pad-div::after {
  content: '';
  position: absolute;
  left: var(--mid);
  top: -4px;
  bottom: -4px;
  width: 1px;
  /* Ticks above and below the bar only, so the line never crosses a number. */
  background: linear-gradient(var(--border-strong) 4px, transparent 4px,
                              transparent calc(100% - 4px), var(--border-strong) calc(100% - 4px));
}
.pad-div-seg {
  display: grid;
  place-items: center;
  height: 100%;
  background: var(--c);
  color: var(--ink);
  font-family: var(--pad-font-fun);
  font-size: 0.72rem;
  font-weight: 600;
  overflow: hidden;
  box-shadow: inset calc(var(--pad-gap) * -1) 0 0 var(--surface);
}
.pad-div-seg:first-of-type { border-radius: 5px 0 0 5px; }
.pad-div-seg:last-of-type { border-radius: 0 5px 5px 0; box-shadow: none; }

.pad-ans {
  display: inline-grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: var(--c);
  color: var(--ink);
  font-family: var(--pad-font-fun);
  font-weight: 600;
}

details.pad-log > summary { cursor: pointer; list-style: none; padding-bottom: 1.1rem; }
details.pad-log > summary::-webkit-details-marker { display: none; }
details.pad-log > summary h2::before { content: '▸ '; color: var(--muted); }
details.pad-log[open] > summary h2::before { content: '▾ '; }
details.pad-log[open] > summary { padding-bottom: 0; }

/* -------------------------------------------------------------- misc --- */
.pad-note {
  margin: 0 0 1.25rem;
  padding: 0.9rem 1.1rem;
  background: var(--amber-bg);
  color: var(--amber);
  border: 1px solid var(--amber);
  border-radius: 12px;
  line-height: 1.5;
  font-size: 0.88rem;
}

.pad-about { max-width: 62ch; margin-top: 2.5rem; }
.pad-about h2 {
  font-family: var(--pad-font-fun);
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
}
.pad-about p { color: var(--muted); line-height: 1.65; margin: 0 0 0.8rem; font-size: 0.92rem; }

.pad-tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  max-width: 16rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  background: var(--pad-stage);
  color: var(--pad-stage-text);
  font-size: 0.78rem;
  line-height: 1.45;
  box-shadow: var(--shadow-md);
  white-space: pre-line;
}
.pad-tip b { font-weight: 600; }

/* ------------------------------------------------------------ small --- */
@media (max-width: 860px) {
  .pad-stats { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 640px) {
  .pad-hero { padding: 1.75rem 1rem 1.5rem; }
  .pad-main { padding: 0 1rem 3rem; }
  .pad-today-big { text-align: left; }
  .pad-buttons { gap: 0.4rem; }
  .pad-button { padding: 0.65rem 0.4rem 0.6rem; border-radius: 12px; text-align: center; }
  .pad-button-key { width: 1.9rem; height: 1.9rem; font-size: 1.05rem; border-radius: 9px; }
  .pad-button-title { display: none; }
  .pad-button-n { font-size: 1.35rem; margin-top: 0.5rem; }
  .pad-button-n small { display: block; margin: 0.2rem 0 0; }
  .pad-toolbar { margin: 0 -1rem 1rem; padding: 0.65rem 1rem; }
  .pad-toolbar .pad-seg { flex: 1; justify-content: space-between; }
  .pad-seg button { padding: 0.45rem 0.6rem; font-size: 0.8rem; }
  .pad-btn { width: 100%; }
  .pad-card { border-radius: 16px; }
  .pad-card-head { padding: 1rem 1rem 0; }
  .pad-body { padding: 1rem; }
  .pad-stats { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
  .pad-stat-v { font-size: 1.5rem; }
  .pad-table th:first-child, .pad-table td:first-child { padding-left: 1rem; }
  .pad-table th:last-child, .pad-table td:last-child { padding-right: 1rem; }
  .pad-table th, .pad-table td { padding: 0.5rem 0.45rem; }
}

@media (prefers-reduced-motion: reduce) {
  .pad-live.is-on .pad-live-dot,
  .pad-button.is-hit,
  .pad-button.is-hit .pad-button-key,
  .pad-chip.is-new { animation: none; }
  .pad-button-bar span,
  .pad-stack-seg { transition: none; }
}
