:root {
  --ink: #1f2e1c;
  --cream: #f7f1df;
  --leaf: #3d7a45;
  --leaf-dark: #2b5631;
  --gold: #e8a838;
  --panel: #5caa63;
  --tile: #8fd18a;
  --shadow: rgba(20, 40, 18, 0.28);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: Nunito, system-ui, sans-serif;
  color: var(--ink);
  background: #2f6a38 url("assets/ui/bg_mobile.png?v=1") center / cover fixed;
}
body { min-height: 100dvh; }

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1.25rem;
  font: inherit;
  font-weight: 800;
  background: var(--gold);
  color: #3b2a1a;
  cursor: pointer;
  box-shadow: 0 3px 0 #b87a1c;
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn-ghost {
  background: rgba(247, 241, 223, 0.92);
  box-shadow: 0 2px 0 rgba(0,0,0,0.15);
}

#sq-open {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: start center;
  align-content: start;
  padding: 3.25rem 0.75rem 0.85rem;
  overflow-y: auto;
  background: rgba(20, 40, 18, 0.55);
}
#sq-open[hidden],
#app[hidden],
.overlay[hidden] {
  display: none !important;
}

.sq-studio {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--cream);
  font-weight: 800;
  background: rgba(0,0,0,0.28);
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
}

.sq-howto {
  width: min(420px, 100%);
}
.sq-howto-card {
  background: var(--cream);
  border-radius: 18px;
  padding: 0.85rem 1rem 1rem;
  box-shadow: 0 10px 30px var(--shadow);
}
.sq-howto-card h2 {
  margin: 0 0 0.35rem;
  font-family: Fredoka, sans-serif;
  font-size: 1.15rem;
}
.sq-howto-card p {
  margin: 0 0 0.4rem;
  line-height: 1.35;
  font-size: 0.9rem;
}
.sq-play { width: 100%; margin-top: 0.45rem; }
.sq-howto-card .sq-mode-note { margin-top: 1.1rem; }
.sq-play-alt { background: #2f6a37; color: #fff; }

#app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  padding-bottom: var(--safe-bottom);
}

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.65rem 0.85rem;
  background: rgba(247, 241, 223, 0.94);
  border-bottom: 3px solid var(--leaf-dark);
}
.brand { display: flex; gap: 0.55rem; align-items: center; }
.brand h1 {
  margin: 0;
  font-family: Fredoka, sans-serif;
  font-size: 1.25rem;
}
.tag { margin: 0; font-size: 0.85rem; opacity: 0.85; }
.logo { font-size: 1.6rem; }
.stats {
  display: flex;
  gap: 0.75rem;
  margin: 0;
  margin-left: auto;
}
.stats div {
  background: #e7f5df;
  border-radius: 12px;
  padding: 0.25rem 0.55rem;
  min-width: 3.4rem;
}
.stats dt { margin: 0; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.7; }
.stats dd { margin: 0; font-weight: 800; font-size: 1.05rem; }
.hud-actions { display: flex; gap: 0.4rem; }
.hud-actions .btn { text-decoration: none; font-size: 0.9rem; padding: 0.45rem 0.8rem; }

.playfield {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  padding: 0.75rem;
  align-content: start;
}

.board-wrap {
  width: min(100%, 520px);
  margin: 0 auto;
  background: rgba(61, 122, 69, 0.55);
  border: 4px solid #24512b;
  border-radius: 18px;
  padding: 0.45rem;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.18), 0 10px 24px var(--shadow);
}
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 3px;
  aspect-ratio: 1;
  touch-action: none;
  user-select: none;
}
.cell {
  position: relative;
  border: 0;
  padding: 0;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.22), transparent 40%),
    url("assets/ui/tile.png?v=1") center / cover,
    var(--tile);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.12);
  cursor: pointer;
}
.cell img {
  width: 86%;
  height: 86%;
  object-fit: contain;
  pointer-events: none;
  position: absolute;
  inset: 7%;
  transition: transform 0.12s ease, opacity 0.18s ease;
}
.cell.selected {
  outline: 3px solid var(--gold);
  outline-offset: -2px;
  z-index: 1;
}
.cell.dragging {
  z-index: 2;
}
.cell.dragging img {
  transition: none;
  filter: drop-shadow(0 6px 8px rgba(0,0,0,0.3));
}
.cell.clearing img {
  transform: scale(0.2);
  opacity: 0;
}

.side-panel {
  width: min(100%, 520px);
  margin: 0 auto;
}
.panel-inner {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.18), transparent 35%),
    url("assets/ui/green_large.png?v=1") center / 100% 100% no-repeat,
    var(--panel);
  border-radius: 18px;
  padding: 1rem 1.1rem 1.15rem;
  color: #16321a;
  box-shadow: 0 8px 20px var(--shadow);
  border: 3px solid #24512b;
}
.panel-inner h2 {
  margin: 0;
  font-family: Fredoka, sans-serif;
}
.big {
  margin: 0.15rem 0 0.55rem;
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
}
.meter {
  height: 14px;
  border-radius: 999px;
  background: rgba(0,0,0,0.18);
  overflow: hidden;
  margin-bottom: 0.55rem;
}
.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f4b942, #fff2b0);
  transition: width 0.25s ease;
}
.meta { margin: 0.15rem 0; font-weight: 700; }
.hint { margin: 0.55rem 0 0; font-size: 0.88rem; opacity: 0.9; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(15, 30, 14, 0.55);
}
.overlay-card {
  width: min(380px, 100%);
  background: var(--cream);
  border-radius: 18px;
  padding: 1.25rem;
  text-align: center;
  box-shadow: 0 12px 36px var(--shadow);
}
.overlay-card h2 {
  margin: 0 0 0.4rem;
  font-family: Fredoka, sans-serif;
}
.overlay-card p { margin: 0 0 1rem; }
.overlay-card .btn { width: 100%; }

@media (min-width: 860px) {
  html, body {
    background-image: url("assets/ui/bg_monitor.png?v=1");
  }
  .playfield {
    grid-template-columns: minmax(0, 560px) minmax(220px, 280px);
    justify-content: center;
    align-items: start;
    padding: 1rem 1.25rem 1.5rem;
  }
  .board-wrap, .side-panel { width: 100%; margin: 0; }
  .side-panel { position: sticky; top: 0.75rem; }
  .panel-inner {
    min-height: 320px;
    background-image:
      linear-gradient(180deg, rgba(255,255,255,0.18), transparent 35%),
      url("assets/ui/green_long_vertical.png?v=1");
    background-size: 100% 100%;
  }
}

@media (max-width: 420px) {
  .stats { gap: 0.4rem; }
  .stats div { min-width: 2.8rem; padding: 0.2rem 0.4rem; }
  .brand h1 { font-size: 1.1rem; }
  .hud-actions .btn { padding: 0.4rem 0.65rem; }
}

#hud-time.urgent,
#side-time.urgent {
  color: #b33a1a;
}

/* Beat the Clock, last 10 seconds: the board throbs red. */
.board-wrap.hurry {
  border-color: #b33a1a;
  animation: hurry 0.5s ease-in-out infinite alternate;
}
@keyframes hurry {
  from { box-shadow: inset 0 0 0 3px rgba(255,255,255,0.18), 0 0 0 0 rgba(179,58,26,0.0); }
  to { box-shadow: inset 0 0 0 3px rgba(255,255,255,0.18), 0 0 18px 6px rgba(179,58,26,0.55); }
}
@media (prefers-reduced-motion: reduce) {
  .board-wrap.hurry { animation: none; box-shadow: 0 0 14px 4px rgba(179,58,26,0.5); }
}

.sq-howto {
  display: grid;
  gap: 0.5rem;
  justify-items: center;
  width: min(440px, 100%);
}
.sq-title-art {
  width: 100%;
  max-height: min(22dvh, 150px);
  object-fit: cover;
  object-position: center;
  border-radius: 14px;
  box-shadow: 0 8px 22px rgba(20, 40, 18, 0.28);
  background: #1a3d22;
}


.burst-leaf {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  pointer-events: none;
  font-size: 1.05rem;
  line-height: 1;
  transform: translate(-50%, -50%);
  animation: leaf-burst 0.7s ease-out forwards;
  filter: drop-shadow(0 1px 2px rgba(40, 80, 30, 0.35));
}
@keyframes leaf-burst {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.35) rotate(0deg); }
  70% { opacity: 1; }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.05) rotate(var(--rot));
  }
}


.overlay-cheer {
  margin: 0 0 0.75rem;
  position: relative;
}
.overlay-cheer[hidden] { display: none !important; }
.cheer-stage {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 0.2rem 0.35rem;
  min-height: 4.5rem;
  padding: 0.25rem 0 0.15rem;
}
.cheer-veg {
  display: inline-flex;
  width: 2.55rem;
  height: 2.55rem;
  animation: veg-dance 0.7s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.08s);
  transform-origin: 50% 90%;
}
.cheer-veg:nth-child(even) {
  animation-name: veg-dance-alt;
}
.cheer-veg img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 3px rgba(40, 70, 30, 0.28));
  pointer-events: none;
  user-select: none;
}
.cheer-yays {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}
.cheer-yays span {
  position: absolute;
  left: calc(18% + var(--n) * 28%);
  top: -0.15rem;
  font-family: Fredoka, sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  color: #3d7a45;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
  animation: cheer-pop 1.4s ease-in-out infinite;
  animation-delay: calc(var(--n) * 0.22s);
  opacity: 0;
}
@keyframes veg-dance {
  0%, 100% { transform: translateY(0) rotate(-6deg) scale(1); }
  35% { transform: translateY(-12px) rotate(8deg) scale(1.08); }
  70% { transform: translateY(-4px) rotate(-4deg) scale(1.02); }
}
@keyframes veg-dance-alt {
  0%, 100% { transform: translateY(0) rotate(7deg) scale(1); }
  40% { transform: translateY(-14px) rotate(-9deg) scale(1.1); }
  75% { transform: translateY(-3px) rotate(5deg) scale(1.03); }
}
@keyframes cheer-pop {
  0%, 100% { opacity: 0; transform: translateY(8px) scale(0.85); }
  25%, 55% { opacity: 1; transform: translateY(-10px) scale(1.05); }
  80% { opacity: 0; transform: translateY(-18px) scale(0.9); }
}
@media (prefers-reduced-motion: reduce) {
  .cheer-veg, .cheer-yays span { animation: none; opacity: 1; }
}
