:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #f8f1e3;
  --muted: #c9beab;
  --coal: #171412;
  --panel: rgba(23, 20, 18, 0.92);
  --line: rgba(248, 241, 227, 0.18);
  --red: #b63c45;
  --mustard: #d5a33a;
  --teal: #287c86;
  --green: #5d7e50;
  --spool-width: 96px;
  --spool-height: 216px;
  --bundle-height: 34px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: var(--coal);
}

body {
  min-height: 100svh;
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  user-select: none;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--mustard);
  outline-offset: 3px;
}

.scene {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(9, 8, 7, 0.13), rgba(9, 8, 7, 0.52)),
    url("assets/faroese-knitting-room.webp");
  background-position: center top;
  background-size: cover;
  transform: scale(1.01);
}

.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(12, 10, 8, 0.12);
  pointer-events: none;
}

.game-shell {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  min-height: 76px;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(44px, 1fr);
  align-items: center;
  gap: 24px;
  padding: calc(10px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(17, 14, 12, 0.82);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand > span:last-child {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.brand strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.32rem;
  line-height: 1;
  letter-spacing: 0;
}

.brand small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 750;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 3px;
  border: 1px solid rgba(248, 241, 227, 0.3);
  background: #29231f;
}

.brand-mark i {
  display: block;
  background: var(--ink);
}

.brand-mark i:nth-child(2),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(6),
.brand-mark i:nth-child(8) {
  background: var(--red);
}

.brand-mark i:nth-child(5) {
  background: var(--mustard);
}

.round-stats {
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.round-stats > span {
  min-width: 90px;
  padding: 0 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-left: 1px solid var(--line);
}

.round-stats > span:last-child {
  border-right: 1px solid var(--line);
}

.round-stats small,
.progress-band,
.kicker,
.win-score span {
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0;
}

.round-stats strong {
  margin-top: 2px;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.top-actions {
  display: flex;
  justify-self: end;
  gap: 7px;
}

.topbar > .icon-button {
  justify-self: end;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(31, 27, 24, 0.78);
  cursor: pointer;
  font-size: 1.35rem;
}

.icon-button:hover,
.tool-button:hover,
.secondary-button:hover {
  border-color: rgba(248, 241, 227, 0.48);
  background-color: rgba(58, 49, 43, 0.92);
}

.icon-button:active,
.tool-button:active,
.secondary-button:active,
.primary-button:active {
  transform: translateY(1px);
}

.progress-band {
  min-height: 34px;
  display: grid;
  grid-template-columns: minmax(110px, auto) minmax(120px, 380px) minmax(72px, auto);
  justify-content: center;
  align-items: center;
  gap: 18px;
  padding: 7px 18px;
  background: rgba(19, 16, 14, 0.68);
  border-bottom: 1px solid rgba(248, 241, 227, 0.1);
}

.progress-band > span:last-child {
  text-align: right;
}

.online-status {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.online-status::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: #6e6962;
}

.online-status.is-online::before {
  background: #73a966;
  box-shadow: 0 0 7px rgba(115, 169, 102, 0.7);
}

.online-status.is-loading::before {
  background: var(--mustard);
  animation: status-pulse 750ms ease-in-out infinite alternate;
}

.progress-track {
  height: 4px;
  overflow: hidden;
  background: rgba(248, 241, 227, 0.16);
}

.progress-track i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--mustard);
  transition: width 240ms ease;
}

.board-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 16px 18px 10px;
  overflow: auto;
}

.spool-board {
  --columns: 5;
  width: min(100%, calc(var(--columns) * (var(--spool-width) + 24px)));
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(var(--spool-width), 1fr));
  align-items: end;
  justify-content: center;
  gap: 16px 24px;
  margin: auto;
}

.spool {
  position: relative;
  width: 100%;
  min-width: var(--spool-width);
  height: var(--spool-height);
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  transition: transform 170ms ease, filter 170ms ease;
}

.spool:hover {
  filter: brightness(1.08);
}

.spool.is-queued::before {
  content: "";
  position: absolute;
  z-index: 6;
  inset: 3px;
  border: 2px solid var(--mustard);
  border-radius: 8px;
  box-shadow: 0 0 0 3px rgba(213, 163, 58, 0.16);
  pointer-events: none;
  animation: queued-tap 520ms ease-in-out infinite alternate;
}

.spool.is-locked {
  cursor: not-allowed;
  filter: grayscale(.55) brightness(.68);
}

.spool.is-locked:hover {
  filter: grayscale(.55) brightness(.75);
}

.spool.is-locked .needle,
.spool.is-locked .spool-base {
  opacity: .58;
}

.spool.is-newly-unlocked {
  animation: spool-unlock 820ms cubic-bezier(.18,.82,.24,1) both;
}

.spool-lock {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 38%;
  min-width: 42px;
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(248, 241, 227, .34);
  border-radius: 6px;
  color: #f8f1e3;
  background: rgba(24, 21, 19, .88);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .38);
  font-size: .82rem;
  line-height: 1;
  pointer-events: none;
}

.spool-lock b {
  color: var(--mustard);
  font-size: .7rem;
}

.spool.is-selected {
  transform: translateY(-12px);
}

.spool.is-selected .yarn-stack {
  animation: yarn-ready 280ms cubic-bezier(.2,.75,.25,1);
}

.spool.is-selected .spool-base,
.spool.is-selected .needle {
  filter: drop-shadow(0 0 8px rgba(213, 163, 58, 0.75));
}

.spool.is-complete::after {
  content: "✓";
  position: absolute;
  top: 3px;
  right: 4px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #201b16;
  background: var(--mustard);
  font-size: 0.78rem;
  font-weight: 900;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.spool.is-new-complete .yarn-stack {
  animation: yarn-complete 560ms cubic-bezier(.2,.78,.24,1) both;
}

.spool.is-new-complete .spool-base {
  animation: base-complete 560ms ease-out both;
}

.spool.hint-source {
  animation: hint-source 800ms ease-in-out infinite alternate;
}

.spool.hint-target .spool-base {
  animation: hint-target 800ms ease-in-out infinite alternate;
}

.needle {
  position: absolute;
  z-index: 0;
  left: 50%;
  bottom: 24px;
  width: 8px;
  height: calc(100% - 30px);
  transform: translateX(-50%);
  border: 1px solid #5a3e27;
  border-radius: 6px 6px 2px 2px;
  background: #a87843;
  box-shadow: inset 2px 0 rgba(255, 235, 188, 0.2), inset -2px 0 rgba(42, 25, 14, 0.28), 0 4px 12px rgba(0, 0, 0, 0.35);
}

.needle::before {
  content: "";
  position: absolute;
  left: 1px;
  top: -6px;
  width: 4px;
  height: 8px;
  border-radius: 50% 50% 0 0;
  background: #d1a66b;
}

.spool-base {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 6px;
  width: 82%;
  height: 24px;
  transform: translateX(-50%);
  border: 1px solid #4d3421;
  border-radius: 50%;
  background: #83562f;
  box-shadow: inset 0 5px rgba(220, 174, 112, 0.28), inset 0 -6px rgba(43, 25, 14, 0.32), 0 7px 12px rgba(0, 0, 0, 0.38);
}

.yarn-stack {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 28px;
  width: 88%;
  height: calc(var(--bundle-height) * 4);
  min-height: calc(var(--bundle-height) * 4);
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
  transform: translateX(-50%);
}

.yarn-bundle,
.moving-yarn {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  height: var(--bundle-height);
  flex: 0 0 var(--bundle-height);
  border: 2px solid #41423f;
  border-radius: 48% 48% 42% 42% / 40% 40% 48% 48%;
  overflow: hidden;
  border-color: #41423f;
  color: #fff4e3;
  background-color: #787875;
  background-image: repeating-linear-gradient(165deg, transparent 0 4px, rgba(255, 255, 255, 0.22) 5px 6px, transparent 7px 10px, rgba(0, 0, 0, 0.13) 11px 12px);
  box-shadow: inset 0 4px 3px rgba(255, 255, 255, 0.13), inset 0 -5px 4px rgba(0, 0, 0, 0.15), 0 3px 5px rgba(0, 0, 0, 0.28);
}

.yarn-color-0 { border-color: #164a52; color: #f7ead8; background-color: #277985; }
.yarn-color-1 { border-color: #9b8e78; color: #3b332d; background-color: #ded3ba; }
.yarn-color-2 { border-color: #6d2029; color: #fff1dc; background-color: #ad3742; }
.yarn-color-3 { border-color: #76541b; color: #2d2418; background-color: #ca9731; }
.yarn-color-4 { border-color: #30472d; color: #f8eddb; background-color: #55794e; }
.yarn-color-5 { border-color: #41423f; color: #fff4e3; background-color: #787875; }
.yarn-color-6 { border-color: #412c40; color: #fff0dc; background-color: #72506f; }
.yarn-color-7 { border-color: #452d20; color: #fff0dc; background-color: #76513a; }

.yarn-bundle.is-covered {
  border-color: #181614;
  color: #eee3cd;
  background-color: #393531;
  background-image: repeating-linear-gradient(165deg, transparent 0 4px, rgba(255, 255, 255, .1) 5px 6px, transparent 7px 10px, rgba(0, 0, 0, .22) 11px 12px);
}

.yarn-bundle.is-covered .yarn-mark {
  font-size: 0;
}

.yarn-bundle.is-covered .yarn-mark::after {
  content: "?";
  font-size: .9rem;
}

.yarn-bundle + .yarn-bundle {
  margin-bottom: -2px;
}

.yarn-bundle.is-arriving {
  opacity: 0;
}

.yarn-bundle::before,
.moving-yarn::before {
  content: "";
  position: absolute;
  inset: 4px 7px;
  border-top: 1px dashed rgba(255, 255, 255, 0.24);
  border-bottom: 1px dashed rgba(0, 0, 0, 0.22);
  border-radius: 50%;
}

.yarn-mark {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: Georgia, serif;
  font-size: 0.9rem;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px rgba(0, 0, 0, 0.35);
}

.moving-yarn {
  position: fixed;
  z-index: 30;
  margin: 0;
  overflow: visible;
  pointer-events: none;
  will-change: transform;
  animation: moving-fibres 135ms linear infinite;
}

.moving-yarn::after {
  content: "";
  position: absolute;
  z-index: -1;
  left: -24px;
  top: 50%;
  width: 30px;
  height: 3px;
  border-radius: 50%;
  background: var(--yarn);
  box-shadow: 0 -1px var(--yarn-light), 0 1px var(--yarn-dark);
  transform: rotate(-8deg);
  transform-origin: right center;
}

.moving-yarn.moves-left::after {
  right: -24px;
  left: auto;
  transform: rotate(8deg);
  transform-origin: left center;
}

.spool.is-unwinding .yarn-stack {
  animation: yarn-unwind 190ms ease-in-out infinite alternate;
}

.spool.is-unwinding {
  animation: spool-release 300ms cubic-bezier(.25,.7,.25,1) both;
}

.spool.is-winding .needle {
  animation: needle-wind 170ms linear infinite;
}

.spool.is-winding .yarn-stack {
  animation: yarn-wind 210ms ease-in-out infinite alternate;
}

.spool-number {
  position: absolute;
  left: 50%;
  bottom: -13px;
  transform: translateX(-50%);
  color: rgba(248, 241, 227, 0.64);
  font-size: 0.65rem;
  font-weight: 800;
}

.tool-dock {
  min-height: 68px;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(17, 14, 12, 0.86);
  backdrop-filter: blur(14px);
}

.tool-button {
  width: 108px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(35, 30, 27, 0.84);
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 750;
}

.tool-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.tool-icon {
  font-size: 1.32rem;
  line-height: 1;
}

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  max-width: min(90vw, 420px);
  padding: 9px 14px;
  transform: translate(-50%, 20px);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(19, 16, 14, 0.94);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.overlay {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: rgba(9, 8, 7, 0.74);
  backdrop-filter: blur(10px);
}

.overlay[hidden] {
  display: none;
}

.win-modal,
.settings-modal,
.leaderboard-modal,
.nickname-modal {
  width: min(100%, 480px);
  max-height: calc(100svh - 36px);
  overflow: auto;
  border: 1px solid rgba(248, 241, 227, 0.25);
  border-radius: 8px;
  background: #201b18;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.52);
}

.win-modal {
  position: relative;
  padding: 34px 34px 28px;
  text-align: center;
}

.pattern-ribbon {
  position: absolute;
  inset: 0 0 auto;
  height: 9px;
  background: repeating-linear-gradient(90deg, var(--red) 0 16px, var(--ink) 16px 24px, var(--teal) 24px 40px, var(--mustard) 40px 48px);
}

.kicker {
  margin: 0 0 6px;
}

.win-modal h1,
.settings-modal h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  letter-spacing: 0;
}

.stars {
  min-height: 34px;
  margin: 13px 0 8px;
  color: var(--mustard);
  font-size: 1.5rem;
  letter-spacing: 0;
}

.win-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
}

.win-score strong {
  font-size: 2.15rem;
  font-variant-numeric: tabular-nums;
}

.score-breakdown {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  margin: 14px 0 18px;
  background: var(--line);
  border: 1px solid var(--line);
}

.score-breakdown span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  background: #29231f;
  color: var(--muted);
  font-size: 0.72rem;
}

.score-breakdown b {
  color: var(--ink);
}

.win-modal blockquote {
  margin: 0;
  color: #e6dccb;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.02rem;
  line-height: 1.48;
}

.source-link {
  display: inline-block;
  margin-top: 8px;
  color: #97c7cb;
  font-size: 0.72rem;
}

.win-actions {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 8px;
  margin-top: 22px;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 850;
}

.primary-button {
  border: 1px solid #e8be62;
  background: var(--mustard);
  color: #1d1814;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #2d2723;
  color: var(--ink);
}

.icon-button.secondary {
  width: 44px;
  height: 44px;
}

.settings-modal {
  padding: 24px;
}

.settings-modal > header,
.leaderboard-modal > header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.settings-modal h2,
.leaderboard-modal h2,
.nickname-modal h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0;
  font-size: 1.65rem;
}

.setting-row {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-top: 1px solid var(--line);
}

.setting-row > span {
  display: flex;
  flex-direction: column;
}

.setting-row small {
  margin-top: 2px;
  color: var(--muted);
}

input[type="checkbox"] {
  appearance: none;
  width: 44px;
  height: 24px;
  flex: 0 0 auto;
  border: 1px solid rgba(248, 241, 227, 0.32);
  border-radius: 12px;
  background: #39322d;
  cursor: pointer;
}

input[type="checkbox"]::before {
  content: "";
  display: block;
  width: 18px;
  height: 18px;
  margin: 2px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 150ms ease;
}

input[type="checkbox"]:checked {
  background: var(--teal);
}

input[type="checkbox"]:checked::before {
  transform: translateX(20px);
}

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

input[type="range"] {
  width: min(52%, 210px);
  accent-color: var(--mustard);
}

.settings-progress {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.settings-progress span {
  min-width: 0;
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--muted);
  font-size: 0.66rem;
  text-align: center;
}

.settings-progress span + span {
  border-left: 1px solid var(--line);
}

.settings-progress strong {
  margin-top: 5px;
  color: var(--ink);
  font-size: 1.15rem;
}

.small-button {
  min-width: 68px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #302923;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 800;
}

.level-picker {
  min-height: 58px;
}

.level-picker-controls {
  display: grid;
  grid-template-columns: 36px 58px 36px 68px;
  align-items: center;
  gap: 6px;
}

.level-step-button,
#levelPickerInput {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #302923;
  color: var(--ink);
}

.level-step-button {
  display: grid;
  place-items: center;
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 1.55rem;
  line-height: 1;
}

.level-step-button:disabled {
  cursor: default;
  opacity: 0.38;
}

#levelPickerInput {
  width: 58px;
  padding: 0 4px;
  appearance: textfield;
  text-align: center;
  font: inherit;
  font-weight: 850;
}

#levelPickerInput::-webkit-inner-spin-button,
#levelPickerInput::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
}

.rank-result {
  min-height: 20px;
  margin: 3px 0 0;
  color: #9fd0d3;
  font-size: 0.78rem;
  font-weight: 800;
}

.leaderboard-modal {
  width: min(100%, 620px);
  padding: 24px;
}

.leaderboard-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 16px;
  border-bottom: 1px solid var(--line);
}

.leaderboard-tabs button {
  min-height: 42px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 850;
}

.leaderboard-tabs button.is-active {
  border-bottom-color: var(--mustard);
  color: var(--ink);
}

.weekly-challenge {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.weekly-challenge > span {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.weekly-challenge small {
  color: var(--mustard);
  font-size: 0.62rem;
  font-weight: 850;
}

.weekly-challenge strong {
  margin-top: 3px;
  overflow: hidden;
  font-size: 0.84rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.weekly-challenge .primary-button {
  min-width: 92px;
  min-height: 38px;
  padding-inline: 14px;
}

.leaderboard-heading,
.leaderboard-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 92px;
  align-items: center;
  gap: 8px;
}

.leaderboard-heading {
  min-height: 34px;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 850;
}

.leaderboard-heading span:last-child,
.leaderboard-row > strong {
  text-align: right;
}

.leaderboard-list {
  min-height: 176px;
  max-height: min(46svh, 420px);
  overflow-y: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.leaderboard-row {
  min-height: 48px;
  padding: 6px 4px;
  border-bottom: 1px solid rgba(248, 241, 227, 0.09);
  font-variant-numeric: tabular-nums;
}

.leaderboard-row:last-child {
  border-bottom: 0;
}

.leaderboard-row.is-player {
  box-shadow: inset 4px 0 var(--mustard);
  background: rgba(213, 163, 58, 0.1);
}

.leaderboard-rank {
  color: var(--mustard);
  font-family: Georgia, serif;
  font-size: 1rem;
  font-weight: 800;
}

.leaderboard-player {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-player small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.64rem;
}

.leaderboard-empty,
.leaderboard-loading {
  min-height: 176px;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.leaderboard-note {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.68rem;
}

.nickname-modal {
  position: relative;
  width: min(100%, 410px);
  padding: 36px 30px 28px;
  text-align: center;
}

.nickname-modal form {
  display: grid;
  gap: 10px;
  margin-top: 20px;
  text-align: left;
}

.nickname-modal label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.nickname-modal input[type="text"] {
  width: 100%;
  min-height: 48px;
  padding: 9px 12px;
  border: 1px solid rgba(248, 241, 227, 0.32);
  border-radius: 6px;
  background: #171412;
  color: var(--ink);
  font-size: 1rem;
}

.nickname-modal .primary-button,
.nickname-modal .secondary-button {
  width: 100%;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: #e9858b;
  font-size: 0.72rem;
}

@keyframes status-pulse {
  from { opacity: 0.45; }
  to { opacity: 1; }
}

@keyframes hint-source {
  from { transform: translateY(0); }
  to { transform: translateY(-10px); }
}

@keyframes hint-target {
  from { box-shadow: inset 0 5px rgba(220, 174, 112, 0.28), inset 0 -6px rgba(43, 25, 14, 0.32), 0 0 0 rgba(213, 163, 58, 0); }
  to { box-shadow: inset 0 5px rgba(220, 174, 112, 0.28), inset 0 -6px rgba(43, 25, 14, 0.32), 0 0 18px rgba(213, 163, 58, 0.92); }
}

@keyframes queued-tap {
  from { opacity: .5; transform: scale(.97); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes spool-unlock {
  0% { filter: grayscale(.6) brightness(.7); transform: scale(.94); }
  42% { filter: brightness(1.45); transform: translateY(-8px) scale(1.08); }
  100% { filter: brightness(1); transform: scale(1); }
}

@keyframes yarn-ready {
  0% { transform: translateX(-50%) translateY(0) scaleX(1); }
  55% { transform: translateX(-50%) translateY(-3px) scaleX(1.07); }
  100% { transform: translateX(-50%) translateY(0) scaleX(1); }
}

@keyframes spool-release {
  from { transform: translateY(-12px); }
  to { transform: translateY(0); }
}

@keyframes yarn-complete {
  0% { transform: translateX(-50%) scale(.94); filter: brightness(1); }
  48% { transform: translateX(-50%) translateY(-8px) scale(1.08); filter: brightness(1.3); }
  72% { transform: translateX(-50%) translateY(1px) scale(.99); }
  100% { transform: translateX(-50%) scale(1); filter: brightness(1); }
}

@keyframes base-complete {
  0%, 100% { filter: none; }
  50% { filter: drop-shadow(0 0 13px rgba(213, 163, 58, .95)); }
}

@keyframes yarn-unwind {
  from { transform: translateX(-50%) scaleX(1.03); filter: brightness(1.08); }
  to { transform: translateX(-50%) scaleX(.96); filter: brightness(.92); }
}

@keyframes yarn-wind {
  from { transform: translateX(-50%) scaleX(.97); }
  to { transform: translateX(-50%) scaleX(1.04); }
}

@keyframes needle-wind {
  0% { transform: translateX(-50%) rotate(-1.5deg); }
  50% { transform: translateX(-50%) rotate(1.5deg); }
  100% { transform: translateX(-50%) rotate(-1.5deg); }
}

@keyframes moving-fibres {
  from { background-position: 0 0; }
  to { background-position: 12px 0; }
}

@media (max-width: 820px) {
  :root {
    --spool-width: 76px;
    --spool-height: 162px;
    --bundle-height: 27px;
  }

  .topbar {
    min-height: 68px;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .top-actions {
    gap: 4px;
  }

  .top-actions .icon-button {
    width: 38px;
    height: 38px;
  }

  .brand small {
    display: none;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
  }

  .round-stats {
    justify-content: flex-end;
  }

  .round-stats > span {
    min-width: 58px;
    padding: 0 8px;
  }

  .score-stat {
    display: none !important;
  }

  .progress-band {
    grid-template-columns: minmax(78px, auto) minmax(80px, 1fr) minmax(54px, auto);
    gap: 10px;
    padding-inline: 12px;
  }

  .board-wrap {
    padding: 9px 6px 7px;
  }

  .spool-board {
    --columns: var(--mobile-columns, 4);
    width: min(100%, calc(var(--columns) * (var(--spool-width) + 9px)));
    gap: 8px 9px;
  }

  .spool-number {
    display: none;
  }

  .tool-dock {
    min-height: 62px;
    padding-top: 7px;
    padding-bottom: calc(7px + env(safe-area-inset-bottom));
  }

  .tool-button {
    width: min(29vw, 102px);
    min-height: 46px;
    padding: 0 7px;
    font-size: 0.7rem;
  }
}

@media (max-width: 390px) {
  :root {
    --spool-width: 69px;
    --spool-height: 148px;
    --bundle-height: 24px;
  }

  .brand strong {
    font-size: 1.12rem;
  }

  .brand-mark {
    display: none;
  }

  .round-stats > span {
    min-width: 54px;
    padding-inline: 6px;
  }

  .round-stats small {
    font-size: 0.56rem;
  }

  .round-stats strong {
    font-size: 0.94rem;
  }

  .timer-stat {
    display: none !important;
  }

  .progress-band {
    font-size: 0.58rem;
  }

  .yarn-mark {
    font-size: 0.76rem;
  }

  .tool-button span:last-child {
    display: none;
  }

  .tool-button {
    width: 58px;
  }

  .tool-icon {
    font-size: 1.45rem;
  }

  .win-modal,
  .settings-modal,
  .leaderboard-modal,
  .nickname-modal {
    padding-left: 20px;
    padding-right: 20px;
  }

  .leaderboard-heading,
  .leaderboard-row {
    grid-template-columns: 40px minmax(0, 1fr) 78px;
  }

  .weekly-challenge strong {
    max-width: 170px;
  }

  .level-picker {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    padding-block: 10px;
  }

  .level-picker-controls {
    width: 100%;
    grid-template-columns: 36px minmax(50px, 1fr) 36px 68px;
  }

  #levelPickerInput {
    width: 100%;
  }
}

@media (max-height: 680px) and (orientation: landscape) {
  :root {
    --spool-height: 140px;
    --bundle-height: 23px;
  }

  .topbar {
    min-height: 58px;
  }

  .brand small,
  .progress-band {
    display: none;
  }

  .board-wrap {
    padding-block: 4px;
  }

  .tool-dock {
    min-height: 54px;
  }
}

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