:root { color-scheme: only light; font-family: Arial, system-ui, sans-serif; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #163d4d; }
body { display: grid; place-items: center; touch-action: none; user-select: none; }
#game { touch-action: none; }
#game-shell { position: relative; overflow: hidden; background: #80d9f0; box-shadow: 0 18px 70px #081e2760; transition: width .3s ease, height .3s ease; }
#game-shell.home-mode { width: 80vw; height: auto; max-width: calc(80vh * 16 / 9); aspect-ratio: 16 / 9; }
#game-shell.gameplay-mode { width: 80vw; height: auto; max-width: calc(80vh * 16 / 9); aspect-ratio: 16 / 9; }
#home-screen { position: absolute; inset: 0; overflow: hidden; background: url("assets/gameplay/home-sanctuary-v2.webp") center/cover no-repeat; }
#game-screen { position: absolute; inset: 0; }
.home-logo {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  margin: 0;
  width: 72%;
  text-align: center;
  color: #ffe27a;
  font: 900 clamp(28px, 5.4vw, 78px)/.92 Arial, sans-serif;
  letter-spacing: .01em;
  -webkit-text-stroke: 7px #163a58;
  paint-order: stroke fill;
  text-shadow: 0 .45vw 0 #c99720, 0 1.2vw 1.1vw #123c4c66;
  filter: none;
}
.home-icon { position: absolute; width: 7%; aspect-ratio: 1; }
.settings-button { left: 2.8%; top: 4.5%; }
.home-actions { position: absolute; left: 50%; bottom: 4%; transform: translateX(-50%); width: 42%; height: 31%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 0; }
.home-wide-button { flex: 0 0 auto; aspect-ratio: 3.2; }
.home-play-button { width: 76%; z-index: 2; }
.home-level-button { width: 59%; margin-top: -2.5%; z-index: 1; }
#game { display: block; width: 100%; height: 100%; background: url("assets/gameplay/meadow-playfield.webp") center/cover no-repeat; }
#hud { position: absolute; inset: 4% 2.5% auto; height: 11%; display: flex; align-items: flex-start; justify-content: space-between; pointer-events: none; z-index: 2; }
.game-left-actions { display: flex; width: 11%; gap: 9%; pointer-events: auto; }
.game-icon-button { width: 46%; aspect-ratio: 1; }
.stage-heading { position: absolute; left: 50%; top: 86%; transform: translateX(-50%); display: flex; align-items: center; gap: 10%; color: #f3a17d; font: 900 clamp(15px, 2vw, 36px)/1 Arial, sans-serif; -webkit-text-stroke: 2px #fff; white-space: nowrap; }
.stage-timer { display: flex; align-items: center; gap: 4px; color: #45606c; -webkit-text-stroke: 0; font-size: .72em; }
.stage-timer img { width: 1.1em; }
.image-button { padding: 0; border: 0; background: transparent; cursor: pointer; pointer-events: auto; filter: drop-shadow(0 5px 2px #2a3c4540); }
.image-button img { display: block; width: 100%; height: 100%; object-fit: contain; }
.image-button:active { transform: translateY(4px) scale(.97); filter: brightness(.92); }
#ink-panel { position: absolute; left: 39%; right: 39%; top: 5%; height: 5.5%; display: flex; flex-direction: column; align-items: center; padding: 0; pointer-events: none; z-index: 3; }
.ink-stars { width: 88%; display: flex; justify-content: space-around; margin-bottom: 2%; }
.ink-stars img { width: 10%; }
.ink-track { flex: 1; height: 42%; overflow: hidden; border-radius: 999px; }
.ink-track { width: 100%; min-height: 12px; border: 3px solid #fff; background: #a9b6b6; box-shadow: 0 2px 4px #37526055; }
#ink-fill { width: 100%; height: 100%; background: linear-gradient(#7bf070, #36cc54); border-radius: inherit; transform-origin: left center; transition: transform 80ms linear; }
#hint { position: absolute; left: 30%; right: 30%; bottom: 23%; text-align: center; color: #fff; font-weight: 900; font-size: clamp(13px, 1.8vw, 32px); text-shadow: 0 3px 0 #315567, 0 0 8px #315567; pointer-events: none; animation: hint-pulse 1.4s ease-in-out infinite; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 8%; background: #173b4e8f; z-index: 10; }
#result.overlay {
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #071f2ccf;
}
#result.is-win { background: radial-gradient(circle at 50% 44%, #5de3b061 0 22%, #143f4dbd 54%, #071822e8 100%); }
#result.is-lose { background: radial-gradient(circle at 50% 44%, #77c8f24d 0 20%, #243b55c9 54%, #0a1725eb 100%); }
.hidden { display: none !important; }
.compact-card { width: 47%; height: 92%; min-height: 0; aspect-ratio: 1024 / 1365; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2.5%; padding: 18% 7% 12%; background: url("assets/ui/pause-panel-v2.webp") center/100% 100% no-repeat; filter: drop-shadow(0 1.2vw 1.2vw #00182078); }
.compact-card .pause-heading { width: 118%; max-width: none; max-height: 27%; object-fit: contain; margin: -2% -9% 2%; }
.compact-card .wide-button { width: 88%; aspect-ratio: 3.2; flex: 0 0 auto; }
.compact-card .wide-button img { display: block; width: 100%; height: 100%; object-fit: contain; }
#settings-menu,
#levels-menu,
#howto-menu { z-index: 12; padding: 0; background: #123c4c55; }
#howto-menu { z-index: 13; }
.levels-modal { width: 64%; max-width: 720px; padding: 5.5% 4% 4%; }
.levels-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
.level-slot {
  appearance: none;
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 18px;
  background: linear-gradient(#f6d56a, #e8b63a);
  color: #fff8e8;
  font: 900 clamp(18px, 2.4vw, 34px)/1 Arial, sans-serif;
  -webkit-text-stroke: 4px #163a58;
  paint-order: stroke fill;
  text-shadow: 0 3px 0 #8a5a18;
  box-shadow: 0 4px 0 #c99720;
  cursor: pointer;
}
.level-slot.is-current {
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px #4adf6a, 0 4px 0 #c99720;
}
.level-slot.is-locked {
  background: linear-gradient(#9eb8c0, #6d8a94);
  color: #d5e4ea;
  -webkit-text-stroke: 4px #3a5560;
  text-shadow: none;
  box-shadow: 0 4px 0 #4a6a74;
  cursor: default;
}
.level-slot:not(:disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 #c99720; }
.level-lock {
  position: absolute;
  right: 8%;
  bottom: 8%;
  width: 26%;
  height: 22%;
  border: 2px solid #fff;
  border-radius: 4px;
  background: #5f7c86;
}
.level-lock::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 72%;
  width: 58%;
  height: 90%;
  border: 2px solid #fff;
  border-bottom: 0;
  border-radius: 50% 50% 0 0;
  transform: translateX(-50%);
}
.settings-modal {
  position: relative;
  width: 42%;
  max-width: 520px;
  padding: 9% 4.2% 3.8%;
  background:
    linear-gradient(#ffffffb8, #ffffff00 32%),
    linear-gradient(#7ef0c4 0%, #4ad8e8 55%, #2ec4ea 100%);
  border: 5px solid #f0c84a;
  border-radius: 32px;
  box-shadow:
    inset 0 8px 0 #ffffff4d,
    0 0 0 3px #163a58,
    0 6px 0 #c99720,
    0 16px 28px #123c4c66;
}
.settings-gear {
  position: absolute;
  left: 50%;
  top: 0;
  width: 16%;
  max-width: 72px;
  transform: translate(-50%, -52%);
  filter: drop-shadow(0 4px 0 #163a5844);
}
.settings-x {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 11%;
  max-width: 44px;
  aspect-ratio: 1;
  background: transparent;
  filter: drop-shadow(0 3px 0 #163a5844);
}
.settings-title {
  margin: 4% 0 5%;
  text-align: center;
  color: #fff6e0;
  font: 900 clamp(22px, 2.6vw, 40px)/1 Arial, sans-serif;
  -webkit-text-stroke: 5px #163a58;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 #0e2b42;
}
.settings-list { display: flex; flex-direction: column; gap: 10px; }
.settings-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px 8px 6px 14px;
  background: linear-gradient(#f6d56a, #e8b63a);
  border: 3px solid #fff;
  border-radius: 999px;
  color: #fff8e8;
  font: 800 clamp(14px, 1.6vw, 22px)/1 Arial, sans-serif;
  text-shadow: 0 2px 0 #8a5a18;
  box-shadow: 0 3px 0 #c99720;
}
.settings-row > img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  filter: brightness(0) invert(1) drop-shadow(0 2px 0 #8a5a18);
}
.settings-switch {
  min-width: 62px;
  height: 32px;
  padding: 0 14px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #4adf6a;
  color: #fff;
  font: 800 14px/28px Arial, sans-serif;
  cursor: pointer;
  text-shadow: 0 1px 0 #1e7a38;
  box-shadow: 0 3px 0 #2ea85a;
}
.settings-switch.is-off { background: #6aa8b8; text-shadow: 0 1px 0 #3a6470; box-shadow: 0 3px 0 #4a7a88; }
.settings-switch:active { transform: translateY(2px); box-shadow: 0 1px 0 #2ea85a; }
.settings-row-button {
  width: 100%;
  appearance: none;
  font: inherit;
  color: inherit;
  text-align: center;
  cursor: pointer;
  display: grid;
  grid-template-columns: 1fr;
  padding: 6px 14px;
}
.howto-modal { padding-top: 5%; }
.howto-title { margin-top: 0; }
.howto-guide {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.howto-guide li {
  display: grid;
  grid-template-columns: 40px 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(#f6d56a, #e8b63a);
  border: 3px solid #fff;
  border-radius: 22px;
  box-shadow: 0 3px 0 #c99720;
}
.howto-guide img { width: 36px; height: 36px; object-fit: contain; }
.howto-guide div { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.howto-guide b {
  color: #fff8e8;
  font: 800 clamp(13px, 1.4vw, 18px)/1.1 Arial, sans-serif;
  text-shadow: 0 2px 0 #8a5a18;
}
.howto-guide span {
  color: #fffaf0;
  font: 700 clamp(11px, 1.15vw, 15px)/1.25 Arial, sans-serif;
  text-shadow: 0 1px 0 #8a5a18;
}
.result-stage {
  height: 90%;
  width: min(68%, 720px);
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.result-hero { order: 2; position: relative; height: 48%; width: 92%; z-index: 2; flex: 0 0 auto; min-height: 0; }
.result-dog { display: block; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 1.1vw 1vw #00000066); }
.result-banner { order: 3; position: relative; width: 60%; height: 12%; margin-top: -3%; z-index: 3; flex: 0 0 auto; min-height: 0; }
.result-stars { position: absolute; inset: 0; display: flex; justify-content: center; gap: 4%; align-items: center; pointer-events: none; }
.result-stars img { height: 100%; width: auto; object-fit: contain; filter: drop-shadow(0 .35vw .35vw #0007); }
.is-lose .result-stars { display: none; }
.is-lose .result-banner { display: none; }
.result-title { order: 1; height: 12%; width: auto; max-width: 84%; object-fit: contain; margin-bottom: -1%; flex: 0 0 auto; min-height: 0; filter: drop-shadow(0 .45vw .4vw #00000070); }
.is-lose .result-title { height: 10%; }
.is-lose .result-hero { height: 53%; }
.result-actions {
  order: 4;
  width: min(82%, 560px);
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3%, 24px);
  margin-top: 2%;
  flex: 0 0 auto;
  min-width: 0;
}
.result-home {
  flex: 0 0 auto;
  width: clamp(52px, 6.5vw, 72px);
  max-width: 18%;
  height: auto;
  aspect-ratio: 1;
}
.result-primary {
  flex: 0 1 auto;
  width: clamp(175px, 25vw, 260px);
  max-width: 72%;
  height: auto;
  min-width: 0;
}
.result-actions .image-button img {
  width: 100%;
  height: auto;
  object-fit: contain;
}
.wide-button { width: 72%; aspect-ratio: 3.2; }
.result-anim .result-hero { animation: result-pop .5s cubic-bezier(.18, 1.45, .32, 1) both; }
.result-anim .result-banner { animation: result-pop .48s .08s cubic-bezier(.18, 1.45, .32, 1) both; }
.result-anim .result-title { animation: result-pop .45s .16s cubic-bezier(.18, 1.45, .32, 1) both; }
.result-anim .result-actions { animation: result-pop .42s .24s cubic-bezier(.18, 1.45, .32, 1) both; }
.result-anim .result-stars img { animation: star-pop .4s cubic-bezier(.16, 1.6, .32, 1) both; }
.result-anim .result-stars img:nth-child(1) { animation-name: star-pop-side; animation-delay: .28s; }
.result-anim .result-stars img:nth-child(2) { animation-delay: .4s; }
.result-anim .result-stars img:nth-child(3) { animation-name: star-pop-side; animation-delay: .52s; }
.result-anim.is-win .result-dog { animation: dog-float 2.2s .55s ease-in-out infinite; }
.result-anim.is-lose .result-dog { animation: dog-sad 2.6s .55s ease-in-out infinite; }
@keyframes result-pop { 0% { transform: scale(.55); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes star-pop { 0% { transform: scale(0) rotate(-18deg); opacity: 0; } 100% { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes star-pop-side { 0% { transform: translateY(24%) scale(0) rotate(-18deg); opacity: 0; } 100% { transform: translateY(24%) scale(1) rotate(0); opacity: 1; } }
@keyframes dog-float { 50% { transform: translateY(-4%); } }
@keyframes dog-sad { 50% { transform: translateY(3%) rotate(-2deg); } }
@keyframes hint-pulse { 50% { transform: scale(1.05); opacity: .78; } }
@media (prefers-reduced-motion: reduce) { #hint, .result-anim .result-hero, .result-anim .result-banner, .result-anim .result-title, .result-anim .result-actions, .result-anim .result-stars img, .result-anim .result-dog, .rotate-phone { animation: none; } }

#rotate-prompt {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  place-items: center;
  padding: 8%;
  background: #163d4d url("assets/gameplay/home-sanctuary-v2.webp") center/cover no-repeat;
}
#rotate-prompt::before {
  content: "";
  position: absolute;
  inset: 0;
  background: #123c4c88;
  backdrop-filter: blur(6px);
}
.rotate-card {
  position: relative;
  z-index: 1;
  width: min(86vw, 420px);
  padding: 12% 8% 10%;
  text-align: center;
  background:
    linear-gradient(#ffffffb8, #ffffff00 32%),
    linear-gradient(#7ef0c4 0%, #4ad8e8 55%, #2ec4ea 100%);
  border: 5px solid #f0c84a;
  border-radius: 32px;
  box-shadow:
    inset 0 8px 0 #ffffff4d,
    0 0 0 3px #163a58,
    0 6px 0 #c99720;
}
.rotate-phone {
  width: 52px;
  height: 86px;
  margin: 0 auto 8%;
  border: 5px solid #163a58;
  border-radius: 10px;
  background: #fff6e0;
  box-shadow: inset 0 -10px 0 #f0c84a;
  animation: phone-tilt 1.6s ease-in-out infinite;
}
.rotate-card p {
  margin: 0 0 6%;
  color: #fff6e0;
  font: 900 clamp(22px, 6.4vw, 34px)/1.15 Arial, sans-serif;
  -webkit-text-stroke: 4px #163a58;
  paint-order: stroke fill;
  text-shadow: 0 3px 0 #0e2b42;
}
.rotate-card span {
  display: block;
  color: #163a58;
  font: 800 clamp(13px, 3.6vw, 16px)/1.3 Arial, sans-serif;
}
@keyframes phone-tilt {
  0%, 24% { transform: rotate(0deg); }
  48%, 100% { transform: rotate(90deg); }
}

@media (orientation: portrait) and (pointer: coarse) {
  #rotate-prompt { display: grid; }
  #game-shell { visibility: hidden; }
}

@media (orientation: landscape) and (pointer: coarse),
       (orientation: landscape) and (max-height: 540px) {
  html, body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    background: #163d4d;
  }
  #game-shell.home-mode,
  #game-shell.gameplay-mode {
    width: min(calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right)), calc((100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 16 / 9));
    height: min(calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)), calc((100vw - env(safe-area-inset-left) - env(safe-area-inset-right)) * 9 / 16));
    max-width: none;
    aspect-ratio: 16 / 9;
    box-shadow: none;
  }
  .result-stage { width: min(72%, 640px); height: 88%; }
  .result-home { width: clamp(46px, 7.5vw, 62px); max-width: 17%; }
  .result-primary { width: clamp(155px, 28vw, 220px); max-width: 68%; }
}
