/* =============================================
   FarmBrawl — NPC Dialog + Don José Advisor
   Overrides juegoprueba.css #npc-panel styles.
   Do not edit juegoprueba.css (protected legacy).
   ============================================= */

:root {
  --npc-w: min(315px, calc(100vw - 36px));
  --npc-panel-bg: #14100c;
  --npc-panel-bg-2: #1f1812;
  --npc-ink: #0a0806;
  --npc-cream: #f5e9cf;
  --npc-gold: #f0c14b;
  --npc-gold-bright: #ffe08a;
  --npc-gold-dim: #b88918;
  --npc-muted: #9a8874;
  --npc-text: #ebe0ce;
  --npc-speech: #17120e;
  --npc-green: #5dcc6a;
  --npc-red: #ef6b6b;
  --npc-blue: #5ec8e8;
}

/* ── Panel shell ── */
#npc-panel {
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom, 0px));
  left: calc(var(--sidebar-w, 180px) + 10px);
  right: auto;
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  width: var(--npc-w);
  max-width: min(315px, calc(100vw - 24px));
  max-height: min(72vh, 555px);
  padding: 0;
  overflow: hidden;
  flex-wrap: nowrap;
  border: none;
  border-radius: 4px;
  background:
    radial-gradient(ellipse 120% 60% at 10% -10%, rgba(240, 193, 75, 0.14), transparent 55%),
    radial-gradient(ellipse 80% 50% at 100% 100%, rgba(93, 204, 106, 0.06), transparent 50%),
    linear-gradient(165deg, var(--npc-panel-bg-2) 0%, var(--npc-panel-bg) 55%, #100c09 100%);
  box-shadow:
    0 0 0 2px var(--npc-gold-dim),
    0 0 0 4px var(--npc-ink),
    0 0 0 5px rgba(240, 193, 75, 0.25),
    0 10px 0 3px rgba(0, 0, 0, 0.28),
    0 20px 36px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
  transition:
    transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.22s ease;
  pointer-events: auto;
}

#npc-panel::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(240, 193, 75, 0.16);
  border-radius: 2px;
  pointer-events: none;
  z-index: 1;
}

#npc-panel::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--npc-gold), var(--npc-gold-bright), var(--npc-gold), transparent);
  opacity: 0.85;
  z-index: 3;
  pointer-events: none;
}

#npc-panel.npc-panel-hidden {
  transform: translateY(32px) scale(0.97);
  opacity: 0;
  pointer-events: none;
}

#npc-panel.npc-panel-active {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* Advisor mode: compact & proportioned */
#npc-panel.npc-panel--advisor {
  max-height: min(72vh, 555px);
}

/* ── Header ── */
#npc-header {
  position: relative;
  z-index: 10;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 48px 1fr 26px;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  background:
    linear-gradient(180deg, rgba(240, 193, 75, 0.18) 0%, rgba(240, 193, 75, 0.04) 100%);
  border-bottom: 2px solid rgba(240, 193, 75, 0.28);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.4);
}

#npc-avatar {
  position: relative;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px solid var(--npc-gold);
  border-radius: 4px;
  background:
    radial-gradient(circle at 50% 25%, #4a3a28 0%, #120e0b 72%);
  box-shadow:
    0 0 0 1px var(--npc-ink),
    0 0 12px rgba(240, 193, 75, 0.2),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  image-rendering: pixelated;
}

#npc-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  transform: scale(1.15);
}

.npc-status-dot {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--npc-green);
  border: 1px solid var(--npc-ink);
  box-shadow: 0 0 6px rgba(93, 204, 106, 0.7);
  animation: npc-pulse 2s ease-in-out infinite;
}

@keyframes npc-pulse {
  0%, 100% { box-shadow: 0 0 4px rgba(93, 204, 106, 0.5); }
  50% { box-shadow: 0 0 10px rgba(93, 204, 106, 0.95); }
}

#npc-title {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 3px;
}

#npc-name {
  display: block;
  font-family: var(--font-game, "Press Start 2P", monospace);
  font-size: 9px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.02em;
  color: var(--npc-gold-bright);
  text-shadow: 1px 1px 0 var(--npc-ink), 0 0 10px rgba(240, 193, 75, 0.35);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

#npc-role {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 2px 6px;
  font-family: var(--font-ui, Nunito, sans-serif);
  font-size: 8.5px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #1a1410;
  background: linear-gradient(180deg, #ffe08a 0%, #d4a017 100%);
  border: 1px solid #8a6810;
  box-shadow: 1px 1px 0 var(--npc-ink), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.npc-wallet-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  max-width: 100%;
  margin-top: 1px;
  padding: 1px 6px;
  font-family: var(--font-ui, Nunito, sans-serif);
  font-size: 8.5px;
  font-weight: 700;
  color: var(--npc-muted);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(154, 136, 116, 0.35);
  border-radius: 99px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.npc-wallet-badge--on {
  color: #b8f5c0;
  border-color: rgba(93, 204, 106, 0.45);
  background: rgba(30, 80, 40, 0.35);
}

.npc-wallet-badge--guest {
  color: #f0d080;
  border-color: rgba(240, 193, 75, 0.35);
  background: rgba(80, 60, 20, 0.35);
}

#npc-close {
  width: 26px !important;
  height: 26px !important;
  min-width: 26px !important;
  min-height: 26px !important;
  max-width: 26px;
  max-height: 26px;
  flex: 0 0 26px;
  margin: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: start;
  background: linear-gradient(180deg, #5a3030 0%, #2e1414 100%);
  border: 1.5px solid #d46a6a;
  border-radius: 3px;
  color: #ffc4c4;
  font-family: var(--font-game, "Press Start 2P", monospace);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 1px 1px 0 var(--npc-ink);
  transition: transform 0.1s ease, filter 0.1s ease;
}

#npc-close:hover {
  filter: brightness(1.18);
  color: #fff;
  border-color: #ef8080;
}

#npc-close:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--npc-ink);
}

/* ── Body (scrollable) ── */
#npc-body {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 10px 12px;
  margin: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(240, 193, 75, 0.35) transparent;
}

#npc-body::-webkit-scrollbar { width: 5px; }
#npc-body::-webkit-scrollbar-thumb {
  background: rgba(240, 193, 75, 0.35);
  border-radius: 4px;
}

/* ── Stats grid ── */
/* === DONJOSE-FIT-FIX === */
.npc-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  flex: 0 0 auto;
  align-items: stretch;
}

.npc-stats[hidden] { display: none !important; }

.npc-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0 !important;
  min-height: 40px !important;
  margin: 0;
  padding: 5px 7px;
  box-sizing: border-box;
  text-align: left;
  cursor: pointer;
  border: 2px solid rgba(240, 193, 75, 0.22);
  border-radius: 4px;
  background:
    linear-gradient(145deg, rgba(50, 40, 28, 0.9) 0%, rgba(22, 16, 12, 0.95) 100%);
  box-shadow:
    0 2px 0 var(--npc-ink),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  color: var(--npc-cream);
  transition: transform 0.12s ease, border-color 0.12s ease, filter 0.12s ease;
}

.npc-stat:hover {
  border-color: var(--npc-gold);
  transform: translateY(-1px);
  filter: brightness(1.08);
  box-shadow: 0 4px 0 var(--npc-ink), 0 0 12px rgba(240, 193, 75, 0.12);
}

.npc-stat:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--npc-ink);
}

.npc-stat-ico {
  flex: 0 0 auto;
  font-size: 18px;
  line-height: 1;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.5));
}

/* === DONJOSE-FIT-FIX === */
.npc-stat-meta {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.npc-stat-label {
  font-family: var(--font-ui, Nunito, sans-serif);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--npc-muted);
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
}

.npc-stat-meta b {
  font-family: var(--font-ui, Nunito, sans-serif);
  font-size: clamp(0.72rem, 2.6vw, 0.95rem);
  font-weight: 800;
  color: var(--npc-cream);
  line-height: 1.2;
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
  max-width: 100%;
}

.npc-stat--urgent {
  border-color: rgba(239, 107, 107, 0.55);
  background: linear-gradient(145deg, rgba(80, 28, 28, 0.85), rgba(28, 12, 12, 0.95));
  animation: npc-urgent-glow 1.6s ease-in-out infinite;
}

.npc-stat--urgent .npc-stat-label { color: #f5b0b0; }
.npc-stat--urgent .npc-stat-meta b { color: #ffc9c9; }

.npc-stat--ok {
  border-color: rgba(93, 204, 106, 0.5);
  background: linear-gradient(145deg, rgba(28, 70, 36, 0.75), rgba(14, 28, 16, 0.95));
}

.npc-stat--ok .npc-stat-label { color: #9de0a6; }
.npc-stat--ok .npc-stat-meta b { color: #b8f5c0; }

@keyframes npc-urgent-glow {
  0%, 100% { box-shadow: 0 3px 0 var(--npc-ink); }
  50% { box-shadow: 0 3px 0 var(--npc-ink), 0 0 14px rgba(239, 107, 107, 0.35); }
}

/* ── Recommendation strip ── */
.npc-rec {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border: 1.5px solid rgba(93, 204, 106, 0.4);
  border-radius: 4px;
  background:
    linear-gradient(100deg, rgba(36, 70, 40, 0.55) 0%, rgba(20, 28, 16, 0.9) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 2px 0 rgba(0, 0, 0, 0.25);
  flex: 0 0 auto;
}

.npc-rec[hidden] { display: none !important; }

.npc-rec-ico {
  font-size: 16px;
  line-height: 1;
  flex: 0 0 auto;
}

.npc-rec-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.npc-rec-label {
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8fd99a;
}

.npc-rec-body b {
  font-family: var(--font-ui, Nunito, sans-serif);
  font-size: 11px;
  font-weight: 800;
  color: #e8ffe8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.npc-rec-btn {
  flex: 0 0 auto;
  min-width: 0 !important;
  min-height: 26px !important;
  margin: 0;
  padding: 3px 8px;
  font-family: var(--font-ui, Nunito, sans-serif);
  font-size: 9.5px;
  font-weight: 800;
  color: #1a1410;
  cursor: pointer;
  border: 1.5px solid #3f6f29;
  border-radius: 3px;
  background: linear-gradient(180deg, #7ed957 0%, #4caf3a 100%);
  box-shadow: 0 2px 0 #1e3a12;
  transition: transform 0.1s ease, filter 0.1s ease;
}

.npc-rec-btn:hover { filter: brightness(1.1); }
.npc-rec-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #1e3a12;
}

/* ── Dialogue bubble ── */
#npc-dialogue {
  position: relative;
  margin: 0;
  padding: 8px 10px 8px 12px;
  background:
    linear-gradient(180deg, #1e1813 0%, var(--npc-speech) 100%);
  border: 1.5px solid rgba(240, 193, 75, 0.38);
  border-left: 3.5px solid var(--npc-gold);
  border-radius: 2px;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.4),
    0 2px 0 rgba(0, 0, 0, 0.25);
  flex: 0 0 auto;
}

#npc-dialogue::before {
  content: "“";
  position: absolute;
  top: -2px;
  left: 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  line-height: 1;
  color: rgba(240, 193, 75, 0.28);
  pointer-events: none;
}

#npc-text {
  margin: 0;
  font-family: var(--font-ui, Nunito, sans-serif);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.38;
  color: var(--npc-text);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.55);
}

#npc-text strong {
  color: var(--npc-gold-bright);
  font-weight: 800;
}

#npc-text i,
#npc-text .fa-solid {
  color: var(--npc-gold);
}

.npc-text-pop {
  animation: npc-text-pop 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes npc-text-pop {
  0% { opacity: 0.35; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ── Topic choices ── */
#npc-choices {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin: 0;
  flex: 0 0 auto;
}

#npc-panel.npc-panel-active #npc-choices,
#npc-choices[style*="flex"],
#npc-choices[style*="grid"] {
  display: grid !important;
}

#npc-choices:empty {
  display: none !important;
}

#npc-choices button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
  width: 100%;
  min-width: 0 !important;
  min-height: 28px !important;
  margin: 0;
  padding: 4px 6px;
  background: linear-gradient(180deg, #3d2f22 0%, #231910 100%);
  border: 1.5px solid var(--npc-gold-dim);
  border-radius: 3px;
  color: var(--npc-cream);
  font-family: var(--font-ui, Nunito, sans-serif);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-align: left;
  text-transform: none;
  cursor: pointer;
  box-shadow:
    0 1.5px 0 var(--npc-ink),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: transform 0.1s ease, filter 0.1s ease, background 0.12s ease, border-color 0.12s ease;
}

#npc-choices button .npc-choice-ico {
  flex: 0 0 auto;
  width: 1.15em;
  text-align: center;
  font-size: 11px;
  line-height: 1;
}

#npc-choices button .npc-choice-lab {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#npc-choices button:hover {
  background: linear-gradient(180deg, #f0c14b 0%, #d4a017 100%);
  border-color: #f6d36a;
  color: #1a1410;
  transform: translateY(-1px);
  box-shadow: 0 3px 0 #5a4308;
}

#npc-choices button:active {
  transform: translateY(1.5px);
  box-shadow: 0 1px 0 var(--npc-ink);
}

#npc-choices button[data-topic="__bye"],
#npc-choices button.npc-choice-bye {
  grid-column: 1 / -1;
  justify-content: center;
  background: linear-gradient(180deg, #2a221c 0%, #18130f 100%);
  border-color: rgba(154, 136, 116, 0.5);
  color: var(--npc-muted);
}

#npc-choices button[data-topic="__bye"]:hover,
#npc-choices button.npc-choice-bye:hover {
  background: linear-gradient(180deg, #4a3a30 0%, #2a2018 100%);
  border-color: var(--npc-muted);
  color: var(--npc-cream);
  box-shadow: 0 3px 0 var(--npc-ink);
}

/* ── Input ── */
#npc-input-wrap {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin: 0;
  border: 1.5px solid rgba(240, 193, 75, 0.42);
  border-radius: 3px;
  background: #0b0907;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.5),
    0 1.5px 0 rgba(0, 0, 0, 0.25);
  flex: 0 0 auto;
}

#npc-input-wrap:focus-within {
  border-color: var(--npc-gold);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.5),
    0 0 0 2px rgba(240, 193, 75, 0.2);
}

#npc-input {
  display: none;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0 !important;
  min-height: 32px !important;
  margin: 0;
  box-sizing: border-box;
  padding: 6px 8px;
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--npc-text);
  font-family: var(--font-ui, Nunito, sans-serif);
  font-size: 11px;
  font-weight: 700;
  caret-color: var(--npc-gold);
  box-shadow: none;
  outline: none;
}

#npc-panel.npc-panel-active #npc-input,
#npc-input[style*="block"] {
  display: block !important;
}

#npc-input::placeholder {
  color: var(--npc-muted);
  opacity: 1;
  font-style: normal;
  font-weight: 600;
}

#npc-input-hint {
  display: none;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 0 10px;
  font-family: var(--font-game, "Press Start 2P", monospace);
  font-size: 8px;
  letter-spacing: 0.04em;
  color: rgba(240, 193, 75, 0.55);
  border-left: 1px solid rgba(240, 193, 75, 0.22);
  background: rgba(240, 193, 75, 0.06);
  user-select: none;
  pointer-events: none;
}

#npc-panel.npc-panel-active #npc-input-hint {
  display: inline-flex;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  #npc-panel {
    left: 56px;
    right: 10px;
    width: auto;
    max-width: none;
  }

  #npc-header {
    grid-template-columns: 52px 1fr 30px;
    gap: 10px;
    padding: 12px;
  }

  #npc-avatar {
    width: 52px;
    height: 52px;
  }

  #npc-name { font-size: 10px; }

  /* === DONJOSE-FIT-FIX === */
  .npc-stats { gap: 6px; align-items: stretch; }
  .npc-stat { min-height: 44px !important; padding: 6px 8px; min-width: 0 !important; box-sizing: border-box; }
  .npc-stat-meta b { font-size: clamp(0.72rem, 2.6vw, 0.95rem); line-height: 1.2; white-space: normal; overflow-wrap: break-word; }
}

@media (max-width: 480px) {
  #npc-panel {
    left: 8px;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    max-height: min(72vh, 560px);
  }

  /* === DONJOSE-FIT-FIX === */
  .npc-stats { grid-template-columns: 1fr 1fr; align-items: stretch; }

  #npc-choices { grid-template-columns: 1fr; }

  #npc-choices button[data-topic="__bye"],
  #npc-choices button.npc-choice-bye {
    grid-column: auto;
  }

  .npc-rec {
    flex-wrap: wrap;
  }

  .npc-rec-btn {
    width: 100%;
  }
}

/* === DONJOSE-FIT-FIX: Ultra-narrow screens (<=380px) === */
@media (max-width: 380px) {
  .npc-stats {
    grid-template-columns: 1fr;
    gap: 4px;
    align-items: stretch;
  }
  .npc-stat {
    padding: 4px 6px;
    gap: 5px;
    min-width: 0 !important;
    box-sizing: border-box;
  }
  .npc-stat-ico {
    font-size: 16px;
  }
  .npc-stat-label {
    font-size: 8.5px;
  }
  .npc-stat-meta b {
    font-size: clamp(0.72rem, 2.6vw, 0.95rem);
    line-height: 1.2;
    white-space: normal;
    overflow-wrap: break-word;
  }
}

/* Override legacy hide in landscape (juegoprueba.css forces display:none) */
@media (max-height: 500px) and (orientation: landscape),
       (max-width: 960px) and (orientation: landscape) {
  #npc-panel.npc-panel-active {
    display: flex !important;
    left: 56px;
    right: 12px;
    width: auto;
    max-width: min(380px, calc(100vw - 72px));
    max-height: calc(100vh - 56px);
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
  }

  #npc-panel.npc-panel-hidden {
    display: flex !important;
  }

  /* Keep 2×2 stats so labels don't truncate */
  .npc-stats {
    grid-template-columns: 1fr 1fr;
  }

  .npc-stat-label { font-size: 9px; }
  .npc-stat-meta b { font-size: 11px; }
  .npc-stat { min-height: 46px !important; }
}

@media (prefers-reduced-motion: reduce) {
  #npc-panel,
  #npc-choices button,
  #npc-close,
  .npc-stat,
  .npc-status-dot,
  .npc-stat--urgent,
  .npc-text-pop {
    animation: none !important;
    transition: none !important;
  }
}
