/* ======================= Fort Division — styles ======================= */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Baloo 2", system-ui, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  /* Fort wood color (recolored by the 🎨 picker). */
  --f-light: #d8a86a;
  --f-main: #b07a3e;
  --f-dark: #845321;

  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: radial-gradient(130% 90% at 50% 0%, #cdeafd 0%, #bfe8c6 55%, #8fd07f 100%);
  transition: background 0.4s ease;
}

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

#hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: clamp(8px, 2.4vw, 22px);
  padding: clamp(6px, 2vw, 14px) clamp(8px, 2vw, 16px);
  flex-wrap: wrap;
}

.hud-item { flex: 0 0 auto; text-align: center; }

#timer-num {
  font-size: clamp(30px, 7vw, 56px);
  font-weight: 800;
  line-height: 1;
  color: #2f9d4e;
  text-shadow: 0 3px 0 #fff, 0 5px 8px rgba(0, 0, 0, 0.15);
  min-width: 1.4em;
}

#timer-num.low {
  color: #e10046;
  animation: pulse 0.6s ease-in-out infinite;
}

@keyframes pulse { 50% { transform: scale(1.18); } }

.stat { min-width: clamp(96px, 22vw, 150px); }

.stat-label {
  font-size: clamp(13px, 3vw, 18px);
  font-weight: 700;
  color: #3a5a3a;
  white-space: nowrap;
}

.stat-label b { color: #1f8f3f; }

#mat-num.bump { display: inline-block; animation: bump 0.3s ease; }

@keyframes bump {
  0% { transform: scale(1); }
  50% { transform: scale(1.5); color: #b07a3e; }
  100% { transform: scale(1); }
}

.mini-bar {
  margin: 5px auto 0;
  width: clamp(70px, 18vw, 130px);
  height: 10px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.65);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12);
}

.mini-bar > div {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  border-radius: 99px;
  transition: transform 0.15s linear;
}

#timer-fill { background: linear-gradient(90deg, #ff5d5d, #ffd23f 40%, #7be06a); }
.fill-green { background: linear-gradient(90deg, #9be86f, #35c65a); }

#customize-btn {
  flex: 0 0 auto;
  margin-left: auto;
  font-size: clamp(20px, 5vw, 30px);
  line-height: 1;
  background: rgba(255, 255, 255, 0.9);
  border: 3px solid #9fe0a5;
  border-radius: 50%;
  width: clamp(42px, 11vw, 56px);
  height: clamp(42px, 11vw, 56px);
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(60, 160, 80, 0.3);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  touch-action: manipulation;
}

#customize-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(60, 160, 80, 0.3);
}

/* ------------------------------ Yard -------------------------------- */

#yard {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: clamp(8px, 2vw, 18px);
  padding: clamp(4px, 1.5vw, 12px) clamp(8px, 2.5vw, 20px);
}

.col-label {
  font-size: clamp(13px, 3.2vw, 20px);
  font-weight: 800;
  color: #3a5a3a;
  text-align: center;
  margin-bottom: 6px;
}

/* --- the goblin's rival fort (a rising brick tower) --- */

#goblin-col {
  flex: 0 0 clamp(78px, 26vw, 150px);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
}

#goblin-tower {
  position: relative;
  flex: 1 1 auto;
  width: clamp(52px, 16vw, 92px);
  min-height: 0;
  border-radius: 10px 10px 0 0;
  background: rgba(255, 255, 255, 0.35);
  border: 3px dashed rgba(120, 90, 60, 0.5);
  border-bottom: none;
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.12);
}

/* The bricks that grow upward as the goblin builds. */
#goblin-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.14) 0 2px, transparent 2px 24px),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.18) 0 2px, transparent 2px 18px),
    linear-gradient(180deg, #c0503e, #9a3a2c);
  transition: height 0.15s linear;
}

#goblin-tower.danger { border-color: #e10046; }
#goblin-tower.danger #goblin-fill {
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.14) 0 2px, transparent 2px 24px),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.18) 0 2px, transparent 2px 18px),
    linear-gradient(180deg, #ff5a46, #c0303a);
}

#goblin-face {
  position: absolute;
  left: 50%;
  top: 6px;
  transform: translateX(-50%);
  font-size: clamp(26px, 8vw, 44px);
  line-height: 1;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
  z-index: 1;
}

#hammer {
  font-size: clamp(20px, 6vw, 32px);
  margin-top: 4px;
  transform-origin: 70% 70%;
  animation: swing 1.2s ease-in-out infinite;
}
#hammer.fast { animation-duration: 0.5s; }

@keyframes swing {
  0%, 100% { transform: rotate(-18deg); }
  50% { transform: rotate(22deg); }
}

/* --- your growing fort --- */

#fort-col {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  min-height: 0;
}

#fort-stack {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column; /* newest piece is prepended, so it sits on top */
  align-items: center;
  gap: clamp(2px, 0.8vw, 6px);
  overflow-y: auto;
  padding: 4px;
}

/* Auto margin on the top row pushes the whole fort down onto its base when
   there's spare room, but collapses (letting the stack scroll) once it's tall. */
#fort-stack > .fort-row:first-child { margin-top: auto; }

.fort-row {
  display: flex;
  align-items: center;
  gap: clamp(4px, 1.5vw, 10px);
  padding: clamp(2px, 0.8vw, 5px) clamp(8px, 2.4vw, 16px);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--f-light), var(--f-main) 60%, var(--f-dark));
  border: 2px solid var(--f-dark);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.22), inset 0 2px 4px rgba(255, 255, 255, 0.28);
  max-width: 100%;
}

.fp-emoji {
  font-size: clamp(20px, 5.5vw, 32px);
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
}

.fp-sticks {
  font-size: clamp(11px, 3vw, 17px);
  line-height: 1;
  letter-spacing: -2px;
  white-space: nowrap;
  overflow: hidden;
}

.fort-row.pop-in { animation: popin 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) 1; }
@keyframes popin {
  0% { transform: scale(0.2) translateY(-14px); opacity: 0; }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); opacity: 1; }
}

/* The grassy platform your fort is built on. */
#fort-base {
  flex: 0 0 auto;
  width: min(320px, 92%);
  height: clamp(10px, 2.4vw, 16px);
  border-radius: 6px;
  background: linear-gradient(180deg, #6fc25a, #4a9a3a);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.22);
  margin-top: 2px;
}

/* ---------------------------- Question ------------------------------ */

#ask {
  flex: 0 0 auto;
  padding: clamp(8px, 2vw, 16px) clamp(10px, 3vw, 24px) clamp(12px, 3vw, 22px);
  text-align: center;
  background: rgba(255, 255, 255, 0.55);
  border-top: 3px solid rgba(255, 255, 255, 0.8);
}

#q-hint {
  font-size: clamp(12px, 3vw, 17px);
  font-weight: 700;
  color: #3a5a3a;
  margin-bottom: 2px;
}

#q-text {
  font-size: clamp(30px, 9vw, 56px);
  font-weight: 800;
  color: #6a3f18;
  line-height: 1.1;
  text-shadow: 0 2px 0 #fff;
  margin-bottom: clamp(8px, 2vw, 14px);
}

#answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 2.4vw, 16px);
  max-width: 460px;
  margin: 0 auto;
}

.answer-btn {
  font-family: inherit;
  font-size: clamp(24px, 6.5vw, 40px);
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #63c76e, #3a9d4e);
  border: none;
  border-radius: 18px;
  padding: clamp(10px, 2.6vw, 18px);
  cursor: pointer;
  box-shadow: 0 6px 0 #2b7d3b, 0 8px 16px rgba(0, 0, 0, 0.2);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  touch-action: manipulation;
}

.answer-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #2b7d3b, 0 4px 8px rgba(0, 0, 0, 0.2);
}

.answer-btn:disabled { opacity: 0.6; cursor: default; }

.answer-btn.wrong {
  background: linear-gradient(180deg, #b0b8c0, #8a929c);
  box-shadow: 0 6px 0 #6a727c, 0 8px 16px rgba(0, 0, 0, 0.2);
}

.answer-btn.shake { animation: shake 0.35s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

/* --------------------------- FX canvas ------------------------------ */

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 40;
}

/* ---------------------------- Overlays ------------------------------ */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(30, 60, 30, 0.45);
  backdrop-filter: blur(3px);
}

.overlay.show { display: flex; }
.overlay.win { background: rgba(255, 220, 120, 0.35); }
.overlay.lose { background: rgba(50, 40, 30, 0.5); }

.card {
  background: #fff;
  border-radius: 28px;
  border: 6px solid #9fe0a5;
  box-shadow: 0 16px 0 rgba(60, 160, 80, 0.25), 0 24px 40px rgba(0, 0, 0, 0.3);
  padding: clamp(20px, 5vw, 40px);
  max-width: 440px;
  width: 100%;
  text-align: center;
  animation: cardIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cardIn {
  from { transform: scale(0.6) translateY(30px); opacity: 0; }
}

.card-emoji {
  font-size: clamp(46px, 12vw, 72px);
  line-height: 1;
  margin-bottom: 6px;
}

.card h1 {
  margin: 6px 0 12px;
  font-size: clamp(28px, 7vw, 44px);
  font-weight: 800;
  color: #2f9d4e;
}

.overlay.win .card h1 { color: #ff9500; }
.overlay.lose .card h1 { color: #b0553a; }

.card p {
  margin: 8px 0;
  font-size: clamp(15px, 3.6vw, 19px);
  font-weight: 500;
  color: #3a4a3a;
}

.card p.small { font-size: clamp(13px, 3vw, 16px); color: #7a8a7a; }

.big-btn {
  margin-top: 18px;
  font-family: inherit;
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #63c76e, #3a9d4e);
  border: none;
  border-radius: 99px;
  padding: 14px 34px;
  cursor: pointer;
  box-shadow: 0 6px 0 #2b7d3b, 0 10px 18px rgba(0, 0, 0, 0.25);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #2b7d3b, 0 4px 10px rgba(0, 0, 0, 0.25);
}

/* ---------------------- Color picker (palette) ---------------------- */

.palette {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: clamp(12px, 4vw, 28px);
  background: rgba(30, 60, 30, 0.28);
  backdrop-filter: blur(2px);
}

.palette.show { display: flex; }

.palette-card {
  background: #fff;
  border-radius: 24px;
  border: 6px solid #9fe0a5;
  box-shadow: 0 14px 0 rgba(60, 160, 80, 0.25), 0 20px 36px rgba(0, 0, 0, 0.3);
  padding: clamp(16px, 4vw, 26px);
  max-width: 460px;
  width: 100%;
  text-align: center;
  animation: cardIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.paused-tag {
  display: inline-block;
  background: #e1ffe6;
  color: #1f8f3f;
  font-weight: 800;
  font-size: clamp(13px, 3vw, 16px);
  padding: 4px 14px;
  border-radius: 99px;
  border: 2px solid #9fe0a5;
}

.palette-card h2 {
  margin: 10px 0 14px;
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 800;
  color: #2f9d4e;
}

.palette-row { margin: 12px 0; }

.palette-label {
  display: block;
  font-size: clamp(13px, 3vw, 16px);
  font-weight: 700;
  color: #3a5a3a;
  margin-bottom: 8px;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(8px, 2.4vw, 14px);
  justify-content: center;
}

.swatch {
  width: clamp(40px, 10vw, 52px);
  height: clamp(40px, 10vw, 52px);
  border-radius: 50%;
  border: 4px solid #fff;
  box-shadow: 0 0 0 2px rgba(60, 160, 80, 0.25), 0 4px 8px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  touch-action: manipulation;
}

.swatch:active { transform: scale(0.92); }

.swatch.active {
  box-shadow: 0 0 0 4px #2f9d4e, 0 4px 8px rgba(0, 0, 0, 0.25);
  transform: scale(1.08);
}

.resume-btn { margin-top: 16px; }
