@font-face {
  font-family: 'Fraunces Soft';
  src: url('fonts/fraunces-soft-latin.woff2') format('woff2');
  font-weight: 300 600;
  font-display: swap;
}

/* Mode palette: app.js sets these on <html>; registered so a mode change fades instead of jumping. */
@property --night { syntax: '<color>'; inherits: true; initial-value: #1e1626; }
@property --dusk { syntax: '<color>'; inherits: true; initial-value: #3d2839; }
@property --glow { syntax: '<color>'; inherits: true; initial-value: #f2b36b; }
@property --fur { syntax: '<color>'; inherits: true; initial-value: #e08d52; }
@property --fur-shade { syntax: '<color>'; inherits: true; initial-value: #a85c33; }
@property --fur-light { syntax: '<color>'; inherits: true; initial-value: #f7c995; }
@property --cushion { syntax: '<color>'; inherits: true; initial-value: #4a3247; }
@property --stripes { syntax: '<number>'; inherits: true; initial-value: 0.55; }
@property --fluff { syntax: '<number>'; inherits: true; initial-value: 0; }
@property --cat-scale { syntax: '<number>'; inherits: true; initial-value: 1; }
@property --head-scale { syntax: '<number>'; inherits: true; initial-value: 1; }
@property --rain { syntax: '<number>'; inherits: true; initial-value: 0; }

:root {
  --ink: #f4e9df;
  --ink-soft: rgb(244 233 223 / 0.62);
  --ink-faint: rgb(244 233 223 / 0.16);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --mode-fade: 1.4s var(--ease);
  /* Written every frame by app.js from the recording: breath 0..1, loudness 0..1. */
  --breath: 0;
  --level: 0;
  color-scheme: dark;
  transition:
    --night var(--mode-fade), --dusk var(--mode-fade), --glow var(--mode-fade), --fur var(--mode-fade),
    --fur-shade var(--mode-fade), --fur-light var(--mode-fade), --cushion var(--mode-fade),
    --stripes var(--mode-fade), --fluff var(--mode-fade), --cat-scale var(--mode-fade), --head-scale var(--mode-fade),
    --rain var(--mode-fade);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100dvh;
  overflow: hidden;
  background-color: var(--night);
  background-image: radial-gradient(120% 75% at 50% 64%, var(--dusk) 0%, var(--night) 64%);
  color: var(--ink);
  font-family: 'Fraunces Soft', Georgia, serif;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* Paper grain over everything, so the flat colours read as a soft print. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.07;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 4px;
  border-radius: 14px;
}

.scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.chrome {
  position: relative;
  z-index: 2;
  transition: opacity 1.6s var(--ease);
}

/* While the cat purrs the controls step back; any touch brings them back. */
body.dim .chrome,
body.dim .status {
  opacity: 0.34;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 0 max(22px, env(safe-area-inset-left));
}

.title {
  margin: 0;
  font-size: 2.1rem;
  font-weight: 340;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variation-settings: 'opsz' 144;
}

.timer {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 15px 8px 12px;
  border: 1px solid var(--ink-faint);
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-variation-settings: 'opsz' 14;
  transition: color 0.3s, border-color 0.3s;
}

.timer svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.timer[data-on='true'] {
  color: var(--ink);
  border-color: color-mix(in oklab, var(--glow) 55%, transparent);
}

.stage {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 0 16px;
}

/* The rain window: an arched pane behind the cat, only in the Rain mode. Sized from the cat. */
.window {
  position: absolute;
  left: 50%;
  bottom: 22%;
  width: 62%;
  height: 118%;
  transform: translateX(-50%);
  border: 1px solid color-mix(in oklab, var(--glow) 30%, transparent);
  border-radius: 50% 50% 6px 6px / 40% 40% 6px 6px;
  background:
    linear-gradient(90deg, transparent calc(50% - 1px), color-mix(in oklab, var(--glow) 22%, transparent) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(180deg, transparent 54%, color-mix(in oklab, var(--glow) 22%, transparent) 54% calc(54% + 2px), transparent calc(54% + 2px)),
    radial-gradient(90% 70% at 50% 30%, color-mix(in oklab, var(--glow) 16%, transparent), transparent);
  opacity: var(--rain);
  pointer-events: none;
}

.cat {
  position: relative;
  width: min(92vw, 470px, calc((100dvh - 250px) * 1.43));
  aspect-ratio: 400 / 280;
  border-radius: 40%;
}

.halo {
  position: absolute;
  inset: -34% -14% -12%;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in oklab, var(--glow) 50%, transparent), transparent);
  opacity: calc(0.2 + var(--level) * 0.42);
  transform: scale(calc(0.9 + var(--level) * 0.07 + var(--breath) * 0.02));
  pointer-events: none;
}

.cat[aria-pressed='false'] .halo {
  opacity: 0.16;
}

.cat-art {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.stop-light { stop-color: var(--fur-light); }
.stop-fur { stop-color: var(--fur); }
.stop-shade { stop-color: var(--fur-shade); }
.stop-cushion-light { stop-color: color-mix(in oklab, var(--cushion) 78%, var(--glow)); }
.stop-cushion { stop-color: var(--cushion); }

.cushion { fill: url(#cushion-shade); }
.cushion-side { fill: color-mix(in oklab, var(--cushion) 72%, #000); }
.contact { fill: rgb(0 0 0 / 0.35); }

.sizer {
  transform-box: view-box;
  transform-origin: 214px 244px;
  transform: scale(var(--cat-scale));
}

.body {
  transform-box: fill-box;
  transform-origin: 40% 100%;
  transform: scale(calc(1 + var(--breath) * 0.012), calc(1 + var(--breath) * 0.05));
}

.head-size {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: scale(var(--head-scale));
}

.head {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: translateY(calc(var(--breath) * -2.4px)) rotate(calc(var(--breath) * -1.4deg));
}

/* Long-haired cats get a soft, tufted edge. */
.fluffy {
  stroke-width: calc(var(--fluff) * 1px);
  stroke-linejoin: round;
  stroke-linecap: round;
  stroke-dasharray: 0.1 2.6;
}

.body .fluffy { stroke: url(#fur-body); }
.head .fluffy { stroke: url(#fur-head); }

.stripes path {
  fill: none;
  stroke: var(--fur-shade);
  stroke-width: 7;
  stroke-linecap: round;
  opacity: var(--stripes);
}

.head-stripes path { stroke-width: 3.6; }

.tail-fur,
.tail-rings {
  fill: none;
  stroke-width: calc(23px + var(--fluff) * 1.4px);
  stroke-linecap: round;
}

.tail-fur { stroke: var(--fur); }

.tail-rings {
  stroke: var(--fur-shade);
  stroke-linecap: butt;
  stroke-dasharray: 9 16;
  opacity: calc(var(--stripes) * 0.9);
}

.tail {
  transform-box: fill-box;
  transform-origin: 100% 0%;
}

.paws path { fill: var(--fur-light); }
.paws .paw-back { fill: color-mix(in oklab, var(--fur-light) 70%, var(--fur)); }

/* Cheek ruff and ear tufts show up as the fur gets longer. */
.long-hair { opacity: calc(var(--fluff) / 6); }
.tufts {
  fill: none;
  stroke: var(--fur-light);
  stroke-width: 2.4;
  stroke-linecap: round;
  opacity: 0.8;
}

.ear-inner {
  fill: color-mix(in oklab, var(--fur-shade) 55%, #d98b8b);
  opacity: 0.75;
}

.ear-right,
.ear-right-inner {
  transform-box: fill-box;
  transform-origin: 40% 100%;
}

.muzzle {
  fill: var(--fur-light);
  opacity: 0.9;
}

.eye,
.mouth {
  fill: none;
  stroke: color-mix(in oklab, var(--fur-shade) 35%, #1c1012);
  stroke-linecap: round;
}

.eye { stroke-width: 3; }
.mouth { stroke-width: 1.6; opacity: 0.7; }
.nose { fill: color-mix(in oklab, var(--fur-shade) 35%, #e39a9a); }

.whiskers path {
  stroke: var(--fur-light);
  stroke-width: 1.1;
  stroke-linecap: round;
  opacity: 0.5;
}

/* Small signs of life, triggered now and then by app.js. */
.cat.twitch .ear-right,
.cat.twitch .ear-right-inner {
  animation: twitch 0.42s var(--ease);
}

.cat.flick .tail {
  animation: flick 1.3s var(--ease);
}

@keyframes twitch {
  35% { transform: rotate(-13deg); }
  70% { transform: rotate(3deg); }
}

@keyframes flick {
  30% { transform: rotate(-3deg); }
  65% { transform: rotate(1.4deg); }
}

.status {
  margin: 0;
  min-height: 1.5em;
  max-width: 34ch;
  color: var(--ink-soft);
  font-size: 1.06rem;
  line-height: 1.5;
  text-align: center;
  font-variation-settings: 'opsz' 18;
  transition: opacity 1.6s var(--ease);
}

.modes {
  display: flex;
  justify-content: center;
  gap: clamp(4px, 3vw, 24px);
  padding: 0 16px max(22px, env(safe-area-inset-bottom));
}

.mode {
  display: grid;
  justify-items: center;
  gap: 9px;
  min-width: 66px;
  padding: 10px 8px;
  border-radius: 16px;
  color: var(--ink-soft);
  font-size: 1rem;
  font-variation-settings: 'opsz' 14;
  transition: color 0.4s var(--ease);
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, var(--sw-light), var(--sw-fur) 55%, var(--sw-shade));
  box-shadow: 0 0 0 0 transparent;
  transition: box-shadow 0.4s var(--ease), transform 0.4s var(--ease);
}

.mode[aria-pressed='true'] {
  color: var(--ink);
}

.mode[aria-pressed='true'] .swatch {
  transform: scale(1.15);
  box-shadow: 0 0 0 3px var(--night), 0 0 0 4.5px var(--ink);
}

@media (hover: hover) {
  .mode:hover { color: var(--ink); }
  .timer:hover { color: var(--ink); }
}

@media (max-height: 560px) {
  .title { font-size: 1.6rem; }
  .modes { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .mode { padding: 6px; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  :root { --mode-fade: 0.01s; }
  .body, .head, .halo { transform: none; }
  .cat.twitch .ear-right, .cat.twitch .ear-right-inner, .cat.flick .tail { animation: none; }
  .chrome, .status { transition: none; }
}
