/**
 * KTL demo widgets: the nine interactive simulators.
 *
 * Markup in parts/demos/*.php, behaviour in js/demos.js. Ported from the app's
 * Tailwind classes onto the Cartridge tokens and lip system in ktl.css, so every
 * colour, depth and press here is the same one the rest of the site uses.
 * Class names start kd- so nothing collides with the page styles around a demo.
 */

/* ── Shared ──────────────────────────────────────────────────────────────── */

.ktl-demo {
  width: 100%;
  min-width: 0;
  color: var(--foreground);
}

/* :where() keeps this reset at zero specificity, so every kd- class below wins over
   it. As plain `.ktl-demo button` it outranked .kd-btn and stripped the demo
   buttons' weight, size and padding. */
:where(.ktl-demo) button {
  font: inherit;
  color: inherit;
  text-align: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.ktl-demo button:disabled {
  cursor: default;
  opacity: 0.55;
}

.ktl-demo [hidden] {
  display: none !important;
}

.ktl-widget-error {
  padding: 12px;
  border: 2px dashed var(--commit);
  font-family: var(--font-mono);
  font-size: 12px;
}

.kd-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.kd-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.kd-row--center {
  align-items: center;
}

.kd-kicker {
  font-weight: 700;
  font-size: 9.5px;
  line-height: 1.4;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.kd-kicker--tight {
  letter-spacing: 0.14em;
}

.kd-kicker--9 {
  font-size: 9px;
  letter-spacing: 0.06em;
}

.kd-kicker--10 {
  font-size: 10px;
  letter-spacing: 0.15em;
}

.kd-kicker--11 {
  font-size: 11px;
  letter-spacing: 0.08em;
}

.kd-mono {
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.5;
  color: var(--muted);
  text-transform: uppercase;
}

.kd-mono--9 {
  font-size: 9.5px;
}

.kd-mono--11 {
  font-size: 11px;
}

.kd-note {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.kd-caption {
  margin-top: 12px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
}

.kd-xp {
  color: var(--xp);
}

.kd-loot {
  color: var(--loot);
}

.kd-commit {
  color: var(--commit);
}

.kd-muted {
  color: var(--muted);
}

.kd-pop {
  animation: ktl-pop 0.3s ease-out both;
}

.kd-btn {
  display: block;
  width: 100%;
  padding: 14px;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ktl-demo .kd-btn {
  text-align: center;
}

.kd-btn--12 {
  font-size: 12px;
  letter-spacing: 0.06em;
}

.kd-btn--inline {
  display: inline-block;
  width: auto;
  padding: 12px 16px;
  font-size: 12px;
  letter-spacing: 0.06em;
}

.ktl-demo .kd-btn--commit {
  background: var(--commit);
  --lip-colour: var(--commit-lip);
}

.ktl-demo .kd-btn--xp {
  background: var(--xp);
  color: var(--void);
  --lip-colour: var(--xp-lip);
}

.ktl-demo .kd-btn--panel {
  background: var(--panel);
  --lip-colour: var(--void);
}

.ktl-demo .kd-btn--ghost {
  background: var(--background);
  color: var(--muted);
}

@media (hover: hover) {
  .ktl-demo .kd-btn--ghost:hover {
    color: var(--foreground);
  }

  .ktl-demo .kd-btn--panel:hover {
    background: var(--coop);
  }
}

.kd-panel {
  background: var(--panel);
  padding: 22px;
}

.kd-panel--24 {
  padding: 24px;
}

.kd-card {
  background: var(--void);
  padding: 16px;
  --lip-colour: var(--panel);
}

.kd-card--coop {
  background: var(--coop);
  --lip-colour: var(--coop-lip);
}

.kd-card--xp {
  background: var(--xp);
  color: var(--void);
  --lip-colour: var(--xp-lip);
}

/* ── Rate Cuteness ───────────────────────────────────────────────────────── */

.kd-boost {
  max-width: 380px;
}

.kd-boost__frame {
  background: var(--void);
  padding: 12px;
  --lip-colour: var(--panel);
}

.kd-boost__screen {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--background);
  padding: 16px;
}

.kd-boost__card {
  background: var(--void);
  padding: 16px;
  text-align: center;
  --lip-colour: var(--panel);
}

.kd-boost__amount {
  margin-top: 4px;
  font-weight: 700;
  font-size: 56px;
  line-height: 1;
  color: var(--xp);
  font-variant-numeric: tabular-nums;
}

.kd-boost__xp {
  display: inline-block;
  margin-top: 12px;
  background: var(--commit);
  padding: 6px 10px;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.06em;
}

.kd-boost__sent {
  margin-top: 12px;
  animation: ktl-pop 0.3s ease-out both;
}

.kd-boost__emoji {
  font-size: 24px;
  line-height: 1;
}

.kd-boost__slider {
  background: var(--loot);
  color: var(--void);
  padding: 12px;
  --lip-colour: var(--loot-lip);
}

.kd-range {
  --fill: 66.67%;
  display: block;
  width: 100%;
  height: 16px;
  margin: 12px 0 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.kd-range::-webkit-slider-runnable-track {
  height: 6px;
  background: linear-gradient(to right, var(--void) var(--fill), #ffffff var(--fill));
}

.kd-range::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--void);
  -webkit-appearance: none;
  appearance: none;
}

.kd-range::-moz-range-track {
  height: 6px;
  background: #ffffff;
}

.kd-range::-moz-range-progress {
  height: 6px;
  background: var(--void);
}

.kd-range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: var(--void);
}

.kd-range:focus-visible {
  outline: 2px solid var(--void);
  outline-offset: 4px;
}

/* ── Talking Hearts ──────────────────────────────────────────────────────── */

.kd-question {
  margin-top: 8px;
  font-size: 18px;
  line-height: 1.35;
  font-weight: 700;
}

.kd-answer {
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.5;
}

.kd-reward {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--xp);
  color: var(--void);
  padding: 12px;
  --lip-colour: var(--xp-lip);
}

.ktl-demo .kd-envelope {
  display: block;
  width: 100%;
  background: var(--void);
  border: 2px dashed rgba(157, 143, 196, 0.5);
  padding: 20px;
  text-align: center;
  --lip-colour: var(--panel);
}

.kd-envelope > span {
  display: block;
}

.kd-envelope__icon {
  font-size: 20px;
  line-height: 1;
}

.kd-envelope .kd-kicker {
  margin-top: 8px;
}

.ktl-demo .kd-envelope .kd-envelope__cta {
  display: inline-block;
  margin-top: 12px;
  background: var(--commit);
  padding: 10px 16px;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ── Bond Streak ─────────────────────────────────────────────────────────── */

.kd-streak__count {
  font-weight: 700;
  font-size: 40px;
  line-height: 1.25;
}

.kd-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.kd-day {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  background: var(--void);
  font-size: 14px;
  line-height: 1;
}

.kd-body {
  font-size: 14px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.7);
}

/* ── A whole day ─────────────────────────────────────────────────────────── */

.kd-loop__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.kd-loop__controls {
  display: flex;
  flex: none;
  gap: 10px;
}

.kd-loop__steps {
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.ktl-demo .kd-step {
  display: block;
  width: 100%;
  height: 100%;
  padding: 15px;
  text-align: left;
  background: var(--background);
  border-top: 4px solid var(--kd-tint, var(--xp));
  opacity: 0.55;
  transition: opacity 0.15s;
}

.ktl-demo .kd-step.is-reached {
  opacity: 1;
}

.ktl-demo .kd-step.is-done {
  background: var(--panel-hi);
}

@media (hover: hover) {
  .ktl-demo .kd-step:hover {
    opacity: 1;
  }
}

.kd-step--xp {
  --kd-tint: var(--xp);
}

.kd-step--coop {
  --kd-tint: var(--coop);
}

.kd-step--commit {
  --kd-tint: var(--commit);
}

.kd-step--loot {
  --kd-tint: var(--loot);
}

.kd-step__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.kd-step__mark {
  font-size: 13px;
  font-weight: 700;
}

.kd-step__name {
  display: block;
  margin-top: 8px;
  font-size: 15.5px;
  font-weight: 700;
}

.kd-step__text {
  display: block;
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.8);
}

.kd-loop__status {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px;
  background: var(--void);
  padding: 17px;
}

.kd-loop__copy {
  flex: 1;
  min-width: min(230px, 100%);
}

.kd-loop__line {
  margin-top: 7px;
  font-size: 16px;
  line-height: 1.35;
  font-weight: 700;
}

.kd-loop__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin: 0;
}

.kd-loop__stats dd {
  margin: 0;
}

.kd-loop__stats .kd-meter {
  display: flex;
  gap: 3px;
  margin-top: 6px;
}

.kd-meter span {
  width: 13px;
  height: 20px;
  background: var(--panel);
}

.kd-meter span.is-on {
  background: var(--xp);
}

.kd-loop__stats .kd-stat {
  margin-top: 4px;
  font-size: 22px;
  line-height: 1.25;
  font-weight: 700;
}

/* ── Six a day ───────────────────────────────────────────────────────────── */

.kd-energy__buttons {
  margin-top: 28px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.kd-energy .kd-btn--inline {
  padding: 14px 20px;
  font-size: 11px;
  letter-spacing: 0.1em;
}

.kd-energy__tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

@media (min-width: 640px) and (max-width: 767px) {
  .kd-energy__tiles {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

.kd-cell {
  padding: 12px;
  text-align: center;
  background: var(--xp);
  color: var(--void);
  --lip-colour: var(--xp-lip);
  transition:
    background-color 0.15s,
    opacity 0.15s;
}

.kd-cell.is-spent {
  background: var(--background);
  color: var(--muted);
  opacity: 0.4;
  --lip-colour: var(--void);
}

.kd-cell__icon {
  display: block;
  font-size: 20px;
  line-height: 1;
}

.kd-cell .kd-kicker {
  display: block;
  margin-top: 6px;
}

.kd-energy__left {
  margin-top: 16px;
}

/* ── Reduce motion ───────────────────────────────────────────────────────── */

.kd-motion {
  display: flex;
  flex: 1;
  flex-direction: column;
}

.kd-motion__title {
  margin-top: 6px;
  font-size: 19px;
  font-weight: 700;
}

.ktl-demo .kd-switch {
  display: flex;
  flex: none;
  justify-content: flex-start;
  width: 52px;
  height: 28px;
  padding: 3px;
  background: var(--void);
}

.ktl-demo .kd-switch[aria-checked='true'] {
  justify-content: flex-end;
  background: var(--xp);
}

.kd-switch__knob {
  display: block;
  width: 22px;
  height: 22px;
  background: #3d2770;
}

.kd-switch[aria-checked='true'] .kd-switch__knob {
  background: var(--xp-lip);
}

.kd-motion__stage {
  margin-top: 16px;
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  background: var(--void);
  padding: 18px;
  text-align: center;
}

.kd-motion__gift {
  font-size: 40px;
  line-height: 1;
}

.kd-bounce {
  animation: kd-bounce 1.4s ease-in-out infinite;
}

@keyframes kd-bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

.kd-motion__text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.kd-motion__foot {
  margin-top: 12px;
}

/* ── Seasonal themes ─────────────────────────────────────────────────────── */

.kd-badge {
  flex: none;
  background: var(--void);
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--muted);
  text-transform: uppercase;
}

.kd-season__title {
  margin-top: 14px;
  font-size: 22px;
  font-weight: 700;
}

.kd-season__body {
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.8);
}

.kd-season__chips {
  margin-top: 16px;
  display: flex;
  gap: 7px;
}

.ktl-demo .kd-chip {
  flex: 1;
  min-width: 0;
  padding: 10px 0;
  text-align: center;
}

.kd-chip__icon {
  display: block;
  font-size: 17px;
  line-height: 1;
}

.kd-chip__label {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kd-season__preview {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
}

.kd-season__line {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 700;
}

.kd-season__bar {
  display: flex;
  flex: none;
  width: 104px;
  gap: 3px;
}

.kd-season__bar span {
  flex: 1;
  height: 9px;
}

.kd-season__note {
  margin-top: 10px;
}

/* ── Love clock ──────────────────────────────────────────────────────────── */

.kd-clock__face {
  margin-top: 16px;
  background: var(--void);
  padding: 20px;
  text-align: center;
  --lip-colour: var(--panel);
}

.kd-clock__units {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 4px 12px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.kd-clock__value {
  font-size: 20px;
}

.kd-clock__unit .kd-kicker {
  margin-left: 4px;
}

.kd-clock__since {
  margin-top: 8px;
}

.kd-clock__people {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.kd-person {
  background: var(--void);
  padding: 16px;
  text-align: center;
  --lip-colour: var(--panel);
}

.kd-person__time {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.kd-clock__send {
  margin-top: 16px;
}

.kd-clock__queued {
  margin-top: 12px;
  text-align: center;
}

.kd-clock__foot {
  margin-top: 16px;
  text-align: center;
}

/* ── Memory map ──────────────────────────────────────────────────────────── */

.kd-map {
  display: flex;
  flex-direction: column;
  height: 380px;
  overflow: hidden;
  background: var(--void);
}

.kd-map__stage {
  position: relative;
  flex: 1;
  min-height: 0;
}

.kd-map__fallback {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

/* Two classes, not one. MapLibre's stylesheet loads after this one and puts
   .maplibregl-map { position: relative } on this same element; at equal
   specificity it would win and collapse the map to zero height. */
.kd-map .kd-map__holder {
  position: absolute;
  inset: 0;
  z-index: 10;
  cursor: crosshair;
}

.kd-map__fog {
  position: absolute;
  inset: 0;
  z-index: 450;
  pointer-events: none;
}

/* The OpenStreetMap tiles wear the app's palette: a green map inside a purple
   cabinet reads as a different product. Same filter as the app. */
.map-demo-tint canvas {
  filter: grayscale(1) brightness(0.62) contrast(1.15) sepia(1) hue-rotate(218deg) saturate(2.6);
}

.kd-map__foot {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  padding: 10px 12px;
}

.kd-map__label {
  flex: 1;
}

.kd-map__label .kd-mono {
  margin-top: 2px;
}

.kd-map__percent {
  font-size: 22px;
  line-height: 1;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.kd-pin {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  font-size: 14px;
  line-height: 1;
}

.kd-pin--you {
  background: var(--commit);
  --lip-colour: var(--commit-lip);
}

.kd-pin--them {
  background: var(--xp);
  --lip-colour: var(--xp-lip);
}

.kd-pin--new {
  background: var(--loot);
  --lip-colour: var(--loot-lip);
}

/* ── Reduced motion ──────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .kd-pop,
  .kd-boost__sent,
  .kd-bounce {
    animation: none;
  }

  .ktl-demo .kd-step,
  .kd-cell {
    transition: none;
  }
}
