/* Movement, feedback and the scores dialog. Every color is a theme role, so each theme reaches it. */

/* The frame that holds the chosen knot. It glides from knot to knot. */
.frame { transition: transform .22s cubic-bezier(.3, 1.4, .5, 1); }
.frame[data-live="false"] { opacity: 0; }
.frame-inner { animation: frame-breathe 1.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.frame-glow { fill: color-mix(in srgb, var(--sw-focus) 13%, transparent); stroke: none; }
.frame-under { fill: none; stroke: color-mix(in srgb, black 70%, transparent); stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; }
.frame-bracket { fill: none; stroke: var(--sw-focus); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.frame-tab { fill: var(--sw-focus); }
@keyframes frame-breathe { 50% { transform: scale(1.05); } }
.track { stroke: color-mix(in srgb, var(--sw-focus) 55%, transparent); stroke-width: 3; stroke-dasharray: 2 8; stroke-linecap: round; }
.stage.shake .frame-bracket, .stage.quake .frame-bracket { stroke: var(--sw-danger); }

/* The bottom rows in Growing: they warm as the tangle comes down. */
.danger-band { fill: transparent; transition: fill .4s; }
.danger-band[data-level="near"] { fill: color-mix(in srgb, var(--sw-caution) 16%, transparent); }
.danger-band[data-level="high"] { fill: color-mix(in srgb, var(--sw-danger) 22%, transparent); animation: alarm 1s ease-in-out infinite; }
@keyframes alarm { 50% { fill: color-mix(in srgb, var(--sw-danger) 8%, transparent); } }
.stage[data-danger="true"] { box-shadow: inset 0 -2.5rem 2.5rem -1.5rem color-mix(in srgb, var(--sw-danger) 45%, transparent); }
.stage[data-danger="true"] .limit { stroke-width: 3.5; opacity: 1; animation: limit-pulse .8s ease-in-out infinite; }
@keyframes limit-pulse { 50% { opacity: .35; } }

/* A turn the wrong way, and a run that chokes */
.stage.shake { animation: shake .32s cubic-bezier(.36, .07, .19, .97) 1; }
.stage.quake { animation: quake .7s cubic-bezier(.36, .07, .19, .97) 1; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes quake { 10%, 50%, 90% { transform: translate(-7px, 2px); } 30%, 70% { transform: translate(7px, -2px); } }
.stage.choked-now #scene-board { animation: tighten 2.2s ease-out 1; }
@keyframes tighten { 0% { filter: none; } 25% { filter: saturate(.3) brightness(.8); transform: scaleX(.97); } 100% { filter: none; } }
.table[data-status="choked"] #scene-board { filter: saturate(.45); }
.stage.won #scene-board { animation: glow 2.4s ease-out 1; }
@keyframes glow { 0% { filter: none; } 30% { filter: brightness(1.18) saturate(1.3); } 100% { filter: none; } }
.layer#fx { pointer-events: none; }

/* A big word over the board */
.banner {
  position: absolute;
  inset: 40% 0 auto;
  width: fit-content;
  max-width: 92%;
  margin: 0 auto;
  padding: .25em .7em .3em;
  text-align: center;
  font: 900 clamp(1.6rem, 6vmin, 3.2rem)/1.05 var(--sw-display);
  letter-spacing: -.03em;
  color: var(--sw-positive);
  background: color-mix(in srgb, var(--sw-surface) 86%, transparent);
  border: 3px solid currentColor;
  border-radius: 999px;
  box-shadow: 0 .3em 1.2em color-mix(in srgb, var(--sw-on-surface) 22%, transparent);
  pointer-events: none;
  opacity: 0;
  z-index: 1;
}
.banner[data-kind="lose"] { color: var(--sw-danger); }
.banner[data-kind="level"], .banner[data-kind="start"] { color: var(--sw-accent); }
.banner.show { animation: banner 2s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes banner {
  0% { opacity: 0; transform: scale(.4); }
  15% { opacity: 1; transform: scale(1.08); }
  25%, 75% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: translateY(-.6em) scale(.95); }
}

/* The streak, under the figures */
.streak { grid-column: 1 / -1; font-weight: 800; font-size: .9rem; color: var(--sw-positive); min-height: 1.25em; font-variant-numeric: tabular-nums; }
.streak[data-hot="true"] { color: var(--sw-caution); animation: hot 1.1s ease-in-out infinite; }
@keyframes hot { 50% { transform: scale(1.06); } }
.streak:empty::before { content: '\00a0'; }

/* Bar icons */
.icon { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon-text { display: inline-flex; align-items: center; gap: .4rem; }
.icon-only { display: inline-grid; place-items: center; min-width: 2.5rem; padding-inline: .5rem; }
#sound .speaker { fill: currentColor; }
#sound[data-sound="off"] .waves, #sound[data-sound="on"] .cross-out { display: none; }
#sound[data-sound="off"] { color: var(--sw-muted); }
@media (max-width: 56rem) {
  #open-scores .wide { display: none; }
  #open-scores { padding-inline: .55rem; }
}

/* The end of a board */
#result { width: min(30rem, calc(100vw - 1.5rem)); text-align: center; overflow: visible; }
#result[open] { animation: rise-in .45s cubic-bezier(.2, 1.3, .4, 1) both; }
@keyframes rise-in { from { opacity: 0; transform: translateY(1.5rem) scale(.92); } }
.result-badge {
  width: 4.5rem; height: 4.5rem; margin: -3.2rem auto .5rem;
  display: grid; place-items: center;
  border-radius: 50%;
  font: 900 2.3rem/1 var(--sw-display);
  color: var(--sw-on-action);
  background: var(--sw-positive);
  border: 4px solid var(--sw-raised);
  box-shadow: 0 .4rem 1.2rem color-mix(in srgb, var(--sw-on-surface) 25%, transparent);
  animation: badge .7s .15s cubic-bezier(.2, 1.6, .4, 1) both;
}
#result[data-outcome="lost"] .result-badge { background: var(--sw-danger); }
@keyframes badge { from { transform: scale(0) rotate(-40deg); } }
#result h2 { margin-bottom: .2rem; }
.result-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem; margin: .9rem 0 .2rem; font-variant-numeric: tabular-nums; }
.result-stats div { min-width: 4.6rem; padding: .35rem .6rem; border: 1px solid color-mix(in srgb, var(--sw-border) 60%, transparent); border-radius: calc(var(--sw-radius) / 2); }
.result-stats dt { font-size: .72rem; color: var(--sw-muted); }
.result-stats dd { margin: 0; font-weight: 800; font-size: 1.2rem; }
.result-stats div[data-figure="score"] { border-color: var(--sw-accent); }
.result-stats div[data-figure="score"] dd { color: var(--sw-accent); font-size: 1.5rem; }
.result-best { color: var(--sw-on-raised) !important; font-weight: 650; }
.result-best:empty { display: none; }
#result .actions { grid-template-columns: 1fr 1fr; }

/* Leaderboards and history */
#scores { width: min(46rem, calc(100vw - 1.5rem)); }
.tabs { display: flex; gap: .35rem; border-bottom: 1px solid color-mix(in srgb, var(--sw-border) 60%, transparent); margin-bottom: .8rem; }
.tabs [role="tab"] { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; color: var(--sw-muted); padding-inline: .8rem; }
.tabs [role="tab"][aria-selected="true"] { color: var(--sw-on-raised); border-bottom-color: var(--sw-accent); }
.panel .boards { display: grid; gap: .2rem 1.5rem; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
.panel h3 { margin-block: .8rem .4rem; }
.panel .hint:empty { display: none; }
.leaders { list-style: none; margin: 0 0 .5rem; padding: 0; display: grid; gap: .2rem; font-variant-numeric: tabular-nums; }
.leaders li { display: grid; grid-template-columns: 1.8rem minmax(0, 1fr) auto; gap: .5rem; align-items: baseline; padding: .3rem .5rem;
  border-radius: calc(var(--sw-radius) / 3); background: color-mix(in srgb, var(--sw-on-raised) 4%, transparent); }
.leaders li.empty { display: block; color: var(--sw-muted); font-size: .88rem; background: none; }
.leaders li[data-mine="true"] { outline: 2px solid var(--sw-accent); background: color-mix(in srgb, var(--sw-accent) 12%, transparent); }
.leaders .rank { font-weight: 850; text-align: center; }
.leaders li:nth-child(1) .rank { color: var(--sw-caution); }
.leaders .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.leaders .what { color: var(--sw-muted); font-size: .85rem; white-space: nowrap; }
.leaders.mini { margin: .6rem auto 0; max-width: 22rem; text-align: left; }
.leaders.mini:empty { display: none; }
.chart-box { margin: .8rem 0; }
.chart { width: 100%; height: 5.5rem; display: block; }
.chart .bar { fill: color-mix(in srgb, var(--sw-accent) 55%, transparent); }
.chart .bar.top { fill: var(--sw-caution); }
.chart-box figcaption { font-size: .8rem; color: var(--sw-muted); margin-top: .25rem; }
.bests { list-style: none; padding: 0; margin: .5rem 0; font-size: .88rem; color: var(--sw-muted); display: grid; gap: .15rem; }
.history { list-style: none; padding: 0; margin: .6rem 0; display: grid; gap: .3rem; max-height: 18rem; overflow: auto; }
.history li { display: grid; grid-template-columns: 4rem minmax(0, 1fr); gap: 0 .6rem; padding: .35rem .5rem; border-inline-start: 4px solid var(--sw-positive);
  background: color-mix(in srgb, var(--sw-on-raised) 4%, transparent); border-radius: calc(var(--sw-radius) / 4); }
.history li[data-status="choked"] { border-color: var(--sw-danger); }
.history li[data-status="retired"] { border-color: var(--sw-muted); }
.history .when { grid-row: span 2; color: var(--sw-muted); font-size: .8rem; }
.history .how { color: var(--sw-muted); font-size: .84rem; }
#history-figures { margin-top: 0; }

@media (prefers-reduced-motion: reduce) {
  .frame { transition: none; }
  .banner.show { opacity: 1; }
}
@media (forced-colors: active) {
  .frame-bracket { stroke: Highlight; }
  .frame-tab { fill: Highlight; }
  .leaders li[data-mine="true"] { outline-color: Highlight; }
}
/* A board that is over has nothing to undo. */
.table:not([data-status="active"]) .ring, .table:not([data-status="active"]) .track { display: none; }

/* Yarn: bold, plied and a little fuzzy, with wound balls lit from the upper left. */
body[data-setting="yarn"] #scene-board { filter: saturate(1.35) contrast(1.04); }
body[data-setting="yarn"] .strands { filter: drop-shadow(0 2.5px 1.5px color-mix(in srgb, var(--sw-on-surface) 30%, transparent)); }
.yarn-fuzz { fill: none; stroke: var(--c); stroke-width: 15; stroke-linecap: round; stroke-linejoin: round; opacity: .32; }
.yarn-edge { fill: none; stroke: color-mix(in srgb, var(--c) 45%, var(--e)); stroke-width: 13.5; stroke-linecap: round; stroke-linejoin: round; }
.ply { fill: none; stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; }
.twist-light { fill: white; fill-opacity: .42; }
.twist-dark { fill: black; fill-opacity: .22; }
.shine { fill: none; stroke: white; stroke-width: 1.6; stroke-linecap: round; opacity: .28; }
.ball-shadow { fill: color-mix(in srgb, var(--sw-on-surface) 25%, transparent); }
.shade-light { stop-color: white; stop-opacity: .55; }
.shade-clear { stop-color: white; stop-opacity: 0; }
.shade-dark { stop-color: black; stop-opacity: .38; }
.loose { fill: none; stroke: var(--c); stroke-width: 3.2; stroke-linecap: round; }
body[data-setting="yarn"] .tag-plate { stroke-width: 1.2; }

/* The kitten, on the rail. app.js moves it and sets its mood. Its fur is a ginger tabby whatever the theme,
   drawn with a dark outline so it stands out on light and dark tables alike. */
.kitten { --fur: color-mix(in srgb, var(--sw-caution) 58%, var(--sw-danger) 42%); --ink: color-mix(in srgb, var(--sw-danger) 22%, black);
  --tabby: color-mix(in srgb, var(--sw-danger) 45%, black 40%); }
.kitten-place { transition: transform var(--walk, .6s) cubic-bezier(.45, .05, .4, 1); }
.kitten-facing { transition: transform .2s; }
.kitten-place[data-facing="left"] .kitten-facing { transform: scaleX(-1); }
.kitten-body { fill: var(--fur); }
.kitten-body { stroke: var(--ink); stroke-width: 1.4; stroke-linejoin: round; }
.kitten-line { fill: none; stroke: var(--ink); stroke-width: 8.8; stroke-linecap: round; }
.kitten-fill { fill: none; stroke: var(--fur); stroke-width: 6; stroke-linecap: round; }
.kitten-belly { fill: color-mix(in srgb, var(--sw-caution) 22%, white); }
.kitten-stripe { fill: none; stroke: var(--tabby); stroke-width: 1.9; stroke-linecap: round; }
.kitten-inner { fill: color-mix(in srgb, var(--sw-danger) 45%, white); }
.kitten-eye { fill: color-mix(in srgb, var(--sw-positive) 75%, var(--sw-caution)); stroke: var(--ink); stroke-width: 1; }
.kitten-glint { fill: white; }
.kitten-lid { fill: var(--fur); }
.kitten-brow { stroke: var(--ink); stroke-width: 1.7; stroke-linecap: round; }
.kitten-nose { fill: color-mix(in srgb, var(--sw-danger) 70%, white); }
.kitten-mouth { fill: none; stroke: var(--ink); stroke-width: 1.2; stroke-linecap: round; }
.kitten-fang { fill: white; }
.kitten-whisker, .kitten-claw { stroke: color-mix(in srgb, var(--ink) 70%, transparent); stroke-width: .8; fill: none; stroke-linecap: round; }
.kitten-pupil { fill: var(--ink); }
.kitten, .kitten-head, .kitten-ears, .kitten-ear, .kitten-paw, .kitten-tail, .kitten-pupil, .kitten-lid, .kitten-brow { transform-box: fill-box; }
.kitten { transform-origin: 50% 100%; }
.kitten-head { transform-origin: 50% 80%; }
.kitten-ear.left { transform-origin: 80% 100%; }
.kitten-ear.right { transform-origin: 20% 100%; }
.kitten-paw { transform-origin: 30% 100%; }
.kitten-tail { transform-origin: 0% 100%; animation: tail-swish 1.6s ease-in-out infinite alternate; }
.kitten-lid, .kitten-brow { transition: transform .2s; }
@keyframes tail-swish { from { transform: rotate(-12deg); } to { transform: rotate(14deg); } }
/* Walking: a trot. */
.kitten-place.walking .kitten { animation: trot .26s ease-in-out infinite alternate; }
@keyframes trot { from { transform: translateY(0) rotate(-2deg); } to { transform: translateY(-2.5px) rotate(2deg); } }
/* Watching where it will strike: pupils follow, head tilts. */
.kitten[data-mood="watch"] .kitten-head { animation: tilt 2.4s ease-in-out infinite; }
@keyframes tilt { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
/* About to strike: low, wiggling, ears forward, pupils wide. */
.kitten[data-mood="crouch"] { animation: wiggle .18s ease-in-out infinite alternate; }
.kitten[data-mood="crouch"] .kitten-pupil { transform: scaleX(2.6); }
.kitten[data-mood="crouch"] .kitten-tail { animation-duration: .25s; }
@keyframes wiggle { from { transform: translateY(3px) scaleY(.9) rotate(-4deg); } to { transform: translateY(3px) scaleY(.9) rotate(4deg); } }
/* The strike: up, down onto the yarn, paw swiping. */
.kitten.pounce, .kitten[data-mood="pounce"] { animation: strike .9s cubic-bezier(.3, .1, .3, 1) 1; }
.kitten[data-mood="pounce"] .kitten-paw { animation: swipe .9s ease-in-out 1; }
@keyframes strike { 0% { transform: none; } 25% { transform: translateY(-16px) rotate(-8deg); } 45% { transform: translateY(10px) scaleY(.92) rotate(5deg); } 70% { transform: translateY(6px); } 100% { transform: none; } }
@keyframes swipe { 0%, 30% { transform: none; } 45% { transform: translate(4px, 7px) rotate(-40deg); } 60% { transform: translate(-3px, 9px) rotate(30deg); } 100% { transform: none; } }
/* A wrong turn: delight. A hop and a happy squint. */
.kitten[data-mood="glee"] { animation: glee .55s ease-in-out 2; }
.kitten[data-mood="glee"] .kitten-lid, .kitten[data-mood="glee"] .kitten-brow { transform: translateY(2.2px); }
@keyframes glee { 0%, 100% { transform: none; } 40% { transform: translateY(-9px) rotate(-5deg); } 70% { transform: translateY(-3px) rotate(4deg); } }
/* A streak: ears flat, glaring. */
.kitten[data-mood="grump"] .kitten-ear.left { transform: rotate(-55deg) translateY(3px); }
.kitten[data-mood="grump"] .kitten-ear.right { transform: rotate(55deg) translateY(3px); }
.kitten[data-mood="grump"] .kitten-pupil { transform: scaleX(.6); }
.kitten[data-mood="grump"] .kitten-tail { animation-duration: .4s; }
/* A cleared board: sulking, ears back, looking away. */
.kitten[data-mood="sulk"] .kitten-head { transform: rotate(-14deg) translateX(-2px); }
.kitten[data-mood="sulk"] .kitten-ear.left { transform: rotate(-40deg); }
.kitten[data-mood="sulk"] .kitten-ear.right { transform: rotate(40deg); }
.kitten[data-mood="sulk"] .kitten-lid, .kitten[data-mood="sulk"] .kitten-brow { transform: translateY(1.6px); }
.kitten[data-mood="sulk"] .kitten-tail { animation: none; transform: rotate(40deg); }
/* A choked run: very pleased with itself. */
.kitten[data-mood="smug"] .kitten-lid, .kitten[data-mood="smug"] .kitten-brow { transform: translateY(2.6px); }
.kitten[data-mood="smug"] .kitten-head { transform: rotate(5deg); }
.kitten[data-mood="smug"] .kitten-tail { animation-duration: 2.6s; }
/* Batting at a strand while it waits in Calm. */
.kitten[data-mood="bat"] .kitten-paw { animation: swipe .7s ease-in-out 2; }
.swat { opacity: 0; }
.claw { stroke: var(--sw-danger); stroke-width: 3; stroke-linecap: round; fill: none; }
.swat.pounce { animation: swat .9s ease-out 1; }
@keyframes swat { 0%, 35% { opacity: 0; } 50% { opacity: 1; } 100% { opacity: 0; } }
@media (forced-colors: active) {
  .ball-shade, .yarn-fuzz, .ply, .shine { display: none; }
}
