/* Build the Word — construction spelling game */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --tile-size: clamp(44px, 8.5vmin, 78px);
  --ink: #4a2c11;
  --outline: 0 2px 0 rgba(255,255,255,.85), 0 -1px 0 rgba(255,255,255,.6), 2px 0 0 rgba(255,255,255,.6), -2px 0 0 rgba(255,255,255,.6);
  font-family: "Arial Rounded MT Bold", ui-rounded, "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
}

html, body { height: 100%; overflow: hidden; }
body { touch-action: manipulation; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }

#game {
  position: fixed;
  inset: 0;
  background: url("assets/img/bg-construction.webp") center / cover no-repeat, #7ec4f2;
  overflow: hidden;
}

.screen { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; }
.screen.active { display: flex; }

img { pointer-events: none; -webkit-user-drag: none; }

/* ---------- shared buttons ---------- */
.img-btn {
  background: none; border: none; cursor: pointer; padding: 0;
  transition: transform .12s ease, filter .12s ease;
  touch-action: manipulation;
}
.img-btn:hover { transform: scale(1.06); }
.img-btn:active { transform: scale(.94); }
.img-btn img { display: block; width: 100%; height: auto; }
.img-btn:focus-visible { outline: 4px solid #ffd23f; outline-offset: 4px; border-radius: 16px; }

.corner-btn { position: absolute; bottom: max(12px, env(safe-area-inset-bottom)); width: clamp(52px, 9vmin, 84px); z-index: 40; }
.corner-left { left: 14px; }
.corner-right { right: 14px; }
.sound-btn.muted { filter: grayscale(1) brightness(.85); }

.round-btn {
  border: none; cursor: pointer;
  background: #2f7fd4; color: #fff;
  font-family: inherit; font-weight: 700;
  font-size: clamp(13px, 2.4vmin, 18px);
  padding: .5em 1.1em; border-radius: 999px;
  box-shadow: 0 3px 0 #1c5a9e, 0 5px 10px rgba(0,0,0,.25);
  transition: transform .12s ease;
}
.round-btn:hover { transform: scale(1.05); }
.round-btn:active { transform: scale(.95); }

/* ---------- start screen ---------- */
.logo-start { width: clamp(220px, 36vmin, 400px); margin-top: max(2vh, 10px); filter: drop-shadow(0 6px 14px rgba(0,0,0,.3)); }
.tagline {
  color: #fff; font-weight: 700; font-size: clamp(15px, 2.8vmin, 22px);
  text-shadow: 0 2px 4px rgba(0,0,0,.5); margin-top: 6px;
}
.start-btn { width: clamp(180px, 30vmin, 300px); margin: 2.2vh 0 1vh; animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.start-btn:active { animation: none; }

.picker { display: flex; flex-direction: column; align-items: center; gap: 2px; z-index: 5; }
.picker-label { color: #fff; font-weight: 700; font-size: clamp(13px, 2.2vmin, 17px); text-shadow: 0 2px 3px rgba(0,0,0,.5); margin-top: 8px; }
.picker-row { display: flex; gap: clamp(6px, 1.4vmin, 14px); flex-wrap: wrap; justify-content: center; padding: 4px; }
.grade-btn { width: clamp(44px, 8vmin, 72px); border-radius: 16px; }
.diff-btn { width: clamp(78px, 14vmin, 130px); border-radius: 16px; }
.grade-btn.selected, .diff-btn.selected { outline: 4px solid #ffd23f; outline-offset: 2px; transform: scale(1.08); filter: drop-shadow(0 0 8px rgba(255,210,63,.9)); }

.prek-btn {
  width: clamp(58px, 10vmin, 92px); aspect-ratio: 123/128; align-self: stretch;
  background: linear-gradient(#ff8fb1, #e5527e); border-radius: 22%;
  border: 3px solid #fdf2dc; box-shadow: 0 4px 0 #b23458, 0 6px 10px rgba(0,0,0,.25);
  display: flex; align-items: center; justify-content: center;
}
.prek-btn span { color: #fff; font-weight: 900; font-size: clamp(12px, 2.2vmin, 19px); text-shadow: 0 2px 0 rgba(0,0,0,.25); }

.deco-start-left, .deco-start-right { position: absolute; bottom: 2vh; width: clamp(120px, 22vmin, 240px); filter: drop-shadow(0 4px 8px rgba(0,0,0,.3)); }
.deco-start-left { left: 2vw; }
.deco-start-right { right: 2vw; }

/* ---------- gameplay HUD ---------- */
.hud {
  width: 100%; display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(10px, 1.4vh) clamp(10px, 2vw, 26px) 0; z-index: 20;
}
.hud-panel { position: relative; width: clamp(120px, 19vmin, 200px); }
.hud-panel > img { width: 100%; display: block; filter: drop-shadow(0 3px 6px rgba(0,0,0,.25)); }
.hud-value {
  position: absolute; left: 8%; right: 8%; top: 35%; height: 41%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; color: #2c5f2d; font-size: clamp(18px, 3.4vmin, 30px);
  -webkit-text-stroke: 0.045em currentColor; letter-spacing: 0.02em;
}
.level-panel .hud-value { color: #b3541e; }
.logo-hud { width: clamp(110px, 17vmin, 190px); filter: drop-shadow(0 4px 8px rgba(0,0,0,.3)); }

/* ---------- board ---------- */
.board-area { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; z-index: 10; min-height: 0; }
.board-wrap { position: relative; width: clamp(300px, 66vmin, 720px); max-width: 94vw; }
.board-img { width: 100%; display: block; filter: drop-shadow(0 6px 12px rgba(0,0,0,.3)); }
.word-row {
  position: absolute; left: 7%; right: 7%; top: 20%; bottom: 22%;
  display: flex; align-items: center; justify-content: center;
  gap: clamp(4px, 1vmin, 10px);
}
.letter-tile {
  position: relative;
  width: var(--tile-size); height: var(--tile-size);
  max-width: 12.5%;
  aspect-ratio: 1;
  background: url("assets/img/tile-plain.png") center / 100% 100% no-repeat;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: calc(var(--tile-size) * .62);
  color: var(--ink);
}
.letter-tile.slot { filter: drop-shadow(0 0 6px rgba(255,210,63,.9)); animation: slotPulse 1.2s ease-in-out infinite; }
.letter-tile.slot .dash {
  width: 46%; height: 7%; min-height: 3px;
  background: #e8973a; border-radius: 99px;
}
@keyframes slotPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.letter-tile.placed { animation: popIn .35s ease; }
@keyframes popIn { 0% { transform: scale(.2); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }

.board-tools { margin-top: clamp(4px, 1vh, 10px); z-index: 12; }
.feedback {
  min-height: 1.6em; margin-top: 4px;
  color: #fff; font-weight: 800; font-size: clamp(15px, 2.8vmin, 24px);
  text-shadow: 0 2px 4px rgba(0,0,0,.55);
  transition: opacity .2s;
}
.feedback.pop { animation: popIn .3s ease; }

/* ---------- vehicles ---------- */
.vehicles {
  display: flex; justify-content: center; align-items: flex-end;
  gap: clamp(8px, 2vw, 30px);
  width: 100%; padding: 0 10px calc(max(10px, env(safe-area-inset-bottom)) + 4px);
  z-index: 15;
}
.vehicle-choice {
  position: relative;
  background: none; border: none; cursor: pointer; padding: 6px;
  width: clamp(130px, 21vw, 230px);
  min-width: 44px; min-height: 44px;
  touch-action: manipulation;
  transition: transform .15s ease;
}
.vehicle-choice:hover:not(:disabled) { transform: translateY(-6px) scale(1.04); }
.vehicle-choice:active:not(:disabled) { transform: scale(.95); }
.vehicle-choice:focus-visible { outline: 4px solid #ffd23f; outline-offset: 2px; border-radius: 20px; }
.vehicle-choice:disabled { cursor: default; }
.vehicle-img { width: 100%; display: block; filter: drop-shadow(0 5px 8px rgba(0,0,0,.35)); }
.vehicle-letter {
  position: absolute; top: -16%; left: 50%; transform: translateX(-50%);
  z-index: 2;
  width: 36%; aspect-ratio: 1;
  background: url("assets/img/tile-plain.png") center / 100% 100% no-repeat;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; color: var(--ink);
  font-size: clamp(20px, 4.6vmin, 40px);
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.3));
}
/* keep letter tiles clear of each vehicle's face */
.vehicle-choice[data-veh="bulldozer"] .vehicle-letter { left: 74%; }
.vehicle-choice[data-veh="excavator"] .vehicle-letter { left: 24%; }
.vehicle-choice[data-veh="dumptruck"] .vehicle-letter { left: 27%; }
.vehicle-choice[data-veh="loader"] .vehicle-letter { left: 24%; }

/* effects */
.fx { position: fixed; pointer-events: none; z-index: 60; }
.flying-tile {
  position: fixed; z-index: 70; pointer-events: none;
  background: url("assets/img/tile-plain.png") center / 100% 100% no-repeat;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; color: var(--ink);
}

/* gameplay decorations */
.deco { position: absolute; z-index: 2; opacity: .95; }
.deco-cone { left: 2%; bottom: 30%; width: clamp(40px, 7vmin, 90px); }
.deco-workzone { right: 2%; bottom: 32%; width: clamp(50px, 9vmin, 110px); }
.deco-pipes { right: 1%; bottom: 2%; width: clamp(60px, 10vmin, 120px); display: none; }
.deco-bunting { left: 50%; top: -6px; transform: translateX(-50%); width: clamp(200px, 40vmin, 440px); }

/* ---------- results ---------- */
.logo-results { width: clamp(160px, 24vmin, 300px); margin-top: max(1.6vh, 8px); filter: drop-shadow(0 5px 12px rgba(0,0,0,.3)); }
.great-job { width: clamp(200px, 32vmin, 380px); margin-top: 1vh; animation: popIn .5s ease; }
.result-stars { width: clamp(150px, 26vmin, 320px); margin-top: .6vh; animation: popIn .7s ease; }
.result-panels { display: flex; gap: clamp(10px, 3vw, 40px); margin-top: 1.4vh; }
.result-panel { width: clamp(140px, 22vmin, 220px); }
.result-accuracy { color: #fff; font-weight: 800; font-size: clamp(14px, 2.6vmin, 21px); text-shadow: 0 2px 4px rgba(0,0,0,.55); margin-top: 8px; }
.result-trophy { position: absolute; right: clamp(8px, 4vw, 60px); bottom: 18vh; width: clamp(70px, 12vmin, 140px); animation: breathe 1.8s ease-in-out infinite; }
.result-buttons { display: flex; gap: clamp(10px, 3vw, 34px); margin-top: 2vh; flex-wrap: wrap; justify-content: center; }
.result-buttons .img-btn { width: clamp(150px, 24vmin, 260px); }

.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti span {
  position: absolute; top: -20px;
  width: 10px; height: 14px; border-radius: 3px;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  to { transform: translateY(110vh) rotate(720deg); opacity: .7; }
}

/* shake for wrong answers (fallback class, WAAPI is primary) */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-10px) rotate(-2deg); }
  40% { transform: translateX(10px) rotate(2deg); }
  60% { transform: translateX(-8px); }
  80% { transform: translateX(8px); }
}

/* ---------- responsive ---------- */
@media (max-width: 640px), (max-height: 480px) {
  .logo-hud { display: none; }
  .deco-cone, .deco-workzone, .deco-bunting { display: none; }
  .deco-start-left, .deco-start-right { width: clamp(80px, 18vmin, 140px); }
}
@media (orientation: portrait) {
  .vehicles { flex-wrap: wrap; gap: clamp(28px, 6vmin, 56px) 10px; }
  .vehicle-choice { width: 40vw; max-width: 230px; }
}
@media (max-width: 560px) and (orientation: portrait) {
  .vehicle-choice { width: 43vw; max-width: 220px; }
  :root { --tile-size: clamp(34px, 10vw, 56px); }
}
