:root {
  --forest: #3f7a3a;
  --forest-dark: #2b5a2a;
  --wood: #8a5a32;
  --wood-dark: #5a3a1e;
  --cream: #fff8e8;
  --ivory: #fffdf6;
  --pink: #ffb7cf;
  --sky: #9fd6f5;
  --gold: #f2c14e;
  --cyan: #7ff3ff;
  --ink: #3b2a1e;
  --shadow: 0 4px 0 rgba(60, 35, 15, 0.25), 0 8px 24px rgba(40, 30, 10, 0.18);
  --font: 'Trebuchet MS', 'Segoe UI', 'Hiragino Maru Gothic ProN', 'Noto Sans TC', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1f3a24;
  font-family: var(--font);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
}

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

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

#ui-root {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#ui-root > * {
  pointer-events: none;
}

.hidden {
  display: none !important;
}

button,
select,
input,
label,
summary,
.panel,
.menu-card,
.dialog,
.party-slot,
.quest {
  pointer-events: auto;
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0.7em 1.4em;
  border-radius: 999px;
  border: 3px solid var(--wood-dark);
  background: var(--ivory);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--wood-dark);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s;
}
.btn:hover:not(:disabled) {
  filter: brightness(1.05);
  transform: translateY(-1px);
}
.btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--wood-dark);
}
.btn.primary {
  background: linear-gradient(#7fd06a, #4f9a3a);
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  border-color: var(--forest-dark);
  box-shadow: 0 4px 0 var(--forest-dark);
}
.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.select {
  font: inherit;
  padding: 0.45em 0.8em;
  border-radius: 12px;
  border: 2px solid #c9b48e;
  background: var(--ivory);
  color: var(--ink);
}

/* ---------- Main menu ---------- */
.menu {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 4vh 6vw;
  background: linear-gradient(90deg, rgba(20, 45, 25, 0.55), rgba(20, 45, 25, 0) 60%);
}
.menu-card {
  width: min(460px, 92vw);
  max-height: 92vh;
  overflow: auto;
  background: rgba(255, 252, 242, 0.94);
  border: 4px solid var(--wood);
  border-radius: 28px;
  padding: 28px 28px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: pop-in 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.menu-kicker {
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--forest);
  font-weight: 700;
}
.title {
  margin: 0;
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  line-height: 0.95;
  color: var(--forest-dark);
  text-shadow: 0 3px 0 #cfe8b8;
}
.title span {
  color: #d9668f;
  text-shadow: 0 3px 0 #ffd9e6;
}
.menu-intro {
  margin: 0 0 6px;
  line-height: 1.45;
  color: #5a4632;
}
.menu-status {
  font-size: 0.85rem;
  color: #7a6a52;
}
.menu-controls summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--wood);
}
.controls-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  margin-top: 8px;
  font-size: 0.85rem;
}
.ck {
  font-weight: 700;
  white-space: nowrap;
}
.cv {
  color: #5a4632;
}

@keyframes pop-in {
  from {
    transform: scale(0.85) translateY(10px);
    opacity: 0;
  }
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  inset: 0;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
}

.status {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  display: flex;
  gap: 10px;
  align-items: center;
}
.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid var(--wood);
  background: radial-gradient(circle at 50% 35%, #e9f8d8, #a8d98a);
  box-shadow: var(--shadow);
  object-fit: cover;
}
.status-bars {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.hearts {
  display: flex;
  gap: 2px;
  filter: drop-shadow(0 2px 0 rgba(60, 30, 20, 0.35));
}
.hearts.shake {
  animation: shake 0.35s;
}
.heart {
  width: 24px;
  height: 22px;
  display: inline-block;
  background: no-repeat center / contain;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 21 2.5 11.5a5.5 5.5 0 0 1 8-7.6L12 5.4l1.5-1.5a5.5 5.5 0 0 1 8 7.6Z' fill='%23ff5a78' stroke='%235a2030' stroke-width='1.6'/%3E%3Cpath d='M6 6.5a2.5 2.5 0 0 1 3 0' stroke='%23fff' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
}
.heart.half {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 21 2.5 11.5a5.5 5.5 0 0 1 8-7.6L12 5.4l1.5-1.5a5.5 5.5 0 0 1 8 7.6Z' fill='%23f3e6dc' stroke='%235a2030' stroke-width='1.6'/%3E%3Cpath d='M12 21 2.5 11.5a5.5 5.5 0 0 1 8-7.6L12 5.4Z' fill='%23ff5a78'/%3E%3C/svg%3E");
}
.heart.empty {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 21 2.5 11.5a5.5 5.5 0 0 1 8-7.6L12 5.4l1.5-1.5a5.5 5.5 0 0 1 8 7.6Z' fill='%23f3e6dc' stroke='%235a2030' stroke-width='1.6'/%3E%3C/svg%3E");
  opacity: 0.85;
}
.stamina {
  width: 150px;
  height: 10px;
  border-radius: 99px;
  background: rgba(60, 40, 20, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.85);
  overflow: hidden;
}
.stamina-fill {
  height: 100%;
  background: linear-gradient(90deg, #9be37a, #e9f77a);
  border-radius: 99px;
  transition: width 0.08s linear;
}
.stamina.low .stamina-fill {
  background: linear-gradient(90deg, #ff9a5a, #ffd25a);
}
.stamina.flash {
  animation: shake 0.3s;
  border-color: #ff8a8a;
}
.gems {
  font-weight: 800;
  color: #fff;
  font-size: 0.95rem;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}

.quest {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: min(320px, 42vw);
  background: rgba(255, 250, 236, 0.9);
  border: 3px solid var(--wood);
  border-radius: 16px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  cursor: help;
}
.quest-title {
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--wood);
}
.quest-objective {
  margin-top: 4px;
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--forest-dark);
}
.quest-hint {
  max-height: 0;
  overflow: hidden;
  font-size: 0.82rem;
  color: #6a5640;
  transition: max-height 0.3s ease, margin 0.3s;
}
.quest-hint.show {
  max-height: 80px;
  margin-top: 4px;
}
.quest-side {
  margin-top: 6px;
  font-size: 0.78rem;
  color: #9a6aa8;
  font-weight: 700;
}

/* Party bar */
.party {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.party-list {
  display: flex;
  gap: 8px;
}
.party-slot {
  position: relative;
  width: 58px;
  height: 58px;
  padding: 0;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.8);
  background: radial-gradient(circle at 50% 35%, #ffffff, var(--accent, #ddd));
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  cursor: pointer;
  overflow: visible;
  transition: transform 0.15s ease, border-color 0.15s;
}
.party-slot img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.party-fallback {
  font-weight: 800;
  font-size: 1.4rem;
}
.party-slot.selected {
  transform: translateY(-6px) scale(1.12);
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(242, 193, 78, 0.5), 0 6px 0 rgba(0, 0, 0, 0.25);
}
.party-slot.busy {
  animation: bob 0.6s ease-in-out infinite;
}
.party-key {
  position: absolute;
  top: -6px;
  left: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--wood);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  display: grid;
  place-items: center;
}
.party-name {
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  font-weight: 800;
  background: var(--ivory);
  border-radius: 99px;
  padding: 0 6px;
  border: 2px solid var(--wood);
  white-space: nowrap;
}
.party-cd {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(rgba(30, 20, 40, 0.55) var(--cd, 0deg), transparent 0);
  pointer-events: none;
}
.ability-label {
  font-weight: 800;
  font-size: 0.85rem;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 6px;
}
.key {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 7px;
  background: var(--ivory);
  color: var(--ink);
  border: 2px solid var(--wood);
  box-shadow: 0 2px 0 var(--wood-dark);
  font-weight: 800;
  font-size: 0.8rem;
  text-shadow: none;
}
.key.hint {
  background: #e8f4ff;
}

.prompt {
  position: absolute;
  left: 50%;
  bottom: 140px;
  transform: translate(-50%, 10px);
  background: rgba(255, 250, 236, 0.95);
  border: 3px solid var(--wood);
  border-radius: 99px;
  padding: 8px 16px 8px 8px;
  font-weight: 700;
  display: flex;
  gap: 10px;
  align-items: center;
  max-width: min(560px, 90vw);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
}
.prompt.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.prompt.actionable {
  border-color: var(--gold);
}

.toasts {
  position: absolute;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  width: min(520px, 90vw);
}
.toast {
  background: rgba(255, 252, 242, 0.96);
  border-radius: 14px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
  border-left: 6px solid var(--sky);
  animation: toast-in 0.3s ease;
  transition: opacity 0.4s, transform 0.4s;
}
.toast.reward {
  border-left-color: var(--gold);
}
.toast.warn {
  border-left-color: #ff8a6a;
}
.toast.out {
  opacity: 0;
  transform: translateY(-8px);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
  }
}

.banner {
  position: absolute;
  top: 26%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(1.6rem, 4.5vw, 2.8rem);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 3px 0 var(--forest-dark), 0 0 24px rgba(0, 0, 0, 0.35);
  letter-spacing: 0.04em;
  opacity: 0;
  white-space: nowrap;
}
.banner.show {
  animation: banner 3s ease forwards;
}
@keyframes banner {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%);
  }
  15%,
  80% {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -60%);
  }
}
.objective-banner {
  position: absolute;
  top: 36%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  background: rgba(255, 250, 236, 0.95);
  border: 3px solid var(--gold);
  border-radius: 16px;
  padding: 10px 20px;
  font-weight: 800;
  font-size: 1.1rem;
  text-align: center;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
}
.objective-banner small {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--wood);
}
.objective-banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Speech bubbles & damage numbers (positioned from JS) */
.bubbles,
.pops {
  position: absolute;
  inset: 0;
}
.bubble {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 200px;
  background: #fff;
  border: 2px solid var(--wood);
  border-radius: 14px;
  padding: 5px 10px;
  font-size: 0.8rem;
  font-weight: 700;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.15);
  white-space: normal;
  text-align: center;
}
.bubble::after {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 50%;
  width: 10px;
  height: 10px;
  background: #fff;
  border-right: 2px solid var(--wood);
  border-bottom: 2px solid var(--wood);
  transform: translateX(-50%) rotate(45deg);
}
.pop {
  position: absolute;
  left: 0;
  top: 0;
  font-weight: 900;
  font-size: 1.3rem;
  text-shadow: 0 2px 0 #5a2a1a, 0 0 6px rgba(0, 0, 0, 0.4);
}

/* Aim reticle */
.reticle {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.reticle.show {
  opacity: 0.85;
}
.reticle-ring {
  position: absolute;
  width: 34px;
  height: 34px;
  left: -17px;
  top: -17px;
  border-radius: 50%;
  background: conic-gradient(var(--cyan) var(--charge, 0deg), rgba(255, 255, 255, 0.35) 0);
  -webkit-mask: radial-gradient(circle, transparent 12px, #000 13px);
  mask: radial-gradient(circle, transparent 12px, #000 13px);
}
.reticle.aiming .reticle-ring {
  transform: scale(1.15);
}
.reticle.charged .reticle-ring {
  background: var(--cyan);
  box-shadow: 0 0 12px var(--cyan);
  animation: pulse 0.4s infinite alternate;
}
.reticle-dot {
  position: absolute;
  width: 6px;
  height: 6px;
  left: -3px;
  top: -3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.3);
}
@keyframes pulse {
  to {
    transform: scale(1.25);
  }
}

.fps {
  position: absolute;
  bottom: 8px;
  right: 10px;
  font: 700 0.75rem monospace;
  color: #fff;
  text-shadow: 0 1px 2px #000;
  display: none;
}
.fps.show {
  display: block;
}

/* Dialog */
.dialog {
  position: absolute;
  left: 50%;
  bottom: 120px;
  transform: translateX(-50%);
  width: min(640px, 92vw);
  background: rgba(255, 252, 242, 0.97);
  border: 4px solid var(--wood);
  border-radius: 20px;
  padding: 14px 20px 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  animation: pop-in 0.25s ease;
}
.dialog-title {
  position: absolute;
  top: -16px;
  left: 18px;
  background: var(--forest);
  color: #fff;
  font-weight: 800;
  padding: 2px 14px;
  border-radius: 99px;
  border: 3px solid var(--forest-dark);
}
.dialog-text {
  font-size: 1.02rem;
  line-height: 1.5;
  font-weight: 600;
  margin-top: 6px;
}
.dialog-next {
  position: absolute;
  right: 16px;
  bottom: 6px;
  color: var(--wood);
  animation: bob 0.8s ease-in-out infinite;
}

/* Panels & overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(25, 40, 25, 0.45);
  backdrop-filter: blur(3px);
  pointer-events: auto;
}
.panel {
  background: rgba(255, 252, 242, 0.97);
  border: 4px solid var(--wood);
  border-radius: 24px;
  padding: 22px 26px;
  box-shadow: var(--shadow);
  max-width: 92vw;
  max-height: 90vh;
  overflow: auto;
  animation: pop-in 0.3s ease;
}
.panel h2 {
  margin: 0 0 12px;
  color: var(--forest-dark);
}
.pause {
  width: min(440px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.settings {
  display: grid;
  gap: 10px;
}
.settings label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}
.toggles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.toggle {
  display: flex;
  gap: 6px;
  align-items: center;
  font-weight: 600;
}
.panel-hint {
  margin-top: 10px;
  font-size: 0.8rem;
  color: #7a6a52;
}

.inventory {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, 92vw);
}
.inv-gems {
  font-weight: 700;
  margin-bottom: 10px;
}
.inv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.inv-slot {
  font: inherit;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 8px;
  text-align: left;
  background: #fff;
  border: 2px solid #d8c4a0;
  border-radius: 14px;
  padding: 8px;
  cursor: pointer;
  position: relative;
}
.inv-slot:hover {
  border-color: var(--gold);
}
.inv-icon {
  font-size: 1.6rem;
  grid-row: span 2;
}
.inv-name {
  font-weight: 700;
  font-size: 0.85rem;
}
.inv-count {
  position: absolute;
  top: 4px;
  right: 8px;
  font-weight: 800;
  font-size: 0.8rem;
  color: var(--wood);
}
.inv-use,
.inv-key {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--forest);
}
.inv-key {
  color: #9a6aa8;
}
.inv-empty {
  color: #7a6a52;
}

.victory-card {
  width: min(520px, 92vw);
  text-align: center;
}
.victory-icon {
  font-size: 3.5rem;
  animation: bob 1.2s ease-in-out infinite;
}
.victory-card h3 {
  margin: -6px 0 10px;
  color: #d9668f;
}
.victory-card p {
  line-height: 1.5;
  color: #5a4632;
}
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 14px 0;
}
.stats div {
  background: #fff;
  border: 2px solid #e2d2b0;
  border-radius: 14px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
}
.stats b {
  font-size: 1.3rem;
  color: var(--forest-dark);
}
.stats span {
  font-size: 0.72rem;
  color: #7a6a52;
}
.row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.fatal {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  color: #fff;
  padding: 20px;
  pointer-events: auto;
}

@keyframes shake {
  20% {
    transform: translateX(-4px);
  }
  40% {
    transform: translateX(4px);
  }
  60% {
    transform: translateX(-3px);
  }
  80% {
    transform: translateX(2px);
  }
}
@keyframes bob {
  50% {
    transform: translateY(-4px);
  }
}

/* ---------- Touch controls ---------- */
.touch {
  position: absolute;
  inset: 0;
}
.touch > * {
  pointer-events: auto;
}
.move-zone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 42%;
  height: 70%;
  touch-action: none;
}
.stick-base {
  position: absolute;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  left: 120px;
  bottom: auto;
  top: calc(100% - 160px);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 3px solid rgba(255, 255, 255, 0.55);
  opacity: 0.5;
  transition: opacity 0.15s;
}
.stick-base.active {
  opacity: 1;
}
.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(255, 252, 242, 0.9);
  border: 3px solid var(--wood);
  transform: translate(-50%, -50%);
}
.tbtn {
  position: absolute;
  border-radius: 50%;
  border: 3px solid rgba(90, 58, 30, 0.85);
  background: rgba(255, 252, 242, 0.82);
  font: 800 1.3rem var(--font);
  color: var(--ink);
  display: grid;
  place-items: center;
  touch-action: none;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
}
.tbtn:active,
.tbtn.active {
  transform: scale(0.94);
  background: #fff6d0;
}
.tbtn.attack {
  right: calc(28px + env(safe-area-inset-right));
  bottom: calc(40px + env(safe-area-inset-bottom));
  width: 96px;
  height: 96px;
  font-size: 2rem;
  background: rgba(255, 236, 200, 0.9);
}
.aim-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(127, 243, 255, 0.6);
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
}
.attack.active .aim-knob {
  opacity: 1;
}
.tbtn.dodge {
  right: calc(140px + env(safe-area-inset-right));
  bottom: calc(26px + env(safe-area-inset-bottom));
  width: 64px;
  height: 64px;
}
.tbtn.ability {
  right: calc(130px + env(safe-area-inset-right));
  bottom: calc(108px + env(safe-area-inset-bottom));
  width: 64px;
  height: 64px;
  color: #c08a10;
}
.tbtn.swap {
  right: calc(56px + env(safe-area-inset-right));
  bottom: calc(150px + env(safe-area-inset-bottom));
  width: 52px;
  height: 52px;
  font-size: 1.1rem;
}
.tbtn.interact {
  right: calc(210px + env(safe-area-inset-right));
  bottom: calc(110px + env(safe-area-inset-bottom));
  width: 64px;
  height: 64px;
  background: rgba(255, 230, 140, 0.95);
  display: none;
}
.tbtn.interact.show {
  display: grid;
  animation: pop-in 0.2s ease;
}
.tbtn.bag {
  top: calc(96px + env(safe-area-inset-top));
  left: calc(14px + env(safe-area-inset-left));
  width: 44px;
  height: 44px;
  font-size: 1rem;
}
.tbtn.pause {
  top: calc(96px + env(safe-area-inset-top));
  left: calc(64px + env(safe-area-inset-left));
  width: 44px;
  height: 44px;
  font-size: 0.9rem;
}

/* On touch devices, keep the party bar clear of the thumbs */
body.touch-mode .party {
  bottom: auto;
  top: max(10px, env(safe-area-inset-top));
  transform: translateX(-50%) scale(0.82);
  transform-origin: top center;
}
body.touch-mode .prompt {
  bottom: 24px;
}
body.touch-mode .dialog {
  bottom: 24px;
}
body.touch-mode .reticle {
  display: none;
}

/* Small / landscape phone screens */
@media (max-height: 520px), (max-width: 760px) {
  .avatar {
    width: 46px;
    height: 46px;
  }
  .heart {
    width: 18px;
    height: 17px;
  }
  .stamina {
    width: 110px;
  }
  .quest {
    width: min(240px, 40vw);
    padding: 6px 10px;
  }
  .quest-objective {
    font-size: 0.82rem;
  }
  .party-slot {
    width: 46px;
    height: 46px;
  }
  .toasts {
    top: 70px;
  }
  .menu {
    padding: 2vh 3vw;
  }
  .menu-card {
    padding: 18px;
    gap: 8px;
  }
}

/* Portrait phones: ask to rotate */
@media (orientation: portrait) and (max-width: 760px) {
  body.touch-mode::after {
    content: '🔄  Rotate your device to landscape for the best adventure!';
    position: fixed;
    left: 50%;
    bottom: 40%;
    transform: translateX(-50%);
    background: rgba(255, 252, 242, 0.95);
    border: 3px solid var(--wood);
    border-radius: 16px;
    padding: 10px 16px;
    font-weight: 800;
    text-align: center;
    width: 80vw;
    z-index: 10;
  }
}
