/* Goorili Catapult - screens, HUD and panels (game world is drawn on the canvas) */
:root {
  --wood: #b85a28;
  --wood-dark: #7a3a17;
  --gold: #f2c14e;
  --ink: #fff4dc;
  --card: rgba(58, 28, 14, 0.94);
  --muted: #e9d7b0;
  --display: "Baloo 2", "Trebuchet MS", sans-serif;
  --body: "Nunito", "Segoe UI", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2a160c; }
body { font-family: var(--body); color: var(--ink); user-select: none; -webkit-user-select: none; }
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; }

/* ---------- loading ---------- */
#loading {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(900px 600px at 50% 30%, #5a2a12, #2a160c 60%, #120c08);
  transition: opacity .4s ease;
}
#loading.hide { opacity: 0; pointer-events: none; }
.load-title { font-family: var(--display); font-weight: 800; font-size: clamp(2rem, 6vw, 3.4rem); color: #ffe7a8; text-shadow: 0 4px 0 #4a240e; }
.load-track { width: min(320px, 70vw); height: 14px; border-radius: 99px; background: #3a1c0e; border: 3px solid var(--gold); overflow: hidden; }
#load-bar { height: 100%; width: 0; background: linear-gradient(90deg, #ffcc33, #ff9d3a); transition: width .2s; }

/* ---------- generic ---------- */
.screen { position: fixed; inset: 0; z-index: 10; display: none; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.screen.show { display: flex; }
.card {
  background: var(--card); border: 4px solid var(--gold); border-radius: 26px; padding: 22px 26px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5); max-width: min(560px, 100%); text-align: center;
}
h1, h2 { font-family: var(--display); font-weight: 800; margin: 0; color: #ffe7a8; text-shadow: 0 3px 0 #4a240e; }
h2 { font-size: clamp(1.6rem, 4.5vw, 2.3rem); line-height: 1.1; }
.btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.btns.col { flex-direction: column; align-items: stretch; }
.btn {
  font-family: var(--display); font-weight: 800; font-size: 1.25rem; color: #fff4dc; cursor: pointer;
  padding: 10px 28px; border-radius: 16px; border: 3px solid var(--gold);
  background: linear-gradient(#d06a30, var(--wood)); box-shadow: 0 5px 0 var(--wood-dark), 0 8px 18px rgba(0,0,0,.35);
  transition: transform .1s ease, box-shadow .1s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--wood-dark); }
.btn:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.btn.big { font-size: 1.6rem; padding: 12px 46px; }
.btn.small { font-size: 1rem; padding: 6px 16px; }
.btn.ghost { background: linear-gradient(#5a3a26, #4a2e1e); box-shadow: 0 5px 0 #2a170c, 0 8px 18px rgba(0,0,0,.3); }

/* ---------- title ---------- */
.title-box { text-align: center; display: flex; flex-direction: column; align-items: center; }
.title-box h1 {
  font-size: clamp(2.6rem, 9vw, 5.4rem); line-height: .95; color: #ffe27a;
  -webkit-text-stroke: 2px #5a2a0e; text-shadow: 0 6px 0 #5a2a0e, 0 14px 30px rgba(0,0,0,.35);
}
.tagline { margin: 8px 0 0; font-family: var(--display); font-weight: 800; font-size: clamp(1.1rem, 3vw, 1.6rem); color: #fff; text-shadow: 0 3px 0 #5a2a0e; }
.crew { display: flex; align-items: flex-end; justify-content: center; gap: clamp(4px, 1.5vw, 14px); margin: 14px 0 4px; height: clamp(90px, 22vh, 180px); }
.crew img { height: 100%; width: auto; filter: drop-shadow(0 8px 10px rgba(0,0,0,.35)); animation: bob 2.4s ease-in-out infinite; }
.crew .c-paliz { height: 88%; animation-delay: .3s; }
.crew .c-hero { height: 72%; }
.crew .c-hero:nth-child(3) { height: 82%; }
.crew .c-hero:nth-child(4) { animation-delay: .6s; }
.crew .c-laki { height: 72%; animation-delay: .9s; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.home-link { margin-top: 18px; color: #fff; font-weight: 800; text-shadow: 0 2px 0 rgba(0,0,0,.5); text-decoration: none; }
.home-link:hover { text-decoration: underline; }

/* ---------- story ---------- */
.story-card p { font-size: 1.08rem; line-height: 1.5; color: var(--ink); margin: 10px 0; }
.story-card h2 { margin-bottom: 4px; }
.couple { display: flex; justify-content: center; align-items: flex-end; gap: 10px; height: 120px; margin-bottom: 8px; }
.couple img { height: 100%; filter: drop-shadow(0 6px 8px rgba(0,0,0,.4)); }
.couple img + img { height: 76%; }
.couple.sad img { filter: grayscale(.35) drop-shadow(0 6px 8px rgba(0,0,0,.4)); transform: rotate(-4deg); }

/* ---------- level select ---------- */
.levels-wrap { width: min(960px, 100%); }
.levels-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.levels-head h2 { font-size: clamp(1.5rem, 4vw, 2.4rem); color: #fff; text-shadow: 0 3px 0 #5a2a0e; }
.star-total { font-family: var(--display); font-weight: 800; font-size: 1.3rem; background: var(--card); border: 3px solid var(--gold); border-radius: 99px; padding: 4px 14px; white-space: nowrap; }
#level-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 720px) { #level-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; } }
.lvl {
  position: relative; aspect-ratio: 1; border-radius: 22px; border: 4px solid var(--gold); cursor: pointer; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px;
  font-family: var(--display); box-shadow: 0 6px 0 rgba(0,0,0,.35), 0 10px 20px rgba(0,0,0,.3);
  transition: transform .12s ease;
}
.lvl:hover:not(.locked) { transform: translateY(-4px) scale(1.03); }
.lvl .num { font-size: clamp(1.8rem, 5vw, 2.8rem); font-weight: 800; line-height: 1; text-shadow: 0 3px 0 rgba(0,0,0,.35); }
.lvl .name { font-family: var(--body); font-weight: 800; font-size: clamp(.68rem, 1.6vw, .9rem); line-height: 1.1; text-align: center; text-shadow: 0 2px 0 rgba(0,0,0,.4); }
.lvl .stars { font-size: clamp(1rem, 2.4vw, 1.35rem); letter-spacing: 1px; }
.theme-meadow { background: linear-gradient(#5ec2ff 0%, #a9e0ff 55%, #62bb3c 56%, #3f8f27 100%); }
.theme-forest { background: linear-gradient(#5fc0b4 0%, #b7ead2 55%, #50a036 56%, #2f6e22 100%); }
.theme-snow { background: linear-gradient(#77b9f2 0%, #cfe6fb 55%, #ffffff 56%, #b9d1ea 100%); }
.theme-snow .num, .theme-snow .name { color: #fff; }
.theme-sunset { background: linear-gradient(#ff7e5f 0%, #ffc174 55%, #8dbf3a 56%, #5f8f22 100%); }
.lvl.locked { filter: grayscale(.8) brightness(.6); cursor: not-allowed; }
.star { color: rgba(255,255,255,.2); text-shadow: none; }
.lvl .star { color: rgba(0,0,0,.3); }
.star.on { color: #ffd23f; text-shadow: 0 2px 0 #9a6b00; }
.story-again { display: block; margin: 18px auto 0; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5; display: none; justify-content: space-between; align-items: center;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
}
#hud.show { display: flex; }
.hud-left, .hud-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  pointer-events: auto; width: 46px; height: 46px; border-radius: 14px; border: 3px solid var(--gold); color: #fff4dc; cursor: pointer;
  background: linear-gradient(#d06a30, var(--wood)); box-shadow: 0 4px 0 var(--wood-dark); display: grid; place-items: center;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--wood-dark); }
#hud-level { font-family: var(--display); font-weight: 800; font-size: 1.15rem; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.55), 0 0 8px rgba(0,0,0,.35); margin-left: 4px; }
.pill {
  font-family: var(--display); font-weight: 800; font-size: 1.35rem; color: #fff; background: rgba(40,20,10,.62);
  border: 3px solid var(--gold); border-radius: 99px; padding: 2px 16px; display: inline-flex; align-items: center; gap: 6px; min-width: 64px; justify-content: center;
}
.score-pill { min-width: 110px; }
@media (max-width: 560px) { #hud-level { display: none; } .pill { font-size: 1.1rem; padding: 1px 12px; } }

/* ---------- panel ---------- */
#panel { position: fixed; inset: 0; z-index: 20; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 8, 4, .45); }
#panel.show { display: flex; animation: fade .25s ease; }
#panel .card { animation: popin .35s cubic-bezier(.2, 1.4, .4, 1); max-height: calc(100vh - 32px); overflow-y: auto; }
@keyframes fade { from { opacity: 0; } }
@keyframes popin { from { transform: scale(.7); opacity: 0; } }
.big-stars { font-size: clamp(2.6rem, 9vw, 4rem); margin: 6px 0 2px; }
.big-stars .star.pop.on { display: inline-block; animation: starpop .5s cubic-bezier(.2, 1.6, .4, 1) both; animation-delay: calc(.35s + var(--i) * .3s); }
@keyframes starpop { from { transform: scale(0) rotate(-90deg); } }
.score-line { font-size: 1.2rem; margin: 4px 0; }
.score-line b { font-family: var(--display); font-size: 1.6rem; color: #ffe27a; }
.tag { background: #ffcc33; color: #3a1c0e; border-radius: 99px; padding: 2px 10px; font-weight: 800; font-size: .9rem; }
.story { color: var(--muted); font-size: 1.05rem; line-height: 1.45; margin: 8px 0 0; }
.howto { text-align: left; padding-left: 20px; margin: 14px 0 0; line-height: 1.5; font-size: 1.02rem; }
.howto li { margin-bottom: 8px; }
.pw { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.pw img { height: 30px; width: 34px; object-fit: contain; }

/* ---------- rotate hint ---------- */
#rotate { position: fixed; inset: 0; z-index: 40; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 8, 4, .6); }
#rotate.show { display: flex; }
.rot-icon { font-size: 2.6rem; }
.wind-pill[hidden] { display: none; }
.wind-pill { min-width: 84px; }
.theme-royal { background: linear-gradient(#8fd0ff 0%, #ffe9b8 55%, #79c04a 56%, #4f8f2a 100%); }
/* Music toggle: bottom-right corner, above every screen */
.music-btn { position: fixed; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); z-index: 30; }
.music-btn .slash { display: none; }
.music-btn.off .slash { display: inline; }
.music-btn.off { filter: grayscale(.6) brightness(.85); }
/* Story illustration on the title screen (replaces the character row) */
.story-scene {
  display: block; width: min(640px, 86vw); height: auto; max-height: 38vh; object-fit: contain;
  margin: 12px auto 2px; filter: drop-shadow(0 10px 18px rgba(0,0,0,.25));
}
@media (max-height: 520px) { .story-scene { max-height: 30vh; margin-top: 6px; } }
