/**
 * Companion Arcade — mini-game hub, overlay shell, and in-game arenas.
 */

/* ===== Hub banner (Games tab + modal) ===== */
.companion-games-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.85rem 1rem;
  margin-bottom: 0.75rem;
  border-radius: 12px;
  border: 1px solid rgba(251, 191, 36, 0.35);
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.12) 0%, rgba(14, 12, 24, 0.95) 55%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.companion-games-pending {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.companion-games-pending span:first-child {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 230, 200, 0.65);
}

.companion-games-pending strong {
  font-size: 1.45rem;
  font-weight: 800;
  color: #fde68a;
  text-shadow: 0 0 18px rgba(251, 191, 36, 0.35);
}

.companion-games-pending-note {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.55);
}

.companion-games-intro {
  margin: 0 0 0.85rem;
  font-size: 0.82rem;
  line-height: 1.45;
  color: rgba(255, 230, 245, 0.72);
}

/* ===== Game cards in shop list ===== */
.companion-game-card {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 0.65rem 0.75rem;
  align-items: center;
  padding: 0.75rem;
  margin-bottom: 0.55rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(12, 10, 22, 0.92);
  border-left: 3px solid var(--game-accent, #c084fc);
}

.companion-game-card.is-locked {
  opacity: 0.72;
}

.companion-game-card-icon {
  font-size: 2rem;
  line-height: 1;
  text-align: center;
}

.companion-game-card-body strong {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 0.15rem;
}

.companion-game-card-body p {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.35;
  color: rgba(255, 230, 245, 0.75);
}

.companion-game-card-meta,
.companion-game-card-high {
  margin-top: 0.25rem !important;
  font-size: 0.72rem !important;
  color: rgba(255, 255, 255, 0.5) !important;
}

.companion-game-play {
  grid-column: 3;
  grid-row: 1 / span 2;
  align-self: center;
  white-space: nowrap;
}

/* ===== Standalone modal ===== */
.companion-games-modal {
  z-index: 12000;
}

.companion-games-modal-card {
  width: min(520px, calc(100vw - 2rem));
  max-height: min(88vh, 720px);
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(180deg, #1a1428 0%, #0d0a14 100%);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.companion-games-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.companion-games-modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.companion-games-modal-list {
  padding: 0.85rem 1rem 1.1rem;
  overflow-y: auto;
}

.cat-room-sidebar-actions .cat-room-games-btn {
  border-color: rgba(192, 132, 252, 0.35);
  color: #e9d5ff;
}

/* ===== Overlay shell ===== */
body.companion-minigame-open {
  overflow: hidden;
}

.companion-minigame-overlay {
  position: fixed;
  inset: 0;
  z-index: 13000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(4, 3, 10, 0.82);
  backdrop-filter: blur(6px);
}

.companion-minigame-card {
  width: min(420px, 100%);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(165deg, #221a35 0%, #100c18 100%);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.companion-minigame-header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.25);
}

.companion-minigame-header h2 {
  margin: 0;
  font-size: 1rem;
}

.companion-minigame-hud {
  display: flex;
  gap: 0.65rem;
  font-size: 0.82rem;
  font-weight: 700;
}

.companion-minigame-score {
  color: #fde68a;
}

.companion-minigame-timer {
  color: #7dd3fc;
}

.companion-minigame-close {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.65);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
}

.companion-minigame-body {
  padding: 0.85rem;
  min-height: 280px;
}

/* ===== Result screen ===== */
.companion-minigame-result {
  text-align: center;
  padding: 1.25rem 0.75rem;
}

.companion-minigame-result-title {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 800;
}

.companion-minigame-result-score {
  margin: 0.35rem 0;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.75);
}

.companion-minigame-result-chips {
  margin: 0.65rem 0;
  font-size: 1.35rem;
  font-weight: 800;
  color: #fbbf24;
}

.companion-minigame-result-chips span {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
}

.companion-minigame-result-note {
  margin: 0.5rem 0 1rem;
  font-size: 0.75rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.55);
}

/* ===== Chip Catch ===== */
.chip-catch-arena {
  position: relative;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(180deg, #1e1630 0%, #0f0b18 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  touch-action: none;
  outline: none;
}

.chip-catch-basket {
  position: absolute;
  bottom: 8px;
  left: 0;
  width: 72px;
  height: 36px;
  border-radius: 8px 8px 12px 12px;
  background: linear-gradient(180deg, #a16207 0%, #713f12 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.2), 0 4px 12px rgba(0, 0, 0, 0.4);
}

.chip-catch-basket::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 4px;
  right: 4px;
  height: 8px;
  border-radius: 4px;
  background: #92400e;
}

.chip-catch-item {
  position: absolute;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  pointer-events: none;
}

.chip-catch-item--coin {
  background-color: #fbbf24;
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
}

.chip-catch-item--gem {
  background: radial-gradient(circle at 35% 30%, #e9d5ff, #7c3aed);
  clip-path: polygon(50% 0%, 85% 35%, 65% 100%, 35% 100%, 15% 35%);
  border-radius: 0;
}

.chip-catch-item--skull {
  background: #374151;
  box-shadow: inset 0 0 0 2px #ef4444;
}

.chip-catch-item--skull::after {
  content: '💀';
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 1rem;
}

.chip-catch-hint {
  position: absolute;
  bottom: 48px;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.45);
  pointer-events: none;
}

/* ===== Ball Rush ===== */
.ball-tap-arena {
  position: relative;
  width: 100%;
  height: 320px;
  border-radius: 12px;
  background: radial-gradient(circle at 50% 40%, #1a2840 0%, #0c1018 75%);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

.ball-tap-target {
  position: absolute;
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 50%;
  background-color: #38bdf8;
  background-size: cover;
  background-position: center;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.45);
  transition: transform 0.08s ease;
}

.ball-tap-target:not(.hidden):active {
  transform: scale(0.92);
}

.ball-tap-target.hidden {
  opacity: 0;
  pointer-events: none;
}

.ball-tap-streak {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: #7dd3fc;
}

/* ===== Memory pairs ===== */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  max-width: 340px;
  margin: 0 auto;
}

.memory-card {
  aspect-ratio: 1;
  position: relative;
  border: none;
  border-radius: 10px;
  padding: 0;
  cursor: pointer;
  background: linear-gradient(145deg, #3b2a55, #1f1530);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.memory-card-back,
.memory-card-front {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.memory-card-back {
  font-size: 1.25rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.55);
}

.memory-card-front {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(0.85);
}

.memory-card.is-flipped .memory-card-back {
  opacity: 0;
}

.memory-card.is-flipped .memory-card-front {
  opacity: 1;
  transform: scale(1);
}

.memory-card.is-matched {
  opacity: 0.45;
  pointer-events: none;
}

/* ===== Merge Kingdom ===== */
.merge-kingdom {
  display: grid;
  grid-template-columns: minmax(0, 220px) minmax(0, 1fr);
  gap: 0.85rem;
  align-items: start;
}

.merge-kingdom-tip {
  margin: 0 0 0.65rem;
  font-size: 0.72rem;
  line-height: 1.4;
  color: rgba(255, 230, 210, 0.75);
}

.merge-kingdom-chains {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.65rem;
}

.merge-kingdom-chain-chip {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.25rem 0.4rem;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--chain-color) 55%, transparent);
  background: color-mix(in srgb, var(--chain-color) 12%, rgba(8, 6, 16, 0.9));
  font-size: 0.72rem;
  font-weight: 700;
}

.merge-kingdom-chain-chip img {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
}

.merge-kingdom-meters {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.55rem;
}

.merge-kingdom-meter {
  font-size: 0.74rem;
  font-weight: 800;
  color: #fde68a;
}

.merge-kingdom-objective {
  color: #c4b5fd;
  font-size: 0.68rem;
}

.merge-kingdom-objective.is-done {
  color: #86efac;
  animation: merge-goal-pulse 1.2s ease-in-out infinite;
}

@keyframes merge-goal-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.72; }
}

.merge-kingdom-powers {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.merge-kingdom-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.35rem;
  padding: 0.55rem;
  border-radius: 14px;
  background:
    radial-gradient(circle at 50% 0%, rgba(245, 158, 11, 0.12), transparent 55%),
    linear-gradient(180deg, rgba(18, 14, 28, 0.98), rgba(8, 6, 14, 0.98));
  border: 1px solid rgba(251, 191, 36, 0.25);
  transition: transform 0.18s ease;
}

.merge-kingdom-board.merge-kingdom-pop {
  transform: scale(1.015);
}

.merge-kingdom-board.merge-kingdom-shake {
  animation: merge-kingdom-shake 0.32s ease;
}

@keyframes merge-kingdom-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.merge-kingdom-cell {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  cursor: pointer;
  padding: 0.2rem;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.merge-kingdom-cell.is-selected {
  border-color: #fde68a;
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.35);
  transform: scale(1.04);
}

.merge-kingdom-cell.is-merged {
  animation: merge-cell-burst 0.42s ease;
}

@keyframes merge-cell-burst {
  0% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(1.12); filter: brightness(1.35); box-shadow: 0 0 18px rgba(251, 191, 36, 0.55); }
  100% { transform: scale(1); filter: brightness(1); }
}

.merge-kingdom-cell.is-blessed {
  background: radial-gradient(circle, rgba(251, 191, 36, 0.18), rgba(0, 0, 0, 0.35));
}

.merge-kingdom-cell.is-empty {
  opacity: 0.55;
}

.merge-kingdom-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.45));
}

.merge-kingdom-tier {
  position: absolute;
  right: 3px;
  bottom: 2px;
  font-size: 0.55rem;
  font-weight: 800;
  color: var(--chain-color, #fff);
  text-shadow: 0 1px 2px #000;
}

.merge-kingdom-fx {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}

.merge-kingdom-fx--frozen {
  background: linear-gradient(135deg, rgba(186, 230, 253, 0.35), transparent 60%);
  box-shadow: inset 0 0 0 2px rgba(125, 211, 252, 0.45);
}

.merge-kingdom-fx--cursed {
  background: radial-gradient(circle, rgba(239, 68, 68, 0.35), transparent 70%);
  animation: merge-cursed-pulse 1.2s ease-in-out infinite;
}

@keyframes merge-cursed-pulse {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}

/* ===== Guild Quest Board ===== */
.guild-quest {
  min-height: 360px;
  padding: 0.35rem;
  background-image: var(--guild-frame);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
}

.guild-quest-panel {
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: rgba(10, 8, 18, 0.88);
  border: 1px solid rgba(129, 140, 248, 0.25);
  animation: guild-panel-in 0.35s ease;
}

@keyframes guild-panel-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.guild-quest-npc-wrap {
  position: relative;
  width: min(160px, 42%);
  margin: 0 auto 0.65rem;
}

.guild-quest-npc {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.45));
}

.guild-quest-badge {
  position: absolute;
  right: -8px;
  top: -8px;
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.guild-quest-roll {
  font-size: 0.85rem;
  min-height: 1.4rem;
  transition: color 0.2s ease;
}

.guild-quest-roll.is-rolling {
  animation: guild-roll-flash 0.9s ease;
}

@keyframes guild-roll-flash {
  0%, 100% { color: rgba(255, 255, 255, 0.85); }
  50% { color: #fde68a; text-shadow: 0 0 12px rgba(251, 191, 36, 0.45); }
}

.guild-quest-timer {
  font-size: 0.72rem;
  font-weight: 800;
  color: #fca5a5;
  margin: 0.35rem 0 0;
}

.guild-quest-timer.is-urgent {
  animation: guild-timer-pulse 0.8s ease-in-out infinite;
}

@keyframes guild-timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.guild-quest-hook {
  font-size: 0.82rem;
  line-height: 1.45;
  color: rgba(255, 240, 250, 0.82);
}

.guild-quest-sub {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.55);
}

.guild-quest-choices {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.guild-quest-choice {
  text-align: left;
  white-space: normal;
}

.guild-quest-sequence {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  margin: 0.65rem 0;
}

.guild-quest-rune {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.guild-quest-rune img {
  width: 36px;
  height: 36px;
  image-rendering: pixelated;
}

.guild-quest-rune.is-lit {
  transform: scale(1.08);
  box-shadow: 0 0 16px rgba(129, 140, 248, 0.55);
  border-color: #818cf8;
}

.guild-quest-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.65rem 0;
}

.guild-quest-stats .is-active {
  border-color: #818cf8;
  box-shadow: 0 0 12px rgba(129, 140, 248, 0.35);
}

.guild-quest-grade {
  font-size: 2.4rem;
  font-weight: 900;
  text-align: center;
  margin-bottom: 0.35rem;
}

.guild-quest-grade--s { color: #fde68a; text-shadow: 0 0 20px rgba(251, 191, 36, 0.5); }
.guild-quest-grade--a { color: #86efac; }
.guild-quest-grade--b { color: #93c5fd; }
.guild-quest-grade--c { color: #cbd5e1; }

.guild-quest-breakdown {
  margin: 0.5rem 0 0.85rem;
  padding-left: 1.1rem;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.72);
}

.companion-game-card--featured {
  border-left-width: 4px;
  box-shadow: 0 0 20px rgba(129, 140, 248, 0.12);
}

@media (max-width: 720px) {
  .merge-kingdom {
    grid-template-columns: 1fr;
  }
}
