/* Sunny Fields — DOM overlays (gate puzzle, grown-ups panel). The game itself is canvas. */

:root {
  --ink: #1F2A38;
  --paper: #FFFDF6;
  --sky: #BDE8FF;
  --sun: #FFC93C;
  --pink: #FFC7E0;
  --mint: #C8F5E4;
  --lilac: #D7CBFF;
  --meadow: #3FA34D;
  --bad: #E5383B;
  --font: "Fredoka", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: #7CC7F2; overflow: hidden; font-family: var(--font); color: var(--ink); -webkit-tap-highlight-color: transparent; }
#app { position: fixed; inset: 0; }
#app canvas { display: block; }

.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 2vh 2vw;
  background: rgba(255, 253, 246, 0.30);
  backdrop-filter: blur(6px);
  opacity: 0; transition: opacity .22s ease;
}
.overlay.show { opacity: 1; }
.overlay[hidden] { display: none; }

.card {
  background: var(--paper);
  border: 5px solid var(--ink);
  border-radius: 34px;
  box-shadow: 0 14px 0 var(--ink), 0 30px 60px rgba(31, 42, 56, .25);
  position: relative;
}

.round-btn {
  width: 92px; height: 92px; border-radius: 50%;
  border: 5px solid var(--ink); background: #fff; color: var(--ink);
  box-shadow: 0 7px 0 var(--ink); cursor: pointer; flex: 0 0 auto;
  display: grid; place-items: center; font: 600 34px var(--font);
  transition: transform .08s ease, box-shadow .08s ease;
}
.round-btn svg { width: 60%; height: 60%; }
.round-btn:hover { transform: translateY(-2px); }
.round-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--ink); }
.round-btn.small { width: 64px; height: 64px; font-size: 26px; box-shadow: 0 5px 0 var(--ink); }
.round-btn.wiggle { animation: wiggle .5s ease; }
.round-btn:focus-visible, .tile:focus-visible, .btn:focus-visible, input:focus-visible { outline: 5px solid #4FA9E0; outline-offset: 3px; }

/* ---------------- Gate ---------------- */
.gate-card {
  width: min(1180px, 96vw);
  max-height: 96vh;
  padding: clamp(18px, 3vh, 34px) clamp(20px, 3vw, 40px);
  display: flex; flex-direction: column; gap: clamp(12px, 2vh, 24px);
  transform: translateY(24px) scale(.98); transition: transform .25s cubic-bezier(.2, .9, .3, 1.2);
  overflow: hidden;
}
.overlay.show .gate-card { transform: none; }
.gate-top { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.gate-prompt { font-weight: 600; font-size: clamp(30px, 4.6vw, 62px); line-height: 1.08; text-wrap: balance; }

.gate-visual { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; min-height: 40px; }
.gate-visual.empty { display: none; }

.objs { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 14px; max-width: 1000px; }
.obj { position: relative; width: clamp(64px, 8vw, 96px); aspect-ratio: 1; transition: transform .25s ease, opacity .4s ease; }
.obj svg { width: 100%; height: 100%; display: block; }
.obj.in { opacity: 0; transform: translateX(60px) scale(.6); }
.obj.in.arrived { opacity: 1; transform: none; }
.obj.leaving.away { opacity: 0; transform: translateY(-50px) rotate(-12deg); }
.obj.counted { animation: pop .35s ease; }
[data-n]::after {
  content: attr(data-n);
  position: absolute; right: -8px; top: -10px;
  min-width: 34px; height: 34px; padding: 0 6px; border-radius: 17px;
  background: var(--sun); border: 3px solid var(--ink);
  font: 600 22px var(--font); display: grid; place-items: center;
  animation: pop .3s ease;
}
.groups { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; justify-content: center; }
.groups .op { font: 600 64px var(--font); }

.frame { display: grid; gap: 6px; padding: 8px; background: #fff; border: 4px solid var(--ink); border-radius: 16px; }
.frame.f5 { grid-template-columns: repeat(5, 1fr); }
.frame.f10 { grid-template-columns: repeat(5, 1fr); }
.frame-wrap { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.frame-wrap[hidden] { display: none; }
.cell { position: relative; width: clamp(46px, 5.4vw, 66px); aspect-ratio: 1; border: 3px solid var(--ink); border-radius: 10px; background: #FFF6D6; display: grid; place-items: center; }
.cell.on { background: #fff; }
.cell.on.extra { background: var(--mint); }
.cell.removed { background: #F3D4D4; }
.cell.removed::before { content: ""; position: absolute; inset: 10%; background: linear-gradient(45deg, transparent 44%, var(--bad) 44%, var(--bad) 56%, transparent 56%), linear-gradient(-45deg, transparent 44%, var(--bad) 44%, var(--bad) 56%, transparent 56%); pointer-events: none; }
.cell svg { width: 80%; height: 80%; }
.cell .dot { width: 60%; aspect-ratio: 1; border-radius: 50%; background: #9B7FE6; border: 3px solid var(--ink); }
.cell.counted { animation: pop .35s ease; background: var(--sun); }

.numerals { font: 600 clamp(48px, 7vw, 96px)/1 var(--font); letter-spacing: .02em; }
.track, .pattern { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; justify-content: center; }
.num, .pshape { width: clamp(80px, 9vw, 120px); aspect-ratio: 1; border: 4px solid var(--ink); border-radius: 18px; background: #fff; display: grid; place-items: center; font: 600 clamp(36px, 4.6vw, 60px) var(--font); }
.num.q, .pshape.q { background: var(--sun); }
.pshape svg { width: 76%; height: 76%; }
.num.counted { animation: pop .35s ease; background: var(--sky); }

/* spelling visuals */
.gate-meta { display: flex; align-items: center; gap: 12px; }
.gate-meta:empty { display: none; }
.planks { display: flex; gap: 8px; }
.plank { width: 64px; height: 20px; border: 3px solid var(--ink); border-radius: 6px; background: #E6E0D0; transition: background .3s; }
.plank.on { background: #C89154; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .15); }
.lockbadge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 16px 6px 10px; border: 3px solid var(--ink); border-radius: 999px; background: var(--sun); font: 600 22px var(--font); }
.lockbadge svg { width: 34px; height: 34px; }
.pic svg { width: clamp(120px, 15vw, 190px); height: auto; display: block; }
.pic.small svg { width: clamp(90px, 10vw, 130px); }
.picrow { display: flex; align-items: center; gap: clamp(16px, 3vw, 40px); flex-wrap: wrap; justify-content: center; }
.lrow { display: flex; gap: 10px; }
.lbox { width: clamp(56px, 6.4vw, 84px); aspect-ratio: 1; border: 4px solid var(--ink); border-radius: 16px; background: #fff; display: grid; place-items: center; font: 600 clamp(36px, 4.6vw, 64px)/1 var(--font); text-transform: lowercase; }
.lbox.gap { background: var(--sun); }
.lbox.slot { background: #FFF6D6; border-style: dashed; }
.lbox.slot.filled { background: var(--mint); border-style: solid; animation: pop .35s ease; }
.listen { border: 5px solid var(--ink); border-radius: 30px; background: #fff; box-shadow: 0 8px 0 var(--ink); padding: 14px 36px; display: flex; align-items: center; gap: 20px; cursor: pointer; font: 600 clamp(48px, 6vw, 80px) var(--font); color: var(--ink); }
.listen svg { width: clamp(60px, 7vw, 90px); height: auto; }
.listen:active { transform: translateY(5px); box-shadow: 0 3px 0 var(--ink); }
.tile.letter { text-transform: lowercase; }
.tile.word { font-size: clamp(28px, 4vw, 56px); text-transform: lowercase; word-break: break-word; }
.tile.used { opacity: .35; }
.gate-tiles.many .tile { min-height: clamp(96px, 15vh, 140px); font-size: clamp(44px, 6vw, 84px); }
.hint-track { margin-top: 10px; }

.gate-tiles { display: flex; gap: clamp(12px, 2vw, 26px); justify-content: center; align-items: stretch; }
.tile {
  flex: 1 1 0; min-width: 0; min-height: clamp(110px, 18vh, 170px);
  border: 5px solid var(--ink); border-radius: 26px; cursor: pointer;
  box-shadow: 0 9px 0 var(--ink);
  font: 600 clamp(56px, 8vw, 104px)/1 var(--font); color: var(--ink);
  display: grid; place-items: center; padding: 10px;
  transition: transform .08s ease, box-shadow .08s ease, background .2s ease;
  font-variant-numeric: tabular-nums;
}
.tile.sky { background: var(--sky); } .tile.sun { background: var(--sun); } .tile.pink { background: var(--pink); } .tile.mint { background: var(--mint); }
.tile:hover { transform: translateY(-3px); box-shadow: 0 12px 0 var(--ink); }
.tile:active { transform: translateY(6px); box-shadow: 0 3px 0 var(--ink); }
.tile.shape svg, .tile.object svg { width: clamp(70px, 9vw, 120px); height: auto; }
.tile.group .mini { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; max-width: 300px; }
.tile.group .mini svg { width: clamp(34px, 3.6vw, 48px); height: auto; }
.tile.wrong { animation: wobble .55s ease; background: #F3D4D4; }
.tile.right { background: #BFF3C8 !important; animation: pop .5s ease; }
.tile.glow { animation: glow 1s ease-in-out infinite; }
.tile.hint { animation: hint 1.6s ease-in-out infinite; }
.tile:disabled { cursor: default; }

.burst { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: 30px; }
.burst span { position: absolute; left: 50%; top: 55%; width: 26px; height: 16px; border-radius: 50%; background: #F9A8C9; border: 2px solid var(--ink); opacity: 0; }
.burst.go span { animation: petal 1s ease-out forwards; }

@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.22); } 100% { transform: scale(1); } }
@keyframes wobble { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-14px) rotate(-3deg); } 40% { transform: translateX(12px) rotate(3deg); } 60% { transform: translateX(-8px); } 80% { transform: translateX(6px); } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }
@keyframes glow { 0%, 100% { box-shadow: 0 9px 0 var(--ink), 0 0 0 0 rgba(255, 201, 60, .9); transform: translateY(0); } 50% { box-shadow: 0 9px 0 var(--ink), 0 0 0 18px rgba(255, 201, 60, 0); transform: translateY(-6px); } }
@keyframes hint { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.12); } }
@keyframes petal { 0% { opacity: 1; transform: translate(0, 0) rotate(0); } 100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); } }

/* ---------------- Grown-ups ---------------- */
.gu-card { width: min(860px, 96vw); max-height: 94vh; overflow: auto; padding: 26px 30px 30px; font-size: 18px; }
.gu-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 8px; }
.gu-kicker { font-size: 14px; letter-spacing: .08em; text-transform: uppercase; color: #5A6878; font-weight: 500; }
.gu-card h2 { margin: 2px 0 0; font-size: 34px; font-weight: 600; }
.gu-card h3 { margin: 22px 0 8px; font-size: 20px; font-weight: 600; }
.gu-q { font-size: 26px; margin: 12px 0; }
.gu-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.gu-err { min-height: 26px; color: var(--bad); font-weight: 500; margin-top: 8px; }
.gu-body input[type="number"], .gu-body input[type="text"], .gu-body select {
  font: 500 22px var(--font); padding: 10px 14px; border: 4px solid var(--ink); border-radius: 14px; background: #fff; color: var(--ink); min-width: 0;
}
.gu-body input[type="number"] { width: 170px; }
.gu-body input[type="text"] { width: min(320px, 100%); }
.btn {
  font: 600 22px var(--font); padding: 12px 22px; border: 4px solid var(--ink); border-radius: 16px;
  background: var(--sun); color: var(--ink); cursor: pointer; box-shadow: 0 6px 0 var(--ink);
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.btn.quiet { background: #fff; }
.btn.danger { background: #F3D4D4; }
.gu-tabs { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.gu-tab { font: 600 20px var(--font); padding: 10px 18px; border: 4px solid var(--ink); border-radius: 999px; background: #fff; cursor: pointer; }
.gu-tab.on { background: var(--sky); }
.gu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.gu-stat { background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 10px 14px; }
.gu-stat b { display: block; font-size: 30px; font-weight: 600; }
.gu-stat span { color: #5A6878; font-size: 15px; }
.gu-body table { border-collapse: collapse; width: 100%; margin-top: 6px; }
.gu-body th, .gu-body td { text-align: left; padding: 6px 8px; border-bottom: 2px solid #E8E1CF; }
.gu-body th { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: #5A6878; }
.gu-body td.r { text-align: right; font-variant-numeric: tabular-nums; }
.gu-body label.chk { display: inline-flex; align-items: center; gap: 10px; margin-right: 18px; cursor: pointer; }
.gu-body label.chk input { width: 26px; height: 26px; }
.gu-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 24px; padding-top: 14px; border-top: 3px solid #E8E1CF; color: #5A6878; font-size: 15px; flex-wrap: wrap; }
.gu-foot a { color: var(--ink); }
.gu-lvl { display: inline-block; background: var(--sun); border: 3px solid var(--ink); border-radius: 999px; padding: 4px 14px; font-weight: 600; }

#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ink); color: #fff; font: 500 18px var(--font);
  padding: 12px 20px; border-radius: 999px; z-index: 40; pointer-events: none;
}
#toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .obj, .tile, .gate-card, .overlay { transition: none; }
  .tile.glow, .tile.hint, .burst.go span { animation: none; }
}
