:root {
  --sky: #AABDC0;
  --forest: #496A36;
  --grass: #71963E;
  --wood: #8A7558;
  --gold: #F2CF56;
  --cream: #FFF3D2;
  --panel: #142522;
  --ink: #161815;
  --rose: #e67b6d;
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", Arial, sans-serif;
  color: var(--ink);
  background: #0d1715;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #0d1715; }
button { font: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

#app {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 620px;
  margin: 0 auto;
  overflow: hidden;
  background: var(--sky);
  isolation: isolate;
}

.screen { position: absolute; inset: 0; visibility: hidden; opacity: 0; pointer-events: none; transition: opacity .24s ease; }
.screen.active { visibility: visible; opacity: 1; pointer-events: auto; }

#home-screen {
  background-image: url("assets/mountain-home.jpg");
  background-position: center;
  background-size: cover;
}

.home-dim {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(20,37,34,.12) 0%, rgba(20,37,34,.05) 42%, rgba(20,37,34,.36) 100%);
}

.home-card {
  position: absolute;
  top: max(8.5%, calc(env(safe-area-inset-top) + 28px));
  left: 7%; right: 7%; bottom: max(7%, calc(env(safe-area-inset-bottom) + 22px));
  display: flex; flex-direction: column; align-items: center;
  padding: 5.5% 6% 4%;
  border: 5px solid rgba(255,243,210,.96);
  border-radius: 34px;
  background: linear-gradient(180deg, rgba(255,250,228,.94), rgba(255,243,210,.84));
  box-shadow: 0 14px 0 rgba(20,37,34,.30), inset 0 0 0 2px rgba(138,117,88,.28);
}

.eyebrow {
  padding: 7px 18px;
  color: white;
  border-radius: 999px;
  background: var(--forest);
  box-shadow: 0 4px 0 rgba(20,37,34,.20);
  font-size: clamp(10px, 2.7vw, 15px);
  font-weight: 900;
  letter-spacing: .18em;
}

h1 { margin: 14px 0 3px; text-align: center; line-height: .83; filter: drop-shadow(0 5px 0 rgba(255,255,255,.65)); }
h1 span, h1 strong { display: block; }
h1 span { color: var(--panel); font-size: clamp(40px, 12vw, 74px); letter-spacing: -.06em; }
h1 strong { color: var(--gold); -webkit-text-stroke: 2px var(--panel); font-size: clamp(46px, 14vw, 82px); letter-spacing: -.055em; }
.tagline { max-width: 340px; margin: 12px 0 8px; text-align: center; color: #4b4237; font-weight: 800; font-size: clamp(14px, 3.7vw, 20px); }

.hero-badge {
  position: relative; flex: 1 1 auto; min-height: 138px; width: min(70%, 320px);
  display: grid; place-items: center; margin: 0 auto 5px;
}
.hero-ring { position: absolute; width: 78%; aspect-ratio: 1; max-height: 95%; border: 9px solid rgba(170,189,192,.74); border-radius: 50%; background: rgba(255,255,255,.48); box-shadow: inset 0 0 0 6px rgba(255,243,210,.9), 0 8px 0 rgba(73,106,54,.3); }
.hero-badge img { position: relative; z-index: 1; width: min(78%, 250px); image-rendering: auto; filter: drop-shadow(0 10px 3px rgba(20,37,34,.28)); animation: hero-bob 2.4s ease-in-out infinite; }
@keyframes hero-bob { 0%,100% { transform: translateY(2px) rotate(-2deg); } 50% { transform: translateY(-9px) rotate(2deg); } }

.primary-button {
  width: min(88%, 390px); min-height: 58px; padding: 12px 18px;
  border: 4px solid white; border-radius: 22px;
  color: var(--panel); background: linear-gradient(#f9dd72, var(--gold));
  box-shadow: 0 8px 0 var(--forest), 0 12px 18px rgba(20,37,34,.20);
  font-size: clamp(18px, 5vw, 28px); font-weight: 1000; letter-spacing: .02em;
}
.primary-button:active { transform: translateY(5px); box-shadow: 0 3px 0 var(--forest); }
.text-button { border: 0; padding: 14px 20px 7px; color: #4b4237; background: transparent; font-size: clamp(13px, 3.4vw, 17px); font-weight: 900; text-decoration: underline; text-underline-offset: 4px; }
.best-line { margin-top: auto; color: var(--forest); font-size: clamp(12px, 3vw, 16px); font-weight: 900; letter-spacing: .14em; }
.best-line span { color: var(--panel); }

.sound-button {
  display: grid; place-items: center; border: 4px solid var(--cream); color: var(--gold); background: var(--panel);
  box-shadow: 0 6px 0 rgba(20,37,34,.45); font-weight: 900;
}
.home-sound { position: absolute; z-index: 5; top: max(5.5%, calc(env(safe-area-inset-top) + 14px)); right: 5%; width: 54px; height: 54px; border-radius: 18px; }
.sound-icon { font-size: 26px; line-height: 1; }
.sound-off .sound-icon { opacity: .38; }
.sound-off .sound-icon::after { content: "×"; position: absolute; font-size: 25px; color: #ff8376; transform: translate(-14px, -3px); }

#game-screen, #game-field { background-position: center; background-size: cover; }
#game-field { position: absolute; inset: 0; overflow: hidden; background-image: url("assets/meadow.jpg"); }
#game-field::after { content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none; background: linear-gradient(180deg, rgba(255,255,255,.09), transparent 55%, rgba(20,37,34,.08)); }

.hud {
  position: absolute; z-index: 30;
  top: max(5.2%, calc(env(safe-area-inset-top) + 10px)); left: 3%; right: 3%;
  display: grid; grid-template-columns: 56px 1fr 1.15fr 56px; align-items: stretch; gap: 7px;
}
.hud-button { width: 56px; height: 56px; border-radius: 18px; font-size: 29px; }
.hud-card { min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 4px solid rgba(255,255,255,.95); border-radius: 18px; background: rgba(255,243,210,.93); box-shadow: 0 6px 0 rgba(20,37,34,.28); }
.hud-card small { color: #66594a; font-size: clamp(9px, 2.4vw, 13px); font-weight: 900; letter-spacing: .12em; }
.hud-card strong { color: var(--forest); font-size: clamp(19px, 5.2vw, 28px); line-height: 1.05; }
.lives-card strong { color: #e56f63; font-size: clamp(15px, 4.2vw, 23px); letter-spacing: .04em; white-space: nowrap; }

.mission-strip { position: absolute; z-index: 24; top: max(13.6%, calc(env(safe-area-inset-top) + 76px)); left: 9%; right: 9%; height: 34px; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 4px 10px; border: 3px solid white; border-radius: 15px; background: rgba(20,37,34,.88); color: white; box-shadow: 0 4px 0 rgba(20,37,34,.23); font-size: clamp(9px, 2.5vw, 13px); font-weight: 900; letter-spacing: .08em; }
.mission-strip b { color: var(--gold); }
.bonus-dots { display: flex; gap: 3px; flex: 1; max-width: 190px; justify-content: center; }
.bonus-dots i { width: clamp(5px, 1.5vw, 9px); aspect-ratio: 1; border: 1px solid rgba(255,255,255,.7); border-radius: 50%; background: rgba(255,255,255,.28); }
.bonus-dots i.on { background: var(--gold); box-shadow: 0 0 8px var(--gold); }

#danger-line { position: absolute; z-index: 12; top: 18%; bottom: 29%; left: 1.5%; width: 38px; display: flex; justify-content: center; border-right: 3px dashed rgba(229,111,99,.8); background: linear-gradient(90deg, rgba(145,52,45,.26), transparent); pointer-events: none; }
#danger-line span { color: #973e39; writing-mode: vertical-rl; padding-top: 20px; font-size: 9px; font-weight: 1000; letter-spacing: .18em; }

#pen-zone { position: absolute; z-index: 4; left: 6%; right: 6%; bottom: max(5.5%, calc(env(safe-area-inset-bottom) + 6px)); height: 24%; border: 4px dashed rgba(255,243,210,.88); border-radius: 30px 30px 18px 18px; background: linear-gradient(180deg, rgba(113,150,62,.03), rgba(73,106,54,.15)); box-shadow: inset 0 0 0 3px rgba(73,106,54,.20); pointer-events: none; }
.pen-glow { position: absolute; inset: 9px; border-radius: 21px; background: radial-gradient(circle at center, rgba(242,207,86,.26), transparent 68%); animation: pen-pulse 2s ease-in-out infinite; }
@keyframes pen-pulse { 50% { opacity: .48; transform: scale(.98); } }
.pen-label { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); padding: 7px 18px; border: 3px solid var(--cream); border-radius: 999px; color: white; background: var(--forest); box-shadow: 0 4px 0 rgba(20,37,34,.3); font-size: clamp(12px, 3.2vw, 17px); font-weight: 1000; letter-spacing: .1em; white-space: nowrap; }
.pen-hint { position: absolute; left: 0; right: 0; bottom: 11px; text-align: center; color: rgba(20,37,34,.65); font-size: clamp(10px, 2.5vw, 13px); font-weight: 900; letter-spacing: .14em; }

.sheep { position: absolute; z-index: 10; width: 86px; height: 66px; overflow: visible; cursor: grab; touch-action: none; will-change: transform, left, top; filter: drop-shadow(0 6px 3px rgba(20,37,34,.28)); }
.sheep .sprite-art { position: absolute; left: 50%; top: 50%; width: 110px; height: 88px; margin: -44px 0 0 -55px; background-repeat: no-repeat; background-size: 1024px 1024px; transform: scale(.78); transform-origin: center; }
.sheep::after { content: ""; position: absolute; left: 13%; right: 13%; bottom: 0; height: 9px; border-radius: 50%; background: rgba(20,37,34,.20); z-index: -1; }
.sheep.dragging { z-index: 50; cursor: grabbing; filter: drop-shadow(0 12px 5px rgba(20,37,34,.35)); }
.sheep.dragging .sprite-art { animation: lift .35s ease-in-out infinite alternate; }
@keyframes lift { to { transform: scale(.86) rotate(3deg); } }
.sheep.rescued { pointer-events: none; animation: rescued .42s cubic-bezier(.15,.8,.3,1) forwards; }
@keyframes rescued { 55% { transform: scale(1.2) rotate(-5deg); } 100% { transform: scale(.15) translateY(50px); opacity: 0; } }

#wolf-warning { position: absolute; z-index: 22; left: 8px; top: 34%; width: 126px; height: 116px; opacity: 0; transform: translateX(-40px) rotate(-5deg); pointer-events: none; transition: .18s ease; }
#wolf-warning.show { opacity: 1; transform: translateX(0) rotate(0); }
.wolf-art { width: 100px; height: 78px; overflow: hidden; background-repeat: no-repeat; background-size: 536px 631px; background-position: -13px -13px; filter: drop-shadow(0 5px 2px rgba(20,37,34,.35)); }
#wolf-warning b { display: block; margin-top: -4px; color: white; -webkit-text-stroke: 3px #8c3630; paint-order: stroke fill; font-size: 17px; transform: rotate(-5deg); }

#particle-layer { position: absolute; z-index: 60; inset: 0; pointer-events: none; overflow: hidden; }
.particle { position: absolute; width: 13px; height: 13px; border-radius: 3px 9px 3px 9px; background: var(--gold); box-shadow: 0 0 0 2px rgba(255,255,255,.8); animation: burst .65s ease-out forwards; }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) rotate(260deg) scale(.2); opacity: 0; } }
.float-score { position: absolute; z-index: 61; color: white; font-size: 24px; font-weight: 1000; -webkit-text-stroke: 4px var(--forest); paint-order: stroke fill; animation: float-score .8s ease-out forwards; }
@keyframes float-score { to { transform: translateY(-70px) scale(1.12); opacity: 0; } }

.overlay { position: absolute; z-index: 100; inset: 0; display: grid; place-items: center; padding: max(6%, env(safe-area-inset-top)) 6% max(6%, env(safe-area-inset-bottom)); background: rgba(20,37,34,.52); backdrop-filter: blur(5px); transition: opacity .2s ease; }
.overlay.hidden { visibility: hidden; opacity: 0; pointer-events: none; }
.modal { position: relative; width: min(100%, 470px); padding: 45px 7% 28px; border: 5px solid white; border-radius: 30px; background: linear-gradient(180deg, #fffbea, #fff0dc); box-shadow: 0 13px 0 rgba(20,37,34,.42), inset 0 0 0 3px rgba(138,117,88,.18); text-align: center; }
.modal-badge { position: absolute; top: -42px; left: 50%; width: 82px; height: 82px; display: grid; place-items: center; transform: translateX(-50%); border: 6px solid white; border-radius: 50%; color: var(--panel); background: var(--gold); box-shadow: 0 8px 0 #9f7429; font-size: 40px; font-weight: 1000; }
.modal .eyebrow { display: inline-block; }
.modal h2 { margin: 14px 0 7px; color: var(--panel); font-size: clamp(26px, 7vw, 40px); line-height: .95; }
.modal p { margin: 7px 0 18px; color: #6d5e53; font-weight: 700; }
.tutorial-demo { position: relative; height: 126px; margin: 8px auto 14px; overflow: hidden; border: 3px solid rgba(138,117,88,.26); border-radius: 20px; background: linear-gradient(180deg, #cfe7e8, #a9d19b); }
.tutorial-demo img { position: absolute; z-index: 3; left: 8%; top: 17px; width: 88px; filter: drop-shadow(0 5px 2px rgba(20,37,34,.25)); animation: tutorial-drag 2.2s ease-in-out infinite; }
@keyframes tutorial-drag { 0%,15% { transform: translate(0,0); } 65%,85% { transform: translate(175px,53px) scale(.88); } 100% { transform: translate(0,0); } }
.drag-path { position: absolute; left: 28%; top: 55%; width: 43%; border-top: 4px dashed white; transform: rotate(11deg); }
.drag-path i { position: absolute; right: -4px; top: -10px; width: 18px; height: 18px; border-right: 5px solid white; border-top: 5px solid white; transform: rotate(45deg); }
.mini-pen { position: absolute; right: 5%; bottom: 8px; width: 34%; height: 48px; display: grid; place-items: end center; padding-bottom: 5px; border: 4px dashed var(--forest); border-radius: 15px; color: var(--forest); background: rgba(255,243,210,.45); font-size: 10px; font-weight: 1000; }
.tutorial-card ol { margin: 0 0 20px; padding-left: 27px; text-align: left; color: #594b40; font-size: clamp(13px, 3.5vw, 17px); font-weight: 700; line-height: 1.5; }
.tutorial-card li::marker { color: var(--forest); font-weight: 1000; }
.modal .primary-button { width: 100%; }

.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0 23px; }
.result-stats div { padding: 12px 4px; border: 3px solid #e8d8c5; border-radius: 16px; background: white; }
.result-stats small { display: block; color: #75685e; font-size: 10px; font-weight: 900; letter-spacing: .1em; }
.result-stats strong { color: var(--forest); font-size: clamp(21px, 6vw, 32px); }

.game-shake { animation: shake .32s linear; }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }

#landscape-warning { display: none; position: fixed; z-index: 999; inset: 0; align-items: center; justify-content: center; flex-direction: column; gap: 10px; padding: 30px; color: var(--cream); background: var(--panel); text-align: center; }
.rotate-phone { font-size: 68px; color: var(--gold); }
#landscape-warning b { font-size: 27px; }
#landscape-warning span { opacity: .75; }

@media (orientation: landscape) and (max-height: 620px) { #landscape-warning { display: flex; } }
@media (max-height: 690px) and (orientation: portrait) {
  .home-card { top: max(6%, calc(env(safe-area-inset-top) + 17px)); bottom: max(4.5%, calc(env(safe-area-inset-bottom) + 14px)); padding-top: 4%; }
  h1 { margin-top: 9px; }
  .tagline { margin: 7px 0 2px; }
  .hero-badge { min-height: 104px; }
  .hero-badge img { max-height: 125px; object-fit: contain; }
  .primary-button { min-height: 51px; }
  .text-button { padding-top: 10px; }
  .hud { grid-template-columns: 50px 1fr 1.12fr 50px; gap: 5px; }
  .hud-button { width: 50px; height: 50px; }
  .mission-strip { top: max(14.2%, calc(env(safe-area-inset-top) + 68px)); }
  .modal { padding-top: 39px; }
  .tutorial-demo { height: 102px; }
  .tutorial-demo img { width: 75px; }
  .tutorial-card ol { margin-bottom: 13px; line-height: 1.35; }
}
