/* Cluckwork Farm -- cozy top-down farming presentation layer. */

:root {
  --green: #5a8a2e;
  --green-dark: #3d6120;
  --green-mid: #79b450;
  --cream: #fdf6e3;
  --brown: #5a3a1a;
  --wood: #9c6b30;
  --wood-dark: #7a4a21;
  --gold: #ffd95e;
  --ink: #3a2410;
  --sky: #b5dfe8;
  --blue: #4a90d9;
  --blue-dark: #2a60a9;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  touch-action: none;
  font-family: 'Fredoka One', 'Comic Sans MS', cursive;
  background:
    repeating-linear-gradient(0deg, rgba(90, 138, 46, 0.18) 0 32px, transparent 32px 64px),
    repeating-linear-gradient(90deg, rgba(90, 138, 46, 0.18) 0 32px, transparent 32px 64px),
    var(--sky);
}

#wrap {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
}

#stage {
  position: relative;
  width: 960px; height: 600px;
  flex: none;
  transform-origin: center center;
  border: 5px solid var(--brown);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(58, 36, 16, 0.45);
  background: var(--green-mid);
}

canvas#game {
  position: absolute;
  left: 0; top: 60px;
  width: 960px; height: 540px;
  display: block;
}

/* ---- HUD ---- */

#hud {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 60px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  background: linear-gradient(var(--wood), var(--wood-dark));
  border-bottom: 4px solid var(--brown);
  color: var(--cream);
  z-index: 5;
  user-select: none;
}

.stat {
  display: flex; align-items: center; gap: 6px;
  background: rgba(58, 36, 16, 0.4);
  border-radius: 9px;
  padding: 5px 11px;
  font-size: 19px;
  letter-spacing: 0.5px;
  min-width: 78px;
  justify-content: center;
  transition: transform 0.12s;
}

.stat svg { flex: none; }

/* scale-pulse on coin/ribbon change */
@keyframes stat-pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.22); }
  100% { transform: scale(1); }
}
.stat.pulse { animation: stat-pulse 0.35s ease-out; }

/* ---- order panel ---- */

#order-panel {
  display: flex; align-items: center; gap: 6px;
  flex: 1;
  overflow: hidden;
  height: 52px;
}

.order-card {
  display: flex; flex-direction: column; justify-content: center;
  background: rgba(58, 36, 16, 0.35);
  border: 2px solid rgba(253, 246, 227, 0.25);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 12px;
  line-height: 1.3;
  color: var(--cream);
  min-width: 90px;
  max-width: 160px;
  height: 46px;
  overflow: hidden;
}

.order-card.grand {
  border-color: var(--gold);
  background: rgba(180, 130, 0, 0.35);
}

.order-card.freeplay {
  opacity: 0.75;
}

.order-card .oc-goods {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.order-card .oc-reward {
  font-size: 11px;
  color: var(--gold);
  white-space: nowrap;
}

/* ---- HUD buttons ---- */

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

.hud-btn {
  height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  background: var(--cream);
  color: var(--ink);
  font-size: 17px;
  border-bottom: 3px solid #cdb795;
  transition: transform 0.08s, filter 0.12s;
  flex: none;
}
.hud-btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.hud-btn:active { transform: translateY(1px); }

.icon-btn { width: 40px; padding: 0; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.icon-btn.on { outline: 3px solid var(--gold); }

/* ---- floating popups (anchored near tap) ---- */

.popup {
  position: absolute;
  z-index: 8;
  background: var(--cream);
  border: 3px solid var(--brown);
  border-radius: 12px;
  padding: 10px 10px 8px;
  box-shadow: 0 8px 22px rgba(58, 36, 16, 0.4);
  display: none;
  color: var(--ink);
}
.popup.show { display: block; }

/* translucent full-stage backdrop behind anchored popups */
.popup-backdrop {
  position: absolute; inset: 0;
  z-index: 7;
  display: none;
}
.popup-backdrop.show { display: block; }

.popup-title {
  font-size: 16px;
  color: var(--green-dark);
  margin-bottom: 6px;
  text-align: center;
}

.popup-close {
  position: absolute;
  top: -12px; right: -12px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #c0392b;
  color: #fff;
  font-size: 13px;
  line-height: 1;
  border: 2px solid #922b21;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  z-index: 9;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.popup-close:hover { filter: brightness(1.15); }

/* ---- seed picker ---- */

#seed-picker { width: 220px; }

#seed-picker-items {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.seed-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: #fff;
  border: 2px solid #e3d5bb;
  border-radius: 9px;
  padding: 8px 4px 6px;
  font-family: inherit;
  color: var(--ink);
  font-size: 11px;
  min-height: 54px;
  cursor: pointer;
  transition: transform 0.08s, border-color 0.08s;
}
.seed-btn:hover { border-color: var(--green); transform: translateY(-2px); }
.seed-btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.seed-btn .seed-icon { font-size: 22px; }
.seed-btn .seed-cost { font-size: 10px; color: var(--wood-dark); }
.seed-btn.replant {
  border-color: var(--green);
  background: #f0f9e8;
  order: -1; /* float to the front of the grid */
}
.seed-btn.replant .seed-replant-tag {
  font-size: 9px;
  color: var(--green-dark);
  font-weight: bold;
  letter-spacing: 0.3px;
}

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

#build-menu { width: 260px; }

#build-menu-items {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.build-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: #fff;
  border: 2px solid #e3d5bb;
  border-radius: 9px;
  padding: 8px 4px 6px;
  font-family: inherit;
  color: var(--ink);
  font-size: 10px;
  min-height: 60px;
  cursor: pointer;
  transition: transform 0.08s, border-color 0.08s;
  text-align: center;
}
.build-btn:hover:not(:disabled) { border-color: var(--green); transform: translateY(-2px); }
.build-btn:disabled { opacity: 0.45; cursor: default; }
.build-btn.locked-catalog { opacity: 0.6; }
.build-btn .build-icon { font-size: 20px; }
.build-btn .build-name { font-size: 10px; line-height: 1.2; }
.build-btn .build-cost { font-size: 10px; color: var(--wood-dark); }
.build-btn .build-hint { font-size: 9px; color: var(--blue); }

/* ---- inspect panel ---- */

#inspect-card { min-width: 260px; max-width: 380px; }

.panel-title {
  font-size: 26px;
  color: var(--green-dark);
  margin-bottom: 8px;
  text-align: center;
}

#inspect-body {
  font-size: 14px;
  color: #8a6d4a;
  margin-bottom: 12px;
  font-family: 'Trebuchet MS', sans-serif;
  line-height: 1.5;
  text-align: left;
}

.panel-row {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
}

.panel-btn {
  flex: 1;
  min-width: 100px;
  padding: 10px 12px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: transform 0.08s, filter 0.12s;
}
.panel-btn:hover { filter: brightness(1.07); transform: translateY(-1px); }
.panel-btn:active { transform: translateY(1px); }
.panel-btn:disabled { filter: saturate(0.3) brightness(0.9); cursor: default; transform: none; }
.panel-btn.primary { background: var(--green); color: #fff; border-bottom-color: var(--green-dark); }
.panel-btn.danger  { background: #c0392b; color: #fff; border-bottom-color: #922b21; }
.panel-btn.gold    { background: var(--gold); color: var(--ink); border-bottom-color: #c4a020; }

/* ---- catalog panel ---- */

/* Panel card: flex column so header/X stay sticky above the scroll zone */
.catalog-card-panel {
  max-width: 620px;
  display: flex;
  flex-direction: column;
  max-height: 80%;     /* never taller than 80% of stage height */
  overflow: hidden;    /* card itself never scrolls — scroll zone is inside */
}

/* overflow:hidden on .catalog-card-panel would clip the absolutely-positioned
   .popup-close that overhangs the corner (top:-12px; right:-12px).
   Move it inside the padding so it stays fully visible and tappable. */
.catalog-card-panel .popup-close {
  top: 10px;
  right: 10px;
}

/* Scroll zone inside catalog card (safety for tiny viewports; empty at 1280×720) */
#catalog-items-scroll {
  overflow-y: auto;
  min-height: 0;       /* flex child must have this to shrink below content size */
  /* Thin themed scrollbar (webkit) */
  scrollbar-width: thin;
  scrollbar-color: var(--brown) var(--cream);
}
#catalog-items-scroll::-webkit-scrollbar {
  width: 6px;
}
#catalog-items-scroll::-webkit-scrollbar-track {
  background: var(--cream);
  border-radius: 3px;
}
#catalog-items-scroll::-webkit-scrollbar-thumb {
  background: var(--brown);
  border-radius: 3px;
}

#catalog-items {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.catalog-card {
  display: flex; align-items: center; gap: 8px;
  background: #fff;
  border: 2px solid #e3d5bb;
  border-radius: 10px;
  padding: 8px 10px;
  text-align: left;
}
.catalog-section-title { width: 100%; margin: 10px 0 4px; font-size: 15px; color: var(--ink); opacity: .85; }

.catalog-icon { font-size: 26px; flex: none; }

.catalog-info { flex: 1; min-width: 0; }
.catalog-info .ci-name { font-size: 13px; color: var(--ink); }
.catalog-info .ci-desc { font-size: 10.5px; color: #8a6d4a; font-family: 'Trebuchet MS', sans-serif; line-height: 1.2; }
.catalog-info .ci-state { font-size: 10.5px; color: #4d9633; }

.catalog-buy {
  flex: none;
  font-family: inherit;
  font-size: 12px;
  padding: 6px 9px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  border-bottom: 3px solid var(--blue-dark);
  white-space: nowrap;
  cursor: pointer;
  transition: filter 0.1s;
}
.catalog-buy:hover { filter: brightness(1.1); }
.catalog-buy:disabled { filter: saturate(0.25) brightness(0.9); cursor: default; }

/* ---- pause overlay ---- */

#pause-overlay { background: rgba(20, 10, 0, 0.6); }

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

.menu-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 340px;
}

#menu-hen {
  display: block;
  margin: 0 auto 4px;
  /* canvas drawn programmatically */
}

.menu-footer {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

.menu-mute-btn {
  background: rgba(58, 36, 16, 0.15);
  border: 2px solid rgba(58, 36, 16, 0.2);
  color: var(--ink);
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.1s;
}
.menu-mute-btn:hover { background: rgba(58, 36, 16, 0.28); }
.menu-mute-btn.on { background: rgba(60, 120, 60, 0.35); border-color: var(--green); }

/* ---- tutorial prompt (arrow tooltip over canvas) ---- */

.attract-pill {
  position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%);
  display: none; z-index: 9; padding: 10px 22px; border-radius: 22px;
  background: rgba(20,10,0,0.55); color: #fff; font-size: 18px; letter-spacing: .03em;
  animation: attractPulse 1.6s ease-in-out infinite; pointer-events: none;
}
.attract-pill.show { display: block; }
@keyframes attractPulse { 0%,100% { opacity: .65; } 50% { opacity: 1; } }
#hud.hud-hidden { visibility: hidden; }

.tut-prompt {
  position: absolute;
  z-index: 11;
  background: var(--cream);
  border: 3px solid var(--brown);
  border-radius: 12px;
  padding: 10px 14px 8px;
  box-shadow: 0 6px 18px rgba(58, 36, 16, 0.35);
  display: none;
  text-align: center;
  min-width: 180px;
  max-width: 240px;
  pointer-events: none;
}
.tut-prompt.show { display: block; }

.tut-prompt-arrow {
  font-size: 18px;
  color: var(--green-dark);
  line-height: 1;
  margin-bottom: 4px;
}

.tut-prompt-text {
  font-size: 14px;
  color: var(--ink);
  font-family: 'Fredoka One', cursive;
  line-height: 1.3;
}

.tut-skip {
  display: block;
  margin: 8px auto 0;
  background: none;
  border: none;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 11px;
  color: #8a6d4a;
  text-decoration: underline;
  cursor: pointer;
  pointer-events: auto;
  padding: 0;
}
.tut-skip:hover { color: var(--brown); }

/* ---- land tooltip ---- */

.land-tip-popup {
  font-size: 13px;
  line-height: 1.4;
  max-width: 200px;
  pointer-events: none;
  text-align: center;
  color: var(--ink);
  font-family: 'Trebuchet MS', sans-serif;
}

/* ---- overlays ---- */

.overlay {
  position: absolute; inset: 0;
  z-index: 10;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(40, 25, 8, 0.45);
}
.overlay.show { display: flex; }

.card {
  position: relative;
  background: var(--cream);
  border: 4px solid var(--brown);
  border-radius: 18px;
  padding: 26px 34px;
  text-align: center;
  color: var(--ink);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  max-width: 560px;
}

#menu .card { background: rgba(253, 246, 227, 0.96); }

.title {
  font-size: 58px;
  line-height: 1;
  color: var(--green);
  text-shadow: 0 4px 0 var(--green-dark), 0 7px 0 rgba(58, 36, 16, 0.2);
  margin-bottom: 4px;
}
.title .bounce { display: inline-block; animation: bounce 1.6s ease-in-out infinite; }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

.subtitle { font-size: 16px; color: #8a6d4a; margin-bottom: 18px; }

.big-btn {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 13px;
  font-size: 22px;
  font-family: inherit;
  border-radius: 12px;
  background: var(--green);
  color: #fff;
  border-bottom: 4px solid var(--green-dark);
  transition: transform 0.08s, filter 0.12s;
}
.big-btn:hover { filter: brightness(1.07); transform: translateY(-2px); }
.big-btn:active { transform: translateY(1px); }
.big-btn.alt { background: var(--wood); border-bottom-color: var(--wood-dark); font-size: 17px; padding: 10px; }

/* ---- cutscene ---- */

#cutscene-overlay { background: rgba(22, 13, 4, 0.78); cursor: pointer; }

#cutscene-box {
  position: relative;
  width: 860px;
  max-width: 94%;
}

#cutscene-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px 10px 0 0;
  border: 4px solid var(--brown);
  border-bottom: none;
  background: #7ec8ef;
}

#cs-dialogue {
  background: var(--cream);
  border: 4px solid var(--brown);
  border-radius: 14px;
  padding: 14px 18px 16px;
  min-height: 64px;
  color: var(--ink);
}
#cs-name { font-size: 15px; letter-spacing: 1px; margin-right: 10px; }
#cs-text { font-size: 17px; font-family: 'Trebuchet MS', sans-serif; line-height: 1.35; }

#cs-skip {
  position: absolute;
  top: -14px; right: -10px;
  font-family: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 9px;
  background: var(--wood);
  color: var(--cream);
  border-bottom: 3px solid var(--wood-dark);
  cursor: pointer;
}
#cs-skip:hover { filter: brightness(1.1); }

/* ---- help panel ---- */

.help-card {
  width: 520px;
  max-width: 94vw;
  max-height: 86%;
  display: flex;
  flex-direction: column;
  padding: 20px 24px 18px;
  overflow: hidden;
}

.stats-card { max-width: 420px; }
#stats-body { display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; font-size: 15px; text-align: left; margin: 8px 4px; }
#stats-body .sb-label { color: var(--ink); opacity: .85; }
#stats-body .sb-val { font-weight: bold; text-align: right; }
#stats-body .sb-head { grid-column: 1 / -1; margin-top: 8px; font-size: 13px; opacity: .6; text-transform: uppercase; letter-spacing: .04em; }

/* X button inside card header, never obscured */
.help-card .popup-close {
  top: 10px;
  right: 10px;
}

.help-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.help-tab {
  flex: 1;
  padding: 7px 6px;
  font-family: inherit;
  font-size: 13px;
  border-radius: 9px;
  background: #e8dfc8;
  color: var(--ink);
  border-bottom: 3px solid #c4b08a;
  cursor: pointer;
  transition: filter 0.1s, transform 0.08s;
  white-space: nowrap;
}
.help-tab:hover { filter: brightness(1.05); transform: translateY(-1px); }
.help-tab.active {
  background: var(--green);
  color: #fff;
  border-bottom-color: var(--green-dark);
}

.help-pane {
  overflow-y: auto;
  min-height: 0;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--brown) var(--cream);
}
.help-pane::-webkit-scrollbar { width: 5px; }
.help-pane::-webkit-scrollbar-track { background: var(--cream); }
.help-pane::-webkit-scrollbar-thumb { background: var(--brown); border-radius: 3px; }
.help-pane.hidden { display: none; }

.help-section-title {
  font-size: 13px;
  color: var(--green-dark);
  letter-spacing: 0.5px;
  margin: 8px 0 5px;
  text-transform: uppercase;
  font-family: 'Fredoka One', cursive;
}

.help-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--ink);
  font-family: 'Trebuchet MS', sans-serif;
  line-height: 1.4;
}

.help-icon {
  font-size: 18px;
  flex: none;
  width: 24px;
  text-align: center;
  line-height: 1.3;
}

.help-divider {
  height: 1px;
  background: #e3d5bb;
  margin: 8px 0;
}

/* Helpers tab */
.help-critter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid #e3d5bb;
}
.help-critter-row:last-of-type { border-bottom: none; }

.help-critter-canvas {
  flex: none;
  border-radius: 8px;
  background: #f0f9e8;
  border: 2px solid #c8e4b0;
}

.help-critter-info { flex: 1; }

.help-critter-name {
  font-family: 'Fredoka One', cursive;
  font-size: 16px;
  color: var(--green-dark);
}

.help-critter-job {
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 12px;
  color: #6a5030;
  line-height: 1.3;
}

.help-catalog-hint {
  margin-top: 10px;
  text-align: center;
  font-size: 13px;
  color: var(--blue);
  font-family: 'Trebuchet MS', sans-serif;
}

/* Orders & More tab — controls row */
.help-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 12px;
  color: var(--ink);
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid #a08060;
  border-radius: 4px;
  background: #f5ede0;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 11px;
  color: var(--ink);
}

/* "How to Play" button in menu — compact alt style */
.menu-help-text-btn {
  font-size: 14px !important;
  padding: 8px !important;
  margin-top: 4px !important;
}

/* Hen-card pulse highlight (tutorial phase 2 step 3) */
@keyframes hen-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(72, 177, 72, 0.85); border-color: #4caf50; }
  50%       { box-shadow: 0 0 0 6px rgba(72, 177, 72, 0); border-color: #81c784; }
}
.catalog-card.hen-highlight {
  animation: hen-pulse 1.1s ease-in-out infinite;
  border-color: #4caf50;
}
.hen-highlight-caption {
  font-size: 10px;
  color: var(--green-dark);
  font-family: 'Trebuchet MS', sans-serif;
  text-align: center;
  margin-top: 3px;
  line-height: 1.2;
}

/* Mobile sizing for help panel */
@media (max-width: 450px) {
  .help-card {
    padding: 14px 14px 12px;
    max-height: 82%;
  }
  .help-tab { font-size: 11px; padding: 6px 4px; }
  .help-row { font-size: 11px; }
  .help-critter-name { font-size: 14px; }
  .help-critter-job  { font-size: 11px; }
  .help-critter-canvas { width: 40px; height: 40px; }
}

/* ---- fullscreen + mute buttons (fixed, outside stage, unscaled) ---- */

#sg-fs-btn, #mute-btn {
  position: fixed; top: 8px; right: 8px;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  padding: 0; border: 0; border-radius: 6px;
  background: rgba(0, 0, 0, 0.45); color: #fff; cursor: pointer; z-index: 9999;
}
#sg-fs-btn:hover, #mute-btn:hover { background: rgba(0, 0, 0, 0.7); }
#mute-btn { right: 42px; }
#mute-btn.on { background: rgba(60, 120, 60, 0.7); }
