/* Prime Rhythm page. Phone first: title, readout, machine, controls, explanation. Desktop: machine left, panel right. */

.intro {
  padding-top: 22px;
}
.kicker {
  margin: 0 0 4px;
  font: 800 12px/1.2 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cyan);
}
.intro h1 {
  margin: 0;
  font-weight: 900;
  font-size: clamp(32px, 8vw, 46px);
  line-height: 1.02;
  letter-spacing: -0.01em;
}
.lede {
  margin: 8px 0 0;
  color: var(--dim);
  font-size: clamp(16px, 2.2vw, 18px);
  max-width: 40em;
}
.lede b {
  color: var(--ink);
  font-weight: 700;
}
.lede .y {
  color: var(--yellow);
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: 'intro' 'readout' 'stage' 'panel';
  gap: 14px;
}
.intro {
  grid-area: intro;
}
.readout {
  grid-area: readout;
}
.stage {
  grid-area: stage;
}
.panel {
  grid-area: panel;
}
@media (min-width: 900px) {
  .app {
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-areas: 'stage intro' 'stage readout' 'stage panel';
    grid-template-rows: auto auto 1fr;
    column-gap: 32px;
    row-gap: 18px;
    align-items: start;
  }
  .stage {
    position: sticky;
    top: 68px;
    padding-top: 16px;
  }
  .machine {
    width: min(100%, calc(100vh - 128px));
  }
  .readout {
    text-align: left;
  }
}

/* --- readout ------------------------------------------------------------------------------------------------------ */
.readout {
  text-align: center;
}
.num {
  font: 800 clamp(46px, 13vw, 76px) / 1 var(--mono);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  transition: color 0.12s;
}
.num.prime {
  color: var(--yellow);
  text-shadow: 0 0 28px rgba(255, 211, 25, 0.45);
}
.gate-label {
  margin-top: 6px;
  font-weight: 700;
  font-size: clamp(17px, 4.4vw, 21px);
  line-height: 1.25;
  color: var(--red);
}
.gate-label.prime {
  color: var(--yellow);
}
.gate-sub {
  margin-top: 2px;
  color: var(--dim);
  font-size: 14px;
  min-height: 1.4em;
}

/* --- the machine ---------------------------------------------------------------------------------------------------- */
.machine {
  position: relative;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  overflow: hidden;
  background: #05060a;
  box-shadow:
    0 0 0 1px var(--line),
    0 30px 80px -40px rgba(157, 92, 255, 0.45);
}
.machine canvas {
  display: block;
  width: 100%;
  height: 100%;
  /* drags and pinches that start on the machine pan and zoom it; the page scrolls everywhere else */
  touch-action: none;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.machine canvas.grabbing {
  cursor: grabbing;
}
/* zoom buttons on the board */
.view-ctl {
  /* top right: the machine never reaches this corner (the gate runs up the middle, the rim curves away) */
  position: absolute;
  right: 10px;
  top: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.vbtn {
  appearance: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--line2);
  background: rgba(11, 14, 23, 0.82);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.vbtn:hover {
  border-color: rgba(45, 226, 230, 0.6);
}
.vbtn:active {
  transform: translateY(1px);
}
.vbtn:disabled {
  opacity: 0.35;
  cursor: default;
}
.vbtn svg {
  width: 20px;
  height: 20px;
}
.view-zoom {
  order: 4;
  min-width: 40px;
  padding: 3px 6px;
  border-radius: 8px;
  background: rgba(11, 14, 23, 0.82);
  font: 800 11.5px/1.2 var(--mono);
  color: var(--dim);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.view-zoom:not(.zoomed) {
  visibility: hidden; /* shown only once the view moves */
}
.view-zoom.zoomed {
  color: var(--cyan);
}
@media (max-width: 480px) {
  .vbtn {
    width: 36px;
    height: 36px;
    border-radius: 11px;
  }
  .vbtn svg {
    width: 18px;
    height: 18px;
  }
}
.view-hint {
  /* top left: the one corner the machine never uses (the gate runs up the middle) */
  position: absolute;
  left: 12px;
  top: 10px;
  max-width: 40%;
  margin: 0;
  color: var(--dim);
  font-size: 12px;
  line-height: 1.3;
  pointer-events: none;
  transition: opacity 0.6s;
}
.view-hint.gone {
  opacity: 0;
}
.badge-row {
  margin-top: 6px;
  min-height: 28px;
}
.badge {
  display: inline-block;
  max-width: 100%;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(255, 211, 25, 0.12);
  border: 1px solid rgba(255, 211, 25, 0.5);
  color: var(--yellow);
  font: 700 13px/1.3 var(--sans);
  visibility: hidden;
}
.badge.show {
  visibility: visible;
}
.mode-note {
  margin: 10px auto 0;
  max-width: 680px;
  text-align: center;
  color: var(--dim);
  font-size: 14px;
  min-height: 1.5em;
}
.mode-note b {
  color: var(--ink);
}
.mode-note .bad {
  color: var(--red);
}

/* --- counters ------------------------------------------------------------------------------------------------------- */
.counters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}
.counters div {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 10px 8px;
  min-width: 0;
}
.counters dt {
  color: var(--dim);
  font-size: 12px;
  line-height: 1.2;
}
.counters dd {
  margin: 3px 0 0;
  font: 800 clamp(15px, 4.2vw, 18px) / 1.1 var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.counters .c-primes dd {
  color: var(--yellow);
}

/* --- controls ------------------------------------------------------------------------------------------------------- */
.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel-box {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.transport {
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  gap: 8px;
}
.transport .btn {
  padding: 0;
  min-height: 48px;
}
.transport .play {
  font-size: 16px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.field label,
.field .label {
  font-weight: 700;
  font-size: 14px;
}
.field output {
  font: 800 14px/1 var(--mono);
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
}
input[type='range'] {
  width: 100%;
  height: 28px;
  accent-color: var(--cyan);
  background: transparent;
  margin: 0;
}
/* speed: preset buttons over the fine slider */
.speeds {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}
.speed-chip {
  appearance: none;
  min-height: 44px;
  padding: 0 4px;
  border-radius: 12px;
  border: 1px solid var(--line2);
  background: var(--bg);
  color: var(--ink);
  font: 800 15px/1 var(--mono);
  cursor: pointer;
  touch-action: manipulation;
}
.speed-chip:hover {
  border-color: rgba(45, 226, 230, 0.6);
}
.speed-chip[aria-pressed='true'] {
  background: rgba(45, 226, 230, 0.16);
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 18px -6px rgba(45, 226, 230, 0.8);
}
.speed-note {
  margin: -2px 0 0;
  color: var(--faint);
  font-size: 12px;
}
.jump {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
input[type='number'],
select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line2);
  background: var(--bg);
  color: var(--ink);
  font: 800 16px/1 var(--mono);
  padding: 0 12px;
}
input[type='number']::-webkit-inner-spin-button {
  opacity: 0.4;
}
select {
  font: 700 15px/1 var(--sans);
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%239aa0b0' stroke-width='1.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
}
.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  appearance: none;
  border: 1px solid var(--line2);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  min-height: 34px;
  padding: 0 11px;
  font: 800 13px/1 var(--mono);
  cursor: pointer;
  touch-action: manipulation;
}
.chip:hover {
  border-color: var(--cyan);
}
.chip small {
  font: 500 11px/1 var(--sans);
  color: var(--dim);
  margin-left: 4px;
}
.toggles {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.toggle {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 700 14px/1.25 var(--sans);
  text-align: left;
  cursor: pointer;
}
.toggle small {
  display: block;
  color: var(--dim);
  font-weight: 500;
  font-size: 12.5px;
}
.toggle .sw {
  flex: none;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--bg3);
  border: 1px solid var(--line2);
  position: relative;
  transition: background 0.15s;
}
.toggle .sw::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--dim);
  transition:
    transform 0.15s,
    background 0.15s;
}
.toggle[aria-pressed='true'] .sw {
  background: rgba(45, 226, 230, 0.2);
  border-color: var(--cyan);
}
.toggle[aria-pressed='true'] .sw::after {
  transform: translateX(18px);
  background: var(--cyan);
}
.field .hint {
  font-weight: 500;
  font-size: 12.5px;
  color: var(--dim);
  margin-left: 4px;
}
@media (hover: none) {
  .keys {
    display: none;
  }
}
.keys {
  margin: 0;
  color: var(--faint);
  font-size: 12.5px;
  text-align: center;
}
.keys kbd {
  font: 700 11px/1 var(--mono);
  color: var(--dim);
  border: 1px solid var(--line2);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 2px 5px;
}

/* --- explanation ---------------------------------------------------------------------------------------------------- */
.explain {
  margin-top: 56px;
  max-width: 760px;
}
.explain h2 {
  margin: 40px 0 8px;
  font-weight: 900;
  font-size: clamp(22px, 5vw, 28px);
  line-height: 1.15;
}
.explain h2:first-child {
  margin-top: 0;
}
.explain p,
.explain li {
  color: #c9ccd6;
  font-size: 17px;
}
.explain b,
.explain strong {
  color: var(--ink);
}
.explain .y {
  color: var(--yellow);
}
.explain .r {
  color: var(--red);
}
.explain ul {
  padding-left: 1.1em;
}
.explain code {
  font: 500 0.92em var(--mono);
  color: var(--ink);
}
.facts {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 4px;
  font-size: 15px;
}
.facts th,
.facts td {
  text-align: left;
  padding: 8px 10px 8px 0;
  border-bottom: 1px solid var(--line);
}
.facts th {
  color: var(--dim);
  font-weight: 500;
  font-size: 13px;
}
.facts td.n {
  font: 800 15px var(--mono);
  white-space: nowrap;
}
.back {
  margin-top: 36px;
}
