:root {
  --bg: #fbf6ee;
  --ink: #3b2f2a;
  --muted: #7d6f64;
  --red: #e5492f;
  --green: #8dbd4b;
  --yellow: #f0b73a;
  --leaf: #4f8f3a;
  --tint: #eee8e0; /* a shade off the background, for inputs and keys */
  --shine: 0.3;
  font-family: ui-rounded, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1917;
    --ink: #efe6dc;
    --muted: #8f837a;
    --red: #e8563d;
    --green: #86b548;
    --yellow: #e6b13b;
    --leaf: #5a9844;
    --tint: #2b2725;
    --shine: 0.14;
  }
}

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

html,
body {
  height: 100%;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  -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 */
}

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

.defs {
  position: absolute;
}

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

.t {
  --hue: var(--red);
  display: block;
}
.t[data-s="b"] {
  --hue: var(--green);
}
.t[data-s="p"] {
  --hue: var(--yellow);
}
.t .skin {
  fill: var(--hue);
  fill-opacity: 0.24;
  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: transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.big:hover {
  transform: scale(1.03);
}
.big:active {
  transform: scale(0.96);
}

#phase {
  margin-top: 1.1rem;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

#time {
  font-size: clamp(3rem, 12vw, 4.5rem);
  font-weight: 300;
  line-height: 1.1;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.quiet {
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  transition: color 0.2s;
}
.quiet:hover {
  color: var(--ink);
}
a.quiet {
  display: inline-block;
  margin-top: 0.4rem;
  text-decoration: underline;
  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 cubic-bezier(0.3, 1.6, 0.5, 1) backwards;
}
#harvest .juice {
  transform: none;
}

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

#field {
  position: fixed;
  inset: 0;
}
#field .t {
  position: absolute;
  opacity: 0.85;
  animation: arrive 0.7s cubic-bezier(0.3, 1.6, 0.5, 1) backwards;
  transition:
    opacity 0.6s,
    left 0.6s,
    top 0.6s;
}
#field .t[data-s="i"] {
  opacity: 0.5;
}
#field .t.leaving {
  opacity: 0;
}

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

/* ---- 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);
}
footer {
  bottom: env(safe-area-inset-bottom);
  justify-content: center;
}

.mark {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

#count {
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* ---- 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: 0;
  border-radius: 20px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.18);
  font-size: 0.95rem;
  line-height: 1.5;
}
dialog::backdrop {
  background: var(--bg);
  opacity: 0.7;
  backdrop-filter: blur(6px);
}
dialog form {
  display: grid;
  gap: 0.9rem;
}
dialog h1 {
  font-size: 1.05rem;
  font-weight: 600;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1rem;
  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(--red);
}
.dot.b {
  background: var(--green);
}
.dot.p {
  background: var(--yellow);
}
.dot.i {
  opacity: 0.24;
}

.fields {
  display: grid;
  gap: 0.5rem;
  padding: 0.3rem 0;
}
.fields label {
  display: grid;
  grid-template-columns: 1fr 4.2rem 2rem;
  align-items: center;
  gap: 0.6rem;
}
input[type="number"] {
  appearance: textfield;
  width: 100%;
  padding: 0.3rem 0.5rem;
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: inherit;
  background: var(--tint);
  border: 0;
  border-radius: 8px;
}
.check {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--red);
}
.fine {
  font-size: 0.82rem;
  color: var(--muted);
}
kbd {
  font: inherit;
  padding: 0 0.3rem;
  border-radius: 4px;
  background: var(--tint);
}
.done {
  justify-self: end;
  color: var(--ink);
}

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