:root {
  --sky: #8aceff;
  --panel-bg: rgba(17, 26, 37, 0.35);
  --panel-border: rgba(255, 255, 255, 0.18);
  --text: #f3ffe8;
  --shadow: rgba(0, 0, 0, 0.2);
  --paw-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='72' height='72'%3E%3Cg fill='white' fill-opacity='0.16'%3E%3Cellipse cx='36' cy='45' rx='12' ry='10'/%3E%3Ccircle cx='19' cy='29' r='5.5'/%3E%3Ccircle cx='30' cy='19' r='6'/%3E%3Ccircle cx='42' cy='19' r='6'/%3E%3Ccircle cx='53' cy='29' r='5.5'/%3E%3C/g%3E%3C/svg%3E");
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background: linear-gradient(#63c3f2 0%, #9fe3ff 40%, #d0f3ff 100%);
  color: var(--text);
  min-width: 100vw;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: grid;
  place-items: center;
  transform-origin: center center;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    var(--paw-pattern),
    linear-gradient(#63c3f2 0%, #9fe3ff 45%, #cdeefb 75%, #dff7b8 100%);
  background-size: 72px 72px, 100% 100%;
  aspect-ratio: 3 / 2;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  /* Hand all touch gestures to the game instead of the browser. */
  touch-action: none;
}

#gameCanvas.dragging {
  cursor: grabbing;
}

.hud {
  position: absolute;
  left: calc(14px + env(safe-area-inset-left));
  top: calc(14px + env(safe-area-inset-top));
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: 0 8px 18px var(--shadow);
  backdrop-filter: blur(10px);
  border-radius: 14px;
  padding: 10px 14px;
  pointer-events: none;
  z-index: 5;
}

.title {
  font-weight: 800;
  font-size: clamp(1rem, 2vw, 1.6rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.controls {
  font-size: 0.74rem;
  opacity: 0.9;
  margin-top: 2px;
}

/* ---------- HUD frame: fixed buttons around the outside of the grid ---------- */

.hud-frame {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

.hud-pill,
.hud-button,
.hud-fab {
  position: absolute;
  pointer-events: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: 0 8px 18px var(--shadow);
  backdrop-filter: blur(10px);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.12s ease, background 0.12s ease;
}

.hud-pill:active,
.hud-button:active,
.hud-fab:active {
  transform: scale(0.92);
}

.hud-pill {
  top: calc(14px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 700;
  font-size: clamp(0.85rem, 1.6vw, 1.1rem);
}

.hud-icon {
  font-size: 1.1em;
}

.hud-button {
  width: clamp(42px, 6vw, 56px);
  height: clamp(42px, 6vw, 56px);
  border-radius: 50%;
  font-size: clamp(1.1rem, 2.4vw, 1.5rem);
  cursor: pointer;
}

.hud-settings {
  top: calc(70px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
}

.hud-shop {
  bottom: calc(14px + env(safe-area-inset-bottom));
  right: calc(14px + env(safe-area-inset-right));
}

.hud-kennel {
  bottom: calc(14px + env(safe-area-inset-bottom));
  left: calc(14px + env(safe-area-inset-left));
}

.hud-fab {
  bottom: calc(12px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: clamp(50px, 7vw, 64px);
  height: clamp(50px, 7vw, 64px);
  border-radius: 50%;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 700;
  cursor: pointer;
  background: rgba(94, 173, 74, 0.55);
}

.hud-fab:active {
  transform: translateX(-50%) scale(0.92);
}

/* ---------- Loading screen ---------- */

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px 0;
  background:
    var(--paw-pattern),
    linear-gradient(#3fa9e8 0%, #7cd1f5 55%, #bdeaff 100%);
  background-size: 72px 72px, 100% 100%;
  transition: opacity 0.6s ease;
}

.loading-screen.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-art {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-art img {
  max-width: min(90vw, 52vh);
  max-height: 68vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
}

.loading-bar {
  width: clamp(200px, 40vw, 360px);
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.6);
  overflow: hidden;
}

.loading-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffd166, #f2994a);
  border-radius: 999px;
  transition: width 0.2s linear;
}

.loading-status {
  font-size: 0.9rem;
  color: #fff;
  opacity: 0.9;
}

/* ---------- Character select ---------- */

.character-select {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 3vh, 28px);
  padding: clamp(16px, 3vh, 32px) 0;
  background:
    var(--paw-pattern),
    linear-gradient(#3fa9e8 0%, #7cd1f5 55%, #bdeaff 100%);
  background-size: 72px 72px, 100% 100%;
  transition: opacity 0.5s ease;
}

.character-select.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.character-select-title {
  font-weight: 800;
  font-size: clamp(1.6rem, 4.5vw, 2.6rem);
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.character-carousel {
  display: flex;
  align-items: center;
  gap: clamp(14px, 2.4vw, 26px);
  width: 100%;
  max-width: 100vw;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  padding: 8px clamp(24px, 12vw, 140px);
  -webkit-overflow-scrolling: touch;
}

.character-carousel::-webkit-scrollbar {
  height: 6px;
}

.character-carousel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.5);
  border-radius: 999px;
}

.character-card {
  flex: 0 0 auto;
  scroll-snap-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
  width: clamp(120px, 16vw, 190px);
  background: var(--panel-bg);
  border: 2px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: 0 8px 18px var(--shadow);
  backdrop-filter: blur(10px);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.character-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  object-position: top center;
  border-radius: 12px;
}

.character-name {
  font-size: clamp(0.72rem, 1.4vw, 0.9rem);
  font-weight: 700;
  text-align: center;
  line-height: 1.15;
}

.character-card:hover {
  transform: translateY(-4px);
}

.character-card.is-selected {
  border-color: #ffd166;
  background: rgba(255, 209, 102, 0.28);
  transform: translateY(-6px) scale(1.04);
}

.choose-button {
  min-width: clamp(160px, 20vw, 240px);
  padding: 14px 32px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(180deg, #7bd957, #4caf3c);
  color: #fff;
  font-weight: 800;
  font-size: clamp(1rem, 2.2vw, 1.3rem);
  letter-spacing: 0.04em;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease;
}

.choose-button:active {
  transform: scale(0.95);
}

.choose-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- Doghouse placement ---------- */

.placement-hint {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: none;
  padding: 10px 22px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  color: var(--text);
  font-weight: 700;
  font-size: clamp(0.85rem, 1.8vw, 1.05rem);
  box-shadow: 0 8px 18px var(--shadow);
  backdrop-filter: blur(10px);
  pointer-events: none;
  text-align: center;
}

.placement-confirm {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: 0 8px 18px var(--shadow);
  backdrop-filter: blur(10px);
}

.placement-text {
  color: var(--text);
  font-weight: 700;
  font-size: clamp(0.85rem, 1.8vw, 1.05rem);
  white-space: nowrap;
}

.placement-actions {
  display: flex;
  gap: 14px;
}

.placement-btn {
  min-width: 72px;
  padding: 10px 22px;
  border: none;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.12s ease;
  color: #fff;
}

.placement-btn:active {
  transform: scale(0.92);
}

.placement-yes {
  background: linear-gradient(180deg, #7bd957, #4caf3c);
}

.placement-no {
  background: linear-gradient(180deg, #ff8a7a, #e0503f);
}

/* Phones in landscape: keep the map clear of the title panel and the prompt. */
@media (max-height: 500px) {
  .hud {
    display: none;
  }

  .placement-confirm {
    left: calc(16px + env(safe-area-inset-left));
    right: auto;
    bottom: calc(72px + env(safe-area-inset-bottom));
    transform: none;
  }

  .placement-confirm.on-right {
    left: auto;
    right: calc(16px + env(safe-area-inset-right));
  }
}

/* ---------- Landscape lock ---------- */

.rotate-prompt {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #16324a;
  color: #fff;
  text-align: center;
  padding: 24px;
}

.rotate-icon {
  font-size: 3rem;
  animation: rotate-hint 1.6s ease-in-out infinite;
}

.rotate-text {
  font-size: 1.1rem;
  font-weight: 600;
  max-width: 260px;
}

@keyframes rotate-hint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}

@media (orientation: portrait) and (pointer: coarse) {
  .rotate-prompt {
    display: flex;
  }

  .app-shell,
  .loading-screen,
  .character-select,
  .placement-hint,
  .placement-confirm {
    display: none;
  }
}
