/* Sprout's Ten Meadows — style.css */

@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@600;800&display=swap');

:root {
  --sky-top: #CFEFFF;
  --sky-bot: #EAF8FF;
  --grass: #3DD68C;
  --grass-dark: #26b571;
  --sun: #FFC93C;
  --sun-dark: #f0b21a;
  --coral: #FF6B6B;
  --ink: #2E3440;
  --ink-soft: #4C566A;
  --card: #ffffff;
  --blue: #4FA8FF;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(46, 52, 64, .16), 0 2px 6px rgba(46, 52, 64, .10);
  --font: 'Baloo 2', 'Baloo', ui-rounded, 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bot) 100%);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 800;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

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

button { font-family: inherit; -webkit-tap-highlight-color: transparent; }

.hidden { display: none !important; }

/* ---------- Canvas ---------- */
canvas#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
  z-index: 0;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bot) 100%);
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 10px calc(12px + env(safe-area-inset-left));
  pointer-events: none;
  flex-wrap: nowrap;
}

#hud > * { pointer-events: auto; }

.hud-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 1 auto;
  min-width: 0;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px 0 10px;
  flex: 0 0 auto;
  min-width: max-content;
  background: rgba(255, 255, 255, .88);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 3px 0 var(--ink), 0 6px 14px rgba(46, 52, 64, .12);
  font-size: 18px;
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
  overflow: visible;
}

/* counters are plain text inside their pill */
#hud-coins, #hud-gems {
  display: inline-block;
  min-width: 1.6em;
  font-size: inherit;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  text-align: left;
}
#hud-gems { min-width: 2.4em; }

#hud-level { border-radius: 999px; min-width: 0; flex: 0 1 auto; display: block; line-height: 34px; }
@media (max-width: 560px) { #hud-level { line-height: 29px; } }

#hud-hearts::before { background-image: url('assets/heart.png'); }
#hud-coins::before { background-image: url('assets/coin_gold.png'); }
#hud-gems::before { background-image: url('assets/gem_blue.png'); }
#hud-key::before { background-image: url('assets/key_yellow.png'); }

#hud img { width: 24px; height: 24px; flex: 0 0 24px; object-fit: contain; display: inline-block; }
#hud-hearts img.empty, #hud-hearts .empty { opacity: .25; filter: grayscale(1); }

#hud-key { padding: 0 8px; min-width: 0; transition: opacity .2s, transform .2s; }
#hud-key.off, #hud-key[data-has="0"], #hud-key[data-has="false"] { opacity: .3; filter: grayscale(1); }
#hud-key.on, #hud-key[data-has="1"], #hud-key[data-has="true"] { animation: pop .35s ease-out; }

#hud-level {
  margin-left: auto;
  font-size: 16px;
  color: var(--ink);
  background: var(--sun);
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

#pause-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: #fff;
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
#pause-btn:empty::before { content: '❚❚'; font-size: 14px; letter-spacing: -1px; }
#pause-btn:active { transform: translateY(3px) scale(.96); box-shadow: 0 1px 0 var(--ink); }

.bump { animation: pop .3s ease-out; }

@media (max-width: 560px) {
  #hud { gap: 6px; padding-left: calc(8px + env(safe-area-inset-left)); padding-right: calc(8px + env(safe-area-inset-right)); }
  .hud-left { gap: 6px; }
  .hud-pill { height: 34px; padding: 0 10px 0 7px; font-size: 15px; gap: 4px; border-width: 2.5px; }
  #hud img { width: 20px; height: 20px; flex-basis: 20px; }
  #hud-level { font-size: 13px; max-width: 28vw; }
  #pause-btn { width: 38px; height: 38px; }
}

/* ---------- Banner ---------- */
#banner {
  position: fixed;
  top: calc(88px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  min-width: 240px;
  max-width: min(90vw, 520px);
  padding: 14px 26px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 5px 0 var(--ink), var(--shadow);
  text-align: center;
  pointer-events: none;
  animation: bannerIn .45s cubic-bezier(.2, 1.4, .4, 1) both;
}
#banner h2, #banner .name, #banner strong {
  display: block;
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
  color: var(--ink);
}
#banner p, #banner .hint, #banner small {
  display: block;
  margin: 4px 0 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-soft);
}
#banner.out { animation: bannerOut .3s ease-in both; }

/* ---------- Touch controls ---------- */
#touch {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}
#touch button {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid rgba(46, 52, 64, .55);
  background: rgba(255, 255, 255, .55);
  color: var(--ink);
  font-size: 28px;
  font-weight: 800;
  display: grid;
  place-items: center;
  padding: 0;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 4px 12px rgba(46, 52, 64, .15);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  transition: transform .06s, background .06s;
}
#touch button:active, #touch button.down, #touch button.active {
  transform: scale(.92);
  background: rgba(255, 255, 255, .8);
}
#btn-left { left: calc(16px + env(safe-area-inset-left)); }
#btn-right { left: calc(100px + env(safe-area-inset-left)); }
#btn-jump {
  right: calc(20px + env(safe-area-inset-right));
  width: 84px !important;
  height: 84px !important;
  font-size: 32px !important;
}
#btn-left:empty::before { content: '◀'; }
#btn-right:empty::before { content: '▶'; }
#btn-jump:empty::before { content: '▲'; }

@media (hover: hover) and (pointer: fine) {
  #touch { display: none !important; }
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
  background: rgba(207, 239, 255, .75);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  text-align: center;
  overflow-y: auto;
  animation: fadeIn .25s ease-out both;
}
.overlay > * { animation: slideUp .25s ease-out both; }

.overlay h1 {
  margin: 0;
  font-size: clamp(40px, 9vw, 76px);
  line-height: .95;
  color: var(--ink);
  letter-spacing: .5px;
  text-shadow: 0 4px 0 #fff, 0 7px 0 rgba(46, 52, 64, .15);
}
.overlay h2 {
  margin: 0 0 6px;
  font-size: clamp(28px, 6vw, 40px);
  line-height: 1.05;
  color: var(--ink);
}
.overlay p {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink-soft);
}

/* Title */
#title {
  background:
    radial-gradient(circle at 80% 15%, rgba(255, 201, 60, .45) 0, rgba(255, 201, 60, 0) 30%),
    linear-gradient(180deg, rgba(207, 239, 255, .8), rgba(234, 248, 255, .7));
}
#title h1 span, #title h1 em { color: var(--grass); font-style: normal; }
#title h1 { -webkit-text-stroke: 0; }
#title h1::after {
  content: '';
  display: block;
  width: 60%;
  height: 8px;
  margin: 10px auto 0;
  border-radius: 8px;
  background: var(--grass);
  border: 3px solid var(--ink);
}
#title img {
  width: clamp(110px, 24vw, 170px);
  height: auto;
  filter: drop-shadow(0 10px 6px rgba(46, 52, 64, .18));
}
#title .buttons, #title .row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }

.bob { animation: bob 1.4s ease-in-out infinite; }

/* ---------- Card ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 3px solid var(--ink);
  padding: 24px 26px;
  width: min(92vw, 440px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: slideUp .25s ease-out both;
}
.card .row, .card .buttons { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; width: 100%; }

/* ---------- Buttons ---------- */
.btn, .overlay button:not(.level-tile) {
  appearance: none;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--sun);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 800;
  font-size: 20px;
  line-height: 1;
  padding: 14px 30px;
  min-width: 150px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform .08s ease, box-shadow .08s ease, background .15s;
  touch-action: manipulation;
}
.btn:hover, .overlay button:not(.level-tile):hover { background: #ffd65e; }
.btn:active, .overlay button:not(.level-tile):active {
  transform: translateY(3px) scale(.96);
  box-shadow: 0 1px 0 var(--ink);
}
.btn:focus-visible, .overlay button:focus-visible, #pause-btn:focus-visible {
  outline: 4px solid var(--blue);
  outline-offset: 3px;
}
#start-btn, #next-btn, #retry-btn, #resume-btn, #again-btn {
  font-size: 24px;
  padding: 16px 40px;
}
#start-btn { background: var(--grass); color: #fff; text-shadow: 0 2px 0 var(--ink); min-width: 200px; }
#start-btn:hover { background: #55e19d; }
#levels-btn, #select-back, #pause-levels, #clear-levels, #restart-btn { background: #fff; }
#levels-btn:hover, #select-back:hover, #pause-levels:hover, #clear-levels:hover, #restart-btn:hover { background: #f3fbff; }
#share-btn { background: var(--coral); color: #fff; text-shadow: 0 2px 0 var(--ink); }
#share-btn:hover { background: #ff8282; }

/* ---------- Level select ---------- */
#select h2 { margin-bottom: 0; }
#level-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: min(94vw, 900px);
}
@media (min-width: 760px) {
  #level-grid { grid-template-columns: repeat(5, 1fr); gap: 16px; }
}

.level-tile {
  position: relative;
  appearance: none;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fff 0%, #fff 62%, #e6fbef 62%, #c8f3dc 100%);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 800;
  padding: 12px 8px 10px;
  min-height: 118px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink), 0 8px 18px rgba(46, 52, 64, .1);
  transition: transform .08s ease, box-shadow .08s ease;
  overflow: hidden;
  animation: slideUp .25s ease-out both;
}
.level-tile:nth-child(2) { animation-delay: .02s; }
.level-tile:nth-child(3) { animation-delay: .04s; }
.level-tile:nth-child(4) { animation-delay: .06s; }
.level-tile:nth-child(5) { animation-delay: .08s; }
.level-tile:nth-child(6) { animation-delay: .10s; }
.level-tile:nth-child(7) { animation-delay: .12s; }
.level-tile:nth-child(8) { animation-delay: .14s; }
.level-tile:nth-child(9) { animation-delay: .16s; }
.level-tile:nth-child(10) { animation-delay: .18s; }
.level-tile:hover { transform: translateY(-2px); }
.level-tile:active { transform: translateY(3px) scale(.96); box-shadow: 0 1px 0 var(--ink); }

.level-tile .num, .level-tile strong, .level-tile b {
  font-size: 32px;
  line-height: 1;
  color: var(--ink);
}
.level-tile .name, .level-tile small, .level-tile span:not(.num):not(.gems) {
  font-size: 13px;
  line-height: 1.15;
  font-weight: 700;
  color: var(--ink-soft);
}
.level-tile .gems {
  display: flex;
  gap: 2px;
  justify-content: center;
  font-size: 14px;
  min-height: 20px;
}
.level-tile .gems img { width: 20px; height: 20px; }
.level-tile .gems img.off, .level-tile .gems .off { opacity: .22; filter: grayscale(1); }
.level-tile.done::after, .level-tile.perfect::after {
  content: '★';
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: 16px;
  color: var(--sun-dark);
}

.level-tile.locked {
  background: #eef1f5;
  color: #9aa3b2;
  cursor: not-allowed;
  box-shadow: 0 4px 0 #9aa3b2;
  border-color: #9aa3b2;
  filter: grayscale(1);
}
.level-tile.locked > * { opacity: .45; }
.level-tile.locked::after {
  content: '🔒';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 30px;
  background: rgba(238, 241, 245, .55);
}
.level-tile.locked:hover, .level-tile.locked:active { transform: none; box-shadow: 0 4px 0 #9aa3b2; }

/* ---------- Clear / Won stats ---------- */
#clear-stats, #won-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  font-size: 18px;
}
#clear-stats > *, #won-stats > * {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 12px;
  background: #f3fbff;
  border: 2px solid #d6ecf7;
}
#clear-stats .stars, #won-stats .stars {
  justify-content: center;
  background: transparent;
  border: none;
  gap: 8px;
  padding: 0 0 4px;
}
#clear-stats .stars img, #won-stats .stars img {
  width: 48px;
  height: 48px;
  animation: starPop .45s cubic-bezier(.2, 1.6, .4, 1) both;
}
#clear-stats .stars img:nth-child(2) { animation-delay: .15s; }
#clear-stats .stars img:nth-child(3) { animation-delay: .3s; }
#clear-stats .stars img.off, #clear-stats .stars .off { opacity: .2; filter: grayscale(1); }
#clear-stats img, #won-stats img { width: 24px; height: 24px; }

#clear .card { border-color: var(--ink); background: linear-gradient(180deg, #fff 0%, #fffdf3 100%); }
#clear h2 { color: var(--grass-dark); }
#fail h2 { color: var(--coral); }
#won h2, #won h1 { color: var(--ink); }
#won .card { background: linear-gradient(180deg, #fff 0%, #fff7dc 100%); }
#pause .card { width: min(92vw, 360px); }
#pause .card button, #fail .card button { width: 100%; }

/* ---------- Animations ---------- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-16px) rotate(2deg); }
}
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}
@keyframes starPop {
  from { opacity: 0; transform: scale(.2) rotate(-40deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes bannerIn {
  from { opacity: 0; transform: translate(-50%, -30px) scale(.9); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
@keyframes bannerOut {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, -20px); }
}

@media (prefers-reduced-motion: reduce) {
  .bob, .overlay, .overlay > *, .card, .level-tile, #banner { animation: none !important; }
}

@media (max-height: 520px) {
  .overlay { gap: 10px; justify-content: flex-start; }
  .overlay h1 { font-size: 40px; }
  #title img { width: 90px; }
  .card { padding: 16px 20px; gap: 10px; }
  .level-tile { min-height: 92px; }
  .level-tile .num, .level-tile strong, .level-tile b { font-size: 24px; }
}
