:root {
  --ink: #fbf5ea;
  --ink-dim: rgba(251, 245, 234, 0.72);
  --ink-faint: rgba(251, 245, 234, 0.45);
  --shade: rgba(28, 24, 34, 0.28);
  --shade-strong: rgba(28, 24, 34, 0.55);
  --warm: #f3c98b;
  --hurt: #f09a6a;
  --down: #e0705a;
  --buried: #b99a74;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --gutter: max(16px, env(safe-area-inset-left));
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2b2a3a;
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#stage:active {
  cursor: grabbing;
}

button {
  font: inherit;
  color: inherit;
}

/* A soft scrim along the top, so pale text still reads against a bright sky. */
body::before {
  content: '';
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  height: 190px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(30, 24, 34, 0.26), rgba(30, 24, 34, 0));
  z-index: 1;
  transition: opacity 1.6s ease;
}

body.bare::before,
body.intro::before {
  opacity: 0;
}

/* A soft vignette over everything. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 55%, transparent 55%, rgba(20, 14, 24, 0.32) 100%);
  z-index: 1;
}

.chrome {
  position: fixed;
  z-index: 2;
  text-shadow: 0 1px 10px rgba(20, 16, 28, 0.55), 0 0 2px rgba(20, 16, 28, 0.35);
  transition: opacity 1.6s ease;
}

body.idle .chrome {
  opacity: 0.18;
}

body.idle #log {
  opacity: 0.8;
}

body.bare .chrome,
body.bare #label {
  opacity: 0 !important;
  pointer-events: none;
}

body.bare #buttons {
  opacity: 0.35 !important;
  pointer-events: auto;
}

body.intro .chrome,
body.intro #label {
  opacity: 0;
  pointer-events: none;
}

/* ------------------------------------------------------------------ almanac */

#almanac {
  top: max(16px, env(safe-area-inset-top));
  left: var(--gutter);
  font-size: 15px;
  line-height: 1.45;
  max-width: min(360px, calc(100vw - 32px));
}

#when {
  font-size: 22px;
  letter-spacing: 0.01em;
  margin-bottom: 2px;
}

.wind-line {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-dim);
}

#wind-arrow {
  flex: none;
  transition: transform 0.4s linear;
  filter: drop-shadow(0 1px 4px rgba(20, 16, 28, 0.5));
}

#tide {
  color: var(--ink-faint);
  font-style: italic;
}

/* --------------------------------------------------------------------- herd */

#side {
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

#buttons {
  display: flex;
  gap: 6px;
  transition: opacity 1.6s ease;
}

#buttons button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(251, 245, 234, 0.25);
  background: var(--shade);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.3s, opacity 0.3s;
}

#buttons button:hover {
  background: var(--shade-strong);
}

#buttons button.off {
  opacity: 0.45;
}

#btn-sound.off .waves {
  display: none;
}

#herd {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 232px;
}

.beest-row {
  display: grid;
  grid-template-columns: 10px 1fr 44px;
  align-items: center;
  gap: 9px;
  padding: 5px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.3s;
}

.beest-row:hover,
.beest-row.selected {
  background: var(--shade);
}

.beest-row .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warm);
  box-shadow: 0 0 8px rgba(243, 201, 139, 0.6);
}

.beest-row[data-state='resting'] .dot {
  background: var(--ink-faint);
  box-shadow: none;
}

.beest-row[data-state='hurt'] .dot {
  background: var(--hurt);
}

.beest-row[data-state='down'] .dot {
  background: var(--down);
  animation: pulse 2.4s ease-in-out infinite;
}

.beest-row[data-state='buried'] .dot {
  background: var(--buried);
  animation: pulse 3.6s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.beest-row .who {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.beest-row .name {
  font-size: 15px;
}

.beest-row .state {
  font-size: 12.5px;
  color: var(--ink-faint);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.beest-row .health {
  height: 3px;
  border-radius: 2px;
  background: rgba(251, 245, 234, 0.16);
  overflow: hidden;
}

.beest-row .fill {
  display: block;
  height: 100%;
  background: var(--ink-dim);
  transform-origin: left;
  transition: transform 0.6s ease;
}

/* ---------------------------------------------------------------------- log */

#log {
  left: var(--gutter);
  bottom: max(52px, calc(env(safe-area-inset-bottom) + 44px));
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}

.note {
  font-style: italic;
  font-size: 15px;
  color: var(--ink-dim);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 1.2s ease, transform 1.2s ease;
}

.note.in {
  opacity: 1;
  transform: none;
}

.note.out {
  opacity: 0;
}

/* --------------------------------------------------------------------- hint */

#hint {
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  font-size: 13.5px;
  color: var(--ink-faint);
  white-space: nowrap;
  pointer-events: none;
}

#hint b {
  font-weight: normal;
  color: var(--ink-dim);
}

/* -------------------------------------------------------------------- label */

#label {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
  text-align: center;
  text-shadow: 0 1px 10px rgba(20, 16, 28, 0.6), 0 0 2px rgba(20, 16, 28, 0.4);
  will-change: transform;
}

#label.on {
  opacity: 1;
}

#label .inner {
  transform: translate(-50%, calc(-100% - 6px));
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 12px 7px;
  border-radius: 12px;
  background: rgba(30, 24, 34, 0.26);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#label-name {
  font-size: 16px;
  white-space: nowrap;
}

#label-state {
  font-size: 13px;
  font-style: italic;
  color: var(--ink-dim);
  white-space: nowrap;
}

#label-hint {
  font-size: 12.5px;
  color: #ffd9a3;
  white-space: nowrap;
  margin-top: 2px;
}


/* --------------------------------------------------------------------- tend */

#tend {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

#tend.on {
  opacity: 1;
}

#tend svg {
  position: absolute;
  left: -28px;
  top: -28px;
  transform: rotate(-90deg);
  filter: drop-shadow(0 1px 6px rgba(20, 16, 28, 0.5));
}

#tend .track {
  fill: none;
  stroke: rgba(251, 245, 234, 0.2);
  stroke-width: 3;
}

#tend .arc {
  fill: none;
  stroke: var(--ink);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.15s linear;
}

#tend-text {
  position: absolute;
  left: 0;
  top: 34px;
  transform: translateX(-50%);
  font-size: 13px;
  font-style: italic;
  white-space: nowrap;
  text-shadow: 0 1px 8px rgba(20, 16, 28, 0.6);
}

/* -------------------------------------------------------------------- intro */

#intro {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at 50% 60%, rgba(40, 30, 44, 0.25), rgba(24, 18, 30, 0.6));
  transition: opacity 1.5s ease;
}

#intro.gone {
  opacity: 0;
  pointer-events: none;
}

#intro .card {
  max-width: 460px;
  text-align: center;
  text-shadow: 0 1px 14px rgba(20, 16, 28, 0.7);
}

#intro h1 {
  font-weight: normal;
  font-size: clamp(42px, 9vw, 64px);
  letter-spacing: 0.02em;
  margin: 0 0 10px;
}

#intro p {
  font-size: 16.5px;
  line-height: 1.55;
  color: var(--ink-dim);
  margin: 0 0 14px;
}

#intro .lede {
  font-size: 19px;
  color: var(--ink);
  font-style: italic;
}

#intro .small {
  font-size: 13px;
  color: var(--ink-faint);
  margin-top: 22px;
}

#intro .actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 26px;
}

#intro .primary {
  padding: 12px 26px;
  border-radius: 999px;
  border: 1px solid rgba(251, 245, 234, 0.55);
  background: rgba(251, 245, 234, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 17px;
  cursor: pointer;
  transition: background 0.3s;
}

#intro .primary:hover {
  background: rgba(251, 245, 234, 0.24);
}

#intro .quiet {
  border: 0;
  background: none;
  color: var(--ink-faint);
  font-size: 14px;
  font-style: italic;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(251, 245, 234, 0.25);
}

/* ------------------------------------------------------------------- mobile */

@media (max-width: 720px) {
  #herd {
    width: 176px;
  }

  .beest-row {
    grid-template-columns: 8px 1fr;
    padding: 4px 8px;
  }

  .beest-row .health {
    display: none;
  }

  .beest-row .name {
    font-size: 14px;
  }

  #almanac {
    font-size: 13.5px;
    max-width: calc(100vw - 210px);
  }

  #when {
    font-size: 19px;
  }

  #hint {
    white-space: normal;
    text-align: center;
    width: calc(100vw - 32px);
    font-size: 12.5px;
  }

  #log {
    bottom: 64px;
  }
}

@media (max-width: 460px) {
  #herd .state {
    display: none;
  }

  #herd {
    width: 132px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .beest-row .dot {
    animation: none !important;
  }
}

/* --------------------------------------------------------------- additions */

#btn-pace {
  width: auto !important;
  padding: 0 10px 0 9px;
  border-radius: 17px !important;
  display: flex !important;
  gap: 4px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

#btn-pace.on,
#btn-strain.on {
  background: rgba(251, 245, 234, 0.2);
  border-color: rgba(251, 245, 234, 0.55);
}

#btn-strain[data-mode='all'] {
  color: #ffd9a3;
}

body.racing #buttons #btn-pace {
  color: #ffd9a3;
}

#herd {
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  scrollbar-width: none;
}

#herd::-webkit-scrollbar {
  display: none;
}

.beest-row {
  padding: 3px 10px;
}

.beest-row[data-size='small'] .name::after {
  content: ' ·';
  opacity: 0.5;
}

.beest-row[data-size='big'] .name {
  letter-spacing: 0.02em;
}

.beest-row[data-state='anchored'] .dot {
  background: #b9c8d8;
  box-shadow: 0 0 6px rgba(185, 200, 216, 0.6);
}

#label-strain {
  font-size: 12px;
  color: var(--ink-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#btn-blow.on {
  background: rgba(251, 245, 234, 0.2);
  border-color: rgba(251, 245, 234, 0.55);
  color: #ffd9a3;
}

body.blowing #hint::after {
  content: ' · swipe to blow';
  color: #ffd9a3;
}

/* ------------------------------------------------- the herd, folded to dots */

/* A column of dots at the edge; names open out on hover or focus, and the
   one you follow keeps its name. */
#herd {
  width: auto;
  align-items: flex-end;
  gap: 0;
}

.beest-row {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 0;
  padding: 4px 8px;
}

.beest-row .who,
.beest-row .health {
  max-width: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-width 0.45s ease, max-height 0.45s ease, opacity 0.35s ease, margin 0.45s ease;
}

.beest-row .who {
  text-align: right;
  align-items: flex-end;
}

.beest-row .health {
  flex: none;
  width: 36px;
}

#herd:hover .beest-row .who,
#herd:focus-within .beest-row .who,
.beest-row.selected .who {
  max-width: 190px;
  max-height: 44px;
  opacity: 1;
  margin-right: 9px;
}

#herd:hover .beest-row .health,
#herd:focus-within .beest-row .health {
  max-width: 36px;
  max-height: 4px;
  opacity: 1;
  margin-right: 10px;
}

#herd:not(:hover):not(:focus-within) .beest-row.selected {
  background: transparent;
}

#herd:not(:hover):not(:focus-within) .beest-row.selected .state {
  display: none;
}

.beest-row .dot {
  flex: none;
  transition: transform 0.3s ease;
}

.beest-row.selected .dot {
  transform: scale(1.35);
}

/* The instructions fade once you have found your way around. */
#hint {
  transition: opacity 2.5s ease;
}

body.knows #hint {
  opacity: 0;
}

body.knows.blowing #hint {
  opacity: 1;
}

/* Crew rings: one over each beest being worked on. */
.crew {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.crew.on {
  opacity: 0.85;
}

.crew.helped.on {
  opacity: 1;
}

.crew svg {
  position: absolute;
  left: -28px;
  top: -28px;
  transform: rotate(-90deg) scale(0.8);
  filter: drop-shadow(0 1px 6px rgba(20, 16, 28, 0.5));
}

.crew.helped svg {
  transform: rotate(-90deg) scale(1);
}

.crew .track {
  fill: none;
  stroke: rgba(251, 245, 234, 0.2);
  stroke-width: 3;
}

.crew .arc {
  fill: none;
  stroke: var(--ink);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s linear;
}

.crew span {
  position: absolute;
  left: 0;
  top: 30px;
  transform: translateX(-50%);
  font-size: 13px;
  font-style: italic;
  white-space: nowrap;
  text-shadow: 0 1px 8px rgba(20, 16, 28, 0.6);
}

/* Send crews to all: a count of how many need help. */
#btn-crews {
  position: relative;
}

#btn-crews[hidden] {
  display: none !important;
}

#btn-crews .count {
  position: absolute;
  right: -3px;
  top: -3px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 8px;
  background: #d9826a;
  color: #fff;
  font-size: 10px;
  line-height: 15px;
  font-variant-numeric: tabular-nums;
}

#btn-crews .count:empty {
  display: none;
}

/* Fingers: larger targets. */
@media (pointer: coarse) {
  #buttons {
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: calc(100vw - 150px);
  }

  #buttons button {
    width: 42px;
    height: 42px;
  }

  #btn-pace {
    border-radius: 21px !important;
  }

  .beest-row {
    padding: 7px 10px;
  }

  .beest-row .dot {
    width: 11px;
    height: 11px;
  }
}
