/* ============================================================
   KreepCore - Comms Screen (AAA Redesign v2)
   "Quantum Relay Terminal" aesthetic
   ============================================================ */

/* ── Shared keyframes for the Comms section ─────────────────── */
@keyframes commsScanLine {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(calc(100vh)); }
}

@keyframes badgePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.15); }
}

@keyframes glowPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

@keyframes tabReveal {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes borderGlow {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.8; }
}

@keyframes activeTabGlow {
  0%, 100% { box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.15), inset 0 0 12px rgba(var(--accent-rgb), 0.05); }
  50% { box-shadow: 0 0 14px rgba(var(--accent-rgb), 0.25), inset 0 0 18px rgba(var(--accent-rgb), 0.08); }
}

/* ── Comms screen wrapper ────────────────────────────────────── */
/* The entire comms screen must fit within the viewport. No page-level
   scroll. Only the inner message panel scrolls. We override the
   default main-content padding-bottom (which accounts for bottom-nav)
   because we handle the height constraint ourselves. The calc must
   subtract every fixed chrome element plus the safe-area insets on
   iOS/notched devices; forgetting banner-offset or bottom-sai made the
   panel extend below the bottom nav and clipped the last entries. */
/* Comms lives under the sticky header; use a flex height chain so only
   #community-content scrolls (not #game-ui / desktop center column). */
html.game-active #game-ui:has(#screen-community.active) {
  display: flex;
  flex-direction: column;
  overflow-y: hidden;
}

#screen-community.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#screen-community .main-content {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: auto;
  max-height: none;
  padding-bottom: 0;
  box-sizing: border-box;
}

/* Fallback when Comms is not the active screen (should not apply). */
#screen-community:not(.active) .main-content {
  height: calc(
    var(--app-height, 100dvh)
    - var(--topbar-height, 84px)
    - env(safe-area-inset-top, 0px)
    - var(--banner-offset, 0px)
    - var(--nav-height, 48px)
    - var(--ticker-height, 26px)
    - var(--bottom-sai, 0px)
  );
  max-height: calc(
    var(--app-height, 100dvh)
    - var(--topbar-height, 84px)
    - env(safe-area-inset-top, 0px)
    - var(--banner-offset, 0px)
    - var(--nav-height, 48px)
    - var(--ticker-height, 26px)
    - var(--bottom-sai, 0px)
  );
}

#screen-community .main-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(var(--accent-rgb), 0.03) 20%,
    rgba(var(--accent-rgb), 0.08) 50%,
    rgba(var(--accent-rgb), 0.03) 80%,
    transparent 100%
  );
  z-index: 1;
  pointer-events: none;
  animation: commsScanLine 8s linear infinite;
  animation-play-state: var(--anim-state, running);
}

/* ── Main tabs - "Frequency Selector" Segmented Control ────── */
.kc-subtabs,
.comms-sub-tabs {
  display: flex;
  gap: 3px;
  padding: 6px 8px;
  margin-bottom: 12px;
  position: relative;
  flex-shrink: 0;
  background:
    linear-gradient(180deg,
      rgba(var(--accent-rgb), 0.04) 0%,
      rgba(6, 6, 15, 0.6) 100%
    );
  border: 1px solid rgba(var(--accent-rgb), 0.08);
  border-radius: 6px;
}

/* Decorative top glow line */
.kc-subtabs::before,
.comms-sub-tabs::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 20px;
  right: 20px;
  height: 1px;
  background: linear-gradient(90deg,
    transparent,
    rgba(var(--accent-rgb), 0.35),
    transparent
  );
  border-radius: 1px;
}

/* ── Tab icon (SVG) ────────────────────────────────────────── */
.kc-subtab-icon,
.comms-tab-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.25s;
}

.kc-subtab.active .kc-subtab-icon,
.comms-sub-tab.active .comms-tab-icon {
  opacity: 1;
  filter: drop-shadow(0 0 4px rgba(var(--accent-rgb), 0.4));
}

.kc-subtab-label,
.comms-tab-label {
  white-space: nowrap;
}

/* Each tab button */
.kc-subtab,
.comms-sub-tab {
  flex: 1;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 0.82rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: all 0.25s ease;
  overflow: hidden;
}

/* Hover light sweep */
.kc-subtab::before,
.comms-sub-tab::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    120deg,
    transparent 30%,
    rgba(var(--accent-rgb), 0.06) 50%,
    transparent 70%
  );
  opacity: 0;
  transition: opacity 0.3s;
}

.kc-subtab:hover::before,
.comms-sub-tab:hover::before {
  opacity: 1;
}

.kc-subtab:hover,
.comms-sub-tab:hover {
  color: var(--text-secondary);
  border-color: rgba(var(--accent-rgb), 0.1);
}

/* Active tab - illuminated state */
.kc-subtab.active,
.comms-sub-tab.active {
  color: var(--cyan);
  background:
    linear-gradient(180deg,
      rgba(var(--accent-rgb), 0.12) 0%,
      rgba(var(--accent-rgb), 0.04) 100%
    );
  border-color: rgba(var(--accent-rgb), 0.25);
  text-shadow: 0 0 10px rgba(var(--accent-rgb), 0.5);
  animation: activeTabGlow 3s ease-in-out infinite;
  animation-play-state: var(--anim-state, running);
}

/* Active bottom accent bar */
.kc-subtab.active::after,
.comms-sub-tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 15%;
  right: 15%;
  height: 2px;
  background: var(--cyan);
  border-radius: 2px 2px 0 0;
  box-shadow:
    0 0 8px rgba(var(--accent-rgb), 0.6),
    0 0 24px rgba(var(--accent-rgb), 0.2);
}

/* Badge - pulsing notification */
.comms-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  background: var(--red, #ef4444);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 0 4px;
  border-radius: 8px;
  margin-left: 4px;
  vertical-align: middle;
  animation: badgePulse 2s ease-in-out infinite;
  animation-play-state: var(--anim-state, running);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}
.comms-tab-badge[title] {
  cursor: help;
}

/* ── Nav badge (bottom bar) ─────────────────────────────────── */
.nav-badge {
  position: absolute;
  top: 0;
  right: 2px;
  background: var(--red, #ef4444);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 6px;
  line-height: 1.2;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
  animation: badgePulse 2.5s ease-in-out infinite;
  animation-play-state: var(--anim-state, running);
}
.nav-badge.hidden {
  display: none;
}
.nav-item {
  position: relative;
}
@media (min-width: 1024px) {
  .nav-badge {
    top: -4px;
    right: -6px;
  }
}

/* ── Community content area ─────────────────────────────────── */
#community-content {
  animation: tabReveal 0.2s ease-out;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
/* Messages tab handles its own internal scroll (only the chat bubble
   area scrolls). Disable the outer scroll so the layout stays locked. */
#community-content:has(.messages-panel) {
  overflow-y: hidden;
}

/* Diplomacy: one scrollport (#community-content); panel grows naturally. */
#community-content:has(.diplomacy-panel) {
  /* Bottom nav overlays the scrollport; keep actions toolbar off the nav edge. */
  padding-bottom: calc(var(--nav-height, 48px) + var(--bottom-sai, 0px) + 1.25rem);
}
#community-content:has(.diplomacy-panel) .diplomacy-panel {
  flex: 0 0 auto;
  overflow: visible;
  max-height: none;
}

/* Forum: same scrollport; keep reply form / bottom actions above the bottom nav. */
#community-content:has(.forum-thread-view),
#community-content:has(.forum-overview),
#community-content:has(.forum-catview),
#community-content:has(.forum-new-form) {
  padding-bottom: calc(var(--nav-height, 48px) + var(--bottom-sai, 0px) + 1.25rem);
}

/* ── Shared panel decorator ────────────────────────────────── */
.diplomacy-panel,
.alliance-dashboard,
.messages-panel {
  position: relative;
}

/* ── Mobile responsive ──────────────────────────────────────── */
@media (max-width: 600px) {
  .kc-subtabs,
  .comms-sub-tabs {
    padding: 4px 4px;
    gap: 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 4px;
  }
  .kc-subtab,
  .comms-sub-tab {
    padding: 8px 6px;
    font-size: 11.5px;
    letter-spacing: 0.04em;
    gap: 3px;
    min-width: 0;
  }
  .kc-subtab-icon,
  .comms-tab-icon {
    width: 12px;
    height: 12px;
  }
  .kc-subtab.active::after,
  .comms-sub-tab.active::after {
    left: 10%;
    right: 10%;
  }
}
