@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;600;700&family=Playfair+Display:wght@600&display=swap');

:root {
  color-scheme: dark;
  font-family: 'DM Sans', sans-serif;
  background: #07111e;
  color: #fff4df;
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #07111e;
  color: #fff4df;
  font-family: inherit;
}

.world-app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 45%, #263e51, #101e2c 65%, #07111e);
}

.viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; }
.viewport.dragging { cursor: grabbing; }
.scene {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(100vw, 1600px);
  transform: translate(-50%, -50%) scale(1);
  transform-origin: center center;
  user-select: none;
  will-change: transform;
  backface-visibility: hidden;
}
.village-image {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 0 42px rgba(255, 190, 98, .13));
}
.objects { position: absolute; inset: 0; }
.placed-object {
  position: absolute;
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  touch-action: none;
}
.placed-object[hidden] { display: none !important; }
.placed-object.image-object { display: block; min-width: 0; min-height: 0; padding: 0; border: 0; background: transparent; box-shadow: none; }
.placed-object.image-object img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}
.placed-object.image-object > img { position: relative; z-index: 2; }

.back-link, .world-tools, .hint { position: absolute; z-index: 5; }
.back-link {
  top: max(18px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  padding: 10px 14px;
  border: 1px solid #ffffff27;
  border-radius: 25px;
  color: #f7e9cc;
  background: #07111e88;
  text-decoration: none;
  backdrop-filter: blur(10px);
}
.world-tools { top: max(18px, env(safe-area-inset-top)); right: max(18px, env(safe-area-inset-right)); display: flex; gap: 7px; }
.world-tools button {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid #ffffff30;
  border-radius: 22px;
  color: #fff4df;
  background: #07111eaa;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  backdrop-filter: blur(10px);
}
.world-tools button:hover { background: #26394a; }
.hint {
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  max-width: calc(100% - 24px);
  padding: 9px 15px;
  transform: translateX(-50%);
  border: 1px solid #ffffff22;
  border-radius: 22px;
  color: #e3e2db;
  background: #07111e99;
  font-size: .75rem;
  text-align: center;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}
.loading {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  padding: 24px;
  color: #f5d89f;
  background: #07111e;
  text-align: center;
  transition: opacity .5s;
}
.loading.done { opacity: 0; pointer-events: none; }
.loading.error { color: #fff1dc; background: #101e2bf2; }
.loading button {
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid #ffffff40;
  border-radius: 22px;
  color: #fff4df;
  background: #23394d;
  font: inherit;
  cursor: pointer;
}

.contact-shadow {
  position: absolute;
  z-index: 0;
  display: block;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0, 0, 0, .82) 0%, rgba(0, 0, 0, .56) 45%, rgba(0, 0, 0, 0) 76%);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.candle-glow {
  position: absolute;
  z-index: 1;
  aspect-ratio: 1.8 / 1;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse, rgba(255, 197, 94, .47) 0%, rgba(255, 168, 56, .24) 32%, rgba(255, 149, 37, .08) 58%, transparent 76%);
  pointer-events: none;
  animation: glow-breathe 2.3s ease-in-out infinite alternate;
}
.candle-flame {
  position: absolute;
  z-index: 3;
  aspect-ratio: .62 / 1;
  border-radius: 55% 45% 50% 50% / 65% 65% 35% 35%;
  transform: translate(-50%, -92%) rotate(4deg);
  transform-origin: 50% 90%;
  background: radial-gradient(ellipse at 50% 68%, #fffce1 0 14%, #ffe492 30%, #ffae3d 64%, rgba(245, 108, 20, .12) 100%);
  box-shadow: 0 0 5px 2px rgba(255, 190, 76, .7), 0 0 14px 5px rgba(255, 142, 34, .35);
  pointer-events: none;
  animation: flame-flicker 1.7s ease-in-out infinite alternate;
}
@keyframes flame-flicker {
  0% { opacity: .88; transform: translate(-50%, -92%) rotate(-3deg) scale(.94, .98); }
  23% { opacity: 1; transform: translate(-50%, -92%) rotate(3deg) scale(1.03, 1.05); }
  57% { opacity: .91; transform: translate(-50%, -92%) rotate(-2deg) scale(.97, .94); }
  79% { opacity: 1; transform: translate(-50%, -92%) rotate(4deg) scale(1.02, 1.02); }
  100% { opacity: .9; transform: translate(-50%, -92%) rotate(-1deg) scale(.96, 1.04); }
}
@keyframes glow-breathe { from { opacity: .82; } to { opacity: 1; } }

@media (max-width: 900px) {
  .placed-object { min-width: 48px; min-height: 48px; }
}
@media (max-width: 650px) {
  .back-link { top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); padding: 8px 11px; }
  .back-link span { display: none; }
  .world-tools { top: auto; right: max(10px, env(safe-area-inset-right)); bottom: max(70px, calc(env(safe-area-inset-bottom) + 62px)); gap: 5px; }
  .world-tools button { min-width: 44px; min-height: 44px; }
  .hint { bottom: max(12px, env(safe-area-inset-bottom)); white-space: normal; max-width: calc(100% - 20px); font-size: .67rem; }
  .scene { width: auto; }
}
@media (max-height: 430px) and (orientation: landscape) {
  .world-tools { top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); bottom: auto; }
  .back-link { top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); }
  .hint { bottom: max(8px, env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  .candle-flame, .candle-glow { animation: none; }
  .candle-flame { opacity: .95; }
  .loading { transition: none; }
}
