/* ============================================================
   Animal Battle — playful, chunky, toy-box UI
   ============================================================ */

:root {
  --ink: #33261f;
  --cream: #fff6e8;
  --sun: #ffc93c;
  --sun-deep: #f5a300;
  --coral: #ff6b6b;
  --coral-deep: #e04848;
  --leaf: #6dbf67;
  --leaf-deep: #4d9c48;
  --sky-top: #8fd3f4;
  --sky-bot: #cdeffd;
  --panel: rgba(255, 246, 232, 0.94);
  --shadow: 0 6px 0 rgba(51, 38, 31, 0.25);
  --radius: 22px;
  --font-display: 'Lilita One', 'Comic Sans MS', cursive;
  --font-body: 'Baloo 2', 'Comic Sans MS', cursive;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  font-family: var(--font-body);
  background: #4f9ec4;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

/* Touch devices: leave a hair of scroll room so one upward swipe makes
   Safari collapse its toolbar into the small pill — the closest thing to
   fullscreen an iPhone allows. The game itself stays position:fixed, and
   in-battle touches are preventDefault'ed so aiming never scrolls. */
@media (pointer: coarse) {
  html, body { overflow: visible; touch-action: pan-y; }
  body { height: auto; min-height: calc(100vh + 2px); }
  @supports (min-height: 100lvh) {
    body { min-height: calc(100lvh + 2px); }
  }
  #controls, #hud { touch-action: none; }
}

#stage { position: fixed; inset: 0; }

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* ============================ Screens ============================ */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.2vh, 26px);
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  z-index: 20;
  overflow-y: auto;
  touch-action: pan-y;
}

.screen-heading {
  font-family: var(--font-display);
  font-size: clamp(26px, 5.5vmin, 52px);
  color: var(--cream);
  text-shadow: 0 4px 0 rgba(51,38,31,.35);
  letter-spacing: 1px;
  text-align: center;
}

/* ------- Title ------- */
.title-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 2vh, 22px);
}

#game-title {
  font-family: var(--font-display);
  font-size: clamp(44px, 11vmin, 118px);
  line-height: 1;
  letter-spacing: 2px;
  color: var(--sun);
  -webkit-text-stroke: clamp(1.5px, 0.45vmin, 4px) var(--ink);
  text-shadow: 0 clamp(4px, 1vmin, 9px) 0 var(--ink);
  text-align: center;
}
#game-title span { display: inline-block; animation: bounce-in .7s cubic-bezier(.2,1.6,.4,1) backwards; }
#game-title span:nth-child(odd) { color: var(--coral); }
#game-title span:nth-child(3n) { color: var(--leaf); }
#game-title span:nth-child(1) { animation-delay: .05s }
#game-title span:nth-child(2) { animation-delay: .1s }
#game-title span:nth-child(3) { animation-delay: .15s }
#game-title span:nth-child(4) { animation-delay: .2s }
#game-title span:nth-child(5) { animation-delay: .25s }
#game-title span:nth-child(6) { animation-delay: .3s }
#game-title span:nth-child(7) { animation-delay: .4s }
#game-title span:nth-child(8) { animation-delay: .45s }
#game-title span:nth-child(9) { animation-delay: .5s }
#game-title span:nth-child(10) { animation-delay: .55s }
#game-title span:nth-child(11) { animation-delay: .6s }
#game-title span:nth-child(12) { animation-delay: .65s }
#game-title span:nth-child(13) { animation-delay: .7s }
#game-title span:nth-child(14) { animation-delay: .75s }

@keyframes bounce-in {
  0% { transform: translateY(-90px) scale(.3); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

.tagline {
  font-weight: 800;
  font-size: clamp(14px, 2.6vmin, 24px);
  color: var(--cream);
  text-shadow: 0 2px 0 rgba(51,38,31,.4);
  animation: bounce-in .6s .7s cubic-bezier(.2,1.6,.4,1) backwards;
}

#title-parade {
  display: flex;
  gap: clamp(4px, 2vw, 30px);
  animation: bounce-in .6s .85s cubic-bezier(.2,1.6,.4,1) backwards;
}
.parade-face {
  width: clamp(84px, 16vmin, 190px);
  height: clamp(84px, 16vmin, 190px);
}

/* ------- Buttons ------- */
.btn-column { display: flex; flex-direction: column; gap: 14px; align-items: center; }

.big-btn {
  font-family: var(--font-display);
  font-size: clamp(20px, 3.6vmin, 34px);
  letter-spacing: 1.5px;
  color: var(--ink);
  background: linear-gradient(180deg, #ffd95e, var(--sun));
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  padding: clamp(10px, 1.6vh, 16px) clamp(28px, 5vw, 54px);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .1s, box-shadow .1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
}
.big-btn small {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: .5em;
  letter-spacing: 0;
  opacity: .75;
}
.big-btn.alt { background: linear-gradient(180deg, #8fd489, var(--leaf)); }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(51,38,31,.25); }

.back-btn {
  font-family: var(--font-body);
  font-weight: 800;
  font-size: clamp(14px, 2.4vmin, 20px);
  color: var(--cream);
  background: rgba(51,38,31,.35);
  border: 3px solid rgba(255,246,232,.6);
  border-radius: 999px;
  padding: 8px 22px;
  cursor: pointer;
}
.back-btn:active { transform: translateY(2px); }

#btn-fullscreen-title {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  z-index: 5;
}
#btn-picker {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  z-index: 5;
  text-decoration: none;
}

/* ------- Cards (difficulty + characters) ------- */
.card-row {
  display: flex;
  gap: clamp(10px, 2vw, 26px);
  justify-content: center;
  flex-wrap: wrap;
}

.diff-card, .char-card {
  font-family: var(--font-body);
  background: var(--panel);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(10px, 2vmin, 22px);
  width: clamp(150px, 26vmin, 250px);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--ink);
}
.diff-card:active, .char-card:active { transform: scale(.96); }
.diff-card:hover, .char-card:hover { transform: translateY(-4px); }

.diff-emoji { font-size: clamp(34px, 7vmin, 64px); }
.diff-name {
  font-family: var(--font-display);
  font-size: clamp(20px, 4vmin, 34px);
  letter-spacing: 1px;
}
.diff-desc { font-weight: 700; font-size: clamp(12px, 2vmin, 17px); line-height: 1.25; opacity: .85; }

.char-card.selected {
  background: #fff;
  border-color: var(--coral-deep);
  box-shadow: 0 0 0 5px var(--coral), 0 6px 0 rgba(51,38,31,.25);
  transform: translateY(-6px) scale(1.03);
}
.char-portrait { width: clamp(90px, 15vmin, 160px); height: clamp(90px, 15vmin, 160px); }
.char-name { font-family: var(--font-display); font-size: clamp(16px, 3vmin, 26px); }
.char-weapon { font-weight: 700; font-size: clamp(12px, 2vmin, 16px); opacity: .8; }

#setup-name {
  font-family: var(--font-body);
  font-weight: 800;
  font-size: clamp(18px, 3.4vmin, 30px);
  text-align: center;
  color: var(--ink);
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 999px;
  padding: clamp(8px, 1.4vh, 14px) 26px;
  width: min(78vw, 420px);
  box-shadow: var(--shadow);
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
#setup-name:focus { border-color: var(--coral-deep); }
#setup-name::placeholder { color: rgba(51,38,31,.35); }

/* ============================ HUD ============================ */

#hud {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left));
  right: calc(10px + env(safe-area-inset-right));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  z-index: 10;
  pointer-events: none;
}

.hud-player {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 5px 12px 5px 6px;
  box-shadow: 0 4px 0 rgba(51,38,31,.25);
  transition: transform .25s, box-shadow .25s;
}
.hud-player.right { padding: 5px 6px 5px 12px; }
.hud-player.active {
  transform: scale(1.07);
  box-shadow: 0 0 0 4px var(--sun), 0 5px 0 rgba(51,38,31,.3);
}
.hud-face { width: 48px; height: 48px; }
.hud-name {
  font-family: var(--font-display);
  font-size: clamp(13px, 2.4vmin, 20px);
  letter-spacing: .5px;
  white-space: nowrap;
}
.hud-hearts { font-size: clamp(12px, 2.2vmin, 18px); letter-spacing: 1px; }
.hud-hearts .lost { opacity: .22; filter: grayscale(1); }
.right .hud-info { text-align: right; }

#hud-center { flex: 1; display: flex; justify-content: center; padding-top: 2px; }

#wind-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 4px 14px;
  box-shadow: 0 4px 0 rgba(51,38,31,.25);
  font-weight: 800;
}
#wind-label { font-size: clamp(11px, 1.8vmin, 14px); letter-spacing: 1px; opacity: .7; }
#wind-meter { width: clamp(60px, 10vmin, 110px); text-align: center; overflow: hidden; }
#wind-arrow {
  font-size: clamp(16px, 3vmin, 24px);
  color: var(--coral-deep);
  transition: transform .4s;
  display: inline-block;
}
#wind-value { font-size: clamp(13px, 2.2vmin, 18px); min-width: 2ch; text-align: center; }

#hud-buttons {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}
.icon-btn {
  width: clamp(34px, 5.6vmin, 46px);
  height: clamp(34px, 5.6vmin, 46px);
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--panel);
  font-family: var(--font-display);
  font-size: clamp(15px, 2.6vmin, 22px);
  color: var(--ink);
  box-shadow: 0 3px 0 rgba(51,38,31,.25);
  cursor: pointer;
}
.icon-btn:active { transform: translateY(2px); box-shadow: none; }

/* ------- Turn banner ------- */
#banner {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-display);
  font-size: clamp(26px, 6vmin, 58px);
  color: var(--cream);
  background: rgba(51,38,31,.78);
  border-radius: 999px;
  padding: .3em 1em;
  white-space: nowrap;
  z-index: 15;
  pointer-events: none;
  animation: banner-pop 2.1s ease forwards;
}
@keyframes banner-pop {
  0% { transform: translateX(-50%) scale(0); opacity: 0; }
  12% { transform: translateX(-50%) scale(1.1); opacity: 1; }
  18% { transform: translateX(-50%) scale(1); }
  82% { transform: translateX(-50%) scale(1); opacity: 1; }
  100% { transform: translateX(-50%) scale(.9); opacity: 0; }
}

/* ============================ Controls ============================ */

#controls {
  position: absolute;
  bottom: calc(8px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: clamp(8px, 2vw, 26px);
  background: var(--panel);
  border: 4px solid var(--ink);
  border-radius: 26px;
  box-shadow: 0 5px 0 rgba(51,38,31,.3);
  padding: clamp(6px, 1.2vh, 12px) clamp(10px, 2vw, 24px);
  z-index: 10;
  max-width: calc(100vw - 16px);
}

.ctrl-group { display: flex; align-items: center; gap: clamp(4px, .8vw, 10px); }

.ctrl-label {
  font-family: var(--font-display);
  font-size: clamp(11px, 2vmin, 17px);
  letter-spacing: 1px;
  opacity: .75;
}
.ctrl-value {
  font-family: var(--font-display);
  font-size: clamp(15px, 2.8vmin, 24px);
  min-width: 3ch;
  text-align: center;
  color: var(--coral-deep);
}

.step-btn {
  width: clamp(30px, 5vmin, 42px);
  height: clamp(30px, 5vmin, 42px);
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: #fff;
  font-family: var(--font-display);
  font-size: clamp(16px, 3vmin, 26px);
  color: var(--ink);
  cursor: pointer;
  flex-shrink: 0;
}
.step-btn:active { background: var(--sun); }

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: clamp(80px, 16vw, 220px);
  height: 14px;
  border-radius: 999px;
  background: #e5d5bd;
  border: 3px solid var(--ink);
  outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: clamp(26px, 4.6vmin, 38px);
  height: clamp(26px, 4.6vmin, 38px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffd95e, var(--sun-deep));
  border: 3px solid var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(51,38,31,.3);
}
input[type=range]::-moz-range-thumb {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--sun); border: 3px solid var(--ink); cursor: pointer;
}

#btn-fire {
  font-family: var(--font-display);
  font-size: clamp(20px, 4.2vmin, 38px);
  letter-spacing: 2px;
  color: #fff;
  -webkit-text-stroke: 1px var(--ink);
  background: radial-gradient(circle at 35% 30%, #ff9d9d, var(--coral) 55%, var(--coral-deep));
  border: 4px solid var(--ink);
  border-radius: 50%;
  width: clamp(74px, 13vmin, 118px);
  height: clamp(74px, 13vmin, 118px);
  box-shadow: 0 6px 0 rgba(51,38,31,.35);
  cursor: pointer;
  flex-shrink: 0;
  animation: fire-pulse 1.6s ease-in-out infinite;
}
#btn-fire:active { transform: translateY(4px) scale(.97); box-shadow: 0 2px 0 rgba(51,38,31,.35); animation: none; }
@keyframes fire-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

#controls.cpu-turn { opacity: .45; pointer-events: none; filter: grayscale(.6); }

/* ============================ Game over ============================ */

.gameover-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#winner-face { width: clamp(120px, 24vmin, 240px); height: clamp(120px, 24vmin, 240px); animation: winner-bob 1.4s ease-in-out infinite; }
@keyframes winner-bob { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-14px) rotate(3deg); } }
#winner-text {
  font-family: var(--font-display);
  font-size: clamp(34px, 8vmin, 80px);
  color: var(--sun);
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 0 5px 0 var(--ink);
  text-align: center;
}
#winner-sub {
  font-weight: 800;
  font-size: clamp(15px, 2.8vmin, 24px);
  color: var(--cream);
  text-shadow: 0 2px 0 rgba(51,38,31,.4);
  text-align: center;
}

/* ============================ Help ============================ */

.help-box {
  background: var(--panel);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(16px, 3vmin, 34px);
  max-width: min(92vw, 640px);
  max-height: 86vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}
.help-box .screen-heading { color: var(--ink); text-shadow: none; }
.help-box ul { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.help-box li { font-weight: 700; font-size: clamp(13px, 2.3vmin, 19px); line-height: 1.35; }

/* ============================ Rotate hint ============================ */

#rotate-hint {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(51,38,31,.85);
  color: var(--cream);
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(22px, 6vw, 40px);
  line-height: 1.5;
  padding: 30px;
  pointer-events: none;
}

@media (orientation: portrait) and (max-width: 620px) {
  #rotate-hint.armed { display: flex !important; }
}

/* ============================ Short screens ============================
   Landscape phones with browser chrome leave ~300px of height — compact
   everything so the battlefield stays visible. */
@media (max-height: 520px) {
  #controls {
    gap: 8px;
    padding: 4px 10px;
    border-width: 3px;
    bottom: calc(4px + env(safe-area-inset-bottom));
  }
  #btn-fire {
    width: 56px;
    height: 56px;
    font-size: 15px;
    letter-spacing: 1px;
    border-width: 3px;
    box-shadow: 0 4px 0 rgba(51,38,31,.35);
  }
  .step-btn { width: 26px; height: 26px; font-size: 15px; border-width: 2.5px; }
  input[type=range] { width: clamp(60px, 13vw, 150px); height: 10px; }
  input[type=range]::-webkit-slider-thumb { width: 24px; height: 24px; }
  .ctrl-label { font-size: 10px; }
  .ctrl-value { font-size: 14px; }
  .hud-player { border-width: 2.5px; padding: 3px 8px 3px 4px; border-radius: 13px; }
  .hud-player.right { padding: 3px 4px 3px 8px; }
  .hud-face { width: 30px; height: 30px; }
  .hud-name { font-size: 12px; }
  .hud-hearts { font-size: 10px; }
  .icon-btn { width: 30px; height: 30px; font-size: 13px; border-width: 2.5px; }
  #hud-buttons { top: calc(100% + 4px); }
  #wind-box { padding: 2px 10px; border-width: 2.5px; }
  #wind-label { font-size: 9px; }
  #wind-value { font-size: 12px; }
  #wind-arrow { font-size: 14px; }
  #banner { font-size: 22px; }

  /* menus must fit above the fold on landscape phones */
  .screen { gap: 8px; }
  .title-wrap { gap: 7px; }
  #game-title { font-size: clamp(28px, 9vmin, 46px); text-shadow: 0 3px 0 var(--ink); }
  .tagline { font-size: 12px; }
  #title-parade { gap: 10px; }
  .parade-face { width: 56px; height: 56px; }
  .btn-column { gap: 8px; }
  .big-btn { font-size: 17px; padding: 7px 26px; border-width: 3px; }
  .screen-heading { font-size: 19px; }
  .diff-card, .char-card { padding: 8px 10px; width: 138px; border-width: 3px; gap: 3px; }
  .diff-emoji { font-size: 24px; }
  .diff-name { font-size: 16px; }
  .diff-desc { font-size: 10.5px; }
  .char-portrait { width: 54px; height: 54px; }
  .char-name { font-size: 13px; }
  .char-weapon { font-size: 10px; }
  #setup-name { font-size: 15px; padding: 5px 16px; border-width: 3px; }
  .back-btn { font-size: 12px; padding: 5px 14px; border-width: 2px; }
  .help-box { padding: 12px 16px; gap: 8px; }
  .help-box ul { gap: 5px; }
  .help-box li { font-size: 11px; }
  .gameover-wrap { gap: 4px; }
  #winner-face { width: 84px; height: 84px; }
  #winner-text { font-size: 30px; }
  #winner-sub { font-size: 13px; }
}
