/* AintGames, ADL design: dark only, tone for elevation, 4px grid */

:root {
  color-scheme: dark;

  --bg: #202020;
  --s1: #2b2b2b;
  --s2: #333333;
  --nav: #1f1f1f;
  --outline: #3a3a3a;
  --nav-outline: #2f2f2f;
  --text: #ffffff;
  --silent: #959595;

  --primary: #91ac67;
  --primary-2: #667d44;
  --on-primary: #000000;
  --primary-container: #3a3e34;
  --on-primary-container: #96b06e;
  --secondary: #8c957e;
  --secondary-container: #3a3b37;
  --on-secondary-container: #9fa693;
  --tertiary: #67ac82;
  --on-tertiary: #000000;

  --error: #f2706b;
  --error-container: #493535;
  --on-error-container: #f4827e;
  --warning: #f5b84d;
  --success: #5cc98a;
  --on-status: #000000;

  --r1: 10px;
  --r2: 30px;
  --r3: 999px;

  --mono: "JetBrains Mono", ui-monospace, monospace;
  --sans: "Inter", system-ui, sans-serif;
  --display: "Plus Jakarta Sans", var(--sans);

  --ease: cubic-bezier(0.2, 0, 0, 1);
  /* stiffness 800, damping ratio 0.6 */
  --spring: linear(0, 0.036, 0.126, 0.249, 0.388, 0.527, 0.659, 0.775, 0.874, 0.952, 1.011, 1.052, 1.078, 1.092, 1.095, 1.091, 1.082, 1.07, 1.056, 1.043, 1.031, 1.02, 1.011, 1.004, 0.998, 0.995, 0.992, 0.991, 0.991, 0.991, 0.992, 0.994, 0.995, 0.996, 0.997, 0.998, 0.999, 1, 1, 1.001, 1.001);
  --spring-time: 400ms;

  --measure: 1080px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scrollbar-width: thin;
  scrollbar-color: var(--outline) transparent;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-thumb {
  background: var(--outline);
  border-radius: var(--r3);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--silent);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
}

h1,
h2 {
  margin: 0;
  font-family: var(--mono);
  font-weight: 400;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 15px;
}

p {
  margin: 0;
}

.silent {
  color: var(--silent);
  font-size: 12px;
}

.icon {
  font-family: "Material Symbols Rounded";
  font-variation-settings: "FILL" 1;
  font-size: 20px;
  line-height: 1;
  font-weight: normal;
  font-style: normal;
  user-select: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --- Top pill --- */

.pill {
  position: sticky;
  top: 8px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  width: calc(100% - 16px);
  max-width: var(--measure);
  margin: 8px auto 0;
  padding: 4px 4px 4px 16px;
  background: var(--nav);
  border: 1px solid var(--nav-outline);
  border-radius: var(--r3);
}

.logo {
  margin: 0;
  color: var(--text);
  font-family: var(--mono);
  font-size: 4.4px;
  line-height: 1;
  white-space: pre;
  text-decoration: none;
}

.tabs {
  display: flex;
  gap: 2px;
  margin-right: auto;
  margin-left: 8px;
}

.tab {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  text-decoration: none;
  border-radius: var(--r3);
}

.tab.is-active {
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.account {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
}

.account summary {
  list-style: none;
  cursor: pointer;
}

.account summary::-webkit-details-marker {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 12px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  background: var(--s1);
  border-radius: var(--r3);
}

.ghz {
  color: var(--on-primary-container);
}

.rank {
  display: inline-block;
  padding: 0 6px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 18px;
  color: var(--on-tertiary);
  background: var(--tertiary);
  border-radius: var(--r3);
}

.dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  padding: 4px;
  background: var(--nav);
  border: 1px solid var(--nav-outline);
  border-radius: var(--r2);
}

.dropdown .btn {
  width: 100%;
  justify-content: flex-start;
}

/* --- Bottom navigation, compact screens only --- */

.bottom-nav {
  display: none;
}

@media (max-width: 599px) {
  .tabs {
    display: none;
  }

  .pill {
    justify-content: space-between;
  }

  body {
    padding-bottom: 72px;
  }

  .bottom-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 10;
    display: flex;
    justify-content: space-around;
    padding: 4px 8px;
    background: var(--nav);
    border-top: 1px solid var(--nav-outline);
  }

  .bottom-nav a {
    display: grid;
    place-items: center;
    width: 64px;
    height: 48px;
    color: var(--text);
    border-radius: var(--r3);
  }

  .bottom-nav a.is-active {
    background: var(--primary-container);
    color: var(--on-primary-container);
  }
}

/* --- Layout --- */

main {
  width: calc(100% - 16px);
  max-width: var(--measure);
  margin: 12px auto 24px;
  display: grid;
  gap: 12px;
}

main.wide {
  max-width: 1440px;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 12px;
  align-items: start;
}

@media (max-width: 839px) {
  .split {
    grid-template-columns: minmax(0, 1fr);
  }
}

.stack {
  display: grid;
  gap: 8px;
}

.head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* --- Cards and frames --- */

.card {
  padding: 12px;
  background: var(--s1);
  border-radius: var(--r1);
}

.card.elevated {
  background: var(--s2);
}

.frames {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.frame {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--s1);
  border-radius: var(--r1);
  color: var(--text);
  text-decoration: none;
}

.frames > :first-child {
  border-top-left-radius: var(--r2);
  border-top-right-radius: var(--r2);
}

.frames > :last-child {
  border-bottom-left-radius: var(--r2);
  border-bottom-right-radius: var(--r2);
}

.frame-body {
  display: grid;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.frame-title {
  font-family: var(--mono);
  font-size: 13px;
}

a.frame {
  position: relative;
  overflow: hidden;
}

.frame.is-you {
  background: var(--primary-container);
}

.place {
  width: 24px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--silent);
  text-align: right;
}

.shape {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  color: var(--on-primary);
  background: var(--primary);
  /* Material cookie shape */
  clip-path: polygon(50% 0%, 61% 9%, 75% 7%, 80% 20%, 93% 25%, 91% 39%, 100% 50%, 91% 61%, 93% 75%, 80% 80%, 75% 93%, 61% 91%, 50% 100%, 39% 91%, 25% 93%, 20% 80%, 7% 75%, 9% 61%, 0% 50%, 9% 39%, 7% 25%, 20% 20%, 25% 7%, 39% 9%);
}

.shape.tertiary {
  background: var(--tertiary);
}

.shape.secondary {
  background: var(--secondary);
}

/* --- Interaction states --- */

.btn,
a.frame,
.option {
  position: relative;
  isolation: isolate;
}

.btn::after,
a.frame::after,
.option::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--primary);
  opacity: 0;
  transition: opacity 150ms var(--ease);
  pointer-events: none;
}

.btn:hover::after,
a.frame:hover::after,
.option:hover:not(:disabled)::after {
  opacity: 0.08;
}

.btn:active::after,
a.frame:active::after,
.option:active:not(:disabled)::after {
  opacity: 0.15;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

:disabled {
  opacity: 0.38;
  pointer-events: none;
}

/* --- Buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  font: inherit;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--primary);
  background: transparent;
  border: 0;
  border-radius: var(--r2);
  text-decoration: none;
  cursor: pointer;
  transition: border-radius var(--spring-time) var(--spring);
}

.btn:active {
  border-radius: var(--r1);
  transition-duration: 150ms;
}

.btn.filled {
  color: var(--on-primary);
  background: var(--primary);
}

.btn.tonal {
  color: var(--on-primary-container);
  background: var(--primary-container);
}

.btn.outlined {
  border: 1px solid var(--outline);
}

.btn.tertiary {
  color: var(--tertiary);
}

.btn.tertiary::after {
  background: var(--tertiary);
}

.btn.destructive {
  color: var(--on-error-container);
  background: var(--error-container);
}

.btn.destructive::after {
  background: var(--error);
}

.btn.small {
  min-height: 32px;
  padding: 0 12px;
}

@media (pointer: coarse) {
  .btn.small {
    min-height: 48px;
  }
}

/* --- Inputs --- */

.field {
  display: grid;
  gap: 4px;
}

.field label {
  font-size: 12px;
  color: var(--silent);
}

.field input {
  min-height: 40px;
  padding: 0 12px;
  font: inherit;
  color: var(--text);
  background: var(--s2);
  border: 0;
  border-radius: var(--r1);
  outline: none;
}

.field input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 0;
}

.error {
  padding: 8px 12px;
  color: var(--on-error-container);
  background: var(--error-container);
  border-radius: var(--r1);
}

/* --- Standing and wavy progress --- */

.big {
  font-family: var(--display);
  font-weight: 800;
  font-style: italic;
  font-size: 48px;
  line-height: 1;
}

.big small {
  font-size: 20px;
  color: var(--silent);
}

.progress {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 12px;
}

.progress-active {
  height: 10px;
  flex: none;
  background: var(--primary);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='10'%3E%3Cpath d='M0 5 Q5 0 10 5 T20 5' fill='none' stroke='black' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E") repeat-x 0 0 / 20px 10px;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='10'%3E%3Cpath d='M0 5 Q5 0 10 5 T20 5' fill='none' stroke='black' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E") repeat-x 0 0 / 20px 10px;
  animation: wave 1.2s linear infinite;
}

.progress-track {
  position: relative;
  flex: 1;
  height: 4px;
  background: color-mix(in srgb, var(--primary) 30%, transparent);
  border-radius: var(--r3);
}

.progress-track::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 4px;
  height: 4px;
  background: var(--primary);
  border-radius: var(--r3);
}

@keyframes wave {
  to {
    -webkit-mask-position: 20px 0;
    mask-position: 20px 0;
  }
}

/* --- Rank ladder --- */

.ladder {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ladder li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 4px 12px 4px 4px;
  white-space: nowrap;
  background: var(--s1);
  border-radius: var(--r1);
}

.ladder li:first-child {
  border-radius: var(--r2) var(--r1) var(--r1) var(--r2);
}

.ladder li:last-child {
  border-radius: var(--r1) var(--r2) var(--r2) var(--r1);
}

.ladder li:not(.is-reached) .rank {
  color: var(--silent);
  background: transparent;
  outline: 1px solid var(--outline);
}

/* --- Quiz --- */

.quiz-image {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: var(--r1);
}

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

@media (max-width: 599px) {
  .options {
    grid-template-columns: minmax(0, 1fr);
  }
}

.option {
  min-height: 48px;
  padding: 8px 16px;
  font: inherit;
  color: var(--text);
  text-align: left;
  background: var(--s2);
  border: 0;
  border-radius: var(--r2);
  cursor: pointer;
  transition: border-radius var(--spring-time) var(--spring);
}

.option:active {
  border-radius: var(--r1);
  transition-duration: 150ms;
}

.option.is-right {
  color: var(--on-status);
  background: var(--success);
  opacity: 1;
}

.option.is-wrong {
  color: var(--on-status);
  background: var(--error);
  opacity: 1;
}

/* --- Chess --- */

.table {
  display: grid;
  grid-template-columns: minmax(0, 600px) minmax(260px, 1fr);
  gap: 12px;
  align-items: start;
}

@media (max-width: 839px) {
  .table {
    grid-template-columns: minmax(0, 1fr);
  }
}

.play {
  display: grid;
  gap: 8px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
  padding: 0 4px;
}

.bar-who {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  min-width: 0;
}

.bar.is-turn .frame-title {
  color: var(--primary);
}

.captured {
  display: flex;
  align-items: center;
}

.captured .piece {
  position: static;
  width: 20px;
  height: 20px;
  margin-right: -6px;
}

.captured .silent {
  margin-left: 12px;
}

.clock {
  min-width: 96px;
  padding: 4px 12px;
  font-family: var(--mono);
  font-size: 20px;
  text-align: right;
  color: var(--silent);
  background: var(--s1);
  border-radius: var(--r1);
  font-variant-numeric: tabular-nums;
  transition: background-color 180ms var(--ease), color 180ms var(--ease);
}

.clock.is-running {
  color: var(--on-primary);
  background: var(--primary);
}

.clock.is-low.is-running {
  color: var(--on-status);
  background: var(--error);
}

/* --- Board --- */

.board-wrap {
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: var(--r1);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  --light: #b5c29a;
  --dark: #6f8a4a;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  --tone: var(--light);
  background: var(--tone);
}

.square.dark {
  --tone: var(--dark);
}

.square.is-last {
  background: color-mix(in srgb, var(--warning) 45%, var(--tone));
}

.square.is-picked {
  background: color-mix(in srgb, var(--warning) 60%, var(--tone));
}

.square.is-premove {
  background: color-mix(in srgb, var(--tertiary) 60%, var(--tone));
}

.square.is-check {
  background: color-mix(in srgb, var(--error) 75%, var(--tone));
  animation: check-pulse 600ms var(--ease) 2;
}

@keyframes check-pulse {
  50% {
    background: color-mix(in srgb, var(--error) 95%, var(--tone));
  }
}

.square.is-hover {
  outline: 4px solid color-mix(in srgb, #ffffff 75%, transparent);
  outline-offset: -4px;
}

.square.is-target::before {
  content: "";
  position: absolute;
  z-index: 3;
  width: 30%;
  height: 30%;
  background: color-mix(in srgb, #000000 22%, transparent);
  border-radius: var(--r3);
  pointer-events: none;
  animation: pop var(--spring-time) var(--spring);
}

.square.is-capture::before {
  content: "";
  position: absolute;
  z-index: 3;
  inset: 3%;
  border: 6px solid color-mix(in srgb, #000000 22%, transparent);
  border-radius: var(--r3);
  pointer-events: none;
  animation: pop var(--spring-time) var(--spring);
}

@keyframes pop {
  from {
    transform: scale(0);
    opacity: 0;
  }
}

.square.is-mine {
  cursor: grab;
}

.board.is-dragging,
.board.is-dragging .square {
  cursor: grabbing;
}

.board.is-flipping {
  animation: flip 300ms var(--ease);
}

@keyframes flip {
  from {
    transform: rotate(-180deg) scale(0.9);
    opacity: 0.4;
  }
}

.coord {
  position: absolute;
  z-index: 0;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
  color: var(--dark);
}

.square.dark .coord {
  color: var(--light);
}

.coord-rank {
  top: 3px;
  left: 4px;
}

.coord-file {
  right: 4px;
  bottom: 3px;
}

/* --- Pieces --- */

.piece {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.piece.fading {
  z-index: 0;
}

.square.is-moving {
  z-index: 2;
}

.square.is-lifted .piece:not(.fading) {
  opacity: 0.3;
}

.square.is-picked:not(.is-lifted) .piece {
  animation: lift var(--spring-time) var(--spring) forwards;
}

@keyframes lift {
  to {
    transform: scale(1.08);
  }
}

.piece.ghost {
  position: fixed;
  inset: auto;
  z-index: 50;
  transform: scale(1.15);
  animation: grab 120ms var(--ease);
}

@keyframes grab {
  from {
    transform: scale(1);
  }
}

.marks {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.marks .mark,
.marks circle {
  animation: fade-in 150ms var(--ease);
}

.promo {
  position: absolute;
  z-index: 5;
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  width: 12.5%;
  height: 50%;
  overflow: hidden;
  background: var(--s2);
  border-radius: var(--r2);
  animation: fade-in 150ms var(--ease);
}

.promo-choice {
  display: grid;
  place-items: center;
  padding: 0;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.promo-choice:hover {
  background: color-mix(in srgb, var(--primary) 15%, transparent);
}

.promo-choice .piece {
  position: static;
  width: 90%;
  height: 90%;
}

/* --- Side panel --- */

.icon-btn {
  width: 40px;
  min-height: 40px;
  padding: 0;
  color: var(--text);
  border-radius: var(--r3);
}

.icon-btn:active {
  border-radius: var(--r1);
}

@media (pointer: coarse) {
  .icon-btn {
    width: 48px;
    min-height: 48px;
  }
}

.review {
  display: flex;
  align-items: center;
  gap: 2px;
}

.review-gap {
  flex: 1;
}

.offer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  background: var(--primary-container);
  border-radius: var(--r1);
  animation: fade-in 200ms var(--ease);
}

[data-status].is-thinking::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 8px;
  vertical-align: middle;
  background: var(--primary);
  border-radius: var(--r3);
  animation: think 900ms var(--ease) infinite alternate;
}

@keyframes think {
  from {
    opacity: 0.2;
    transform: scale(0.6);
  }
}

.moves {
  display: grid;
  gap: 2px;
  max-height: 320px;
  min-height: 120px;
  align-content: start;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  font-family: var(--mono);
  font-size: 13px;
}

.moves li {
  display: grid;
  grid-template-columns: 36px 1fr 1fr;
  align-items: center;
  gap: 4px;
}

.moves .silent {
  text-align: right;
  padding-right: 4px;
}

.move {
  min-height: 28px;
  padding: 0 8px;
  font: inherit;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--r1);
  cursor: pointer;
}

.move:hover {
  background: color-mix(in srgb, var(--primary) 8%, transparent);
}

.move.is-current {
  color: var(--on-primary-container);
  background: var(--primary-container);
}

dialog.result {
  width: min(360px, calc(100% - 32px));
  padding: 24px;
  color: var(--text);
  background: var(--s2);
  border: 0;
  border-radius: var(--r2);
}

dialog.result::backdrop {
  background: rgb(0 0 0 / 50%);
}

dialog.result[open] {
  animation: dialog-in var(--spring-time) var(--spring);
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

/* --- Games menu --- */

.menu {
  position: relative;
}

.menu > summary {
  list-style: none;
  cursor: pointer;
}

.tabs .menu > summary {
  gap: 2px;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu > summary .icon {
  font-size: 18px;
  transition: transform 180ms var(--ease);
}

.menu[open] > summary .icon {
  transform: rotate(180deg);
}

.dropdown-left {
  right: auto;
  left: 0;
}

.menu[open] .dropdown {
  animation: drop-in 180ms var(--ease);
}

@keyframes drop-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 0 12px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  text-decoration: none;
  border-radius: var(--r2);
}

.menu-item:hover {
  background: color-mix(in srgb, var(--primary) 8%, transparent);
}

.menu-item.is-active {
  color: var(--on-primary-container);
  background: var(--primary-container);
}

.chip.is-risk {
  color: var(--tertiary);
}

/* --- Switch, as design.md describes it --- */

.risk-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.risk-toggle:has(:disabled) {
  cursor: default;
}

.switch {
  appearance: none;
  position: relative;
  flex: none;
  width: 52px;
  height: 32px;
  margin: 0;
  background: var(--s2);
  border: 1px solid var(--outline);
  border-radius: var(--r3);
  cursor: inherit;
  transition: background-color 180ms var(--ease), border-color 180ms var(--ease);
}

.switch::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 5px;
  width: 18px;
  height: 18px;
  background: #ffffff;
  border-radius: var(--r3);
  transform: translateY(-50%);
  transition:
    left var(--spring-time) var(--spring),
    width var(--spring-time) var(--spring),
    height var(--spring-time) var(--spring),
    background-color 180ms var(--ease);
}

.switch:checked {
  background: var(--primary);
  border-color: var(--primary);
}

.switch:checked::before {
  left: 22px;
  width: 24px;
  height: 24px;
  background: var(--on-primary);
}

.switch:active::before {
  width: 26px;
}

.switch:checked:active::before {
  left: 20px;
}

.frame.is-muted {
  opacity: 0.5;
}

.snake-actions {
  display: grid;
  justify-items: center;
  gap: 16px;
}

/* --- Minesweeper --- */

.sweeper-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.sweeper-bar .chip {
  font-variant-numeric: tabular-nums;
}

.field-scroll {
  overflow-x: auto;
  padding-bottom: 4px;
}

/* Squares grow with the page, but the field always fits the screen height */
.minefield {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 2px;
  width: min(100%, calc((100svh - 230px) * 30 / 16));
  min-width: calc(var(--cols) * 34px + (var(--cols) - 1) * 2px);
  margin: 0 auto;
  container-type: inline-size;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  font-family: var(--mono);
  font-size: max(15px, 1.7cqi);
  font-weight: 700;
  color: var(--text);
  background: #3d3d3d;
  border: 0;
  border-radius: var(--r1);
  cursor: pointer;
  transition: border-radius var(--spring-time) var(--spring);
}

.cell:hover:not(.is-open) {
  background: color-mix(in srgb, var(--primary) 18%, #3d3d3d);
}

.cell:active:not(.is-open),
.cell.is-pending {
  background: #2a2a2a;
  border-radius: 6px;
  transition-duration: 80ms;
}

.cell .icon {
  font-size: max(18px, 1.9cqi);
  color: var(--error);
  animation: pop var(--spring-time) var(--spring);
}

.cell.is-open {
  background: var(--bg);
  cursor: default;
  animation: open-cell 140ms var(--ease) var(--delay, 0ms) backwards;
}

.cell.is-open:not(:empty) {
  cursor: pointer;
}

@keyframes open-cell {
  from {
    opacity: 0;
    transform: scale(0.5);
    background: #3d3d3d;
  }
}

.cell.n1 { color: #8ab4f8; }
.cell.n2 { color: var(--success); }
.cell.n3 { color: var(--error); }
.cell.n4 { color: #c58af9; }
.cell.n5 { color: var(--warning); }
.cell.n6 { color: var(--tertiary); }
.cell.n7 { color: var(--text); }
.cell.n8 { color: var(--silent); }

.cell.is-hint {
  animation: hint 300ms var(--ease);
}

@keyframes hint {
  50% {
    background: color-mix(in srgb, var(--warning) 35%, #3d3d3d);
  }
}

.cell.is-mine {
  color: var(--text);
  background: #4a3535;
  animation: pop var(--spring-time) var(--spring) var(--delay, 0ms) backwards;
}

.cell.is-hit {
  color: #000000;
  background: var(--error);
  animation: boom 500ms var(--ease);
}

@keyframes boom {
  0% {
    transform: scale(1);
  }
  30% {
    transform: scale(1.5);
  }
  100% {
    transform: scale(1);
  }
}

.cell .mine {
  width: 70%;
  height: 70%;
}

.cell.is-wrong-flag {
  background: var(--error-container);
  text-decoration: line-through;
}

.cell.is-right-flag .icon {
  color: var(--success);
}

.minefield.is-won .cell.is-open {
  animation: won-wave 700ms var(--ease) calc(var(--wave, 0) * 1ms);
}

@keyframes won-wave {
  40% {
    background: color-mix(in srgb, var(--primary) 45%, var(--bg));
  }
}

/* --- Snake --- */

.snake {
  display: grid;
  grid-template-columns: minmax(0, 640px) minmax(220px, 1fr);
  gap: 12px;
  align-items: start;
}

@media (max-width: 839px) {
  .snake {
    grid-template-columns: minmax(0, 1fr);
  }
}

.snake-stage {
  position: relative;
}

.snake-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--r1);
  touch-action: none;
  outline-offset: 4px;
}

.snake-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(0 0 0 / 50%);
  border-radius: var(--r1);
}

.snake-card {
  display: grid;
  justify-items: center;
  gap: 24px;
  max-width: 360px;
  padding: 24px;
  text-align: center;
  background: var(--s2);
  border-radius: var(--r2);
}

.snake-overlay.is-in .snake-card {
  animation: dialog-in var(--spring-time) var(--spring);
}

.snake-card-text {
  display: grid;
  gap: 8px;
}

.snake-card .row {
  justify-content: center;
}

.snake-score {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.snake-score .big.is-bump {
  animation: bump var(--spring-time) var(--spring);
}

@keyframes bump {
  from {
    transform: scale(1.25);
  }
}

.dpad {
  display: none;
  grid-template-columns: repeat(3, 48px);
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  gap: 4px;
  justify-content: center;
}

.dpad [data-dir="0"] { grid-area: up; }
.dpad [data-dir="3"] { grid-area: left; }
.dpad [data-dir="1"] { grid-area: right; }
.dpad [data-dir="2"] { grid-area: down; }

@media (pointer: coarse) {
  .dpad {
    display: grid;
  }
}

/* --- Toast --- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  z-index: 20;
  padding: 12px 16px;
  background: var(--s2);
  border-radius: var(--r2);
  transform: translateX(-50%);
  animation: toast-in 200ms var(--ease);
}

@media (max-width: 599px) {
  .toast {
    bottom: 80px;
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0ms !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
  }

  .progress-active {
    height: 4px;
    border-radius: var(--r3);
    -webkit-mask: none;
    mask: none;
    animation: none;
  }

  .toast {
    animation-name: fade-in;
  }

  @keyframes fade-in {
    from {
      opacity: 0;
    }
  }
}
