:root {
  color-scheme: dark;
  --table: #1f2420;
  --paper: #fbf1dc;
  --paper-2: #f3e2c2;
  --ink: #3b2718;
  --muted: #8a6c52;
  --water: #3d8fd6;
  --clay: #d0623a;
  --shadow: 0 3px 0 rgba(58, 32, 14, 0.28), 0 10px 24px rgba(0, 0, 0, 0.3);
  --sans: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--table);
  color: var(--paper);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

canvas#game { position: fixed; inset: 0; display: block; }

button { font: inherit; color: inherit; cursor: pointer; }

/* the top bar: little paper labels pinned to the table */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 58px;
  padding: max(8px, env(safe-area-inset-top)) 8px 0;
  display: flex;
  align-items: center;
  gap: 5px;
  z-index: 5;
}
.hud[hidden] { display: none; }
.hud p { margin: 0; }
.hud-season {
  flex: 1;
  min-width: 0;
  padding: 6px 8px 7px;
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.hud-season p { display: flex; justify-content: space-between; gap: 4px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.hud-season p span { flex: none; }
.hud-season p small { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 11px; font-weight: 600; color: var(--muted); }
.bar { height: 5px; margin-top: 4px; border-radius: 3px; background: var(--paper-2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--water); }
.stat {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  padding: 8px 5px;
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.stat b { font-variant-numeric: tabular-nums; }
.icon {
  flex: none;
  width: 34px;
  height: 38px;
  border-radius: 10px;
  border: 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 16px;
  font-weight: 800;
}
.icon:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(58, 32, 14, 0.28); }

.hint-line {
  position: fixed;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 24px);
  margin: 0;
  padding: 7px 12px;
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  text-align: center;
  font-size: 14px;
  line-height: 1.35;
  pointer-events: none;
  z-index: 5;
}
.hint-line:empty { display: none; }

/* a new player's task of the moment, under the top bar */
.quest {
  position: fixed;
  left: 8px;
  top: calc(max(8px, env(safe-area-inset-top)) + 54px);
  max-width: min(320px, calc(100vw - 16px));
  margin: 0;
  padding: 5px 10px;
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.3;
  pointer-events: none;
  z-index: 5;
}
.quest[hidden] { display: none; }
.quest.done { background: #6fb43f; color: #fff; animation: questpop 0.5s ease-out; }
@keyframes questpop { 0% { transform: scale(0.85); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }

/* a panel taller than the screen scrolls instead of being cut at both ends (CrazyGames frame is 520 px high) */
#ui { position: fixed; inset: 0; display: flex; overflow-y: auto; padding: 10px 0; pointer-events: none; z-index: 10; }
#ui > * { margin: auto; flex: none; }
.panel {
  pointer-events: auto;
  width: min(340px, calc(100vw - 32px));
  padding: 26px 22px 22px;
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 5px 0 rgba(58, 32, 14, 0.3), 0 22px 50px rgba(0, 0, 0, 0.45);
}
.panel h1 { margin: 0 0 8px; font-size: 46px; letter-spacing: 0.02em; color: var(--clay); }
.panel h2 { margin: 0 0 8px; font-size: 28px; }
.panel p { margin: 6px 0; line-height: 1.4; }
.panel .big { font-size: 19px; font-weight: 700; }
.panel .muted { color: var(--muted); font-size: 14px; }
.btn {
  margin-top: 14px;
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 14px;
  background: var(--clay);
  color: #fff8ec;
  font-size: 18px;
  font-weight: 800;
  box-shadow: 0 4px 0 #9c4325;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #9c4325; }

.choices { display: grid; gap: 8px; margin-top: 12px; }
.choice {
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: var(--paper-2);
  color: var(--ink);
  box-shadow: 0 3px 0 rgba(58, 32, 14, 0.25);
}
.choice:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(58, 32, 14, 0.25); }
.choice-icon { grid-row: span 2; display: grid; place-items: center; }
.choice b { font-size: 16px; }
.choice small { color: var(--muted); font-size: 13px; }
.rewards .big { font-size: 15px; }

.btn small { display: block; font-size: 12px; font-weight: 600; opacity: 0.85; margin-top: 2px; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--paper-2); margin-top: 8px; }
/* "all three gifts for an ad" (Playgama): gold like the goal of the year, it stands out from the single gifts */
.btn.gifts-ad { background: linear-gradient(180deg, #f8d35c, #eab43a); color: var(--ink); box-shadow: 0 4px 0 #b8862a; margin-top: 10px; }
.btn.gifts-ad:active { box-shadow: 0 1px 0 #b8862a; }
.btn.gifts-ad:disabled { opacity: 0.75; }
.choice.picked { box-shadow: inset 0 0 0 2px var(--clay), 0 3px 0 rgba(58, 32, 14, 0.25); }
.panel .choices { margin-top: 14px; }

.stat.empty { animation: empty 0.9s ease-in-out infinite; }
@keyframes empty { 50% { background: #f6c3b4; color: #8f1f12; } }
.bar.goal { height: 4px; margin-top: 3px; background: #efe0b8; }
.bar.goal i { background: linear-gradient(90deg, #e3a72f, #f6cf4a); }
.bar.goal.done i { background: #6fb43f; }
.hud-season p small.low { color: #c0392b; font-weight: 800; animation: lowwater 1.1s ease-in-out infinite; }
@keyframes lowwater { 50% { color: #ff6a4d; } }

.update {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100vw - 24px);
  padding: 9px 14px;
  border: 0;
  border-radius: 12px;
  background: var(--water);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow);
}
.langs { display: flex; justify-content: center; gap: 6px; margin: 14px 0 0; }
.langs button { border: 0; background: transparent; color: var(--muted); font-weight: 700; padding: 4px 8px; border-radius: 8px; }
.langs button.on { background: var(--paper-2); color: var(--ink); }

.panel.help { width: min(400px, calc(100vw - 24px)); max-height: calc(100vh - 40px); overflow-y: auto; text-align: left; }
.panel.help h2 { text-align: center; }
.legend { display: grid; gap: 8px; margin-top: 8px; }
.legend-row { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: center; font-size: 14px; line-height: 1.35; }
.legend-pic { display: grid; place-items: center; }
.panel .logo-sub { margin: -10px 0 10px; font-weight: 800; letter-spacing: 0.04em; color: var(--water); }

/* a short screen (a laptop with the CrazyGames frame, a phone on its side): a tighter menu */
@media (max-height: 700px) {
  .panel { padding: 16px 18px 14px; }
  .panel h1 { font-size: 36px; margin-bottom: 2px; }
  .panel .logo-sub { margin: -2px 0 6px; }
  .panel p { margin: 4px 0; font-size: 14px; line-height: 1.35; }
  .btn { margin-top: 10px; padding: 10px; font-size: 17px; }
  .panel .choices { margin-top: 8px; gap: 6px; }
  .choice { padding: 7px 10px; }
  .langs { margin-top: 8px; }
}
/* wide and short: the valleys side by side */
@media (max-height: 700px) and (min-width: 540px) {
  .panel.menu { width: min(580px, calc(100vw - 32px)); }
  .panel.menu .choices { grid-template-columns: 1fr 1fr; }
}
/* a phone on its side and the CrazyGames frame (844×390, 924×520): the game-over panel in two columns, so its buttons stay on screen */
@media (max-height: 600px) and (min-width: 540px) {
  .panel.over { width: min(660px, calc(100vw - 32px)); display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; align-items: center; }
  .panel.over .over-acts > .btn:first-child { margin-top: 0; }
  /* the year panel with "all three gifts for an ad" (Playgama): the gifts in one row, so the ad button fits */
  .panel.rewards.with-ad { width: min(660px, calc(100vw - 32px)); }
  .panel.rewards.with-ad .choices { grid-template-columns: repeat(3, 1fr); }
}
/* the help is long on a short screen: its button stays in sight at the bottom while the list scrolls */
.panel.help > .btn { position: sticky; bottom: -12px; box-shadow: 0 4px 0 #9c4325, 0 -16px 14px var(--paper); }
/* a narrow phone (320–420 px): smaller buttons and counters, so the season card keeps its words */
@media (max-width: 420px) {
  .hud { gap: 3px; padding-left: 6px; padding-right: 6px; }
  .icon { width: 29px; font-size: 14px; }
  .stat { font-size: 13px; padding: 8px 4px; }
  .hud-season { padding: 6px 6px 7px; }
  .hud-season p { flex-direction: column; gap: 0; font-size: 12px; }
  .hud-season p small { font-size: 10.5px; }
  .bar { margin-top: 2px; }
}

/* the village on the game-over panel: its level, this game's apples and how far to the next level */
.village { margin: 10px 0 4px; padding: 8px 12px 9px; border-radius: 12px; background: var(--paper-2); text-align: left; }
.village-line { display: flex; justify-content: space-between; gap: 8px; margin: 0 0 6px !important; font-weight: 800; font-size: 14px; }
.village-line b { color: #4c8a2a; }
.village .bar { height: 7px; margin: 0; background: #e6d3ad; }
.village .bar i { background: #6fb43f; }
.village p.muted, .village .village-up { margin: 6px 0 0 !important; font-size: 13px; line-height: 1.3; }
.village .village-up { color: #3e7a1e; font-weight: 800; }
