/* ==========================================================================
   SURVIVAL — UI styles. Big, bright, chunky: built for kids on an iPad.
   ========================================================================== */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, "Segoe UI", "Comic Sans MS", "Chalkboard SE", sans-serif;
  background: #1a2238;
  color: #fff;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- screens ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: linear-gradient(160deg, #2d3a6b 0%, #1a2238 70%);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  z-index: 10;
}
.screen.hidden { display: none; }
.screen-transparent { background: none; pointer-events: none; }
.screen-transparent button, .screen-transparent .joystick { pointer-events: auto; }

.title {
  font-size: clamp(48px, 10vw, 96px);
  letter-spacing: 6px;
  color: #ffd54f;
  text-shadow: 0 6px 0 #b8860b, 0 10px 24px rgba(0,0,0,.5);
  transform: rotate(-2deg);
}
.tagline { font-size: clamp(16px, 3vw, 24px); opacity: .85; }

.menu { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; min-width: 260px; }

.btn {
  font: inherit;
  font-size: 22px;
  font-weight: 700;
  padding: 14px 28px;
  border: none;
  border-radius: 18px;
  background: #3f51b5;
  color: #fff;
  box-shadow: 0 5px 0 #283593, 0 8px 16px rgba(0,0,0,.35);
  cursor: pointer;
  transition: transform .06s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #283593; }
.btn-big {
  font-size: 28px;
  background: #43a047;
  box-shadow: 0 6px 0 #2e7031, 0 10px 20px rgba(0,0,0,.35);
}
.btn-big:active { box-shadow: 0 1px 0 #2e7031; }

.panel {
  background: rgba(20, 26, 50, .92);
  border: 3px solid #ffd54f;
  border-radius: 28px;
  padding: 32px 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: min(90vw, 520px);
}
.panel h2 { font-size: 34px; text-align: center; }
.big-emoji { font-size: 72px; }
.score-line { font-size: 26px; }
.score-line span { color: #ffd54f; font-weight: 800; }
.best-line { font-size: 22px; color: #7cffb2; }
.hidden { display: none !important; }

.version-tag {
  position: absolute;
  bottom: calc(10px + env(safe-area-inset-bottom));
  right: calc(14px + env(safe-area-inset-right));
  font-size: 13px;
  opacity: .45;
}

.animal-card {
  position: absolute;
  bottom: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255,255,255,.1);
  border-radius: 16px;
  padding: 10px 18px;
  font-size: 18px;
}

/* ---------- creator ---------- */

.creator-layout {
  display: flex;
  width: 100%;
  height: 100%;
  gap: 0;
}
.creator-preview {
  flex: 1 1 45%;
  position: relative;
  min-width: 0;
}
.creator-preview canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.creator-panel {
  flex: 1 1 55%;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: rgba(0,0,0,.25);
  touch-action: pan-y;
}
.creator-panel h2 { color: #ffd54f; }

.creator-group { display: flex; flex-direction: column; gap: 8px; }
.creator-group > label { font-size: 15px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; opacity: .75; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 14px;
  border: 3px solid transparent;
  background: #2d3a6b;
  color: #fff;
  cursor: pointer;
}
.chip.selected { border-color: #ffd54f; background: #3f51b5; }
.chip-emoji { font-size: 26px; padding: 8px 14px; }

.swatch {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 4px solid transparent;
  cursor: pointer;
}
.swatch.selected { border-color: #ffd54f; transform: scale(1.12); }
.swatch-rainbow {
  background: conic-gradient(#f44, #fa0, #fd0, #4c4, #29f, #92f, #f44);
}

.toggle-row { display: flex; gap: 8px; }

/* preset row — one-tap starting animals */
.preset-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  flex-shrink: 0;
}
.chip-preset {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  padding: 8px 12px;
  white-space: nowrap;
}
.preset-emoji { font-size: 28px; }

/* tab bar */
.tab-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.tab {
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  padding: 10px 14px;
  border-radius: 14px 14px 4px 4px;
  border: 3px solid transparent;
  border-bottom: none;
  background: #222c52;
  color: #fff;
  cursor: pointer;
  opacity: .7;
}
.tab.selected { background: #3f51b5; border-color: #ffd54f; opacity: 1; }

/* morph sliders — big fat touch targets for small fingers */
.slider-row { display: flex; flex-direction: column; gap: 6px; }
.slider-row > label {
  font-size: 14px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 1px; opacity: .75;
}
.creator-panel input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 30px;
  border-radius: 15px;
  background: #2d3a6b;
  outline: none;
}
.creator-panel input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: #ffd54f;
  border: 3px solid #b8860b;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.creator-panel input[type=range].slider-hue {
  background: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}

/* spin pause/play button over the preview */
.tool-btn {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: 14px;
  height: 52px;
  padding: 0 20px;
  border-radius: 26px;
  border: none;
  font: inherit;
  font-size: 19px;
  font-weight: 800;
  background: rgba(10, 14, 30, .65);
  color: #fff;
  cursor: pointer;
}
.name-input {
  font: inherit; font-size: 20px;
  padding: 10px 14px;
  border-radius: 12px;
  border: none;
  width: 100%;
  max-width: 320px;
}

/* ---------- HUD ---------- */

.hud-top {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: 16px; right: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
}
.hud-card, .hud-clock-wrap {
  background: rgba(10, 14, 30, .55);
  border-radius: 14px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
}
.hud-clock-wrap { flex-direction: column; gap: 0; align-items: center; }
.hud-day { font-size: 13px; opacity: .8; }
.hud-score {
  font-size: 42px;
  font-weight: 900;
  color: #ffd54f;
  text-shadow: 0 3px 0 rgba(0,0,0,.5);
}
.hud-goal {
  position: absolute;
  top: calc(64px + env(safe-area-inset-top));
  width: 100%;
  text-align: center;
  font-size: 15px;
  opacity: .8;
  pointer-events: none;
}

.mini-face {
  display: inline-block;
  width: 30px; height: 30px;
  border-radius: 50%;
  position: relative;
}
.mini-face::before {
  content: '';
  position: absolute;
  top: 9px; left: 6px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #111;
  box-shadow: 13px 0 0 #111;
}

.hud-banner {
  position: absolute;
  top: 30%;
  width: 100%;
  text-align: center;
  font-size: clamp(28px, 6vw, 52px);
  font-weight: 900;
  color: #ff5252;
  text-shadow: 0 4px 0 rgba(0,0,0,.6);
  animation: banner-pulse .5s infinite alternate;
  pointer-events: none;
}
@keyframes banner-pulse { from { transform: scale(1); } to { transform: scale(1.08); } }

#hud-popups { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.popup {
  position: absolute;
  font-size: 30px;
  font-weight: 900;
  text-shadow: 0 3px 0 rgba(0,0,0,.6);
  animation: popup-rise 1.1s ease-out forwards;
  pointer-events: none;
}
@keyframes popup-rise {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(-90px) scale(1.3); }
}

.joystick {
  position: absolute;
  width: 130px; height: 130px;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  border: 2px solid rgba(255,255,255,.35);
  pointer-events: none;
}
.joystick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 56px; height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: rgba(255,255,255,.55);
}

/* on-screen D-pad — hold to move/turn (iPad friendly) */
.dpad {
  position: absolute;
  left: calc(22px + env(safe-area-inset-left));
  bottom: calc(22px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 74px);
  grid-template-rows: repeat(3, 74px);
  gap: 6px;
  pointer-events: none;
}
.dpad-btn {
  border: none;
  border-radius: 18px;
  font-size: 30px;
  font-weight: 900;
  color: #fff;
  background: rgba(30, 40, 80, .65);
  box-shadow: 0 4px 0 rgba(0,0,0,.35);
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.dpad-btn.held { background: rgba(63, 81, 181, .95); transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.dpad-up    { grid-column: 2; grid-row: 1; }
.dpad-left  { grid-column: 1; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down  { grid-column: 2; grid-row: 3; }

/* in-game exit-to-menu button */
.btn-exit {
  border: none;
  border-radius: 14px;
  font-size: 24px;
  padding: 8px 14px;
  background: rgba(10, 14, 30, .55);
  color: #fff;
  pointer-events: auto;
  cursor: pointer;
}

.btn-jump {
  position: absolute;
  right: calc(26px + env(safe-area-inset-right));
  bottom: calc(30px + env(safe-area-inset-bottom));
  width: 110px; height: 110px;
  border-radius: 50%;
  border: none;
  font: inherit;
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  background: rgba(255, 152, 0, .85);
  box-shadow: 0 6px 0 rgba(160, 90, 0, .9);
  pointer-events: auto;
}
.btn-jump:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(160,90,0,.9); }

.lava-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 120px 40px rgba(255, 40, 0, .55);
  animation: banner-pulse .4s infinite alternate;
}

/* ---------- scores ---------- */

.scores-list { list-style: none; width: 100%; min-width: 300px; }
.scores-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.scores-list .rank { width: 28px; opacity: .6; font-weight: 800; }
.scores-list .sname { flex: 1; }
.scores-list .sscore { color: #ffd54f; font-weight: 800; }
.scores-list .sday { font-size: 14px; opacity: .6; }

/* ---------- settings ---------- */

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 20px;
  width: 100%;
  min-width: 280px;
}
.setting-row input[type=range] { width: 100%; height: 36px; }
.setting-row input[type=checkbox] { width: 28px; height: 28px; }
