/* theme.js sets data-theme to "light" or "dark", and data-cvd for the
   colour-blind palette, before the first paint. */
:root {
  color-scheme: light;
  --bg: #fbf6ee;
  --ink: #3b2f2a;
  --muted: #7d6f64;
  --tint: #eee8e0; /* a shade off the background, for controls */
  --focus: #e5492f;
  --rest: #8dbd4b;
  --pause: #f0b73a;
  --leaf: #4f8f3a;
  --skin: 0.24; /* how strongly an empty tomato is tinted */
  --shine: 0.3;
  --tap: 0.35rem 0.6rem; /* padding that makes a word a comfortable target */
  --spring: cubic-bezier(0.3, 1.6, 0.5, 1); /* overshoots a little, then settles */
  font-family: ui-rounded, system-ui, sans-serif;
}
/* On a dark page the colours are lifted, so they glow instead of sinking in. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1c1917;
  --ink: #efe6dc;
  --muted: #8f837a;
  --tint: #2b2725;
  --focus: #f0654a;
  --rest: #a3d063;
  --pause: #f5c653;
  --leaf: #6fb157;
  --skin: 0.36;
  --shine: 0.16;
}
/* The colour-blind palette. Red and green are the pair most often confused, so
   the break becomes a purple tomato: blue against yellow and light against
   dark are what red-green colour blindness leaves intact. */
:root[data-cvd] {
  --rest: #7b68d9;
  --pause: #f4c838;
}
:root[data-cvd][data-theme="dark"] {
  --focus: #f0683f;
  --rest: #8a84f0;
  --pause: #f6d04e;
}

* {
  box-sizing: border-box;
  margin: 0;
}

html,
body {
  height: 100%;
}

/* Three text sizes in all: this one, a smaller one for fine print, and a
   slightly larger one for dialog titles. The clock is the one exception. */
body {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-size: 0.95rem;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation; /* no double-tap zoom on quick taps */
  -webkit-user-select: none; /* a long press should not select a button's word */
  user-select: none;
}

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

.defs {
  position: absolute;
}

/* Lets the hidden attribute win over any display set below. */
[hidden] {
  display: none !important;
}

/* The quiet words around the timer: muted, and slightly spaced. */
#phase,
#count,
.quiet,
dialog h2 {
  color: var(--muted);
  letter-spacing: 0.04em;
}

.fine,
dialog h2,
#tip {
  font-size: 0.85em;
}

/* ---- the tomato ---- */

.t {
  --hue: var(--focus);
  display: block;
}
.t[data-s="b"] {
  --hue: var(--rest);
}
.t[data-s="p"] {
  --hue: var(--pause);
}
.t .skin {
  fill: var(--hue);
  fill-opacity: var(--skin);
  transition: fill 0.6s;
}
/* The juice level is a transform. JavaScript sets where it is now and where it
   will be when the session ends, and the browser animates the time between. */
.t .juice {
  fill: var(--hue);
  transform: translateY(75px);
  transition:
    transform var(--over, 0ms) linear,
    fill 0.6s;
}
.t .shine {
  fill: #fff;
  opacity: var(--shine);
}
.t .top {
  fill: var(--leaf);
  stroke: var(--leaf);
}

/* ---- you ---- */

main {
  position: relative; /* keeps the buttons above the field of neighbours */
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.big {
  width: min(52vw, 30vh, 240px);
  border-radius: 50%;
  transition: scale 0.25s var(--spring);
}
.big:active {
  scale: 0.96;
}

#phase {
  margin-top: 1.1rem;
}

/* The clock, with − and + either side while it waits. They keep their place
   when they are out of use, so the digits never shift. */
.clock {
  display: flex;
  align-items: center;
}
.clock button {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  color: var(--muted);
  font-size: 1.4em;
}
.clock button:disabled {
  visibility: hidden;
}

#time {
  font-size: clamp(2.25rem, min(12vw, 13vh), 4.5rem); /* fits narrow and short screens alike */
  font-weight: 300;
  line-height: 1.1;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.quiet,
.mark {
  padding: var(--tap);
  border-radius: 6px;
}
.quiet {
  transition: color 0.2s;
}
/* A press shows at once, which matters most where there is no hover. */
.quiet:active,
.clock button:active {
  color: var(--ink);
}
a.quiet {
  display: inline-block;
  margin-top: 0.4rem;
  text-underline-offset: 0.25em;
}

.controls {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.2rem;
}

#harvest {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  width: 9.5rem;
  min-height: 15px;
  margin-top: 0.7rem;
}
#harvest .t {
  width: 15px;
  animation: arrive 0.5s var(--spring) backwards;
}
#harvest .juice {
  transform: none;
}

/* ---- the town ---- */

#field {
  position: fixed;
  inset: 0;
}
#field .t {
  position: absolute;
  opacity: 0.85;
  animation: arrive 0.7s var(--spring) backwards;
  transition:
    opacity 0.6s,
    left 0.6s,
    top 0.6s,
    scale 0.25s var(--spring);
}
#field .t.pointed {
  scale: 1.15;
}
#field .t[data-s="i"] {
  opacity: 0.5;
}
#field .t.leaving {
  opacity: 0;
}

@keyframes arrive {
  from {
    opacity: 0;
    scale: 0.5;
  }
}

#tip {
  position: fixed;
  translate: -50% calc(-100% - 6px);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  white-space: nowrap;
  pointer-events: none;
}

/* ---- edges ---- */

header,
footer {
  position: fixed;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem max(1.1rem, env(safe-area-inset-right)) 0.9rem
    max(1.1rem, env(safe-area-inset-left));
}
header {
  top: env(safe-area-inset-top);
}
/* The header's buttons carry their own padding. Pulling the header in by the
   same amount keeps their words lined up with the edges of the page. */
header {
  margin: 0 -0.6rem;
}
footer {
  bottom: env(safe-area-inset-bottom);
  justify-content: center;
}

.mark {
  font-weight: 600;
}
/* Holds its line while empty, so the footer is the same height before the town
   has answered as after. The seats are laid out around it. */
#count {
  min-height: 1lh;
}

/* ---- about and settings ---- */

dialog {
  margin: auto;
  width: min(23rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  padding: 1.6rem 1.6rem 1.1rem;
  border: 1px solid var(--tint); /* gives the dialog an edge in the dark theme */
  border-radius: 20px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.18);
  line-height: 1.5;
}
dialog::backdrop {
  background: var(--bg);
  opacity: 0.7;
  backdrop-filter: blur(6px);
}
dialog form {
  display: grid;
  gap: 1.1rem;
}
dialog section {
  display: grid;
  gap: 0.3rem;
}
#settings section {
  gap: 0.55rem;
}
dialog h1 {
  font-size: 1.1em;
  font-weight: 600;
}
dialog h2 {
  font-weight: 600;
}
dialog a {
  color: inherit;
  text-underline-offset: 0.2em;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.7rem;
  padding: 0;
  list-style: none;
  color: var(--muted);
}
.dot {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  margin-right: 0.4rem;
  border-radius: 50%;
  background: var(--focus);
}
.dot.b {
  background: var(--rest);
}
.dot.p {
  background: var(--pause);
}
.dot.i {
  opacity: var(--skin);
}

/* A number setting: its name, −, the number, +, its unit, and a ↺ that
   appears once the number differs from the default. */
.field {
  display: grid;
  grid-template-columns: 1fr 1.9rem 2.4rem 1.9rem 3.8rem 1.2rem;
  align-items: center;
  gap: 0.4rem;
}
.field button {
  font-size: 1.15em;
  line-height: 1;
}
.field [data-step] {
  height: 1.9rem;
  border-radius: 50%;
  background: var(--tint);
}
.field span,
.field [data-reset] {
  color: var(--muted);
}
/* The − and + buttons stand in for the browser's own little arrows. */
input[type="number"] {
  appearance: textfield;
  width: 100%;
  padding: 0.3rem 0;
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: inherit;
  background: none;
  border: 0;
}
input[type="number"]::-webkit-inner-spin-button {
  appearance: none;
}

/* An on-off setting: its name on the left, its box on the right. */
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--focus);
}

/* Three radio buttons drawn as words; the chosen one sits on a tinted pill. */
.theme {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}
.theme > span {
  margin-right: auto;
}
.theme input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.theme label span {
  display: block;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
}
.theme input:checked + span {
  background: var(--tint);
  color: var(--ink);
}
.theme input:focus-visible + span {
  outline: 2px solid var(--muted);
  outline-offset: 2px;
}

.fine {
  color: var(--muted);
}
kbd {
  font: inherit;
  padding: 0 0.3rem;
  border-radius: 6px;
  background: var(--tint);
}
.done {
  justify-self: end;
  color: var(--ink);
}

/* Hover effects only where there is a pointer that hovers. On a touch screen
   they would stick to whatever was tapped last. */
@media (hover: hover) {
  .big:hover {
    scale: 1.03;
  }
  .quiet:hover,
  .clock button:hover {
    color: var(--ink);
  }
}

/* On touch screens: bigger targets for the small words, and no keyboard hints. */
@media (pointer: coarse) {
  :root {
    --tap: 0.75rem 0.9rem;
  }
  header {
    margin: 0 -0.9rem;
  }
  .keys {
    display: none;
  }
}

/* On a short, wide screen, such as a phone on its side, the tomato sits beside
   the clock instead of above it. */
@media (max-height: 440px) and (orientation: landscape) {
  main {
    display: grid;
    grid-template-columns: auto 16rem; /* a fixed column, so changing words never move the tomato */
    place-items: center;
    align-content: center;
    column-gap: 1.5rem;
  }
  .big {
    grid-row: 1 / span 4;
    width: min(50vh, 240px);
  }
  #phase {
    margin-top: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .big,
  #field .t,
  #harvest .t {
    animation: none;
    transition: none;
  }
}
