:root {
  --bg: #12211b;
  --panel: rgba(14, 28, 22, 0.94);
  --panel-2: #1a3228;
  --line: rgba(201, 164, 74, 0.55);
  --line-dim: rgba(90, 122, 104, 0.5);
  --gold: #e7c56a;
  --gold-2: #f7e7b0;
  --cream: #f3efe4;
  --muted: #b7c4bb;
  --green: #2f6b4f;
  --green-2: #3a8460;
  --danger: #8a3a3a;
  --radius: 14px;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  --hud-h: 52px;
  --foot-h: 76px;
  --rail-clear: 0px;
  --pad: 10px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --ui: "Nunito", "Segoe UI", sans-serif;
  --display: "Cinzel", Palatino, Georgia, serif;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.hud-ico, .rail-ico-img {
  display: block;
  object-fit: contain;
  flex-shrink: 0;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}
.hud-ico { width: 26px; height: 26px; }
.rail-ico-img { width: 32px; height: 32px; }

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--ui);
  background: var(--bg);
  color: var(--cream);
  user-select: none;
  touch-action: none;
}

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

#world {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}
#world.dragging,
#world.holding { cursor: grabbing; }

#hud-top, #hud-bottom, #quest-panel, #shop-panel, #codex-panel, #menu-panel,
#rail-left, #rail-right, #splash, #modal, #toasts, #talk-box, #quest-tracker, #tutorial-dim {
  position: absolute;
  z-index: 3;
}

#hud-top {
  top: calc(var(--pad) + var(--safe-t));
  left: calc(var(--pad) + var(--safe-l));
  right: calc(var(--pad) + var(--safe-r));
  height: var(--hud-h);
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
#hud-top > * { pointer-events: auto; }

.profile-pill {
  position: relative;
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}
.profile-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(#8b5cf6 var(--xp-pct, 0%), rgba(255,255,255,0.12) 0);
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
}
#xp-fill { display: none; }
.profile-avatar-img {
  position: absolute;
  inset: 5px;
  width: calc(100% - 10px);
  height: calc(100% - 10px);
  border-radius: 50%;
  border: 2px solid #f0d48a;
  object-fit: cover;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  background: #2a4a38;
}
.profile-level {
  position: absolute;
  right: -2px;
  bottom: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 99px;
  background: linear-gradient(180deg, #f0d36a, #c9a030);
  color: #3a2808;
  font-size: 11px;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
  border: 2px solid #2a1810;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

.hud-pills {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.hud-pills::-webkit-scrollbar { display: none; }

.pill {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  height: 36px;
  min-height: 36px;
  box-sizing: border-box;
  padding: 4px 12px 4px 6px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, transparent 40%),
    linear-gradient(165deg, rgba(22, 44, 34, 0.96) 0%, rgba(10, 22, 16, 0.98) 100%);
  border: 2px solid rgba(212, 175, 90, 0.45);
  border-radius: 999px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35) inset,
    0 4px 14px rgba(0, 0, 0, 0.32);
  flex-shrink: 0;
}
button.pill {
  color: inherit;
  cursor: pointer;
  font: inherit;
}
.pill-res .hud-ico {
  width: 22px;
  height: 22px;
  object-fit: contain;
  flex-shrink: 0;
}
.pill-energy {
  min-width: 86px;
}
.pill-energy .hud-ico,
.pill-energy .pill-val {
  margin-bottom: 3px;
}
.pill-energy .pill-val {
  min-width: 2.6em;
  text-align: center;
}
.pill-val {
  font-family: "Cinzel", var(--display);
  font-weight: 700;
  font-size: 12px;
  color: var(--gold-2);
  line-height: 1;
  transition: color 0.25s ease;
}
.pill-bar {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 4px;
  height: 3px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
  pointer-events: none;
}
#energy-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, #22c55e, #86efac);
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 0 0 8px rgba(62, 207, 122, 0.45);
}

.hud-icon-btn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  padding: 6px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    linear-gradient(165deg, rgba(22, 44, 34, 0.96) 0%, rgba(10, 22, 16, 0.98) 100%);
  border: 2px solid rgba(212, 175, 90, 0.45);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.32);
  cursor: pointer;
}
.hud-icon-btn.active { border-color: var(--gold); background: var(--green-2); }

#quest-tracker {
  left: calc(var(--pad) + var(--safe-l));
  top: calc(var(--hud-h) + 14px + var(--safe-t));
  width: 132px;
  padding: 8px 8px 10px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  background:
    linear-gradient(165deg, rgba(22, 44, 34, 0.96) 0%, rgba(10, 22, 16, 0.98) 100%);
  border: 2px solid rgba(212, 175, 90, 0.5);
  border-radius: 18px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.38);
  cursor: pointer;
  z-index: 4;
  color: var(--cream);
  font-family: var(--ui);
  text-align: left;
}
#quest-tracker.hidden { display: none; }
#quest-tracker.active { border-color: var(--gold); background: rgba(30, 52, 40, 0.98); }
.quest-tracker-icon { width: 36px; height: 36px; flex-shrink: 0; }
.quest-tracker-body {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
}
.quest-tracker-title {
  font-family: "Cinzel", var(--display);
  font-size: 11px;
  font-weight: 700;
  color: var(--cream);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.quest-tracker-bar {
  width: 100%;
  height: 8px;
  background: rgba(0,0,0,0.35);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
}
#quest-tracker-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22c55e, #86efac);
  border-radius: 99px;
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.quest-tracker-progress {
  font-family: "Cinzel", var(--display);
  font-size: 10px;
  font-weight: 700;
  color: var(--gold-2);
  line-height: 1;
}
#quest-tracker.pulse,
#quest-tracker.ready {
  animation: readyPulse 1.4s ease-in-out infinite;
  border-color: var(--gold);
}

#rail-left, #rail-right {
  top: auto;
  bottom: calc(var(--foot-h) + 18px + var(--safe-b));
  transform: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 4;
}
#rail-left { left: calc(var(--pad) + var(--safe-l)); }
#rail-right { right: calc(var(--pad) + var(--safe-r)); }

.rail-btn {
  font-family: var(--ui);
  width: 52px;
  height: 52px;
  padding: 8px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(165deg, rgba(22, 44, 34, 0.96) 0%, rgba(10, 22, 16, 0.98) 100%);
  border: 2px solid rgba(212, 175, 90, 0.45);
  border-radius: 50%;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.3) inset,
    0 6px 18px rgba(0, 0, 0, 0.35);
  line-height: 1;
  transition: transform 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.rail-btn:hover:not(:disabled) { transform: scale(1.04); border-color: var(--gold); }
.rail-btn.active { border-color: var(--gold); background: rgba(36, 68, 52, 0.98); box-shadow: 0 0 16px rgba(240, 211, 106, 0.2); }

.drawer {
  top: calc(var(--hud-h) + 16px + var(--safe-t));
  bottom: calc(var(--foot-h) + 16px + var(--safe-b));
  width: min(320px, calc(100vw - 88px));
  left: calc(68px + var(--safe-l));
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05) 0%, transparent 32px),
    linear-gradient(165deg, #1a382c 0%, #12261e 100%);
  border: 2px solid #c9a44a;
  border-radius: 20px;
  padding: 14px;
  box-shadow:
    0 0 0 1px rgba(255, 232, 160, 0.2) inset,
    0 20px 48px rgba(0, 0, 0, 0.48);
  display: flex;
  flex-direction: column;
  transform: translateX(-120%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
  overflow: hidden;
}
.drawer-right {
  left: auto;
  right: calc(58px + var(--safe-r));
  transform: translateX(120%);
}
.drawer.open {
  transform: none;
  pointer-events: auto;
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.drawer h2 {
  font-family: var(--display);
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}
.drawer-close {
  font-family: "Cinzel", var(--display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(212, 175, 90, 0.45);
  background: rgba(8, 18, 14, 0.55);
  color: var(--gold-2);
}

#quest-list, #shop-list, #codex-list {
  list-style: none;
  overflow: auto;
  flex: 1;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: #4a6d5a transparent;
}
#quest-list::-webkit-scrollbar,
#shop-list::-webkit-scrollbar,
#codex-list::-webkit-scrollbar { width: 8px; }
#quest-list::-webkit-scrollbar-thumb,
#shop-list::-webkit-scrollbar-thumb { background: #3d5c4c; border-radius: 99px; }

.quest-card {
  display: grid;
  grid-template-columns: 8px 1fr;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line-dim);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}
.quest-card.current {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(231, 197, 106, 0.25);
}
.quest-card.done { opacity: 0.55; }
.quest-card.done b { text-decoration: line-through; }
.quest-status { width: 8px; border-radius: 99px; background: #4b6a58; }
.quest-card.current .quest-status { background: var(--gold); }
.quest-card.done .quest-status { background: #3ecf7a; }
.quest-card b { display: block; color: var(--gold-2); }
.quest-card p { color: var(--muted); margin: 3px 0 6px; line-height: 1.35; }
.quest-reward { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 99px;
  background: rgba(0,0,0,0.22);
  color: var(--gold);
}

.shop-item, .codex-item {
  width: 100%;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line-dim);
  border-radius: 12px;
  color: var(--cream);
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  font-family: var(--ui);
}
.shop-item:hover:not(:disabled) { border-color: var(--gold); background: #214233; }
.shop-item:disabled { opacity: 0.42; cursor: not-allowed; }
.shop-ico, .codex-swatch {
  width: 36px;
  height: 36px;
  border-radius: 10px;
}
.shop-ico.wood { background: radial-gradient(circle at 35% 30%, #e0b078, #8b5a2b); }
.shop-ico.plant { background: radial-gradient(circle at 35% 30%, #b6e89a, #2f7d3e); }
.shop-ico.stone { background: radial-gradient(circle at 35% 30%, #d5dbe0, #6d7378); }
.shop-ico.energy { background: radial-gradient(circle at 35% 30%, #b6ffd0, #22c55e); }
.shop-ico.gem { background: radial-gradient(circle at 35% 30%, #c4ecff, #3b9ee0); }
.shop-ico.chest { background: radial-gradient(circle at 35% 30%, #e8c07a, #7a4b1e); }
.shop-item b, .codex-item b { display: block; font-size: 13px; }
.shop-item .shop-desc, .codex-item span { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.shop-price { font-weight: 800; font-size: 12px; color: var(--gold); white-space: nowrap; }
.codex-item { cursor: default; }
.menu-copy { color: var(--muted); font-size: 13px; line-height: 1.45; margin: 12px 0 8px; }
.menu-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: #4a6d5a transparent;
  padding-right: 2px;
}
.menu-scroll::-webkit-scrollbar { width: 8px; }
.menu-scroll::-webkit-scrollbar-thumb {
  background: rgba(74, 109, 90, 0.55);
  border-radius: 999px;
}
.menu-new { width: 100%; margin-bottom: 4px; }

.menu-settings {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid rgba(212, 175, 90, 0.35);
  background: rgba(8, 18, 14, 0.45);
}
.settings-row {
  display: grid;
  grid-template-columns: 36px 1fr 22px;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(212, 175, 90, 0.28);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(24, 46, 36, 0.92), rgba(14, 28, 22, 0.92));
  color: var(--cream);
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.settings-row:hover { border-color: rgba(212, 175, 90, 0.55); }
.settings-open {
  width: 9px;
  height: 9px;
  margin-right: 4px;
  justify-self: end;
  border-right: 2px solid var(--gold-2);
  border-top: 2px solid var(--gold-2);
  transform: rotate(45deg);
  opacity: 0.85;
}

#guide-modal {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(12px + var(--safe-t))
    calc(12px + var(--safe-r))
    calc(12px + var(--safe-b))
    calc(12px + var(--safe-l));
  background: rgba(8, 14, 11, 0.68);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
#guide-modal.hidden { display: none; }
.guide-modal-card {
  position: relative;
  width: min(440px, 100%);
  max-height: min(88dvh, 760px);
  overflow: auto;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #4a6d5a transparent;
  animation: guide-pop 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.guide-modal-card::-webkit-scrollbar { width: 8px; }
.guide-modal-card::-webkit-scrollbar-thumb {
  background: rgba(74, 109, 90, 0.55);
  border-radius: 999px;
}
.guide-modal-close {
  position: sticky;
  top: 0;
  z-index: 2;
  float: right;
  margin: 0 0 8px 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(212, 175, 90, 0.45);
  background: rgba(8, 18, 14, 0.72);
  color: var(--gold-2);
  font-family: var(--display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}
.guide-modal-close:hover { border-color: var(--gold); }
@keyframes guide-pop {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to { opacity: 1; transform: none; }
}

.guide-box {
  position: relative;
  margin-bottom: 0;
  padding: 22px 16px 16px;
  border-radius: 18px;
  border: 2px solid #c9a44a;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, transparent 28px),
    linear-gradient(165deg, rgba(28, 54, 42, 0.98) 0%, rgba(14, 28, 22, 0.98) 100%);
  box-shadow:
    0 0 0 1px rgba(255, 232, 160, 0.22) inset,
    0 14px 36px rgba(0, 0, 0, 0.35);
}
.guide-deco { position: absolute; width: 44px; height: 44px; pointer-events: none; opacity: 0.92; }
.guide-corner-tl { top: 4px; left: 4px; transform: rotate(0deg); }
.guide-corner-tr { top: 4px; right: 4px; transform: scaleX(-1); }
.guide-corner-bl { bottom: 4px; left: 4px; transform: scaleY(-1); }
.guide-corner-br { bottom: 4px; right: 4px; transform: scale(-1); }
.guide-inner { position: relative; z-index: 1; }
.guide-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(212, 175, 90, 0.28);
}
.guide-crest {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
}
.guide-kicker {
  font-family: var(--display);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(244, 215, 138, 0.75);
  margin-bottom: 2px;
}
.guide-title {
  font-family: var(--display);
  font-size: clamp(18px, 4vw, 22px);
  color: var(--gold-2);
  line-height: 1.15;
}
.guide-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
}
.guide-item {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px 10px 10px 8px;
  border-radius: 12px;
  border: 1px solid rgba(212, 175, 90, 0.22);
  background: rgba(8, 18, 14, 0.38);
}
.guide-badge {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-family: var(--display);
  font-size: 12px;
  font-weight: 700;
  color: #173328;
  background: linear-gradient(180deg, #f0d36a, #c9a44a);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.guide-copy b {
  display: block;
  font-family: var(--display);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold-2);
  margin-bottom: 4px;
}
.guide-copy p {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}
.guide-replay {
  width: 100%;
  margin-top: 14px;
  padding: 11px 14px;
  border-radius: 999px;
  border: 1px solid rgba(212, 175, 90, 0.55);
  background: linear-gradient(180deg, rgba(36, 68, 52, 0.95), rgba(22, 44, 34, 0.95));
  color: var(--gold-2);
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.guide-replay:hover {
  border-color: var(--gold);
  box-shadow: 0 0 14px rgba(240, 211, 106, 0.18);
  transform: translateY(-1px);
}

.menu-settings .audio-row { margin: 0; }

.menu-audio {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid rgba(212, 175, 90, 0.35);
  background: rgba(8, 18, 14, 0.45);
}
.audio-row {
  display: grid;
  grid-template-columns: 36px 1fr 46px;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(212, 175, 90, 0.28);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(24, 46, 36, 0.92), rgba(14, 28, 22, 0.92));
  color: var(--cream);
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: border-color 0.15s, opacity 0.15s, filter 0.15s;
}
.audio-row:hover { border-color: rgba(212, 175, 90, 0.55); }
.audio-row.is-off { opacity: 0.62; filter: saturate(0.35); }
.audio-label { font-size: 14px; font-weight: 700; letter-spacing: 0.02em; }
.audio-ico {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 236, 190, 0.35), rgba(18, 38, 28, 0.2));
  border: 1px solid rgba(212, 175, 90, 0.45);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 18px 18px;
}
.audio-ico-music {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23f4d78a'%3E%3Cpath d='M12 3v10.55A4 4 0 1 0 14 17V7h4V3h-6z'/%3E%3C/svg%3E");
}
.audio-ico-guide {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23f4d78a'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16l4-2 4 2 4-2 4 2V8l-6-6zm-1 2 5 5h-5V4zM8 12h8v2H8v-2zm0 4h6v2H8v-2z'/%3E%3C/svg%3E");
}
.audio-ico-sfx {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23f4d78a'%3E%3Cpath d='M3 10v4h4l5 5V5L7 10H3zm13.5 2a4.5 4.5 0 0 0-2.5-4.03v8.05a4.48 4.48 0 0 0 2.5-4.02z'/%3E%3C/svg%3E");
}
.audio-row.is-off .audio-ico-music {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%238a9a90'%3E%3Cpath d='M12 3v10.55A4 4 0 1 0 14 17V7h4V3h-6z'/%3E%3Cpath d='M2 2l20 20' stroke='%238a9a90' stroke-width='2'/%3E%3C/svg%3E");
}
.audio-row.is-off .audio-ico-sfx {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%238a9a90'%3E%3Cpath d='M3 10v4h4l5 5V5L7 10H3zm13.5 2a4.5 4.5 0 0 0-2.5-4.03v8.05a4.48 4.48 0 0 0 2.5-4.02z'/%3E%3Cpath d='M2 2l20 20' stroke='%238a9a90' stroke-width='2'/%3E%3C/svg%3E");
}
.audio-switch {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: rgba(40, 52, 46, 0.95);
  border: 1px solid rgba(120, 130, 120, 0.55);
  justify-self: end;
}
.audio-row.is-on .audio-switch {
  background: linear-gradient(180deg, #3ecf7a, #249a55);
  border-color: rgba(170, 255, 200, 0.45);
}
.audio-switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #d8dde0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.18s ease;
}
.audio-row.is-on .audio-switch-knob { transform: translateX(20px); }

.level-up-card h3 {
  font-size: clamp(22px, 4vw, 28px);
  color: var(--gold);
  margin-bottom: 8px;
}

#hud-bottom {
  left: 50%;
  right: auto;
  bottom: calc(var(--pad) + var(--safe-b));
  transform: translateX(-50%);
  width: max-content;
  max-width: min(520px, calc(100vw - 140px - var(--safe-l) - var(--safe-r)));
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05) 0%, transparent 36%),
    linear-gradient(165deg, rgba(18, 36, 28, 0.96) 0%, rgba(8, 18, 14, 0.98) 100%);
  border: 2px solid rgba(212, 175, 90, 0.45);
  border-radius: 18px;
  padding: 8px 12px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35) inset,
    0 10px 28px rgba(0, 0, 0, 0.4);
  z-index: 5;
}
#item-info {
  flex: 0 1 auto;
  min-width: 0;
  max-width: min(320px, 42vw);
}
#info-title {
  font-family: "Cinzel", var(--display);
  font-size: clamp(11px, 1.1vw, 14px);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold-2);
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.25;
}
#info-sub {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.25;
}
.hud-actions { display: flex; gap: 6px; flex-shrink: 0; }

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 52px;
  padding: 6px 8px;
  border-radius: 14px;
  border: 2px solid rgba(212, 175, 90, 0.35);
  background: rgba(8, 18, 14, 0.72);
  font-family: "Cinzel", var(--display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cream);
  transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease;
}
.action-btn img {
  display: block;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}
.action-btn:hover:not(:disabled) { transform: scale(1.05); border-color: var(--gold); }
.action-btn:active:not(:disabled) { transform: scale(0.96); }
.action-trash:not(:disabled) { border-color: rgba(200, 90, 90, 0.55); background: rgba(60, 20, 20, 0.55); }
.action-collect:not(:disabled) { border-color: rgba(212, 175, 90, 0.65); background: linear-gradient(180deg, rgba(201, 164, 74, 0.25), rgba(120, 90, 30, 0.2)); }
.action-collect.ready:not(:disabled) {
  animation: readyPulse 1.6s ease-in-out infinite;
  border-color: #f0d48a;
}

button {
  font-family: var(--display);
  background: var(--green);
  color: var(--gold-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--green-2); }
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { opacity: 0.38; cursor: not-allowed; }
button.ghost, .btn-ghost {
  background: transparent;
  color: var(--cream);
  border-color: var(--line-dim);
}
.btn-gold { background: linear-gradient(180deg, #c9a44a, #9a7428); color: #1a1408; border-color: #f0d48a; }
.btn-gold.ready:not(:disabled) { animation: readyPulse 1.6s ease-in-out infinite; }
.btn-danger { background: var(--danger); border-color: #c97a7a; }
.rail-btn.pulse,
.pill.pulse,
.hud-icon-btn.pulse,
#quest-tracker.pulse {
  animation: readyPulse 1.4s ease-in-out infinite;
  border-color: var(--gold);
}
@keyframes readyPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 211, 106, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(240, 211, 106, 0); }
}

#toasts {
  left: 50%;
  top: calc(var(--hud-h) + 14px + var(--safe-t));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  width: min(380px, calc(100% - 32px - var(--safe-l) - var(--safe-r)));
  max-width: calc(100vw - 32px);
  z-index: 7;
  padding: 0 8px;
  box-sizing: border-box;
}
.toast {
  background: linear-gradient(145deg, #1f3f31, #12261e);
  border: 1px solid #c9a44a;
  border-radius: 12px;
  padding: 8px 12px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  overflow-wrap: anywhere;
  word-break: break-word;
}

#tutorial-dim {
  inset: 0;
  z-index: 2;
  background: radial-gradient(ellipse at 50% 42%, transparent 0 36%, rgba(6, 12, 10, 0.42) 100%);
  pointer-events: none;
}
#tutorial-dim.hidden { display: none; }

#talk-box {
  left: calc(58px + var(--safe-l));
  right: calc(58px + var(--safe-r));
  bottom: calc(var(--foot-h) + 18px + var(--safe-b));
  width: auto;
  max-width: min(480px, calc(100vw - 116px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: stretch;
  gap: 0;
  padding: 0;
  z-index: 6;
  border-radius: 20px;
  border: 3px solid #c9a44a;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12) 0%, transparent 28%),
    linear-gradient(165deg, #f8f2e4 0%, #efe6d4 48%, #e6dcc8 100%);
  box-shadow:
    0 0 0 1px rgba(90, 60, 20, 0.35) inset,
    0 0 0 5px rgba(18, 38, 30, 0.55),
    0 14px 36px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
#talk-box.hidden { display: none; }

.talk-portrait-wrap {
  padding: 10px 8px 10px 12px;
  display: flex;
  align-items: center;
  background: linear-gradient(180deg, rgba(201, 164, 74, 0.18), transparent);
  border-right: 1px solid rgba(180, 140, 60, 0.35);
}
.talk-portrait-img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid #d4af5a;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  object-fit: cover;
  background: #2a4a38;
}

.talk-body {
  padding: 10px 12px 10px 10px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.talk-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}
.talk-step {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #fff;
  background: linear-gradient(180deg, #3ecf7a, #1f7a45);
  padding: 2px 7px;
  border-radius: 99px;
  border: 1px solid rgba(255, 255, 255, 0.35);
}
.talk-speaker {
  font-family: "Cinzel", var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #6b4e14;
  text-transform: uppercase;
}
#talk-text {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(15px, 3.6vw, 17px);
  font-weight: 600;
  line-height: 1.35;
  color: #243028;
  margin: 0;
}
.talk-hint {
  font-size: 12px;
  font-weight: 700;
  color: #5a7248;
  margin: 0;
  font-style: italic;
}

.talk-next-btn {
  align-self: stretch;
  min-width: 72px;
  margin: 8px 10px 8px 0;
  padding: 10px 14px;
  border-radius: 14px;
  border: 2px solid #f0d48a;
  font-family: "Cinzel", var(--display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #fffef8;
  background: linear-gradient(180deg, #45d884 0%, #2a9f5a 55%, #1f7344 100%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  cursor: pointer;
}
.talk-next-btn:hover {
  background: linear-gradient(180deg, #58e894 0%, #34b068 55%, #258050 100%);
}
.talk-next-btn.hidden { display: none; }

/* Tutorial active: keep bottom chrome from stacking on mobile */
#app.has-tutorial #info-sub { display: none; }
#app.has-tutorial.drawer-open #talk-box { display: none; }
#app.has-tutorial #quest-tracker { z-index: 7; }
#app.has-tutorial #btn-energy.pulse,
#app.has-tutorial #quest-tracker.pulse,
#app.has-tutorial #btn-shop.pulse {
  z-index: 7;
  position: relative;
}

#modal {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(12px + var(--safe-t))
    calc(12px + var(--safe-r))
    calc(12px + var(--safe-b))
    calc(12px + var(--safe-l));
  background: rgba(8, 14, 11, 0.68);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
#modal.hidden { display: none; }
.premium-modal-card {
  position: relative;
  width: min(420px, 100%);
  animation: guide-pop 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.premium-modal-body {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}
.premium-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.premium-modal-actions.single { justify-content: center; }
.premium-modal-btn {
  min-width: 108px;
  padding: 10px 18px;
  border-radius: 999px;
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.premium-modal-btn.ghost {
  background: transparent;
  color: var(--cream);
  border: 1px solid rgba(212, 175, 90, 0.35);
}
.premium-modal-btn.ghost:hover {
  border-color: var(--gold);
  transform: translateY(-1px);
}
.premium-modal-btn.gold {
  background: linear-gradient(180deg, rgba(36, 68, 52, 0.98), rgba(22, 44, 34, 0.98));
  color: var(--gold-2);
  border: 1px solid rgba(212, 175, 90, 0.65);
  box-shadow: 0 0 0 1px rgba(255, 232, 160, 0.12) inset;
}
.premium-modal-btn.gold:hover:not(:disabled) {
  border-color: var(--gold);
  box-shadow: 0 0 14px rgba(240, 211, 106, 0.18);
  transform: translateY(-1px);
}
.premium-modal-btn.gold:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}
.premium-modal-lock {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  object-fit: contain;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
}
.premium-modal-body b {
  color: var(--gold-2);
  font-weight: 700;
}
.level-up-card .guide-kicker { color: rgba(180, 230, 200, 0.85); }

#splash {
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: calc(24px + var(--safe-b)) calc(16px + var(--safe-l)) calc(28px + var(--safe-b)) calc(16px + var(--safe-r));
  overflow: hidden;
  background: #1a3a2e;
}
#splash.hidden { display: none; }

.splash-bg {
  position: absolute;
  inset: -4%;
  background: url("../assets/splash-landscape.webp") center 42% / cover no-repeat;
  transform: scale(1.06);
  animation: splash-ken 28s ease-in-out infinite alternate;
}
.splash-overlay {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(8, 18, 14, 0.08) 0%, rgba(8, 18, 14, 0.05) 38%, rgba(8, 18, 14, 0.55) 72%, rgba(8, 18, 14, 0.88) 100%);
  pointer-events: none;
}
.splash-fx {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.splash-mist {
  position: absolute;
  left: -20%;
  width: 140%;
  height: 42%;
  opacity: 0.35;
  filter: blur(18px);
  background:
    radial-gradient(ellipse at 30% 60%, rgba(230, 245, 255, 0.45), transparent 62%),
    radial-gradient(ellipse at 70% 40%, rgba(200, 230, 220, 0.28), transparent 58%);
}
.splash-mist-a {
  bottom: 18%;
  animation: splash-mist-drift 22s ease-in-out infinite alternate;
}
.splash-mist-b {
  bottom: 8%;
  height: 28%;
  opacity: 0.22;
  animation: splash-mist-drift 30s ease-in-out infinite alternate-reverse;
}
.splash-snow,
.splash-motes {
  position: absolute;
  inset: 0;
}
.splash-snow span {
  position: absolute;
  top: -8%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, rgba(220, 240, 255, 0.75) 55%, rgba(200, 220, 240, 0.2) 100%);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.45);
  animation-name: splash-snow-fall;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  will-change: transform;
}
.splash-snow span:nth-child(3n) {
  border-radius: 2px;
  transform: rotate(18deg);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(210, 235, 255, 0.35));
  box-shadow: none;
}
.splash-motes span {
  position: absolute;
  bottom: -4%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 232, 160, 0.95) 0%, rgba(120, 220, 160, 0.45) 45%, transparent 72%);
  box-shadow: 0 0 10px rgba(255, 220, 120, 0.35);
  animation-name: splash-mote-rise;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  will-change: transform, opacity;
}

@keyframes splash-ken {
  from { transform: scale(1.05) translate3d(0, 0, 0); }
  to { transform: scale(1.1) translate3d(-1.4%, -1.2%, 0); }
}
@keyframes splash-mist-drift {
  from { transform: translate3d(-3%, 0, 0); }
  to { transform: translate3d(4%, -2%, 0); }
}
@keyframes splash-snow-fall {
  0% { transform: translate3d(0, -10vh, 0); }
  100% { transform: translate3d(var(--drift, 40px), 110vh, 0); }
}
@keyframes splash-mote-rise {
  0% { transform: translate3d(0, 0, 0) scale(0.6); opacity: 0; }
  15% { opacity: 0.85; }
  50% { transform: translate3d(var(--drift, 20px), -45vh, 0) scale(1); opacity: 0.7; }
  100% { transform: translate3d(calc(var(--drift, 20px) * -0.4), -95vh, 0) scale(0.4); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .splash-bg,
  .splash-mist,
  .splash-snow span,
  .splash-motes span {
    animation: none !important;
  }
  .splash-snow,
  .splash-motes { display: none; }
}

.splash-panel {
  position: relative;
  z-index: 1;
  width: min(400px, 100%);
  margin-top: 28px;
  padding: 34px 22px 26px;
  border-radius: 26px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(62, 120, 88, 0.18), transparent 55%),
    linear-gradient(165deg, #1a382c 0%, #142820 42%, #0f1e18 100%);
  border: 2px solid #d4af5a;
  box-shadow:
    0 0 0 1px rgba(255, 232, 160, 0.35) inset,
    0 0 0 4px rgba(12, 28, 22, 0.95),
    0 0 0 5px rgba(180, 140, 60, 0.45),
    0 22px 56px rgba(0, 0, 0, 0.55),
    0 0 40px rgba(76, 160, 110, 0.12);
}
.splash-ui-img {
  display: block;
  pointer-events: none;
  user-select: none;
  object-fit: contain;
}
.splash-crest {
  position: absolute;
  top: -38px;
  left: 50%;
  transform: translateX(-50%);
  width: 72px;
  height: 72px;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.45));
}
.splash-corner {
  position: absolute;
  width: 56px;
  height: 56px;
  opacity: 0.95;
}
.splash-corner-tl { top: 6px; left: 6px; }
.splash-corner-tr { top: 6px; right: 6px; transform: scaleX(-1); }
.splash-corner-bl { bottom: 6px; left: 6px; transform: scaleY(-1); }
.splash-corner-br { bottom: 6px; right: 6px; transform: scale(-1, -1); }
.splash-foot-gem {
  position: absolute;
  bottom: -14px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 24px;
  filter: drop-shadow(0 0 10px rgba(90, 230, 140, 0.45));
}
.splash-inner {
  position: relative;
  z-index: 1;
  text-align: center;
}

.splash-kicker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
  font-family: "Cinzel", var(--display);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 10px;
  font-weight: 700;
  color: #e7c56a;
}
.splash-kicker::before,
.splash-kicker::after {
  content: "";
  width: 32px;
  height: 1px;
  background: linear-gradient(90deg, transparent, #e7c56a 40%, #f7e7b0 100%);
  opacity: 0.85;
}
.splash-kicker::after {
  background: linear-gradient(270deg, transparent, #e7c56a 40%, #f7e7b0 100%);
}

.splash-inner h1 {
  font-family: "Cinzel", var(--display);
  font-size: clamp(34px, 8.5vw, 44px);
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.05;
  margin-bottom: 6px;
  color: #ffe8a8;
  text-shadow:
    0 1px 0 #6b4e14,
    0 2px 0 #5a4210,
    0 3px 0 #4a3810,
    0 4px 0 #3a2808,
    0 6px 16px rgba(0, 0, 0, 0.55),
    0 0 28px rgba(240, 211, 106, 0.22);
}

.splash-leaf {
  width: 28px;
  height: 28px;
  margin: 0 auto 12px;
  filter: drop-shadow(0 0 8px rgba(90, 230, 140, 0.35));
}

.splash-copy {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(16px, 3.8vw, 19px);
  font-weight: 600;
  line-height: 1.45;
  color: #eef4ef;
  margin-bottom: 22px;
  padding: 0 6px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.splash-copy em {
  font-style: italic;
  color: #f7e7b0;
  font-weight: 700;
}

.splash-primary-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-bottom: 12px;
}
.splash-btn-leaf {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  opacity: 0.95;
}
.splash-btn-leaf-r { transform: scaleX(-1); }

.splash-btn-primary {
  flex: 1;
  min-width: 0;
  max-width: 280px;
  font-family: "Cinzel", var(--display);
  font-size: clamp(15px, 3.6vw, 17px);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 14px 20px;
  border-radius: 999px;
  border: 2px solid #f0d48a;
  color: #fffef8;
  background:
    radial-gradient(ellipse at 50% 28%, rgba(255, 255, 255, 0.22) 0%, transparent 52%),
    radial-gradient(ellipse at 50% 120%, rgba(0, 0, 0, 0.28), transparent 55%),
    linear-gradient(180deg, #4fe090 0%, #2db868 38%, #1a7a45 72%, #145a34 100%);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.14) inset,
    0 0 0 3px rgba(180, 140, 60, 0.35),
    0 8px 22px rgba(0, 0, 0, 0.38),
    0 0 26px rgba(62, 207, 122, 0.28);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.splash-btn-primary:hover {
  background:
    radial-gradient(ellipse at 50% 28%, rgba(255, 255, 255, 0.28) 0%, transparent 52%),
    radial-gradient(ellipse at 50% 120%, rgba(0, 0, 0, 0.22), transparent 55%),
    linear-gradient(180deg, #62f0a0 0%, #38c878 38%, #228a52 72%, #186840 100%);
}

.splash-btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 56%;
  font-family: "Cinzel", var(--display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid rgba(212, 175, 90, 0.55);
  color: #d8e4dc;
  background: rgba(6, 14, 10, 0.72);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
}
.splash-btn-secondary:hover {
  color: #f7e7b0;
  border-color: #e7c56a;
  background: rgba(12, 26, 20, 0.88);
}
.splash-diamond {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  opacity: 0.9;
}

@media (min-width: 700px) {
  #splash {
    align-items: center;
    padding-bottom: calc(40px + var(--safe-b));
  }
  .splash-bg { background-position: center center; }
  .splash-panel { margin-top: 36px; }
  .splash-snow span { opacity: 0.85; }
}

@media (max-width: 1100px) {
  .pill-val { font-size: 12px; }
  .pill-ico, .ico { width: 20px; height: 20px; }
}

/* Tablet + large phones */
@media (max-width: 860px) {
  :root {
    --hud-h: 48px;
    --foot-h: 96px;
    --rail-clear: 58px;
  }
  .profile-pill { width: 40px; height: 40px; }
  .hud-icon-btn { width: 38px; height: 38px; padding: 5px; }
  .hud-pills {
    justify-content: flex-start;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(90deg, #000 0%, #000 92%, transparent 100%);
  }
  .pill { padding: 3px 8px 3px 4px; height: 30px; min-height: 30px; gap: 4px; }
  .pill-res .hud-ico { width: 18px; height: 18px; }
  .pill-energy { min-width: 70px; }
  .pill-bar { bottom: 3px; height: 2px; left: 8px; right: 8px; }
  .pill-val { font-size: 11px; }
  #quest-tracker {
    top: calc(var(--hud-h) + 12px + var(--safe-t));
    width: 118px;
    padding: 6px 7px;
  }
  .quest-tracker-icon { width: 28px; height: 28px; }
  .quest-tracker-title { font-size: 10px; }
  #rail-left, #rail-right {
    flex-direction: row;
    bottom: calc(var(--foot-h) + 8px + var(--safe-b));
    z-index: 4;
  }
  #rail-left { left: calc(10px + var(--safe-l)); }
  #rail-right { right: calc(10px + var(--safe-r)); }
  .rail-btn { width: 46px; height: 46px; padding: 7px; }
  .rail-ico-img { width: 28px; height: 28px; }
  .drawer, .drawer-right {
    left: calc(10px + var(--safe-l));
    right: calc(10px + var(--safe-r));
    width: auto;
    top: auto;
    bottom: calc(var(--foot-h) + var(--rail-clear) + 12px + var(--safe-b));
    max-height: min(46vh, calc(100dvh - var(--hud-h) - var(--foot-h) - var(--rail-clear) - 48px));
    transform: translateY(120%);
  }
  .drawer.open { transform: none; }
  #hud-bottom {
    left: 50%;
    right: auto;
    width: max-content;
    max-width: calc(100vw - 24px - var(--safe-l) - var(--safe-r));
    transform: translateX(-50%);
  }
  #talk-box {
    left: calc(10px + var(--safe-l));
    right: calc(10px + var(--safe-r));
    width: auto;
    max-width: none;
    transform: none;
    bottom: calc(var(--foot-h) + var(--rail-clear) + 12px + var(--safe-b));
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
  }
  .talk-next-btn {
    grid-column: 1 / -1;
    margin: 0 10px 10px;
    min-height: 44px;
  }
  .talk-portrait-img { width: 48px; height: 48px; }
  #app.has-tutorial #hud-bottom {
    min-height: 44px;
    padding: 6px 10px;
  }
  #app.has-tutorial #rail-left,
  #app.has-tutorial #rail-right {
    opacity: 0.4;
    pointer-events: none;
  }
  #talk-text { font-size: 14px; }
  .splash-panel { padding: 30px 16px 22px; margin-top: 32px; max-height: none; }
  .splash-crest { width: 64px; height: 64px; top: -34px; }
  .splash-corner { width: 44px; height: 44px; }
  .splash-btn-leaf { width: 28px; height: 28px; }
}

/* Phones — keep all resource pills visible */
@media (max-width: 430px) {
  :root { --hud-h: 44px; }
  #hud-top { gap: 4px; }
  .profile-pill { width: 36px; height: 36px; }
  .profile-level { min-width: 18px; height: 18px; line-height: 18px; font-size: 10px; }
  .hud-icon-btn { width: 34px; height: 34px; padding: 4px; }
  .hud-icon-btn .hud-ico { width: 22px; height: 22px; }
  .hud-pills {
    gap: 3px;
    mask-image: none;
    overflow-x: visible;
    flex-wrap: nowrap;
    justify-content: space-between;
  }
  .pill {
    flex: 1 1 0;
    min-width: 0;
    max-width: none;
    padding: 2px 5px 2px 3px;
    height: 28px;
    min-height: 28px;
    gap: 3px;
    justify-content: center;
  }
  .pill-res .hud-ico { width: 15px; height: 15px; }
  .pill-energy { min-width: 0; flex: 1.35 1 0; }
  .pill-energy .hud-ico,
  .pill-energy .pill-val { margin-bottom: 2px; }
  .pill-val {
    font-size: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }
  .pill-bar { left: 5px; right: 5px; bottom: 2px; }
}

/* Tall stacked bottom bar on small phones */
@media (max-width: 700px) {
  :root {
    --foot-h: 118px;
    --rail-clear: 54px;
  }
  #hud-bottom {
    flex-direction: column;
    align-items: stretch;
    width: calc(100vw - 20px - var(--safe-l) - var(--safe-r));
    max-width: none;
    gap: 8px;
    padding: 8px 10px;
  }
  #item-info { max-width: none; text-align: center; }
  #info-title, #info-sub {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
  }
  #info-title { font-size: 12px; }
  #info-sub { font-size: 12px; line-height: 1.25; }
  .hud-actions { width: 100%; justify-content: stretch; }
  .hud-actions .action-btn { flex: 1; min-width: 0; }
  .action-btn span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }
  #toasts { width: calc(100% - 24px); }
}

/* Narrow + short splash (small phones / landscape phone) */
@media (max-width: 860px) and (max-height: 720px) {
  #splash {
    align-items: center;
    padding: calc(10px + var(--safe-t)) calc(10px + var(--safe-l)) calc(12px + var(--safe-b)) calc(10px + var(--safe-r));
  }
  .splash-panel {
    margin-top: 12px;
    padding: 48px 14px 16px;
    width: min(400px, 100%);
    max-height: calc(100dvh - 24px - var(--safe-t) - var(--safe-b));
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  .splash-crest { width: 52px; height: 52px; top: 8px; }
  .splash-inner h1 { font-size: clamp(28px, 7vw, 36px); margin-bottom: 4px; }
  .splash-copy { margin-bottom: 14px; font-size: 15px; }
  .splash-kicker { margin-bottom: 6px; }
  .splash-leaf { margin-bottom: 8px; }
  .splash-btn-primary { padding: 12px 16px; }
  .splash-corner { width: 36px; height: 36px; }
}

@media (max-width: 360px) {
  .splash-btn-leaf { display: none; }
  .splash-primary-row { gap: 0; }
  .splash-copy { padding: 0; }
  .guide-deco { width: 32px; height: 32px; }
  .guide-modal-card { width: 100%; }
}

/* Landscape phones: keep HUD usable */
@media (max-height: 480px) and (orientation: landscape) {
  :root {
    --hud-h: 40px;
    --foot-h: 68px;
    --rail-clear: 0px;
  }
  #hud-top { gap: 6px; }
  .hud-pills { overflow-x: auto; mask-image: none; }
  .pill { flex: 0 0 auto; }
  #hud-bottom {
    flex-direction: row;
    width: max-content;
    max-width: calc(100vw - 120px);
    min-height: 48px;
    gap: 10px;
  }
  #item-info { max-width: 180px; text-align: left; }
  #info-title, #info-sub {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .hud-actions { width: auto; }
  .hud-actions .action-btn { flex: 0 0 auto; }
  #rail-left, #rail-right {
    flex-direction: column;
    bottom: calc(var(--foot-h) + 8px + var(--safe-b));
  }
  #talk-box {
    top: calc(var(--hud-h) + 8px + var(--safe-t));
    bottom: auto !important;
    left: 50% !important;
    right: auto !important;
    width: min(560px, calc(100vw - 128px)) !important;
    max-width: min(560px, calc(100vw - 128px)) !important;
    transform: translateX(-50%) !important;
    max-height: calc(100dvh - var(--hud-h) - var(--foot-h) - 24px);
    overflow: auto;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto;
  }
  .talk-next-btn {
    grid-column: auto;
    margin: 8px 10px 8px 0;
    min-height: 40px;
    align-self: center;
  }
  #app.has-tutorial #rail-left,
  #app.has-tutorial #rail-right {
    opacity: 0.35;
    pointer-events: none;
  }
  #splash {
    align-items: center;
    padding: 8px;
  }
  .splash-panel {
    margin-top: 24px;
    max-height: calc(100dvh - 16px);
    overflow: auto;
    padding: 22px 14px 14px;
  }
  .splash-fx { opacity: 0.55; }
}

/* Desktop: keep talk clear of bottom bar */
@media (min-width: 861px) {
  :root {
    --foot-h: 80px;
    --rail-clear: 0px;
  }
  #talk-box {
    bottom: calc(var(--foot-h) + 16px + var(--safe-b));
  }
  #app.has-tutorial #talk-box {
    bottom: calc(var(--foot-h) + 16px + var(--safe-b));
  }
}
