/* ============================================================
   Non-Combat HUD (NCH) — Solitaire-Tableau Styling
   Fixed overlay capsule + expanded modal with hand, backup deck, vault
   ============================================================ */

/* ============================================================
   1. CAPSULE (Closed State — Bottom-Right, Draggable)
   ============================================================ */

/* Capsule: compact draggable joker stack — no frame, just overlapping emojis.
   Default position: bottom-right, above the footer tooltip expander.
   JS overrides top/left via inline style when user drags. */
.nch-capsule-wrapper {
  position: fixed;
  bottom: 48px;
  right: 14px;
  z-index: 1801;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  border-radius: 10px;
  background: transparent;
  cursor: grab;
  pointer-events: auto;
  user-select: none;
  touch-action: none; /* prevent scroll during drag on mobile */
}
.nch-capsule-wrapper.nch-dragging {
  cursor: grabbing;
  opacity: 0.85;
}

.nch-capsule {
  display: flex;
  align-items: center;
}

/* Stack container — sized to fit up to 8 overlapping jokers.
   Each joker is ~20px wide; 70% overlap = 6px advance per card.
   Width: first card 20px + (n-1)*6px.  Max 8 → 20+42 = 62px. Height ~28px. */
.nch-capsule-stack {
  position: relative;
  height: 28px;
  min-width: 20px;
}

.nch-capsule-joker {
  position: absolute;
  font-size: 20px;
  line-height: 1;
  top: 0;
  transition: left 0.25s ease, top 0.25s ease;
  filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.7));
}

/* Each successive joker offset 6px right + 2px down (diagonal cascade) */
.nch-capsule-joker.joker-0 { left: 0;  top: 0; }
.nch-capsule-joker.joker-1 { left: 6px;  top: 2px; }
.nch-capsule-joker.joker-2 { left: 12px; top: 4px; }
.nch-capsule-joker.joker-3 { left: 18px; top: 2px; }
.nch-capsule-joker.joker-4 { left: 24px; top: 0; }
.nch-capsule-joker.joker-5 { left: 30px; top: 2px; }
.nch-capsule-joker.joker-6 { left: 36px; top: 4px; }
.nch-capsule-joker.joker-7 { left: 42px; top: 2px; }

/* Hover: fan out slightly */
.nch-capsule-wrapper:hover .nch-capsule-joker.joker-0 { left: 0;    top: 0; }
.nch-capsule-wrapper:hover .nch-capsule-joker.joker-1 { left: 8px;  top: 2px; }
.nch-capsule-wrapper:hover .nch-capsule-joker.joker-2 { left: 16px; top: 4px; }
.nch-capsule-wrapper:hover .nch-capsule-joker.joker-3 { left: 24px; top: 2px; }
.nch-capsule-wrapper:hover .nch-capsule-joker.joker-4 { left: 32px; top: 0; }
.nch-capsule-wrapper:hover .nch-capsule-joker.joker-5 { left: 40px; top: 2px; }
.nch-capsule-wrapper:hover .nch-capsule-joker.joker-6 { left: 48px; top: 4px; }
.nch-capsule-wrapper:hover .nch-capsule-joker.joker-7 { left: 56px; top: 2px; }

/* Greyed joker for BLVCK / unusable cards */
.nch-joker-greyed {
  filter: grayscale(1) brightness(0.5) drop-shadow(1px 1px 2px rgba(0,0,0,0.7));
  opacity: 0.55;
}

/* ── Combat Capsule (CH) — intelligent joker nodes ──────── */

/* Active node: selected card reveals its actual emoji */
.nch-joker-active {
  filter: drop-shadow(0 0 4px rgba(28, 255, 155, 0.6)) drop-shadow(1px 1px 2px rgba(0,0,0,0.7));
  font-size: 21px;
}

/* Resolving node: pulse animation during resolution sequence */
.nch-joker-resolving {
  animation: nch-joker-resolve-pulse 0.45s ease-in-out infinite alternate;
}

@keyframes nch-joker-resolve-pulse {
  from { filter: drop-shadow(0 0 4px rgba(28, 255, 155, 0.6)) brightness(1); }
  to   { filter: drop-shadow(0 0 10px rgba(255, 193, 7, 0.8)) brightness(1.15); }
}

/* Timer-critical pulse on the entire capsule wrapper (<20% time) */
.nch-capsule-critical {
  animation: nch-capsule-critical-pulse 0.55s ease-in-out infinite;
}

@keyframes nch-capsule-critical-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.6; }
}

/* Resolution edge flash (replaces old mini-indicator flash) */
.nch-capsule-flash {
  animation: nch-capsule-incinerator-flash 0.38s ease-out forwards;
}

@keyframes nch-capsule-incinerator-flash {
  0%   { filter: brightness(1); }
  30%  { filter: brightness(2.2) saturate(1.5); }
  100% { filter: brightness(1); }
}

/* ============================================================
   2. EXPANDED OVERLAY
   ============================================================ */

#nch-expanded {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: min(95vw, 1020px);
  max-height: min(82vh, 620px);
  display: flex;
  flex-direction: column;
  z-index: 1850;
  background: linear-gradient(145deg, rgba(8, 12, 8, 0.96), rgba(16, 22, 16, 0.96));
  border: 2px solid rgba(28, 255, 155, 0.45);
  border-radius: 14px;
  box-shadow: 0 0 40px rgba(28, 255, 155, 0.15);
  overflow: hidden;
  pointer-events: auto;
}

#nch-expanded.nch-locked {
  opacity: 0.7;
  filter: saturate(0.85);
  pointer-events: none;
}

.nch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 10px;
  border-bottom: 1px solid rgba(28, 255, 155, 0.25);
  background: rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
}

.nch-header-title {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(28, 255, 155, 0.85);
}

.nch-close-btn {
  appearance: none;
  background: transparent;
  border: 1px solid rgba(28, 255, 155, 0.4);
  color: rgba(28, 255, 155, 0.7);
  width: 22px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  transition: all 0.2s;
  padding: 0;
}

.nch-close-btn:hover {
  background: rgba(28, 255, 155, 0.1);
  border-color: rgba(28, 255, 155, 0.8);
  color: rgba(28, 255, 155, 0.95);
}

.nch-content {
  flex: 1;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 4px;
  padding: 4px 6px;
  overflow: hidden;
  min-height: 0;
}

/* ============================================================
   3. HAND ZONE (Zone 1 — Top)
   ============================================================ */

.nch-zone {
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(28, 255, 155, 0.2);
  border-radius: 6px;
  padding: 4px 6px;
  overflow: hidden;
  min-height: 0;
}

.nch-zone-label {
  font-family: 'Courier New', monospace;
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(28, 255, 155, 0.6);
  margin-bottom: 2px;
  padding-bottom: 1px;
  border-bottom: 1px solid rgba(28, 255, 155, 0.12);
  flex-shrink: 0;
}

.nch-zone-hand {
  display: flex;
  flex-direction: column;
  min-height: 130px;
  overflow: hidden;
}

.nch-hand-container {
  display: flex;
  gap: 8px;
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
  align-items: flex-end;
  -webkit-overflow-scrolling: touch;
}

.nch-hand-container .hand-card-wrapper {
  flex: 0 0 auto;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

.nch-hand-container .hand-card-wrapper:hover {
  transform: translateY(calc(var(--fan-ty, 0px) - 14px)) scale(1.04);
  z-index: 200;
  transition: transform 0.15s ease;
}

/* ============================================================
   3b. DRAW BAR (Between Hand and Backup)
   ============================================================ */

.nch-zone-drawbar {
  min-height: auto;
  padding: 2px 6px;
}

.nch-zone-drawbar .nch-zone-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nch-drawbar {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  padding: 6px 0;
  flex-wrap: nowrap;
}

.nch-drawbar-empty {
  color: rgba(28, 255, 155, 0.3);
  font-family: 'Courier New', monospace;
  font-size: 11px;
  padding: 12px;
  text-align: center;
}

.nch-draw-btn {
  appearance: none;
  width: 80px;
  height: 112px;
  border: 2px solid rgba(28, 255, 155, 0.3);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(8, 12, 8, 0.9), rgba(15, 25, 15, 0.8));
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  padding: 6px;
}

.nch-draw-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(28, 255, 155, 0.04) 0%, transparent 70%);
  pointer-events: none;
}

.nch-draw-btn:hover:not(:disabled) {
  transform: translateY(-4px) scale(1.05);
  border-color: rgba(28, 255, 155, 0.7);
  box-shadow: 0 4px 16px rgba(28, 255, 155, 0.15), 0 0 8px rgba(28, 255, 155, 0.1);
}

.nch-draw-btn:active:not(:disabled) {
  transform: translateY(-1px) scale(0.98);
}

.nch-draw-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.nch-draw-btn-joker {
  font-size: 32px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.nch-draw-btn.face-up {
  background: linear-gradient(135deg, rgba(12, 20, 12, 0.95), rgba(20, 35, 20, 0.85));
}

.nch-draw-btn-emoji {
  font-size: 28px;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.4));
}

.nch-draw-btn-name {
  font-family: 'Courier New', monospace;
  font-size: 8px;
  letter-spacing: 0.5px;
  color: rgba(28, 255, 155, 0.7);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.nch-draw-btn.nch-draw-btn-hover {
  border-color: rgba(28, 255, 155, 0.9);
  box-shadow: 0 0 12px rgba(28, 255, 155, 0.2);
}

.nch-draw-btn.drawing {
  animation: draw-fly 0.3s ease-out forwards;
}

.nch-draw-btn.shuffling {
  animation: shuffle-scatter 0.25s ease-in-out;
}

.nch-drawbar-more {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  color: rgba(28, 255, 155, 0.4);
  display: flex;
  align-items: center;
  padding: 0 4px;
  white-space: nowrap;
}

/* Shuffle / Sort buttons */
.nch-shuffle-btn,
.nch-sort-btn {
  appearance: none;
  background: rgba(28, 255, 155, 0.08);
  border: 1px solid rgba(28, 255, 155, 0.3);
  color: rgba(28, 255, 155, 0.7);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  margin-left: 4px;
  transition: all 0.2s;
  line-height: 1.2;
}

.nch-shuffle-btn:hover:not(:disabled),
.nch-sort-btn:hover:not(:disabled) {
  background: rgba(28, 255, 155, 0.15);
  border-color: rgba(28, 255, 155, 0.6);
  color: rgba(28, 255, 155, 0.95);
}

.nch-shuffle-btn:disabled,
.nch-sort-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Draw animation */
@keyframes draw-fly {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  60% { transform: translateY(-30px) scale(1.1); opacity: 0.8; }
  100% { transform: translateY(-60px) scale(0.5); opacity: 0; }
}

@keyframes shuffle-scatter {
  0% { transform: rotate(0deg) translateX(0); }
  25% { transform: rotate(-8deg) translateX(-6px); }
  50% { transform: rotate(6deg) translateX(4px); }
  75% { transform: rotate(-3deg) translateX(-2px); }
  100% { transform: rotate(0deg) translateX(0); }
}

/* ============================================================
   3c. GHOST JOKER CURSOR
   ============================================================ */

/* Ghost joker cursor intentionally removed.
   Reason: hiding the real cursor and replacing it with an emoji cursor felt laggy
   and reduced precision during deck management.
*/

/* ============================================================
   4. BACKUP DECK ZONE (Zone 2 — Middle, Scrollable Band)
   ============================================================ */

.nch-zone-backup {
  flex: 1;
  min-height: 80px;
  display: flex;
  flex-direction: column;
}

.nch-backup-scroll-wrapper {
  position: relative;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.nch-backup-scroll-wrapper::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 30px;
  background: linear-gradient(to right, rgba(8, 12, 8, 0.95), transparent);
  z-index: 2;
  pointer-events: none;
}

.nch-backup-scroll-wrapper::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 30px;
  background: linear-gradient(to left, rgba(8, 12, 8, 0.95), transparent);
  z-index: 2;
  pointer-events: none;
}

.nch-backup-scroller {
  display: flex;
  gap: -20px;
  padding: 2px 28px;
  overflow-x: auto;
  overflow-y: hidden;
  align-items: flex-end;
  min-width: 100%;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.nch-backup-scroller .hand-card-wrapper {
  flex: 0 0 100px;
  transform-origin: bottom center;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

.nch-backup-scroller .hand-card {
  width: 100px;
  height: 140px;
  font-size: inherit;
}

.nch-backup-scroller .hand-card-emoji {
  font-size: 24px;
}

.nch-backup-scroller .hand-card-name {
  font-size: 9px;
}

.nch-backup-scroller .hand-card-cost {
  width: 18px;
  height: 18px;
  font-size: 10px;
}

.nch-backup-scroller .hand-card-wrapper.nch-backup-old {
  opacity: 0.5;
  filter: grayscale(0.3);
}

.nch-backup-scroller .hand-card-wrapper.nch-backup-dying {
  opacity: 0.3;
  filter: grayscale(0.6);
}

/* Visual aging transition: smooth shift when backup changes */
.nch-backup-scroller .hand-card-wrapper {
  transition: transform 0.3s ease, opacity 0.3s ease, filter 0.3s ease;
}

/* Newest cards (left): slightly elevated */
.nch-backup-scroller .hand-card-wrapper:first-child {
  transform: translateY(-1px);
}

/* Oldest visible cards: slight downward drift */
.nch-backup-scroller .hand-card-wrapper:nth-child(n+15) {
  transform: translateY(2px);
}

/* ── Incineration animation ── */
.nch-card-incinerating {
  position: fixed;
  z-index: 99999;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translate(-50%, -50%);
  animation: nch-incinerate 0.6s ease-out forwards;
}

.nch-incinerate-emoji {
  font-size: 1.8em;
  filter: brightness(2);
}

.nch-incinerate-name {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  color: #ff5722;
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
}

@keyframes nch-incinerate {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    filter: brightness(1) saturate(1);
  }
  30% {
    transform: translate(-50%, -50%) scale(1.1);
    opacity: 0.9;
    filter: brightness(2) saturate(1.5);
    text-shadow: 0 0 10px rgba(255, 87, 34, 0.8);
  }
  100% {
    transform: translate(-50%, -50%) scale(0.4);
    opacity: 0;
    filter: brightness(3) saturate(0);
  }
}

.nch-backup-count {
  font-family: 'Courier New', monospace;
  font-size: 11px;
  color: rgba(28, 255, 155, 0.5);
  text-align: right;
  margin-top: 4px;
  flex-shrink: 0;
  padding: 0 8px;
}

/* ============================================================
   5. VAULT ZONE (Zone 3 — Bottom Strip)
   ============================================================ */

.nch-zone-vault {
  max-height: 100px;
  display: flex;
  flex-direction: column;
}

.nch-vault-slots {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 0;
  -webkit-overflow-scrolling: touch;
}

.nch-vault-slot {
  flex: 0 0 52px;
  height: 72px;
  background: rgba(10, 10, 10, 0.5);
  border: 1px dashed rgba(28, 255, 155, 0.2);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: grab;
  transition: all 0.25s ease;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.nch-vault-slot:hover {
  border-color: rgba(28, 255, 155, 0.5);
  border-style: solid;
  background: rgba(28, 255, 155, 0.04);
}

.nch-vault-slot.empty {
  color: rgba(28, 255, 155, 0.25);
  font-size: 20px;
  cursor: default;
}

.nch-vault-slot.occupied {
  cursor: grab;
}

.nch-vault-joker {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  transition: opacity 0.3s ease;
  z-index: 1;
}

.nch-vault-portrait {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 2;
  transform: scale(0.85);
}

.nch-vault-slot:hover .nch-vault-joker {
  opacity: 0;
}

.nch-vault-slot:hover .nch-vault-portrait {
  opacity: 1;
}

/* ============================================================
   6. DRAG & DROP
   ============================================================ */

.nch-drag-ghost {
  position: fixed;
  z-index: 99999;
  pointer-events: none;
  font-size: 36px;
  filter: drop-shadow(0 0 10px rgba(28, 255, 155, 0.35));
  opacity: 0.85;
  transform: translate(-18px, -18px);
}

.nch-drop-highlight {
  outline: 2px solid rgba(28, 255, 155, 0.7) !important;
  outline-offset: -2px;
  background: rgba(28, 255, 155, 0.06) !important;
}

.nch-drop-highlight-warn {
  outline-color: rgba(255, 152, 0, 0.7) !important;
}

/* ============================================================
   7. ANIMATIONS
   ============================================================ */

@keyframes nch-card-dissolve {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: grayscale(0) blur(0);
  }
  100% {
    opacity: 0;
    transform: translateY(30px) scale(0.85);
    filter: grayscale(1) blur(2px);
  }
}

.nch-card-dissolving {
  animation: nch-card-dissolve 0.5s ease-out forwards;
  pointer-events: none;
}

@keyframes nch-drop-zone-pulse {
  0%, 100% {
    outline-color: rgba(28, 255, 155, 0.4);
  }
  50% {
    outline-color: rgba(28, 255, 155, 0.8);
  }
}

.nch-drop-active {
  animation: nch-drop-zone-pulse 1s ease-in-out infinite;
}

/* ============================================================
   8. PRINTER (3D Printer Armed Cue — Reused from Original)
   ============================================================ */

.printer-x2 {
  position: absolute;
  top: -6px;
  right: -6px;
  background: linear-gradient(135deg, #ff6b00 0%, #ff9500 100%);
  color: #fff;
  font-size: 9px;
  font-weight: bold;
  padding: 2px 5px;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  z-index: 10;
  pointer-events: none;
  animation: printer-x2-glow 1.5s ease-in-out infinite;
}

@keyframes printer-x2-glow {
  0%, 100% {
    box-shadow: 0 2px 6px rgba(255, 107, 0, 0.4);
  }
  50% {
    box-shadow: 0 2px 12px rgba(255, 107, 0, 0.7);
  }
}

.printer-eligible {
  border-color: #ff6b00 !important;
}

.printer-eligible:hover {
  background: rgba(255, 107, 0, 0.15) !important;
  border-color: #ff9500 !important;
}

/* ============================================================
   9. RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
  #nch-expanded {
    width: min(98vw, 600px);
    max-height: min(85vh, 500px);
    bottom: calc(6px + env(safe-area-inset-bottom));
    /* Shift right to avoid overlapping left column action buttons */
    left: calc(50% + 20px);
  }

  .nch-content {
    grid-template-rows: auto auto 1fr auto;
    gap: 3px;
    padding: 3px 4px;
  }

  .nch-zone {
    padding: 2px 4px;
  }

  .nch-zone-hand {
    min-height: 110px;
  }

  .nch-draw-btn {
    width: 64px;
    height: 90px;
  }

  .nch-draw-btn-joker {
    font-size: 24px;
  }

  .nch-draw-btn-emoji {
    font-size: 22px;
  }

  .nch-hand-container .hand-card-wrapper .hand-card {
    width: 90px;
    height: 126px;
  }

  .nch-hand-container .hand-card-emoji {
    font-size: 22px;
  }

  .nch-capsule-wrapper {
    bottom: calc(40px + env(safe-area-inset-bottom));
    right: 10px;
  }
}

@media (max-width: 480px) {
  .nch-vault-slot {
    flex: 0 0 48px;
    height: 67px;
  }

  .nch-vault-joker {
    font-size: 24px;
  }
}

/* ── Equipped item slot (interactive) ─────────────────── */
#nch-equipped-display {
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
  transition: background 0.15s, box-shadow 0.15s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
#nch-equipped-display:hover {
  background: rgba(0, 255, 128, 0.12);
  box-shadow: 0 0 4px rgba(0, 255, 128, 0.25);
}
#nch-equipped-display:active,
#nch-equipped-display.nch-equipped-active:active {
  background: rgba(0, 255, 128, 0.22);
}
#nch-equipped-display .nch-equipped-emoji {
  font-size: 1.1em;
}
#nch-equipped-display .nch-equipped-empty {
  opacity: 0.35;
  font-size: 1.2em;
}
