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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* Portrait: rotate app 90deg */
@media (orientation: portrait) {
  #app {
    position: fixed;
    width: 100vh;
    height: 100vw;
    top: 50%;
    left: 50%;
    margin-top: -50vw;
    margin-left: -50vh;
    -webkit-transform: rotate(90deg);
    transform: rotate(90deg);
    -webkit-transform-origin: center center;
    transform-origin: center center;
  }
}

/* ── Game World ── */
#game-container {
  width: 100%;
  height: 100%;
  background: #1a1a2e;
  position: relative;
  overflow: hidden;
}

/* ── Player ── */
#player {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
  pointer-events: none;
  display: inline-flex;
  align-items: flex-start;
  z-index: 8;
}

#player-body {
  font-size: 44px;
  line-height: 1;
  display: block;
}

#player-hand {
  position: absolute;
  font-size: 22px;
  top: 0px;
  right: -20px;
  -webkit-transform: rotate(-20deg);
  transform: rotate(-20deg);
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.6));
}


/* ── Emoji Items (ground loot: wood etc) ── */
.emoji-item {
  position: absolute;
  font-size: 36px;
  pointer-events: none;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.5));
}

/* ── Bottom UI Bar ── */
#ui-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  pointer-events: none;
}

/* ── Joystick ── */
#joystick-area {
  pointer-events: all;
  display: flex;
  align-items: center;
  justify-content: center;
}

#joystick-outer {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  border: 2px solid rgba(255,255,255,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#joystick-inner {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.45);
  border: 2px solid rgba(255,255,255,0.6);
  position: absolute;
  transition: transform 0.05s;
  pointer-events: none;
}

/* ── Bag ── */
#bag-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  pointer-events: all;
}

#bag-icon {
  font-size: 36px;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#bag-count {
  font-family: "Nunito", sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: rgba(0,0,0,0.45);
  border-radius: 8px;
  padding: 2px 8px;
}

/* ── Equipment Bar ── */
#equip-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.equip-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 58px;
  height: 68px;
  background: rgba(255,255,255,0.08);
  border: 1.5px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  justify-content: center;
  pointer-events: all;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.equip-slot:active {
  transform: scale(0.93);
}

.equip-emoji {
  font-size: 26px;
  line-height: 1;
}

.equip-label {
  font-family: "Nunito", sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.02em;
}

.equip-empty {
  font-size: 22px;
  color: rgba(255,255,255,0.18);
  line-height: 1;
}

/* Quality tiers */
.equip-slot[data-quality="gold"] {
  border-color: #ffd700;
  background: rgba(255,215,0,0.12);
  box-shadow: 0 0 12px rgba(255,215,0,0.45);
}
.equip-slot[data-quality="diamond"] {
  border-color: #4fc3f7;
  background: rgba(79,195,247,0.12);
  box-shadow: 0 0 14px rgba(79,195,247,0.55);
}

/* Equipped state — green glow */
.equip-slot.equipped {
  border-color: #66bb6a !important;
  background: rgba(76,175,80,0.22) !important;
  box-shadow: 0 0 16px rgba(76,175,80,0.65) !important;
}

/* Upgrade flash animation */
@keyframes upgradeFlash {
  0%   { transform: scale(1);    filter: brightness(1); }
  20%  { transform: scale(1.28); filter: brightness(2.8) saturate(2); }
  55%  { transform: scale(0.94); filter: brightness(1.4); }
  100% { transform: scale(1);    filter: brightness(1); }
}
.equip-slot.upgrading {
  animation: upgradeFlash 0.65s ease-out forwards;
}

/* ── World Tool Items ── */
.tool-item {
  position: absolute;
  cursor: pointer;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-align-items: center;
  align-items: center;
  gap: 3px;
  z-index: 5;
}

.tool-item-inner {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  font-size: 28px;
  background: rgba(0,0,0,0.58);
  border: 2px solid rgba(255,255,255,0.32);
  box-shadow: 0 4px 12px rgba(0,0,0,0.45);
}

.tool-item-inner.quality-gold {
  border-color: #ffd700;
  background: rgba(80,55,0,0.65);
  box-shadow: 0 0 14px rgba(255,215,0,0.7), 0 4px 12px rgba(0,0,0,0.45);
}

.tool-item-inner.quality-diamond {
  border-color: #4fc3f7;
  background: rgba(0,35,75,0.65);
  box-shadow: 0 0 16px rgba(79,195,247,0.8), 0 4px 12px rgba(0,0,0,0.45);
}

.tool-label {
  font-family: "Nunito", sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  white-space: nowrap;
}

/* ── World Bag Items ── */
.bag-world-item {
  position: absolute;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-align-items: center;
  align-items: center;
  gap: 3px;
  z-index: 5;
}

.bag-world-inner {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  font-size: 30px;
  background: rgba(30,0,60,0.65);
  border: 2px solid rgba(200,168,255,0.5);
  box-shadow: 0 0 14px rgba(180,100,255,0.5), 0 4px 12px rgba(0,0,0,0.45);
  animation: bagPulse 2s ease-in-out infinite;
}

.bag-level-2 .bag-world-inner {
  border-color: #d4a0ff;
  background: rgba(50,0,90,0.70);
  box-shadow: 0 0 20px rgba(200,100,255,0.75), 0 0 40px rgba(140,0,255,0.35), 0 4px 12px rgba(0,0,0,0.45);
}

@keyframes bagPulse {
  0%, 100% { box-shadow: 0 0 14px rgba(180,100,255,0.5), 0 4px 12px rgba(0,0,0,0.45); }
  50%       { box-shadow: 0 0 26px rgba(200,120,255,0.85), 0 4px 12px rgba(0,0,0,0.45); }
}

.bag-world-label {
  font-family: "Nunito", sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: #d4a0ff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  white-space: nowrap;
}

/* ── Attack Button ── */
#attack-btn {
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background: rgba(220, 60, 40, 0.28);
  border: 2px solid rgba(255, 90, 60, 0.52);
  box-shadow: 0 4px 18px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,140,100,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  cursor: pointer;
  pointer-events: all;
  transition: transform 0.08s, background 0.08s, box-shadow 0.08s;
  -webkit-tap-highlight-color: transparent;
}

#attack-btn:active,
#attack-btn.pressed {
  background: rgba(220, 60, 40, 0.55);
  transform: scale(0.88);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,140,100,0.2);
}

/* ── Inventory Overlay ── */
#inventory-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

#inventory-panel {
  background: #16213e;
  border: 2px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  width: 360px;
  max-width: 90%;
  padding: 20px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.7);
}

#inventory-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-family: "Nunito", sans-serif;
  font-size: 20px;
  font-weight: 800;
  color: #fff;
}

#inventory-close {
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#inventory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.inv-slot {
  background: rgba(255,255,255,0.07);
  border: 2px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 28px;
  cursor: grab;
  transition: background 0.15s;
  position: relative;
}

.inv-slot:hover {
  background: rgba(255,255,255,0.14);
}

.inv-slot .inv-count {
  font-family: "Nunito", sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: rgba(0,0,0,0.5);
  border-radius: 6px;
  padding: 1px 6px;
}

/* Dragging ghost */
.drag-ghost {
  position: fixed;
  font-size: 36px;
  pointer-events: none;
  z-index: 999;
  transform: translate(-50%, -50%);
}

/* ── Toast ── */
#toast {
  position: absolute;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #e74c3c, #e67e22);
  color: #fff;
  font-family: "Nunito", sans-serif;
  font-size: 15px;
  font-weight: 700;
  padding: 10px 24px;
  border-radius: 40px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  z-index: 100;
  transition: opacity 0.3s;
  white-space: nowrap;
}

/* ── Float Text ── */
.float-text {
  position: absolute;
  font-family: "Nunito", sans-serif;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  pointer-events: none;
  z-index: 20;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
  animation: floatUp 0.6s ease-out forwards;
}

@keyframes floatUp {
  0%   { opacity: 1; transform: translateY(0) translateX(-50%); }
  100% { opacity: 0; transform: translateY(-50px) translateX(-50%); }
}

/* ── Trees ── */
.tree-item {
  position: absolute;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-align-items: center;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  z-index: 6;
}

.tree-hp-bg {
  width: 60px;
  height: 8px;
  background: rgba(0,0,0,0.65);
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.25);
  overflow: hidden;
  flex-shrink: 0;
}

.tree-hp-fill {
  height: 100%;
  width: 100%;
  background: #4caf50;
  border-radius: 4px;
  -webkit-transition: width 0.15s, background 0.3s;
  transition: width 0.15s, background 0.3s;
}

.tree-emoji {
  font-size: 52px;
  line-height: 1;
  display: block;
  -webkit-transform-origin: center bottom;
  transform-origin: center bottom;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
}

/* Range indicator when player near tree */
.tree-item.in-range .tree-hp-bg {
  border-color: rgba(255,220,50,0.7);
  box-shadow: 0 0 6px rgba(255,200,0,0.5);
}

@-webkit-keyframes treeShakeEl {
  0%   { -webkit-transform: rotate(0deg) translateX(0); }
  20%  { -webkit-transform: rotate(-8deg) translateX(-4px); }
  45%  { -webkit-transform: rotate(8deg) translateX(4px); }
  65%  { -webkit-transform: rotate(-5deg) translateX(-2px); }
  82%  { -webkit-transform: rotate(3deg) translateX(1px); }
  100% { -webkit-transform: rotate(0deg) translateX(0); }
}
@keyframes treeShakeEl {
  0%   { transform: rotate(0deg) translateX(0); }
  20%  { transform: rotate(-8deg) translateX(-4px); }
  45%  { transform: rotate(8deg) translateX(4px); }
  65%  { transform: rotate(-5deg) translateX(-2px); }
  82%  { transform: rotate(3deg) translateX(1px); }
  100% { transform: rotate(0deg) translateX(0); }
}

@-webkit-keyframes treeFall {
  0%   { -webkit-transform: translate(-50%, -50%) rotate(0deg); opacity: 1; }
  55%  { -webkit-transform: translate(-15%, -35%) rotate(85deg); opacity: 0.9; }
  100% { -webkit-transform: translate(5%, -15%) rotate(115deg); opacity: 0; }
}
@keyframes treeFall {
  0%   { transform: translate(-50%, -50%) rotate(0deg); opacity: 1; }
  55%  { transform: translate(-15%, -35%) rotate(85deg); opacity: 0.9; }
  100% { transform: translate(5%, -15%) rotate(115deg); opacity: 0; }
}

/* ── Swing Animation ── */
@-webkit-keyframes axeSwing {
  0%   { -webkit-transform: translate(-50%, -50%) rotate(-65deg) scale(1.3); opacity: 1; }
  55%  { -webkit-transform: translate(-50%, -50%) rotate(20deg) scale(1.0); opacity: 1; }
  100% { -webkit-transform: translate(-50%, -50%) rotate(30deg) scale(0.7); opacity: 0; }
}
@keyframes axeSwing {
  0%   { transform: translate(-50%, -50%) rotate(-65deg) scale(1.3); opacity: 1; }
  55%  { transform: translate(-50%, -50%) rotate(20deg) scale(1.0); opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(30deg) scale(0.7); opacity: 0; }
}

.swing-el {
  position: absolute;
  font-size: 30px;
  pointer-events: none;
  z-index: 15;
  -webkit-animation: axeSwing 0.32s ease-out forwards;
  animation: axeSwing 0.32s ease-out forwards;
}

@-webkit-keyframes screenShake {
  0%   { -webkit-transform: translate(0,0); }
  15%  { -webkit-transform: translate(-7px,-4px); }
  30%  { -webkit-transform: translate(7px,4px); }
  50%  { -webkit-transform: translate(-5px,3px); }
  68%  { -webkit-transform: translate(4px,-3px); }
  85%  { -webkit-transform: translate(-2px,2px); }
  100% { -webkit-transform: translate(0,0); }
}
@keyframes screenShake {
  0%   { transform: translate(0,0); }
  15%  { transform: translate(-7px,-4px); }
  30%  { transform: translate(7px,4px); }
  50%  { transform: translate(-5px,3px); }
  68%  { transform: translate(4px,-3px); }
  85%  { transform: translate(-2px,2px); }
  100% { transform: translate(0,0); }
}
.screen-shake {
  -webkit-animation: screenShake 0.42s ease-out forwards;
  animation: screenShake 0.42s ease-out forwards;
}

/* ── Helpers ── */
.hidden {
  display: none !important;
}

/* ── Time Display ── */
#time-display {
  position: absolute;
  top: 10px;
  left: 50%;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.50);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 5px 14px;
  z-index: 30;
  pointer-events: none;
  white-space: nowrap;
}

#time-phase-emoji {
  font-size: 18px;
  line-height: 1;
}

#time-countdown {
  font-family: "Nunito", sans-serif;
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.06em;
}

/* ── Campfire ── */
#campfire {
  position: absolute;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-align-items: center;
  align-items: center;
  gap: 4px;
  z-index: 4;
  pointer-events: none;
}

#campfire-progress-bg {
  width: 66px;
  height: 6px;
  background: rgba(0,0,0,0.6);
  border-radius: 3px;
  border: 1px solid rgba(255,180,60,0.35);
  overflow: hidden;
  display: none;
}

#campfire.has-fuel #campfire-progress-bg {
  display: block;
}

#campfire-progress-fill {
  height: 100%;
  background: -webkit-linear-gradient(left, #ff4500, #ffd700);
  background: linear-gradient(to right, #ff4500, #ffd700);
  border-radius: 3px;
  -webkit-transition: width 0.8s linear;
  transition: width 0.8s linear;
  width: 100%;
}

#campfire-ring {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(70,50,25,0.92) 0%, rgba(35,22,8,0.88) 100%);
  border: 3px solid #6e5230;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  font-size: 26px;
  box-shadow: 0 3px 12px rgba(0,0,0,0.6);
  -webkit-transition: box-shadow 0.4s;
  transition: box-shadow 0.4s;
}

#campfire.lit #campfire-ring {
  border-color: #c07820;
  box-shadow: 0 0 28px 8px rgba(255,120,0,0.35), 0 0 60px 20px rgba(255,60,0,0.12), 0 3px 12px rgba(0,0,0,0.6);
}

#campfire-unlit { font-size: 22px; }
#campfire.lit #campfire-unlit { display: none; }

#campfire-flame {
  font-size: 28px;
  display: none;
}

#campfire.lit #campfire-flame {
  display: inline;
  -webkit-animation: campfireFlicker 0.38s ease-in-out infinite alternate;
  animation: campfireFlicker 0.38s ease-in-out infinite alternate;
}

@-webkit-keyframes campfireFlicker {
  0%   { -webkit-transform: scale(1)   rotate(-3deg); }
  100% { -webkit-transform: scale(1.12) rotate(3deg); }
}
@keyframes campfireFlicker {
  0%   { transform: scale(1)   rotate(-3deg); }
  100% { transform: scale(1.12) rotate(3deg); }
}

#campfire-label {
  font-family: "Nunito", sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: rgba(240,200,120,0.75);
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  letter-spacing: 0.04em;
}

/* ── Pickup Protected Items ── */
.pickup-protected {
  -webkit-animation: protectPulse 0.6s ease-in-out infinite alternate;
  animation: protectPulse 0.6s ease-in-out infinite alternate;
}

@-webkit-keyframes protectPulse {
  0%   { -webkit-filter: drop-shadow(0 0 4px rgba(100,200,255,0.9)); opacity: 0.75; }
  100% { -webkit-filter: drop-shadow(0 0 10px rgba(100,200,255,0.5)); opacity: 1; }
}
@keyframes protectPulse {
  0%   { filter: drop-shadow(0 0 4px rgba(100,200,255,0.9)); opacity: 0.75; }
  100% { filter: drop-shadow(0 0 10px rgba(100,200,255,0.5)); opacity: 1; }
}
