/* ── Variables ── */
:root {
  --bg: #0d0d1a;
  --surface: #141428;
  --surface2: #1c1c35;
  --border: rgba(200,169,126,0.18);
  --gold: #c8a97e;
  --gold-bright: #e8c99e;
  --gold-dim: #8a6f50;
  --text: #e8e4dc;
  --text-dim: #8a8678;
  --green: #6fcf97;
  --radius: 16px;
  --panel-bg: rgba(14,14,28,0.97);
  --font-body: 'Outfit', sans-serif;
  --font-display: 'Playfair Display', serif;
}

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

body {
  background: var(--bg);
  font-family: var(--font-body);
  color: var(--text);
  overflow: hidden;
  height: 100dvh;
  width: 100vw;
  touch-action: none;
}

/* ── Map ── */
#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  filter: brightness(0.7) saturate(0.5) hue-rotate(200deg);
}

/* Leaflet dark override */
.leaflet-tile {
  filter: invert(1) hue-rotate(180deg) brightness(0.85) saturate(0.6);
}

/* ── HUD ── */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: linear-gradient(to bottom, rgba(13,13,26,0.95) 60%, transparent);
  pointer-events: none;
}

#game-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 6px;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(200,169,126,0.5);
}

#token-display {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(200,169,126,0.1);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  pointer-events: all;
}
.token-icon { color: var(--gold); font-size: 15px; }
#token-count { font-weight: 700; color: var(--gold-bright); font-size: 15px; }
.token-label { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }

#status-display {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text-dim);
  pointer-events: all;
}
#status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%,100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── D-pad ── */
#dpad {
  position: fixed;
  bottom: 36px;
  right: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  user-select: none;
}
.dpad-row {
  display: flex;
  align-items: center;
  gap: 3px;
}
.dpad-btn {
  width: 52px; height: 52px;
  background: rgba(200,169,126,0.12);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  color: var(--gold);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, transform 0.1s;
  backdrop-filter: blur(8px);
}
.dpad-btn:active, .dpad-btn.pressed {
  background: rgba(200,169,126,0.3);
  transform: scale(0.92);
}
.dpad-center {
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  color: var(--gold-dim);
  font-size: 22px;
  font-weight: 300;
}

/* ── Panels ── */
.panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 200;
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 20px 32px;
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  backdrop-filter: blur(20px);
  max-height: 70dvh;
  overflow-y: auto;
}
.panel.hidden {
  transform: translateY(110%);
  pointer-events: none;
}

/* ── Interaction Panel ── */
.panel-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
#sim-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}
#sim-avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--surface2);
  border: 2px solid var(--gold-dim);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
}
#sim-online-dot {
  position: absolute;
  bottom: 1px; right: 1px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--green);
  border: 2px solid var(--panel-bg);
  box-shadow: 0 0 5px var(--green);
}
#sim-name {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
#sim-trait {
  font-size: 12px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}
#close-panel, #close-gift {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}

/* Relationship bar */
#sim-relationship-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.rel-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
}
#sim-relationship-bar {
  flex: 1;
  height: 6px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
}
#sim-relationship-fill {
  height: 100%;
  background: linear-gradient(to right, var(--gold-dim), var(--gold-bright));
  border-radius: 999px;
  transition: width 0.5s ease;
  width: 5%;
}
#rel-tier-label {
  font-size: 11px;
  color: var(--gold);
  white-space: nowrap;
  min-width: 70px;
  text-align: right;
}

/* Chat */
#chat-window {
  background: var(--surface);
  border-radius: 12px;
  padding: 12px;
  min-height: 120px;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg {
  font-size: 14px;
  line-height: 1.5;
  animation: fadeUp 0.3s ease;
}
.chat-msg.sim {
  color: var(--text);
}
.chat-msg.player {
  color: var(--gold);
  text-align: right;
}
.chat-msg.system {
  color: var(--text-dim);
  font-size: 11px;
  text-align: center;
  font-style: italic;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
#chat-input-wrap {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
#chat-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
}
#chat-input:focus { border-color: var(--gold-dim); }
#chat-send {
  background: var(--gold);
  border: none;
  border-radius: 10px;
  color: var(--bg);
  font-size: 18px;
  font-weight: 700;
  padding: 0 18px;
  cursor: pointer;
  transition: background 0.15s;
}
#chat-send:hover { background: var(--gold-bright); }

/* Action buttons */
#panel-actions {
  display: flex;
  gap: 10px;
}
.action-btn {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.action-btn:hover, .action-btn:active {
  background: rgba(200,169,126,0.15);
  border-color: var(--gold-dim);
}

/* ── Walk Panel ── */
#walk-header {
  font-family: var(--font-display);
  font-size: 18px;
  text-align: center;
  margin-bottom: 20px;
  color: var(--gold);
}
#walk-header span { color: var(--text); }
#walk-distance-wrap {
  position: relative;
  width: 140px; height: 140px;
  margin: 0 auto 16px;
}
#walk-ring {
  width: 100%; height: 100%;
}
#walk-ring-fill {
  transition: stroke-dashoffset 0.5s ease;
}
#walk-distance-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#walk-meters {
  font-size: 28px;
  font-weight: 700;
  color: var(--gold-bright);
  font-family: var(--font-display);
}
#walk-meters-label {
  font-size: 12px;
  color: var(--text-dim);
}
#walk-reward-hint {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 16px;
}
#btn-end-walk {
  display: block;
  margin: 0 auto;
  width: 100%;
  max-width: 200px;
}

/* ── Token Popup ── */
#token-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  z-index: 500;
  background: var(--surface2);
  border: 1.5px solid var(--gold);
  border-radius: 20px;
  padding: 24px 36px;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  opacity: 0;
}
#token-popup.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  animation: popIn 2.5s ease forwards;
}
@keyframes popIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  25% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -58%) scale(0.95); }
}
.token-popup-icon { font-size: 36px; color: var(--gold); margin-bottom: 6px; }
.token-popup-text { font-size: 15px; color: var(--text); }

/* ── Gift Shop ── */
#gift-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
}
#gift-balance {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--gold);
  font-size: 14px;
  font-weight: 600;
}
#gift-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}
.gift-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.gift-item:hover { border-color: var(--gold-dim); background: rgba(200,169,126,0.08); }
.gift-emoji { font-size: 28px; display: block; margin-bottom: 6px; }
.gift-name { font-size: 12px; color: var(--text); margin-bottom: 4px; }
.gift-cost {
  font-size: 11px;
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 160px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 600;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
}
#toast.show { opacity: 1; }

/* ── Intro Overlay ── */
#intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(10,10,20,0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#intro-box {
  max-width: 360px;
  width: 100%;
  text-align: center;
}
#intro-logo {
  font-family: var(--font-display);
  font-size: 56px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 12px;
  text-shadow: 0 0 40px rgba(200,169,126,0.4);
  margin-bottom: 4px;
}
#intro-tagline {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 16px;
  color: var(--text-dim);
  margin-bottom: 20px;
}
#intro-box p {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 24px;
}
#intro-instructions {
  background: var(--surface);
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.intro-step {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text);
  text-align: left;
}
.intro-step span {
  font-size: 20px;
  width: 28px;
  flex-shrink: 0;
  text-align: center;
}
#intro-start {
  background: var(--gold);
  border: none;
  border-radius: 12px;
  color: var(--bg);
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 700;
  padding: 14px 40px;
  cursor: pointer;
  letter-spacing: 1px;
  width: 100%;
  transition: background 0.15s, transform 0.1s;
}
#intro-start:hover { background: var(--gold-bright); }
#intro-start:active { transform: scale(0.97); }

/* ── Leaflet marker override ── */
.sim-house-marker {
  background: none;
  border: none;
}
.sim-house-icon {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(200,169,126,0.15);
  border: 2px solid rgba(200,169,126,0.4);
  border-radius: 50%;
  font-size: 20px;
  transition: all 0.2s;
  cursor: pointer;
  position: relative;
}
.sim-house-icon.in-range {
  background: rgba(200,169,126,0.35);
  border-color: var(--gold);
  box-shadow: 0 0 16px rgba(200,169,126,0.5);
  animation: houseGlow 1.5s ease infinite alternate;
}
@keyframes houseGlow {
  from { box-shadow: 0 0 10px rgba(200,169,126,0.3); }
  to { box-shadow: 0 0 22px rgba(200,169,126,0.7); }
}
.sim-house-name {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 10px;
  font-family: 'Outfit', sans-serif;
  color: var(--gold);
  background: rgba(13,13,26,0.8);
  padding: 2px 6px;
  border-radius: 4px;
}

/* player marker */
.player-marker {
  background: none;
  border: none;
}
.player-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--gold-bright);
  border: 3px solid white;
  box-shadow: 0 0 0 4px rgba(200,169,126,0.3), 0 2px 8px rgba(0,0,0,0.4);
}

/* range circle */
.leaflet-interactive.range-circle {
  stroke: var(--gold) !important;
  fill: rgba(200,169,126,0.07) !important;
}

/* ── Shop Map Markers ── */
.shop-map-marker { background: none; border: none; }
.shop-icon-wrap {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(111,207,151,0.15);
  border: 2px solid rgba(111,207,151,0.35);
  border-radius: 50%;
  font-size: 17px;
  position: relative;
  cursor: pointer;
  transition: all 0.2s;
}
.shop-icon-wrap.in-range {
  background: rgba(111,207,151,0.35);
  border-color: var(--green);
  box-shadow: 0 0 14px rgba(111,207,151,0.5);
  animation: houseGlow 1.5s ease infinite alternate;
}
.shop-icon-name {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 10px;
  font-family: 'Outfit', sans-serif;
  color: var(--green);
  background: rgba(13,13,26,0.8);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ── Sim Walking State ── */
.sim-house-icon.sim-walking {
  animation: simWalk 0.45s ease-in-out infinite alternate;
  border-color: rgba(200,169,126,0.7);
  box-shadow: 0 0 12px rgba(200,169,126,0.4);
}
@keyframes simWalk {
  from { transform: translateY(0) rotate(-3deg); }
  to   { transform: translateY(-4px) rotate(3deg); }
}
.sim-house-icon.sim-at-dest::after {
  content: attr(data-dest-hint);
  position: absolute;
  top: -8px; right: -8px;
  font-size: 11px;
  background: rgba(13,13,26,0.85);
  border-radius: 4px;
  padding: 1px 3px;
}

/* ── Gift Bag Empty State ── */
.gift-empty-msg {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  padding: 28px 12px;
  line-height: 1.7;
}
.gift-give-label {
  color: var(--green) !important;
}

/* ── Shop Panel subtitle ── */
.shop-balance-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--gold);
  font-size: 14px;
  font-weight: 600;
}
.shop-subtitle {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

/* ── Typing Indicator ── */
.chat-msg.sim.typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 2px;
}
.chat-msg.sim.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: typingDot 1.2s ease-in-out infinite;
}
.chat-msg.sim.typing span:nth-child(1) { animation-delay: 0s; }
.chat-msg.sim.typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-msg.sim.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%, 60%, 100% { opacity: 0.2; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
