/* «Собери слово» — styling inspired by «Три поросёнка» */

:root {
  --ink: #3d2b2f;
  --muted: #8b7576;
  --sky: #d7f0ff;
  --cream: #fff8ec;
  --pig: #ff7096;          /* main colour — piggy pink */
  --pig-dark: #e04f78;
  --pig-soft: #ffe1ea;
  --cell: #ffffff;
  --cell-border: #eadfcd;
  --ok: #22a35a;
  --ok-bg: #dcf8e7;
  --bad: #e5484d;
  --bad-bg: #ffe4e4;
  --accent: #f2b31c;       /* level colour: straw / sticks / stone */
  --accent-soft: #fff1c9;
  --grass: #7ccf5b;
}

body[data-level="1"] { --accent: #b9773d; --accent-soft: #f5e4d2; }
body[data-level="2"] { --accent: #6f7d95; --accent-soft: #e6ebf3; }

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--sky) 0%, var(--cream) 55%) fixed;
  color: var(--ink);
  font-family: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
button:disabled { cursor: default; }

/* ---------- Levels (houses) ---------- */

header { padding: 14px 16px 0; }

.levels {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.level {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas: "icon name" "icon pips";
  align-items: center;
  column-gap: 10px;
  padding: 8px 16px 8px 10px;
  background: rgba(255, 255, 255, 0.7);
  border: 3px solid transparent;
  border-radius: 18px;
  text-align: left;
  transition: transform 0.15s, background 0.15s;
}
.level:hover { transform: translateY(-2px); }
.level.current { background: #fff; border-color: var(--accent); box-shadow: 0 4px 0 var(--accent-soft); }
.level-icon { grid-area: icon; font-size: 34px; line-height: 1; }
.level-name { grid-area: name; font-weight: 800; font-size: 16px; }
.pips { grid-area: pips; display: flex; gap: 4px; margin-top: 4px; }
/* A pip lights up: --fill goes from 0 to 1 — each word makes it brighter and slightly bigger */
.pips { align-items: center; }
.level:nth-child(1) { --pip: #f2b31c; }  /* each house has its own pip colour */
.level:nth-child(2) { --pip: #b9773d; }
.level:nth-child(3) { --pip: #6f7d95; }
.pips i {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--pip, var(--accent)) calc(var(--fill, 0) * 100%), #e7ddd0);
  transform: scale(calc(0.8 + var(--fill, 0) * 0.3));
  transition: background 0.4s, transform 0.4s;
}
.pips i.full { box-shadow: 0 0 0 2px #fff, 0 0 8px 1px var(--pip, var(--accent)); }
.level.done .pips i { --pip: var(--ok); }

/* ---------- Word ---------- */

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.board {
  min-height: 38vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

/* Word picture — a hint of what is being assembled */
.picture {
  width: clamp(120px, 22vh, 200px);
  aspect-ratio: 1;
  object-fit: contain;
  background: #fff;
  border-radius: 28px;
  padding: 8px;
  box-shadow: 0 6px 0 var(--accent-soft), 0 10px 24px rgba(61, 43, 47, 0.08);
  animation: pop 0.35s ease-out;
}
.picture[hidden] { display: none; }

.word-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}

.word {
  /* --n is set from the script: letter count + room for the dots */
  --box: min(118px, calc((100vw - 150px) / var(--n, 6)));
  display: flex;
  align-items: center;
  gap: calc(var(--box) * 0.16);
}

.group { display: flex; gap: calc(var(--box) * 0.07); }

.cell {
  width: var(--box);
  height: calc(var(--box) * 1.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--box) * 0.82);
  font-weight: 900;
  line-height: 1;
  background: var(--cell);
  border: 3px solid var(--cell-border);
  border-radius: calc(var(--box) * 0.2);
  box-shadow: inset 0 -5px 0 rgba(61, 43, 47, 0.05);
}
.cell.filled { border-color: var(--accent); background: #fff; animation: pop 0.22s ease-out; }
.cell.ok { border-color: var(--ok); background: var(--ok-bg); color: var(--ok);
           animation: hop 0.5s ease-out both; animation-delay: calc(var(--i, 0) * 70ms); }
.cell.bad { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }

.dot {
  width: calc(var(--box) * 0.2);
  height: calc(var(--box) * 0.2);
  border-radius: 50%;
  background: var(--ink);
  flex: none;
}

.speaker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--pig-soft);
  color: var(--pig-dark);
  transition: transform 0.1s;
}
.speaker svg { width: 60%; height: 60%; }
.speaker:active:not(:disabled) { transform: scale(0.9); }
.speaker.big { width: 84px; height: 84px; background: var(--pig); color: #fff; box-shadow: 0 5px 0 var(--pig-dark); }
.speaker.small { width: 36px; height: 36px; flex: none; }
.speaker:disabled { opacity: 0.4; }

/* ---------- Buttons ---------- */

#message { margin: 0; min-height: 1.4em; font-size: 30px; font-weight: 900; text-align: center; }
#message.ok { color: var(--ok); animation: pop 0.3s ease-out; }
#message.bad { color: var(--bad); }

.controls { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

.btn {
  font-size: 21px;
  font-weight: 800;
  padding: 12px 26px;
  border-radius: 999px;
  border: 3px solid #eadfcd;
  background: #fff;
  box-shadow: 0 4px 0 #eadfcd;
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #eadfcd; }
.btn.primary { background: var(--pig); border-color: var(--pig); color: #fff; box-shadow: 0 4px 0 var(--pig-dark); }
.btn.primary:active:not(:disabled) { box-shadow: 0 1px 0 var(--pig-dark); }
.btn:disabled { opacity: 0.45; }
.btn[hidden] { display: none; }

/* ---------- Tiles ---------- */

.tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; max-width: 900px; }

.tile {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 8px;
  background: #fff;
  border: 3px solid #ffc4d3;
  border-radius: 20px;
  box-shadow: 0 5px 0 #ffb0c4;
  transition: transform 0.12s, opacity 0.2s;
}
.tile:not(.used):hover { transform: translateY(-3px); }
.tile.used { opacity: 0.25; box-shadow: none; transform: scale(0.94); }

.tile-text {
  border: none;
  background: none;
  font-size: 46px;
  font-weight: 900;
  padding: 6px 4px 6px 18px;
  min-width: 70px;
}
.tile-text:disabled { color: var(--ink); }

/* ---------- "House built" dialog ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(61, 43, 47, 0.35);
}
.overlay[hidden] { display: none; }
.card {
  max-width: 440px;
  width: 100%;
  padding: 28px 24px;
  background: #fff;
  border-radius: 28px;
  text-align: center;
  box-shadow: 0 10px 0 var(--accent-soft), 0 20px 50px rgba(0, 0, 0, 0.2);
  animation: pop 0.35s ease-out;
}
.card-icon { font-size: 84px; line-height: 1.1; }
.card h2 { margin: 10px 0 6px; font-size: 30px; font-weight: 900; }
.card p { margin: 0 0 22px; color: var(--muted); font-size: 18px; }

/* ---------- Confetti and grass ---------- */

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 20; }
.confetti span { position: absolute; top: -50px; animation: fall 1.8s ease-in forwards; }

.grass {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 44px;
  pointer-events: none;
  background:
    radial-gradient(circle at 20px 0, transparent 22px, var(--grass) 23px) 0 0 / 40px 44px repeat-x;
  opacity: 0.85;
}

/* ---------- Animations ---------- */

@keyframes pop { 0% { transform: scale(0.85); } 70% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-18%); } }
@keyframes fall {
  to { transform: translate(var(--drift, 0), 110vh) rotate(540deg); opacity: 0.9; }
}
.shake { animation: shake 0.4s; }
@keyframes shake {
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Phone ---------- */

@media (max-width: 700px) {
  header { padding: 10px 8px 0; }
  .levels { gap: 6px; }
  .level { grid-template-columns: auto; grid-template-areas: "icon" "pips"; justify-items: center; padding: 6px 10px; }
  .level-name { display: none; }
  .level-icon { font-size: 28px; }
  .pips i { width: 11px; height: 11px; }
  main { gap: 14px; padding-bottom: 70px; }
  .board { min-height: 26vh; gap: 10px; }
  .word-row { flex-direction: column; gap: 10px; }
  .picture { width: 120px; border-radius: 22px; padding: 6px; }
  .word { --box: min(84px, calc((100vw - 32px) / var(--n, 6))); }
  .cell { border-width: 2px; }
  .speaker.big { width: 64px; height: 64px; }
  .btn { font-size: 17px; padding: 10px 16px; }
  #message { font-size: 22px; }
  .tiles { gap: 9px; }
  .tile { border-radius: 16px; padding-right: 6px; }
  .tile-text { font-size: 34px; padding: 4px 2px 4px 12px; min-width: 52px; }
  .speaker.small { width: 30px; height: 30px; }
  .grass { height: 30px; background-size: 30px 30px; }
}
