/* ============================================================
   Ecosystem Puzzle
   A meadow read from above: paper-pale ground, soft green ink,
   and one warm accent that only the animals are allowed to use.
   ============================================================ */

:root {
  --ink: #3c4a36;
  --ink-soft: #6d7a66;
  --ink-faint: #9aa593;

  --paper: #f7f9f0;
  --card: #ffffff;
  --ground: #e9f0dc;
  --ground-deep: #dde8cc;
  --line: #d3e0be;

  --green: #5a9e4b;
  --green-bright: #7ec05c;
  --warm: #e08a4a;
  --bone: #cfc8b3;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(60, 74, 54, .08), 0 6px 18px rgba(60, 74, 54, .07);

  --font: "Hiragino Sans", "Noto Sans JP", -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 16px 8px;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 400px at 50% -80px, #eef6e2 0%, rgba(238, 246, 226, 0) 70%),
    var(--paper);
  -webkit-text-size-adjust: 100%;
}

body.is-modal { overflow: hidden; }

.sprite-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.wrap {
  max-width: 480px;
  margin: 0 auto;
  padding-block: 20px 8px;
}

/* ---------- Title ---------- */

.topbar { text-align: center; margin-bottom: 18px; }

.title {
  position: relative;
  display: inline-block;
  margin: 0;
  padding-bottom: 12px;
  font-size: clamp(1.55rem, 7vw, 2.1rem);
  line-height: 1.05;
  letter-spacing: -.015em;
  font-weight: 700;
}

.title-word { color: var(--ink); }

/* the second word is lifted a touch and a sprout pushes up between the
   two, so the name itself looks like something growing out of a field */
.title-word--2 {
  position: relative;
  margin-left: .34em;
  color: var(--green);
}

.title-sprout {
  position: absolute;
  left: -.58em;
  bottom: -.02em;   /* its stem has to reach the field line, or it reads
                       as a stray mark rather than something growing */
  width: .7em;
  height: .92em;
  overflow: visible;
}

.title-field {
  position: absolute;
  left: -4%;
  right: -4%;
  bottom: 0;
  width: 108%;
  height: 12px;
}

.tagline {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: .92rem;
}

/* ---------- Scores ---------- */

.scorebar {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.score {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 14px;
  box-shadow: var(--shadow);
}

.score-label {
  display: block;
  font-size: .7rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.score-value {
  display: block;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.score--best .score-value { color: var(--ink-soft); }

/* ---------- Hand ---------- */

.handbar {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.hand-slot { text-align: center; }

.hand-label {
  display: block;
  font-size: .64rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 2px;
}

.tile {
  display: block;
  width: 46px;
  height: 46px;
  border-radius: var(--radius-sm);
  background: var(--ground);
  border: 1px solid var(--line);
}

.tile--next {
  width: 34px;
  height: 34px;
  opacity: .62;
  margin-top: 6px;
}

.tile-art { display: block; width: 100%; height: 100%; }

/* the standing instruction: what the board is one step away from */
.goal {
  grid-column: 3;
  align-self: center;
  margin: 0;
  padding-left: 2px;
  font-size: .88rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--green);
}

/* and under it, what just happened */
.ticker {
  grid-column: 1 / -1;
  margin: 0;
  padding-top: 2px;
  min-height: 2.4em;
  font-size: .82rem;
  line-height: 1.35;
  color: var(--ink-faint);
}

/* ---------- Season ---------- */

.season {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: 4px 10px;
  margin-bottom: 10px;
  padding: 9px 14px 12px;
  border: 1px solid var(--season-line, var(--line));
  border-radius: var(--radius);
  background: var(--season-bg, #fff);
  overflow: hidden;
  transition: background .4s ease, border-color .4s ease;
}

.season-name {
  font-size: .95rem;
  font-weight: 700;
  color: var(--season-ink, var(--green));
}

.season-note {
  font-size: .76rem;
  line-height: 1.3;
  color: var(--ink-soft);
}

.season-mult {
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--season-ink, var(--green));
}

/* how far through this season the run is */
.season-track {
  grid-column: 1 / -1;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(90, 110, 80, .1);
}

.season-fill {
  display: block;
  height: 100%;
  background: var(--season-ink, var(--green));
  opacity: .55;
  transition: width .25s ease;
}

/* Each season repaints the strip, so the run visibly moves through the
   year rather than just getting harder for no stated reason. */
.season[data-season="0"] { --season-bg: #f2f9ea; --season-line: #cfe4bb; --season-ink: #5a9e4b; }
.season[data-season="1"] { --season-bg: #f6fbe6; --season-line: #d9e6ae; --season-ink: #7a9b32; }
.season[data-season="2"] { --season-bg: #fdf4e6; --season-line: #ecd3ac; --season-ink: #c47f34; }
.season[data-season="3"] { --season-bg: #eef2f6; --season-line: #ccd7e0; --season-ink: #5b7890; }

/* ---------- Board ---------- */

.board-frame { position: relative; }

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  padding: 9px;
  background: linear-gradient(160deg, var(--ground) 0%, var(--ground-deep) 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .7), var(--shadow);
}

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  min-width: 0;
  padding: 0;
  border: 1px solid rgba(120, 150, 100, .18);
  border-radius: 11px;
  background: rgba(255, 255, 255, .42);
  font: inherit;
  cursor: pointer;
  transition: background .12s ease, transform .12s ease;
  -webkit-tap-highlight-color: transparent;
}

.cell:not(:disabled):hover { background: rgba(255, 255, 255, .8); }
.cell:not(:disabled):active { transform: scale(.95); }

.cell:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.cell--taken {
  background: rgba(255, 255, 255, .72);
  cursor: default;
}

.cell--bones,
.cell--scrub,
.cell--stone {
  background: rgba(206, 198, 178, .38);
  border-color: rgba(150, 142, 120, .3);
}

/* anything alive carries a meter, so it sits high in the square */
.cell .tile-art {
  position: absolute;
  inset: 2% 4% 16%;
  width: 92%;
  height: 82%;
}

/* dead ground has no clock, so it gets the whole square */
.cell--bones .tile-art,
.cell--scrub .tile-art,
.cell--stone .tile-art { inset: 7%; width: 86%; height: 86%; }

/* a tile in its last turns loses a little colour */
.cell--fading .tile-art { opacity: .72; }

/* within reach of a hungry mouth next turn: a dashed warm ring, so the
   shape of an animal's reach is something you can see and build around */
.cell--inreach {
  border-color: transparent;
  box-shadow: inset 0 0 0 2px var(--warm);
  background: rgba(224, 138, 74, .12);
}

.cell--inreach::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1.5px dashed rgba(224, 138, 74, .55);
  border-radius: 8px;
  pointer-events: none;
}

/* ---------- Hunger meter ---------- */

.meter {
  position: absolute;
  left: 16%;
  right: 16%;
  bottom: 7%;
  height: 5px;
  border-radius: 3px;
  background: rgba(90, 110, 80, .18);
  overflow: hidden;
}

.meter-fill {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--green-bright);
  transition: width .18s ease;
}

.meter-fill.is-mid { background: #e8c057; }
.meter-fill.is-low { background: #dd6a52; }

/* ---------- Turn feedback ---------- */

@keyframes grew {
  0% { transform: scale(.6); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes eaten {
  0% { background: rgba(224, 138, 74, .5); }
  100% { background: rgba(255, 255, 255, .42); }
}
@keyframes died {
  0%, 40% { background: rgba(196, 150, 84, .38); }
  100% { background: rgba(206, 198, 178, .38); }
}

.cell--grew { animation: grew .28s ease-out; }
.cell--eaten { animation: eaten .5s ease-out; }
.cell--died { animation: died .6s ease-out; }

@media (prefers-reduced-motion: reduce) {
  .cell--grew, .cell--eaten, .cell--died { animation: none; }
  .cell:not(:disabled):active { transform: none; }
}

/* ---------- Game over ---------- */

/* both overlays set `display`, which outranks the browser's own rule for
   [hidden] — without this they are never actually hidden */
.modal[hidden],
.gameover[hidden] { display: none; }

.gameover {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  border-radius: 18px;
  background: rgba(247, 249, 240, .88);
  backdrop-filter: blur(2px);
}

.gameover-card {
  width: 100%;
  max-width: 300px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 18px;
  box-shadow: var(--shadow);
}

.gameover-card h2 { margin: 0 0 6px; font-size: 1.15rem; }

.go-score {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: .85rem;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.go-score strong {
  display: block;
  font-size: 2rem;
  color: var(--ink);
  letter-spacing: normal;
  font-variant-numeric: tabular-nums;
}

.go-note {
  margin: 0 0 16px;
  font-size: .86rem;
  line-height: 1.45;
  color: var(--ink-soft);
}

/* ---------- Buttons ---------- */

.controls {
  display: flex;
  gap: 10px;
  margin: 14px 0 20px;
}

.btn {
  flex: 1;
  padding: 11px 14px;
  font: inherit;
  font-weight: 600;
  font-size: .92rem;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}

.btn:hover { background: #f2f7e9; }
.btn:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.btn--primary {
  width: 100%;
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}
.btn--primary:hover { background: #4f8e42; }

.btn--armed {
  color: var(--warm);
  border-color: var(--warm);
  background: #fdf4ec;
}

/* ---------- Food chain reference ---------- */

.chain {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 10px 14px;
  box-shadow: var(--shadow);
}

.chain-head {
  margin: 0 0 10px;
  text-align: center;
  font-size: .68rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 600;
}

.chain-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chain-step {
  flex: 0 1 auto;
  min-width: 0;
  text-align: center;
}

.tile--mini {
  width: 38px;
  height: 38px;
  margin: 0 auto 4px;
}

.chain-name {
  display: block;
  font-size: .72rem;
  font-weight: 600;
}

.chain-eats {
  display: block;
  font-size: .62rem;
  color: var(--ink-faint);
  line-height: 1.25;
}

.chain-arrow {
  align-self: center;
  padding: 0 2px 14px;
  font-size: .7rem;
  font-weight: 700;
  color: var(--ink-faint);
}

/* ---------- How to play ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: end center;
  padding: 0;
  background: rgba(45, 56, 40, .42);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 22px 18px 24px;
}

.modal-card h2 { margin: 0 0 4px; font-size: 1.2rem; }

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink-soft);
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.modal-close:hover { background: #f1f5e9; }

.guide {
  margin: 14px 0 18px;
  padding: 0;
  list-style: none;
}

.guide-step {
  padding: 14px 0;
  border-top: 1px solid #eef2e6;
}
.guide-step:first-child { border-top: 0; padding-top: 0; }

.guide-step h3 {
  margin: 0 0 8px;
  font-size: .95rem;
  color: var(--green);
}

.guide-step p {
  margin: 8px 0 0;
  font-size: .87rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

.guide-art {
  display: block;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
  height: auto;
}

.ga-grid rect {
  fill: #eef4e4;
  stroke: var(--line);
  stroke-width: 1.2;
}
.ga-grid rect.ga-empty { fill: #f7faf1; stroke-dasharray: 3 3; }
.ga-grid rect.ga-dead { fill: #eae5d6; stroke: #d6cfba; }

.ga-arrow { stroke: #c3d6ac; stroke-width: 2.4; stroke-linecap: round; fill: none; }
.ga-head { fill: #c3d6ac; }
.ga-tap { fill: rgba(90, 158, 75, .3); }
.ga-ring { fill: none; stroke: var(--green); stroke-width: 1.6; stroke-dasharray: 4 4; }
.ga-spark { fill: var(--green-bright); }

.ga-pts {
  fill: var(--warm);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
}

.ga-cap {
  fill: var(--ink-faint);
  font-family: var(--font);
  font-size: 10px;
  text-anchor: middle;
}

.ga-meter-bg { fill: rgba(90, 110, 80, .18); }
.ga-meter-low { fill: #dd6a52; }

.ga-season rect { stroke-width: 1.2; }

.ga-seasonname text {
  font-family: var(--font);
  font-size: 9px;
  font-weight: 700;
  text-anchor: middle;
}

.ga-seasonmult text {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  text-anchor: middle;
}

.ga-stones circle { fill: #b9b7ad; }

.modal-done { margin-top: 4px; }

/* ---------- Footer ---------- */

.app-footer {
  margin-top: 18px;
  text-align: center;
  font-size: .76rem;
  color: var(--ink-faint);
}
.app-footer p { margin: 0; }

/* ---------- Narrow screens ---------- */

@media (max-width: 380px) {
  .board { gap: 5px; padding: 7px; }
  .tile { width: 40px; height: 40px; }
  .tile--next { width: 30px; height: 30px; }
  .tile--mini { width: 32px; height: 32px; }
  .chain-eats { display: none; }
  .chain-arrow { padding-bottom: 8px; }
  /* the name and the multiplier are the part that matters; the sentence
     wraps to two lines down here and is spelled out in the guide anyway */
  .season-note { display: none; }
  .season { grid-template-columns: auto 1fr; }
}

/* ---------- Wide screens ---------- */

@media (min-width: 700px) {
  .modal { place-items: center; padding: 24px; }
  .modal-card { border-radius: 20px; max-height: 86vh; }
}
