/*
 * Zen Fingers — rice paper, sumi ink and a single vermilion seal.
 */

:root {
  --paper: #f4f1ea;
  --ink: #2a2925;
  --ink-soft: #5c5850;
  --muted: #a39e92;
  --faint: #e2ddd1;
  --wash: #ebe7dd;
  --accent: #b5533c;
  --accent-wash: rgb(181 83 60 / 0.14);

  /* One quiet tint per finger, mirrored across both hands */
  --finger-pinky: #d9e1e8;
  --finger-ring: #d8e3d5;
  --finger-middle: #ece0c6;
  --finger-index: #efd9ce;
  --finger-thumb: #e6e2d8;

  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  --measure: 46rem;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1a1917;
    --ink: #e8e3d8;
    --ink-soft: #bbb5a8;
    --muted: #6f6a60;
    --faint: #33312d;
    --wash: #24221f;
    --accent: #da8467;
    --accent-wash: rgb(218 132 103 / 0.16);

    --finger-pinky: #28313a;
    --finger-ring: #27332b;
    --finger-middle: #39341f;
    --finger-index: #432a2a;
    --finger-thumb: #2b2926;

    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, p, dl, dd {
  margin: 0;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
}

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

.inline-form {
  display: inline;
}

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

/* Small caps labels used throughout */
.nav-link,
.stat dt,
.panel-title,
.key-hint,
.collection,
.text-button,
.recent th {
  font-family: var(--sans);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

/* Header ------------------------------------------------------------------ */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem clamp(1rem, 4vw, 2.5rem);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
}

.brand-name {
  font-family: var(--serif);
  font-size: 1.125rem;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
}

.nav {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 3vw, 2rem);
}

.nav-link {
  padding: 0.25rem 0;
  border: 0;
  background: none;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.3s var(--ease);
}

.nav-link:hover,
.nav-link.is-current {
  color: var(--ink);
}

.flash {
  align-self: center;
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--faint);
}

.flash--alert {
  color: var(--accent);
}

/* Ensō -------------------------------------------------------------------- */

.enso {
  display: block;
  overflow: visible;
}

.enso circle {
  fill: none;
  stroke-linecap: round;
}

.enso-track {
  stroke: var(--faint);
  stroke-width: 7;
}

.enso-stroke {
  stroke: var(--ink);
  stroke-width: 7;
  transition: stroke-dasharray 1.2s var(--ease);
}

.enso--small {
  width: 1.75rem;
  height: 1.75rem;
}

.enso--small .enso-track,
.enso--small .enso-stroke {
  stroke-width: 9;
}

.enso--large {
  width: clamp(7rem, 22vw, 9.5rem);
  height: clamp(7rem, 22vw, 9.5rem);
}

.enso--large .enso-track {
  stroke: transparent;
}

.enso--large .enso-stroke {
  stroke-width: 6;
}

.enso.is-drawing .enso-stroke {
  animation: draw-enso 2.8s var(--ease) 0.2s both;
}

@keyframes draw-enso {
  from {
    stroke-dashoffset: 231;
    opacity: 0.2;
  }
  to {
    stroke-dashoffset: 0;
    opacity: 1;
  }
}

/* Layout ------------------------------------------------------------------ */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem clamp(1rem, 4vw, 2.5rem) 3rem;
}

/* Welcome ----------------------------------------------------------------- */

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.75rem;
  text-align: center;
  animation: rise 1.2s var(--ease) both;
}

.welcome-title {
  margin-top: 0.5rem;
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(2.25rem, 6vw, 3rem);
  letter-spacing: 0.01em;
}

.welcome-lede {
  max-width: 26rem;
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.7;
  color: var(--ink-soft);
}

.welcome-note {
  max-width: 26rem;
  margin-top: 0.75rem;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--muted);
}

.welcome-note code {
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

.button {
  margin-top: 0.75rem;
  padding: 0.8rem 1.75rem;
  border: 1px solid var(--ink-soft);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 0.9375rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background-color 0.4s var(--ease), color 0.4s var(--ease);
}

.button:hover {
  background: var(--ink);
  color: var(--paper);
}

.text-button {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.3s var(--ease);
}

.text-button:hover {
  color: var(--ink);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(0.75rem);
  }
}

/* Practice ---------------------------------------------------------------- */

.practice {
  width: min(var(--measure), 100%);
}

.passage-frame {
  position: relative;
  cursor: text;
}

.passage {
  position: relative;
  font-family: var(--serif);
  font-size: clamp(1.375rem, 1rem + 1.6vw, 1.875rem);
  font-weight: 350;
  line-height: 1.8;
  color: var(--muted);
  transition: filter 0.5s var(--ease), opacity 0.5s var(--ease);
}

.word {
  display: inline-block;
  white-space: pre;
}

.char[data-state="correct"] {
  color: var(--ink);
}

.char[data-state="incorrect"] {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.3em;
}

.char.space[data-state="incorrect"] {
  background: var(--accent-wash);
  border-radius: 2px;
}

.caret {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--accent);
  pointer-events: none;
  transition: transform 0.1s ease-out;
  animation: breathe 1.4s ease-in-out infinite;
}

.is-typing .caret {
  animation: none;
}

.is-finished .caret {
  opacity: 0;
  transition: opacity 0.4s;
}

@keyframes breathe {
  50% {
    opacity: 0.15;
  }
}

.typing-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  padding: 0;
  font-size: 16px; /* stops iOS zooming in on focus */
  color: transparent;
  background: transparent;
  caret-color: transparent;
  cursor: text;
  resize: none;
}

.focus-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.875rem;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s var(--ease);
}

.is-blurred .passage {
  filter: blur(4px);
  opacity: 0.5;
}

.is-blurred .focus-hint {
  opacity: 1;
}

.is-blurred .caret {
  visibility: hidden;
}

.attribution {
  margin-top: 1.75rem;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--muted);
}

/* Stats ------------------------------------------------------------------- */

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem 3rem;
  margin-top: 2.75rem;
}

.stat {
  display: flex;
  flex-direction: column-reverse;
  gap: 0.25rem;
}

.stat dt {
  color: var(--muted);
}

.stat dd {
  font-family: var(--serif);
  font-size: 1.75rem;
  font-weight: 300;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  transition: color 0.6s var(--ease);
}

.stat small {
  font-size: 0.9rem;
  color: var(--muted);
}

.practice .stats {
  opacity: 0.55;
  transition: opacity 0.6s var(--ease);
}

.practice.is-typing .stats {
  opacity: 0.8;
}

.practice.is-finished .stats {
  opacity: 1;
}

.practice.is-finished .stat dd {
  color: var(--ink);
}

.stats--grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: 2rem;
}

/* Controls ---------------------------------------------------------------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 2rem;
  margin-top: 2.5rem;
}

.key-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.25rem 0;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.3s var(--ease);
}

.key-hint:hover {
  color: var(--ink);
}

kbd {
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--faint);
  border-radius: 4px;
  font-family: var(--sans);
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  text-transform: lowercase;
}

.when-finished,
.is-finished .when-typing {
  display: none;
}

.is-finished .when-finished {
  display: inline;
}

.is-finished .key-hint--next {
  color: var(--ink);
}

/* Finger map -------------------------------------------------------------- */

.finger-map {
  display: grid;
  grid-template-rows: 0fr;
  margin-top: 0;
  opacity: 0;
  transition: grid-template-rows 0.6s var(--ease), margin-top 0.6s var(--ease), opacity 0.5s var(--ease);
}

.finger-map.is-open {
  grid-template-rows: 1fr;
  margin-top: 2.5rem;
  opacity: 1;
}

.finger-map-inner {
  min-height: 0;
  overflow: hidden;
}

[data-finger-type="pinky"] { --tint: var(--finger-pinky); }
[data-finger-type="ring"] { --tint: var(--finger-ring); }
[data-finger-type="middle"] { --tint: var(--finger-middle); }
[data-finger-type="index"] { --tint: var(--finger-index); }
[data-finger-type="thumb"] { --tint: var(--finger-thumb); }

.keyboard-frame {
  container-type: inline-size;
  padding: 2px; /* room for the highlight ring */
}

.keyboard {
  --gap: 4px;
  --unit: calc((100cqi - 59 * var(--gap)) / 15 + 3 * var(--gap));

  display: grid;
  grid-template-columns: repeat(60, minmax(0, 1fr));
  grid-auto-rows: calc(var(--unit) * 0.82);
  gap: var(--gap);
}

.key {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--tint);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: clamp(0.625rem, 1.9cqi, 0.875rem);
  line-height: 1;
  user-select: none;
  transition: box-shadow 0.15s ease, color 0.15s ease;
}

.key-shift {
  position: absolute;
  top: 16%;
  left: 14%;
  font-size: 0.75em;
  color: var(--muted);
}

@container (max-width: 32rem) {
  .key-shift {
    display: none;
  }
}

.key--modifier {
  place-items: end start;
  padding: 0 0 14% 12%;
  font-size: clamp(0.5rem, 1.4cqi, 0.6875rem);
  letter-spacing: 0.08em;
  color: var(--muted);
}

.key--home {
  color: var(--ink);
  font-weight: 500;
}

/* The raised bumps on F and J */
.key--bump::after {
  content: "";
  position: absolute;
  bottom: 17%;
  left: 50%;
  width: 22%;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  opacity: 0.45;
  transform: translateX(-50%);
}

.key.is-next {
  color: var(--accent);
  box-shadow: 0 0 0 1.5px var(--accent);
}

.key.is-next .key-shift {
  color: var(--accent);
}

.finger-map-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  margin-top: 1.25rem;
}

.finger-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.finger-legend li {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.2s ease;
}

.finger-legend li.is-active {
  color: var(--ink);
}

.finger-swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 3px;
  background: var(--tint);
}

.finger-caption {
  flex: 1;
  min-width: 9rem;
  min-height: 1.4em;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--muted);
  text-align: center;
}

.layout-switch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
}

.layout-switch button {
  padding: 0.2rem 0;
  border: 0;
  border-bottom: 1px solid transparent;
  background: none;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.3s var(--ease);
}

.layout-switch button:hover,
.layout-switch button[aria-pressed="true"] {
  color: var(--ink-soft);
}

.layout-switch button[aria-pressed="true"] {
  border-bottom-color: var(--faint);
}

/* Collections ------------------------------------------------------------- */

.collections {
  display: flex;
  justify-content: center;
  gap: 1.75rem;
  padding: 0 1rem 2rem;
}

.collection {
  padding: 0.25rem 0;
  border: 0;
  border-bottom: 1px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.3s var(--ease), border-color 0.3s var(--ease);
}

.collection:hover {
  color: var(--ink-soft);
}

.collection.is-current {
  color: var(--ink-soft);
  border-bottom-color: var(--faint);
}

/* Progress ---------------------------------------------------------------- */

.main:has(.progress-page) {
  justify-content: flex-start;
}

.progress-page {
  width: min(var(--measure), 100%);
  display: flex;
  flex-direction: column;
  gap: 3.5rem;
  animation: rise 0.8s var(--ease) both;
}

.page-heading h1 {
  font-family: var(--serif);
  font-weight: 300;
  font-size: 2.5rem;
}

.page-lede {
  margin-top: 0.5rem;
  font-family: var(--serif);
  font-size: 1.125rem;
  color: var(--ink-soft);
}

.panel-title {
  margin-bottom: 1.25rem;
  color: var(--muted);
}

.empty {
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
}

.calendar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.calendar-week {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.calendar-day {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ink);
}

.calendar-day.level-0 {
  background: var(--faint);
}

.calendar-day.level-1 { opacity: 0.3; }
.calendar-day.level-2 { opacity: 0.5; }
.calendar-day.level-3 { opacity: 0.72; }
.calendar-day.level-4 { opacity: 1; }

.calendar-day.is-future {
  background: transparent;
}

.panel:has(.trend) {
  position: relative;
}

.trend {
  display: block;
  width: 100%;
  height: 7.5rem;
  overflow: visible;
}

.trend polyline {
  fill: none;
  stroke: var(--ink-soft);
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.trend-dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 7.5rem;
  pointer-events: none;
}

.trend-dot {
  position: absolute;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 50%;
  background: var(--paper);
  border: 1.5px solid var(--ink-soft);
  pointer-events: auto;
}

.recent {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.recent th {
  padding: 0 0 0.75rem;
  text-align: left;
  color: var(--muted);
}

.recent td {
  padding: 0.7rem 0;
  border-top: 1px solid var(--faint);
  color: var(--ink-soft);
  font-size: 0.9375rem;
}

.recent th:nth-child(n + 3),
.recent td:nth-child(n + 3) {
  text-align: right;
}

.recent-source {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  padding-right: 1rem;
}

.goal-form {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  font-family: var(--serif);
  font-size: 1.125rem;
  color: var(--ink-soft);
}

.goal-input {
  width: 4rem;
  padding: 0.25rem 0;
  border: 0;
  border-bottom: 1px solid var(--faint);
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.5rem;
  text-align: center;
}

.goal-input:focus {
  outline: none;
  border-bottom-color: var(--ink-soft);
}

/* Small screens ----------------------------------------------------------- */

@media (max-width: 40rem) {
  .brand-name {
    display: none;
  }

  .stats {
    gap: 1.25rem 2rem;
  }

  .stat dd {
    font-size: 1.5rem;
  }

  .recent th:nth-child(1),
  .recent td:nth-child(1) {
    display: none;
  }
}

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