/* Negative World — paper and ink. Light: ink on warm paper; dark: paper on ink.
   One geometric sans, generous space, thin lines, springy motion on transform and
   opacity only. Colour is never the only signal: medals have letters in their
   labels, stars have shapes, keys and doors match by shape. */

:root {
  --paper: #f4f2ee;
  --ink: #141414;
  --bg: var(--paper);
  --fg: var(--ink);
  --muted: #5b574f;
  --line: rgba(20, 20, 20, 0.14);
  --line-2: rgba(20, 20, 20, 0.28);
  --card: #fbfaf7;
  --card-2: #ebe8e2;
  --shadow: 0 1px 2px rgba(20, 20, 20, 0.06), 0 10px 30px -12px rgba(20, 20, 20, 0.28);
  --btn-bg: var(--ink);
  --btn-fg: var(--paper);
  --focus: #2e86de;
  --gold: #f5c542;
  --silver: #b8bcc4;
  --bronze: #c27b4a;
  --danger: #b4321f;
  --ca-accent: #262626;
  --font: 'Avenir Next', Avenir, Futura, 'Century Gothic', 'Segoe UI', 'Helvetica Neue', Roboto, system-ui, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --spring: cubic-bezier(0.2, 1.3, 0.35, 1);
  --ease: cubic-bezier(0.3, 0.7, 0.2, 1);
  --cols: 5;
  --cell: clamp(54px, min(13.5vw, 10.5vh), 88px);
  color-scheme: light;
}
[data-theme='dark'] {
  --bg: #141414;
  --fg: #e6e3dd;
  --muted: #aaa59c;
  --line: rgba(230, 227, 221, 0.14);
  --line-2: rgba(230, 227, 221, 0.3);
  --card: #1d1d1c;
  --card-2: #292927;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 14px 34px -12px rgba(0, 0, 0, 0.7);
  --btn-bg: #e6e3dd;
  --btn-fg: #141414;
  --focus: #6fb0f0;
  --danger: #f08d7c;
  --ca-accent: #3b3b39;
  color-scheme: dark;
}

/* before the app has read the player's choice: the system's */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #141414;
    --fg: #e6e3dd;
    --muted: #aaa59c;
    --line: rgba(230, 227, 221, 0.14);
    --line-2: rgba(230, 227, 221, 0.3);
    --card: #1d1d1c;
    --card-2: #292927;
    --btn-bg: #e6e3dd;
    --btn-fg: #141414;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  overflow: hidden;
  overscroll-behavior: none;
}
button,
select,
input {
  font: inherit;
  color: inherit;
}
h1,
h2,
h3,
p {
  margin: 0;
}
[hidden] {
  display: none !important;
}
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.i {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.i.big {
  width: 34px;
  height: 34px;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.85rem;
}

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border: 1.5px solid var(--line-2);
  border-radius: 14px;
  background: transparent;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.28s var(--spring), background-color 0.15s, border-color 0.15s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active {
  transform: scale(0.96);
  transition-duration: 0.08s;
}
.btn.primary {
  background: var(--btn-bg);
  color: var(--btn-fg);
  border-color: var(--btn-bg);
}
.btn.big {
  min-height: 54px;
  padding: 0 26px;
  font-size: 1.05rem;
}
.btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}
.btn.ghost {
  border-color: transparent;
}
.btn[disabled] {
  opacity: 0.4;
  cursor: default;
}
@media (hover: hover) {
  .btn:hover {
    border-color: var(--fg);
  }
  .btn.primary:hover {
    background: color-mix(in srgb, var(--btn-bg) 86%, var(--btn-fg));
  }
  .icon-btn:hover:not([disabled]) {
    background: var(--line);
  }
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  transition: transform 0.28s var(--spring), background-color 0.15s, opacity 0.2s;
  touch-action: manipulation;
}
.icon-btn:active {
  transform: scale(0.92);
  transition-duration: 0.08s;
}
.icon-btn[disabled] {
  opacity: 0.25;
  cursor: default;
}

/* -------------------------------------------------------------------- boot */
.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 50;
}
body:not(.booting) .boot {
  display: none;
}
.boot-sq {
  width: 54px;
  height: 54px;
  border: 2px solid var(--fg);
  border-radius: 4px;
  overflow: hidden;
  animation: boot-flip 1.4s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
.boot-sq i {
  display: block;
  height: 50%;
  margin-top: 50%;
  background: var(--fg);
}
@keyframes boot-flip {
  0%,
  20% {
    transform: rotate(0);
  }
  60%,
  100% {
    transform: rotate(180deg);
  }
}

/* ----------------------------------------------------------------- landing */
.landing {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  background: var(--bg);
  padding-bottom: calc(28px + var(--sab));
}
.hero {
  position: relative;
  height: clamp(220px, 46vh, 520px);
  background: var(--paper);
  overflow: hidden;
}
.hero canvas,
.hero-stills canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}
.hero-stills canvas {
  opacity: 0;
  transition: opacity 0.9s ease;
}
.hero-stills canvas.on {
  opacity: 1;
}
.landing-body {
  max-width: 620px;
  margin: 0 auto;
  padding: 26px calc(22px + var(--sar)) 0 calc(22px + var(--sal));
  display: grid;
  gap: 22px;
}
.landing-brand {
  display: flex;
  gap: 16px;
  align-items: center;
}
.landing-brand img {
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.landing-brand h1 {
  font-size: clamp(1.9rem, 6vw, 2.6rem);
  letter-spacing: -0.02em;
  line-height: 1.05;
}
.slogan {
  font-size: 1.15rem;
  color: var(--muted);
  margin-top: 4px;
}
.points {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
}
.points li {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.points .i {
  width: 30px;
  height: 30px;
  margin-top: 2px;
}
.points b {
  display: block;
  font-size: 1.02rem;
}
.points span {
  color: var(--muted);
  font-size: 0.95rem;
}
.note {
  font-size: 0.93rem;
  color: var(--muted);
  border-left: 3px solid var(--line-2);
  padding-left: 12px;
}
#landing-cta {
  justify-self: start;
}
@media (max-width: 640px) {
  .hero {
    height: clamp(200px, 36vh, 360px);
  }
  /* the way in stays at hand while the page scrolls */
  #landing-cta {
    position: sticky;
    bottom: calc(14px + var(--sab));
    justify-self: stretch;
    box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.55);
    z-index: 1;
  }
}

/* ------------------------------------------------------------------- shell */
.shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + var(--sat)) calc(10px + var(--sar)) 8px calc(14px + var(--sal));
  border-bottom: 1px solid var(--line);
  min-height: 60px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-icon {
  border-radius: 9px;
  flex: none;
}
.brand-text {
  min-width: 0;
}
.brand h1 {
  font-size: 1.12rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand p {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}
.chip-slot {
  margin-left: 4px;
  min-width: 40px;
}
@media (max-width: 480px) {
  .brand p {
    display: none;
  }
  /* statistics stay in the profile menu; the title keeps its room */
  #open-stats {
    display: none;
  }
}
@media (max-width: 400px) {
  .brand-icon {
    display: none;
  }
  .brand h1 {
    font-size: 1.04rem;
  }
}
@media (max-width: 350px) {
  /* help stays in the profile menu */
  #open-help {
    display: none;
  }
  .bar-tools .icon-btn {
    width: 38px;
  }
  .bar {
    padding-left: calc(10px + var(--sal));
  }
}

/* --------------------------------------------------------------------- map */
.map {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 var(--sar) var(--sab) var(--sal);
}
.map-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 12px 4px;
}
.world-title {
  text-align: center;
  min-width: 0;
}
.world-title h2 {
  font-size: clamp(1.15rem, 4.5vw, 1.5rem);
  letter-spacing: -0.01em;
}
.world-counts {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 4px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
}
.world-counts > span {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.world-counts .i {
  width: 17px;
  height: 17px;
  fill: var(--gold);
  stroke: var(--fg);
  stroke-width: 1.4;
}
.dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid var(--fg);
}
.dot.m3 {
  background: var(--gold);
}
.pager {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: pan-y;
}
.track {
  display: flex;
  height: 100%;
  transform: translate3d(calc(var(--page, 0) * -100% + var(--drag, 0px)), 0, 0);
  transition: transform 0.55s var(--spring);
  will-change: transform;
}
.track.dragging,
.track.instant {
  transition: none;
}
.page {
  position: relative;
  flex: 0 0 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 10px 8px 14px;
}
.page .path {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.page .path path {
  fill: none;
  stroke: var(--line-2);
  stroke-width: 2;
  stroke-dasharray: 2 7;
  stroke-linecap: round;
}
.page .path path.done {
  stroke: var(--fg);
  stroke-dasharray: none;
  opacity: 0.32;
}
.grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  gap: clamp(12px, 3.2vw, 30px) clamp(10px, 4vw, 40px);
  transition: opacity 0.4s, filter 0.4s;
}
.lvl {
  grid-row: var(--r);
  grid-column: var(--c);
  position: relative;
  display: grid;
  place-items: center;
  border: 2px solid var(--fg);
  border-radius: 12px;
  background: var(--bg);
  cursor: pointer;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: transform 0.3s var(--spring), box-shadow 0.25s;
  touch-action: manipulation;
}
.lvl .num {
  font-size: clamp(1rem, 4.2vw, 1.35rem);
  margin-top: -6px;
}
.lvl.done {
  background: var(--fg);
  color: var(--bg);
}
.lvl.locked {
  color: var(--muted);
  border: 1.5px dashed var(--line-2);
  cursor: default;
}
.lvl.locked .i {
  width: 18px;
  height: 18px;
}
.lvl.open::after {
  content: '';
  position: absolute;
  inset: -6px;
  border: 2px solid var(--fg);
  border-radius: 16px;
  animation: lvl-pulse 2.2s var(--ease) infinite;
  pointer-events: none;
}
@keyframes lvl-pulse {
  0% {
    opacity: 0.55;
    transform: scale(0.94);
  }
  70%,
  100% {
    opacity: 0;
    transform: scale(1.12);
  }
}
.lvl-time {
  position: absolute;
  bottom: 5px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(0.56rem, 2.2vw, 0.68rem);
  font-weight: 600;
  opacity: 0.85;
}
.lvl-medal {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid var(--bg);
}
.lvl-medal.m1 {
  background: var(--bronze);
}
.lvl-medal.m2 {
  background: var(--silver);
}
.lvl-medal.m3 {
  background: var(--gold);
}
.lvl-star {
  position: absolute;
  top: 3px;
  left: 4px;
  opacity: 0.45;
}
.lvl-star .i {
  width: 14px;
  height: 14px;
  stroke-width: 1.6;
}
.lvl-star.got {
  opacity: 1;
}
.lvl-star.got .i {
  fill: var(--gold);
  stroke: currentColor;
}
@media (hover: hover) {
  .lvl:not(.locked):hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 18px -10px rgba(20, 20, 20, 0.45);
  }
}
.lvl:not(.locked):active {
  transform: scale(0.95);
  transition-duration: 0.08s;
}
.page.locked .grid {
  opacity: 0.18;
  filter: grayscale(1);
}
.page-lock {
  position: absolute;
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 22px 26px;
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 80%;
}
.page.opening .page-lock {
  display: grid !important;
  animation: lock-open 1.2s var(--ease) forwards;
}
.page.opening .grid {
  animation: grid-in 1.2s var(--ease) forwards;
}
@keyframes lock-open {
  0% {
    transform: scale(1);
  }
  25% {
    transform: scale(1.08) rotate(-4deg);
  }
  45% {
    transform: scale(1.08) rotate(4deg);
  }
  100% {
    transform: scale(0.6);
    opacity: 0;
  }
}
@keyframes grid-in {
  from {
    opacity: 0.18;
    filter: grayscale(1);
  }
  to {
    opacity: 1;
    filter: none;
  }
}
.map-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
}
.worlds {
  display: flex;
  gap: 4px;
}
.world-tab {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1.5px solid var(--line-2);
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  transition: transform 0.3s var(--spring), background-color 0.2s;
}
.world-tab[aria-selected='true'] {
  border-color: var(--fg);
  box-shadow: inset 0 -3px 0 var(--fg);
}
.world-tab.done {
  background: var(--fg);
  color: var(--bg);
}
.world-tab.gold {
  border: 2.5px solid var(--gold);
}
.world-tab.locked {
  opacity: 0.4;
}
.tab-star {
  display: none;
  position: absolute;
  top: -6px;
  right: -6px;
}
.tab-star .i {
  width: 16px;
  height: 16px;
  fill: var(--gold);
  stroke: var(--fg);
}
.world-tab.stars .tab-star {
  display: block;
}
.world-done {
  position: fixed;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  z-index: 20;
  pointer-events: none;
}
.world-done-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 22px;
  border-radius: 18px;
  background: var(--fg);
  color: var(--bg);
  font-size: 1.2rem;
  font-weight: 700;
  box-shadow: var(--shadow);
  animation: rise-in 0.5s var(--spring) both;
}
.world-done.gone .world-done-card {
  animation: fade-out 0.45s ease forwards;
}
.lock-open {
  width: 28px;
  height: 28px;
}
@media (max-width: 520px) {
  .map-foot {
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .worlds {
    justify-content: center;
  }
}
@media (max-height: 520px) and (orientation: landscape) {
  .map-head {
    padding-top: 6px;
  }
  .map-foot {
    padding-top: 6px;
    padding-bottom: 8px;
  }
  .bar {
    min-height: 50px;
    padding-top: calc(4px + var(--sat));
    padding-bottom: 4px;
  }
  :root {
    --cell: clamp(46px, 12vh, 64px);
  }
}

/* ------------------------------------------------------------------- sheets */
dialog.sheet {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0 auto;
  width: 100%;
  max-width: 100%;
  max-height: calc(92dvh - var(--sat));
  overflow-y: auto;
  padding: 18px calc(20px + var(--sar)) calc(20px + var(--sab)) calc(20px + var(--sal));
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--card);
  color: var(--fg);
  box-shadow: var(--shadow);
  animation: sheet-up 0.42s var(--spring) both;
  overscroll-behavior: contain;
}
dialog.sheet::backdrop {
  background: rgba(10, 10, 10, 0.38);
  animation: fade-in 0.3s ease both;
}
dialog.sheet.closing {
  animation: sheet-down 0.24s ease-in both;
}
dialog.sheet.closing::backdrop {
  animation: fade-out 0.24s ease both;
}
@media (min-width: 640px) {
  dialog.sheet {
    inset: 0;
    margin: auto;
    width: min(480px, calc(100% - 48px));
    max-height: min(86dvh, 820px);
    border-radius: 22px;
    padding: 22px 26px 24px;
    animation-name: sheet-pop;
  }
  dialog.sheet.wide {
    width: min(660px, calc(100% - 48px));
  }
  dialog.sheet.closing {
    animation-name: sheet-unpop;
  }
}
dialog.sheet.small {
  max-width: 420px;
}
@keyframes sheet-up {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}
@keyframes sheet-down {
  to {
    transform: translateY(40px);
    opacity: 0;
  }
}
@keyframes sheet-pop {
  from {
    transform: translateY(18px) scale(0.97);
    opacity: 0;
  }
}
@keyframes sheet-unpop {
  to {
    transform: translateY(12px) scale(0.98);
    opacity: 0;
  }
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes fade-out {
  to {
    opacity: 0;
  }
}
@keyframes rise-in {
  from {
    transform: translateY(14px) scale(0.96);
    opacity: 0;
  }
}
.sheet h2 {
  font-size: 1.32rem;
  letter-spacing: -0.01em;
}
.sheet h3 {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 18px 0 8px;
}
.sheet-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}
.sheet-head h2 {
  flex: 1;
  padding-top: 8px;
}
.sheet-head .sub {
  color: var(--muted);
  padding-top: 12px;
  font-size: 0.92rem;
}
.sheet-head .close {
  margin: -2px -8px 0 auto;
}
.actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  flex-wrap: wrap;
}
.actions .btn {
  flex: 1 1 auto;
}
.actions.three .btn {
  flex: 1 1 0;
  padding: 0 10px;
  min-width: 0;
}
@media (max-width: 440px) {
  /* the way on gets its own row; map and retry share the next */
  .actions.three {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .actions.three .btn.primary {
    grid-column: 1 / -1;
    order: -1;
  }
}
.stack {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}
.stack .btn {
  justify-content: flex-start;
}
.pause-sheet {
  text-align: left;
}
@media (max-width: 639px) {
  .pause-sheet {
    border-radius: 22px 22px 0 0;
  }
}

/* level detail */
.detail-best {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--card-2);
}
.label {
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.big-time {
  font-size: 1.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.limits {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.limits li {
  display: flex;
  gap: 10px;
  align-items: center;
}
.limits .gap {
  width: 20px;
}
.medal {
  display: inline-block;
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--fg);
  background: transparent;
  position: relative;
}
.medal.m1 {
  background: var(--bronze);
}
.medal.m2 {
  background: var(--silver);
}
.medal.m3 {
  background: var(--gold);
}
.medal.big {
  width: 52px;
  height: 52px;
  border-width: 3px;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.12), inset 0 4px 0 rgba(255, 255, 255, 0.35);
}
.medal.big.m0 {
  border-style: dashed;
  opacity: 0.5;
  box-shadow: none;
}
.mini-star {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  flex: none;
}
.mini-star .i {
  width: 18px;
  height: 18px;
  fill: var(--gold);
  stroke: var(--fg);
  stroke-width: 1.4;
}
.mini-star.off .i {
  fill: none;
  opacity: 0.45;
}
.mini-star.off:empty::before {
  content: '';
  width: 12px;
  height: 12px;
}
.friends-box {
  margin-top: 4px;
}
.friends {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}
.friends li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 12px;
  min-height: 46px;
}
.friends li.me {
  background: var(--fg);
  color: var(--bg);
  position: sticky;
  bottom: 0;
  top: 0;
  z-index: 1;
}
.friends li.me .medal {
  border-color: var(--bg);
}
.friends li.me .mini-star .i {
  stroke: var(--bg);
}
.f-rank {
  width: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  flex: none;
}
.f-name {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.f-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.f-col {
  display: grid;
  min-width: 0;
}
.f-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.f-line small {
  opacity: 0.75;
  flex: none;
}
.f-sub {
  display: flex;
  gap: 10px;
}
.f-score .points {
  font-size: 1.1rem;
}
.f-score .unit {
  opacity: 0.7;
  font-size: 0.75rem;
}
.avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  font-size: 0.82rem;
  font-weight: 700;
  flex: none;
}
.heart {
  color: #e4572e;
  flex: none;
}
.f-score {
  display: flex;
  align-items: center;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  flex: none;
}
.f-meta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.82rem;
  opacity: 0.85;
}
.f-meta .i {
  width: 14px;
  height: 14px;
  fill: var(--gold);
  stroke: currentColor;
}
.f-meta .dot {
  width: 10px;
  height: 10px;
  border-color: currentColor;
}
.empty {
  display: grid;
  gap: 12px;
  justify-items: start;
  padding: 10px 2px;
  color: var(--muted);
}
.empty .btn {
  color: var(--fg);
}
.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  background: var(--card-2);
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 8px;
}

/* the end of a level */
.end-sheet {
  text-align: center;
}
.end-sheet h2 {
  margin-top: 4px;
}
.end-time {
  font-size: clamp(2.6rem, 12vw, 3.6rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-top: 8px;
}
.record {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 12px;
  border-radius: 99px;
  background: var(--fg);
  color: var(--bg);
  font-weight: 700;
  font-size: 0.9rem;
  animation: rise-in 0.4s var(--spring) 0.45s both;
}
.record.first {
  background: transparent;
  color: var(--fg);
  border: 1.5px solid var(--line-2);
}
.end-medal {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 16px 0 6px;
  font-weight: 600;
}
.end-medal .medal {
  animation: medal-drop 0.4s cubic-bezier(0.3, 1.6, 0.5, 1) 0.2s both;
}
@keyframes medal-drop {
  from {
    transform: translateY(-46px) scale(0.6);
    opacity: 0;
  }
}
.end-sheet.reduced .end-medal .medal {
  animation: fade-in 0.3s ease 0.1s both;
}
.end-rows {
  display: flex;
  justify-content: center;
  gap: 26px;
  margin: 10px 0 0;
}
.end-rows div {
  display: grid;
}
.end-rows dt {
  font-size: 0.78rem;
  color: var(--muted);
}
.end-rows dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.end-rows .better dd {
  color: #2b8a3e;
}
[data-theme='dark'] .end-rows .better dd {
  color: #6fd08a;
}
.end-star {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  margin-top: 12px;
}
.end-rank {
  margin-top: 8px;
  min-height: 1.4em;
}

/* leaderboard */
.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: var(--card-2);
  margin-bottom: 14px;
}
.tab {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
  padding: 0 8px;
}
.tab.on {
  background: var(--fg);
  color: var(--bg);
}
.picker {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 10px;
}
.picker select,
.row select {
  flex: 1;
  min-height: 44px;
  border: 1.5px solid var(--line-2);
  border-radius: 12px;
  background: var(--bg);
  padding: 0 12px;
  min-width: 0;
}
.board-body {
  max-height: 56dvh;
  overflow-y: auto;
}

/* statistics */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.tile {
  padding: 14px;
  border-radius: 16px;
  background: var(--card-2);
  display: grid;
  gap: 6px;
  align-content: start;
}
.tile .value {
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.tile .value:empty {
  display: none;
}
.medal-row {
  display: flex;
  gap: 14px;
}
.medal-row span {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-size: 1.2rem;
}

/* settings */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 52px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.row.col {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 12px 0;
}
.row-label {
  display: flex;
  justify-content: space-between;
  font-weight: 500;
}
.row-label output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.row.buttons {
  flex-wrap: wrap;
  justify-content: flex-start;
  border-bottom: 0;
  padding-top: 14px;
}
.row select {
  flex: 0 1 200px;
}
.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--card-2);
}
.seg-btn {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  padding: 0 6px;
  transition: background-color 0.2s, color 0.2s;
  line-height: 1.15;
}
.seg-btn[aria-checked='true'] {
  background: var(--fg);
  color: var(--bg);
}
input.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 52px;
  height: 32px;
  border-radius: 99px;
  background: var(--card-2);
  border: 1.5px solid var(--line-2);
  position: relative;
  cursor: pointer;
  transition: background-color 0.2s;
  margin: 0;
}
input.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: var(--fg);
  transition: transform 0.3s var(--spring);
}
input.switch:checked {
  background: var(--fg);
}
input.switch:checked::after {
  background: var(--bg);
  transform: translateX(20px);
}
input[type='range'] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 30px;
  background: transparent;
  margin: 0;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(to right, var(--fg) var(--v, 50%), var(--card-2) var(--v, 50%));
}
input[type='range']::-moz-range-track {
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(to right, var(--fg) var(--v, 50%), var(--card-2) var(--v, 50%));
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--bg);
  border: 2.5px solid var(--fg);
}
input[type='range']::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  border: 2.5px solid var(--fg);
}
.about {
  margin-top: 8px;
  display: grid;
  gap: 10px;
  justify-items: start;
}
.about-row {
  display: flex;
  gap: 12px;
  align-items: center;
}
.about-row img {
  border-radius: 10px;
}

/* help */
.help-body h3:first-child {
  margin-top: 4px;
}
.keytable,
.gestures,
.score-list,
.modes {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.keytable li,
.gestures li,
.score-list li {
  display: flex;
  align-items: center;
  gap: 12px;
}
.keys {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  min-width: 132px;
}
kbd {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
  border-radius: 8px;
  border: 1.5px solid var(--line-2);
  border-bottom-width: 3px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
}
.g {
  position: relative;
  width: 54px;
  height: 36px;
  border-radius: 10px;
  background: var(--card-2);
  flex: none;
  overflow: hidden;
}
.g i {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--fg);
}
.g-tap i {
  animation: g-tap 1.6s ease-in-out infinite;
}
.g-click i {
  border-radius: 3px;
  animation: g-tap 1.6s ease-in-out infinite;
}
.g-swipe i {
  animation: g-swipe 1.6s ease-in-out infinite;
}
.g-two i:first-child {
  margin-left: -15px;
  animation: g-tap 1.6s ease-in-out infinite;
}
.g-two i:last-child {
  margin-left: 1px;
  animation: g-tap 1.6s ease-in-out infinite;
}
@keyframes g-tap {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.35;
  }
  40% {
    transform: scale(0.7);
    opacity: 1;
  }
}
@keyframes g-swipe {
  0% {
    transform: translateX(-16px);
    opacity: 0;
  }
  30% {
    opacity: 1;
  }
  80% {
    transform: translateX(16px);
    opacity: 1;
  }
  100% {
    transform: translateX(18px);
    opacity: 0;
  }
}
.help-body .note {
  margin-top: 16px;
}
.el-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}
.el-card {
  margin: 0;
  border-radius: 16px;
  background: var(--card-2);
  overflow: hidden;
  display: grid;
}
.el-demo {
  width: 100%;
  height: 128px;
  display: block;
  background: var(--paper);
}
.el-card figcaption {
  padding: 10px 12px 12px;
  display: grid;
  gap: 2px;
  font-size: 0.9rem;
}
.el-card figcaption span {
  color: var(--muted);
}
.score-list .i {
  width: 22px;
  height: 22px;
}
.score-list .medals {
  display: flex;
  gap: 2px;
  flex: none;
}
.score-list .medals .medal {
  width: 14px;
  height: 14px;
}
.modes li {
  display: flex;
  gap: 14px;
  align-items: center;
}
.modes li div {
  display: grid;
}
.modes li span:not(.mode-swatch) {
  color: var(--muted);
  font-size: 0.92rem;
}
.mode-swatch {
  display: flex;
  width: 66px;
  height: 40px;
  border-radius: 10px;
  overflow: hidden;
  flex: none;
  border: 1.5px solid var(--line-2);
}
.mode-swatch i {
  flex: 1;
  background: var(--paper);
}
.mode-swatch i:nth-child(2) {
  background: var(--ink);
}
.mode-swatch i:nth-child(3) {
  background: #8a8a8a;
}
.mode-contrast .mode-swatch i:nth-child(2) {
  box-shadow: inset 3px 0 0 #7a7a7a, inset -3px 0 0 #7a7a7a;
}
.mode-pattern .mode-swatch i:nth-child(3) {
  background: repeating-linear-gradient(45deg, #8a8a8a 0 4px, #5f5f5f 4px 6px);
}

/* --------------------------------------------------------------------- game */
.game {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--paper);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
  transition: filter 0.3s ease, opacity 0.3s ease;
}
.game.paused #stage {
  filter: blur(5px);
  opacity: 0.55;
}
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: calc(6px + var(--sat)) calc(8px + var(--sar)) 0 calc(14px + var(--sal));
  height: calc(58px + var(--sat));
  pointer-events: none;
  color: var(--ink);
}
.hud > * {
  pointer-events: auto;
}
.hud .paper,
.hud-keys.paper,
.hud-timer.paper,
.hud-star.paper,
.hud-btn.paper {
  color: #e6e3dd;
}
.hud-keys,
.hud-timer,
.hud-star,
.hud-btn {
  transition: color 0.06s linear;
}
.hud .none {
  visibility: hidden;
}
.hud-keys {
  display: flex;
  gap: 6px;
  justify-self: start;
  pointer-events: none;
}
.key-slot {
  position: relative;
  width: 22px;
  height: 22px;
}
.key-slot svg {
  position: absolute;
  inset: 0;
  transition: opacity 0.2s, transform 0.3s var(--spring);
}
.key-slot svg:last-child {
  opacity: 0;
  transform: scale(0.4);
}
.key-slot.held svg:last-child {
  opacity: 1;
  transform: scale(1);
}
.key-slot.used svg:first-child {
  opacity: 0.3;
}
.hud-timer {
  font-weight: 700;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  pointer-events: none;
}
.hud-timer.off {
  visibility: hidden;
}
.hud-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
}
.hud-star {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  pointer-events: none;
}
.hud-star .i {
  width: 22px;
  height: 22px;
  transition: fill 0.2s, transform 0.4s var(--spring);
}
.hud-star.got .i {
  fill: var(--gold);
  transform: scale(1.12);
}
.hud-btn {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
  transition: transform 0.28s var(--spring), color 0.06s linear;
  touch-action: manipulation;
}
.hud-btn .i {
  width: 26px;
  height: 26px;
  stroke-width: 2.2;
}
.hud-btn:active {
  transform: scale(0.9);
}
.hud-btn.soft {
  animation: soft-in 1.2s ease both;
}
@keyframes soft-in {
  0% {
    opacity: 0;
  }
  40% {
    opacity: 0.85;
  }
  100% {
    opacity: 0.6;
  }
}
.first-hint {
  position: absolute;
  left: 50%;
  bottom: calc(22px + var(--sab));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 8px 28px -10px rgba(20, 20, 20, 0.5), 0 0 0 1.5px rgba(20, 20, 20, 0.12);
  color: var(--ink);
  pointer-events: none;
  animation: hint-pulse 1.8s ease-in-out infinite;
  transition: opacity 0.35s;
}
.first-hint.gone {
  opacity: 0;
  animation: none;
}
.first-hint .cap {
  display: grid;
  place-items: center;
  width: 92px;
  height: 34px;
  border: 2px solid currentColor;
  border-bottom-width: 4px;
  border-radius: 9px;
  font-size: 1.1rem;
}
.first-hint .i {
  width: 36px;
  height: 36px;
}
@media (pointer: coarse) {
  .first-hint .cap {
    display: none;
  }
}
@media (pointer: fine) {
  .first-hint .i {
    display: none;
  }
}
@keyframes hint-pulse {
  0%,
  100% {
    transform: translateX(-50%) scale(1);
  }
  50% {
    transform: translateX(-50%) scale(0.92);
  }
}
.turn-hint {
  position: absolute;
  left: 50%;
  bottom: calc(24px + var(--sab));
  transform: translateX(-50%);
  color: var(--ink);
  opacity: 0;
  animation: turn-hint 4s ease both;
  pointer-events: none;
}
.turn-hint .i {
  width: 40px;
  height: 40px;
}
@keyframes turn-hint {
  10%,
  70% {
    opacity: 0.6;
  }
  30% {
    transform: translateX(-50%) rotate(-90deg);
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) rotate(-90deg);
  }
}
body.in-game .shell {
  visibility: hidden;
}

/* ------------------------------------------------------------------- ending */
.ending {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--paper);
  color: var(--ink);
  transition: color 0.6s;
}
.ending.dark-half {
  color: #e6e3dd;
}
.ending canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.ending-line {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(8% + var(--sab));
  text-align: center;
  font-size: clamp(1.3rem, 5vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  padding: 0 20px;
  opacity: 0;
}
.ending-line.in {
  animation: ending-line 4s ease both;
}
@keyframes ending-line {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }
  15%,
  80% {
    opacity: 1;
    transform: none;
  }
  100% {
    opacity: 0;
  }
}
.ending-skip {
  position: absolute;
  top: calc(12px + var(--sat));
  right: calc(12px + var(--sar));
  color: inherit;
}

/* ------------------------------------------------------------ reduced motion */
html.reduced *,
html.reduced *::before,
html.reduced *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.15s !important;
}
html.reduced .track {
  transition: opacity 0.2s !important;
}
html.reduced .lvl.open::after {
  animation: none;
  opacity: 0.35;
  transform: none;
}
html.reduced .boot-sq {
  animation: none;
}
html.reduced dialog.sheet {
  animation: fade-in 0.2s ease both !important;
}
html.reduced dialog.sheet.closing {
  animation: fade-out 0.15s ease both !important;
}
html.reduced .ending-line.in {
  animation: fade-in 0.4s ease both !important;
  opacity: 1;
}
@media (prefers-reduced-motion: reduce) {
  .boot-sq {
    animation: none;
  }
}
