/* flummoxxed — an alien clicker.
 *
 * Light "paper" ground on purpose: the tile art is crayon on off-white, so a
 * dark UI would frame every sprite in a white box. */

:root {
  --font: "Flummox", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --paper: #efe9db;
  --card: #fbf8f1;
  --ink: #17140f;
  --rule: #17140f;
  --gain: #2e8b57;
  --spend: #cc4433;
  --accent: #7b5fd0;
}

/* ?plain — the debug build. Same game, readable Hungarian. */
.plain {
  --font: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* An author `display` rule outranks the UA stylesheet's [hidden], so anything
 * toggled by the hidden attribute needs this to actually disappear. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  letter-spacing: 0.04em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#game {
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px 18px 40px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100vh;
}

/* Digits are the one readable thing in the game: the Flummox font has no
 * glyphs for 0-9, so they fall through to the mono fallback on their own. */
.num {
  display: inline-block;      /* so it can be scaled */
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

/* ------------------------------------------------------------------- icons */

.icon {
  display: inline-block;
  width: 1.7em;
  height: 1.7em;
  flex: none;
  vertical-align: middle;
  background-repeat: no-repeat;
  background-size: 400% 300%;   /* 4 columns, 3 rows */
}
.icon svg { display: block; width: 100%; height: 100%; overflow: visible; }
.icon.big { width: 190px; height: 190px; }

/* The real art, once img/tiles.png exists. Middle row of three, hence 50%.
 * Only icons carrying [data-sheet] have a column; meat has none, so it keeps
 * its drawn SVG. Adding a fifth column means editing background-size here and
 * the four positions below. */
.has-tiles .icon[data-sheet] { background-image: url("../img/tiles.png"); }
.has-tiles .icon[data-sheet] svg { display: none; }
.has-tiles .icon[data-icon="coin"]    { background-position: 0%      50%; }
.has-tiles .icon[data-icon="rice"]    { background-position: 33.333% 50%; }
.has-tiles .icon[data-icon="chicken"] { background-position: 66.667% 50%; }
.has-tiles .icon[data-icon="land"]    { background-position: 100%    50%; }

/* --------------------------------------------------------------- resources */

.topbar:empty, .bottom:empty, .panels:empty, .slot:empty { display: none; }

.topbar { display: flex; align-items: flex-start; gap: 10px; }
.topbar > .slot:not(:empty) { display: block; }
.topbar > .slot:first-child { flex: 1; min-width: 0; }

/* Slots exist to fix ordering, not to lay anything out. */
.bar > .slot { display: contents; }

.bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  align-items: center;
  padding: 10px 16px;
  background: var(--card);
  border: 2px solid var(--rule);
  border-radius: 16px 11px 15px 10px;
  box-shadow: 3px 3px 0 var(--rule);
}

.chip {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 1.12rem;
  padding: 2px 6px;
}

/* Mining is the only thing that animates a value. Every other source — sales,
 * purchases, harvests, pinned restarts — changes the number in silence, because
 * a signal that fires constantly stops carrying information. */
.chip .num.bounce { animation: bounce 0.34s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes bounce {
  0% { transform: scale(1); }
  35% { transform: scale(1.4); }
  70% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

/* Sell ten at a stroke, once nagybani eladás is bought. */
.bulk {
  display: inline-flex;
  align-items: center;
  margin-left: 1px;
  padding: 1px 7px 2px;
  font: inherit;
  font-size: 0.9rem;
  letter-spacing: inherit;
  color: var(--gain);
  background: none;
  border: 2px solid var(--rule);
  border-radius: 9px 6px 8px 7px;
  cursor: pointer;
  user-select: none;
}
.bulk:hover { background: rgba(46, 139, 87, 0.15); }
.bulk:active { transform: translate(1px, 1px); }
.bulk.off { opacity: 0.28; }
.bulk.off:active { transform: none; }

/* ----------------------------------------------------------------- clicker */

.stage {
  display: flex;
  gap: 28px;
  justify-content: center;
  flex: 1;
  /* Cold open: nothing but the coin, so centre it in the page. */
  align-items: center;
}
/* Once there is anything to play with, the panels set the height and the coin
 * rides along at the top of them. */
.stage:has(.panel) { align-items: flex-start; }

.clicker-wrap {
  display: flex;
  justify-content: center;
  flex: none;
  /* Keeps the coin reachable however far the board grows below it. */
  position: sticky;
  top: 18px;
}

.clicker {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 18px 26px;
  background: none;
  border: none;
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.clicker .icon.big { transition: transform 0.12s ease-out; }
.clicker:hover .icon.big { transform: rotate(-2deg) scale(1.03); }
.clicker.hit .icon.big { animation: hit 0.18s ease-out; }
@keyframes hit {
  0% { transform: scale(0.9) rotate(2deg); }
  100% { transform: scale(1) rotate(0); }
}

.clicker-label { font-size: 1.25rem; }

.pop {
  position: absolute;
  pointer-events: none;
  font-size: 1.3rem;
  color: var(--gain);
  animation: floatUp 0.85s ease-out forwards;
}
@keyframes floatUp {
  0% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-50%, -190%); }
}

/* ------------------------------------------------------------------ panels */

/* Panels tile into as many columns as the window can hold — one on a phone,
 * three on a desktop — with no breakpoints to keep in step. align-items:start
 * lets a short panel stay short instead of stretching to its row. */
.panels {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  align-items: start;
  gap: 14px;
}
/* An empty grid still reserves its width, which would shove the coin off centre
 * before the first click. A collapsed panel must take its gap with it. */
.panels:not(:has(.panel)) { display: none; }
.panels > .slot:has(.panel.collapsed) { display: none; }

/* The process board takes the whole width, because that is what lets its crumbs
 * tile several across rather than queue up one per column. */
.panels > .slot.wide { grid-column: 1 / -1; }

.panel {
  background: var(--card);
  border: 2px solid var(--rule);
  border-radius: 15px 10px 16px 11px;
  box-shadow: 3px 3px 0 var(--rule);
  padding: 12px 14px 14px;
}

.panel.collapsed { display: none; }

.panel-title {
  margin: 0 0 8px;
  font-size: 1.05rem;
  font-weight: normal;
  opacity: 0.65;
  border-bottom: 2px solid var(--rule);
  padding-bottom: 6px;
}

.rows { display: flex; flex-direction: column; gap: 4px; }

.enter { animation: enter 0.45s ease-out; }
@keyframes enter {
  0% { opacity: 0; transform: translateY(-10px); }
  100% { opacity: 1; transform: none; }
}

/* -------------------------------------------------------------------- rows */

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 9px;
  background: none;
  border: 2px solid transparent;
  border-radius: 11px 8px 12px 7px;
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: opacity 0.2s, border-color 0.15s, background-color 0.15s;
}
.row:hover { border-color: var(--rule); background: rgba(123, 95, 208, 0.09); }
.row:active { transform: translate(1px, 1px); }

/* Revealed but unaffordable. Dimmed piece by piece rather than with one opacity
 * on the row, because the missing-ingredient chips have to stay at full
 * strength — they are the only explanation of why the row is dead. */
.row.off > .label,
.row.off > .price,
.row.off > .icon,
.row.off .req { opacity: 0.33; }
.row.off .arrow { opacity: 0.18; }
.row.off .req.lack { opacity: 1; }
.row.off:active { transform: none; }

.row .label { flex: 1; }
.row .price { display: flex; align-items: center; gap: 5px; font-size: 1.05rem; }
.row.sell .price { color: var(--gain); }

.farm-row { flex-direction: column; align-items: stretch; gap: 6px; }
.farm-row .label { font-size: 1.02rem; }

.strip { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.side { display: flex; align-items: center; gap: 7px; }
.req { display: inline-flex; align-items: center; gap: 3px; font-size: 0.95rem; }
.req .icon { width: 1.5em; height: 1.5em; }
.arrow { opacity: 0.45; padding: 0 2px; }

/* The missing ingredient names itself. */
.req.lack {
  color: var(--spend);
  background: rgba(204, 68, 51, 0.14);
  border-radius: 6px;
  padding: 1px 4px;
  margin: -1px -1px;
}
.row:hover .req.lack { animation: pulse 0.75s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ------------------------------------------------------------------ crumbs */

/* Processes tile rather than stack. Full-width rows read fine at three and
 * would read as a scroll-bar at thirty. auto-fill keeps them at two across a
 * narrow panel and more as it widens. */
/* auto-fill, not auto-fit: leftover tracks stay empty so three crumbs stay
 * crumb-sized on a wide board instead of stretching to fill it. The track is
 * wide enough for the longest recipe to stay on one line. */
.crumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(246px, 1fr));
  gap: 6px;
}

/* Two lines and no more: the name over its recipe, with the quota alongside
 * rather than under. Stacking the quota was what made these read as cards. */
.crumb {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  padding: 4px 5px;
  border: 2px solid rgba(23, 20, 15, 0.14);
  border-radius: 11px 8px 12px 7px;
  background: rgba(23, 20, 15, 0.02);
}
.crumb:hover { border-color: var(--rule); }

.crumb-go {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  padding: 3px 4px;
  background: none;
  border: none;
  border-radius: 8px 6px 8px 6px;
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  user-select: none;
}
.crumb-go:hover { background: rgba(123, 95, 208, 0.1); }
.crumb-go:active { transform: translate(1px, 1px); }
.crumb-go .label {
  font-size: 0.82rem;
  line-height: 1.15;
  opacity: 0.75;
}
.crumb-go .strip { gap: 4px; }
.crumb-go .side { gap: 3px; }
.crumb-go .req { font-size: 0.8rem; gap: 1px; }
.crumb-go .req .icon { width: 1.5em; height: 1.5em; }
.crumb-go .arrow { padding: 0; font-size: 0.8rem; }

/* A compact stepper, sized for a crumb rather than a row. */
.crumb .stepper { padding: 1px; border-radius: 9px 6px 10px 5px; }
.crumb .step { width: 19px; height: 21px; font-size: 0.95rem; border-radius: 6px; }
.crumb .qty { min-width: 1.25em; font-size: 0.85rem; }

.crumb-go.off .label,
.crumb-go.off .req { opacity: 0.33; }
.crumb-go.off .arrow { opacity: 0.18; }
.crumb-go.off .req.lack { opacity: 1; }
.crumb-go.off:active { transform: none; }

/* A row and the control that belongs to it — a quota stepper on a farm row, a
 * ×10 on a sell row. Both are siblings rather than children, because the row is
 * a <button> and nested buttons are invalid. */
.row-wrap { display: flex; align-items: stretch; gap: 6px; }
.row-wrap > .row { flex: 1; min-width: 0; }
.row-wrap > .slot:not(:empty) { display: flex; align-items: center; }

/* How many of this process run at once. */
.stepper {
  display: flex;
  align-items: center;
  flex: none;
  padding: 2px;
  border: 2px solid var(--rule);
  border-radius: 11px 7px 12px 6px;
  opacity: 0.45;
  transition: opacity 0.15s;
}
.stepper.live { opacity: 1; }
.stepper .qty {
  min-width: 1.6em;
  text-align: center;
  font-size: 0.98rem;
}
.stepper.live .qty { color: var(--accent); }

.step {
  width: 25px;
  height: 27px;
  padding: 0;
  font: inherit;
  font-size: 1.15rem;
  line-height: 1;
  color: inherit;
  background: none;
  border: none;
  border-radius: 8px 6px 8px 6px;
  cursor: pointer;
  user-select: none;
}
.step:hover { background: rgba(123, 95, 208, 0.18); }
.step:active { transform: translate(1px, 1px); }
.step.off { opacity: 0.22; cursor: default; }
.step.off:hover { background: none; }
.step.off:active { transform: none; }

/* Research is bought once and kept, so a spent row stays put with a mark on it
 * — the panel doubles as a record of what you have. */
/* The level a repeatable upgrade has reached, between its name and its next
 * price. Dim at zero so it reads as "not started" rather than as a quantity. */
.research-row .lvl {
  min-width: 1.6em;
  text-align: center;
  font-size: 0.95rem;
  opacity: 0.3;
}
.research-row .lvl.on { opacity: 1; color: var(--accent); }

.research-row.done { cursor: default; }
.research-row.done .price { display: none; }
.research-row.done > .label { opacity: 0.5; }
.research-row.done::after {
  content: "✓";
  color: var(--gain);
  font-size: 1.15rem;
}

/* -------------------------------------------------------------------- jobs */

/* Running jobs tile for the same reason processes do: a quota of ten is ten
 * cards, and thirty plots would be a column you scroll past. */
.jobs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: 4px 10px;
}

.job {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 7px;
}
.job .icon { width: 1.45em; height: 1.45em; }
.job .track {
  flex: 1;
  height: 13px;
  background: rgba(23, 20, 15, 0.1);
  border: 2px solid var(--rule);
  border-radius: 7px;
  overflow: hidden;
}
.job .fill {
  height: 100%;
  width: 0;
  background: var(--accent);
}
.job .left { font-size: 0.86rem; opacity: 0.7; min-width: 3.9em; text-align: right; }

/* -------------------------------------------------------------------- menu */

.menu { position: relative; flex: none; }

.menu-btn {
  width: 42px;
  height: 42px;
  padding: 10px;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--rule);
  border-radius: 14px 10px 15px 9px;
  box-shadow: 3px 3px 0 var(--rule);
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s;
}
.menu-btn:hover { opacity: 1; }
.menu-btn svg { display: block; width: 100%; height: 100%; }

.menu-pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 10;
  min-width: 190px;
  padding: 7px;
  background: var(--card);
  border: 2px solid var(--rule);
  border-radius: 14px 10px 15px 9px;
  box-shadow: 3px 3px 0 var(--rule);
}

.menu-item, .menu-ask {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 9px;
  background: none;
  border: none;
  border-radius: 10px 7px 11px 6px;
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover { background: rgba(204, 68, 51, 0.13); }

.glyph { display: inline-block; flex: none; width: 1.5em; height: 1.5em; }
.glyph svg { display: block; width: 100%; height: 100%; }

.menu-ask { cursor: default; justify-content: space-between; }
.confirm {
  width: 34px;
  height: 30px;
  padding: 6px 7px;
  background: none;
  border: 2px solid var(--rule);
  border-radius: 10px 7px 11px 6px;
  cursor: pointer;
}
.confirm svg { display: block; width: 100%; height: 100%; }
.confirm.yes { color: var(--spend); }
.confirm.yes:hover { background: rgba(204, 68, 51, 0.16); }
.confirm.no { color: var(--ink); }
.confirm.no:hover { background: rgba(23, 20, 15, 0.09); }

/* ---------------------------------------------------------------- info box */

.infobox {
  display: flex;
  gap: 12px;
  align-items: baseline;
  min-height: 3.6em;
  padding: 11px 15px;
  background: var(--card);
  border: 2px solid var(--rule);
  border-radius: 14px 10px 15px 11px;
  box-shadow: 3px 3px 0 var(--rule);
}
.info-label { opacity: 0.5; flex: none; }
.info-text { line-height: 1.5; }

/* ------------------------------------------------------------- narrow view */

@media (max-width: 760px) {
  .stage { flex-direction: column; align-items: center; }
  .clicker-wrap { position: static; }
  .panels { width: 100%; max-width: 440px; columns: auto; }
  .icon.big { width: 150px; height: 150px; }
}
