import styled, { keyframes } from 'styled-components';
import { Link } from 'react-router-dom';

const fadeUp = keyframes`from{opacity:0;transform:translateY(12px)}to{opacity:1;transform:translateY(0)}`;

export const PageWrapper = styled.div`
  min-height: calc(100vh - 140px);
  padding: 20px 0;
  opacity: 0;
  transform: translateY(20px);
  animation: pageEnter 0.8s ease-out forwards;
  position: relative;

  @keyframes pageEnter {
    0% { opacity: 0; transform: translateY(20px); }
    100% { opacity: 1; transform: translateY(0); }
  }
`;

export const Container = styled.div`
  max-width: ${props => props.$narrow ? '800px' : '1200px'};
  margin: 0 auto;
  padding: 0 ${props => props.$px || '16px'};
`;

export const PageHeader = styled.div`
  text-align: center;
  margin-bottom: 40px;
`;

export const PageTitle = styled.h1`
  color: white;
  font-size: 40px;
  font-weight: 700;
  margin-bottom: 10px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);

  @media (max-width: 768px) {
    font-size: 33.6px;
  }
`;

export const PageSubtitle = styled.p`
  color: rgba(255, 255, 255, 0.8);
  font-size: 18px;
  max-width: 600px;
  margin: 0 auto;
`;

export const Card = styled.div`
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  padding: ${props => props.$padding || '32px'};
  box-shadow: 0 8px 32px rgba(168, 230, 207, 0.3);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(168, 230, 207, 0.2);
  margin-bottom: ${props => props.$mb || '24px'};
`;


export const ItemGrid = styled.div`
  display: grid;
  grid-template-columns: repeat(${props => props.$cols || 5}, 1fr);
  gap: ${props => props.$gap || '16px'};
  margin-bottom: ${props => props.$mb || '40px'};

  @media (max-width: 1024px) {
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
  }

  @media (max-width: 768px) {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  @media (max-width: 480px) {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
`;

/**
 * 统一功能卡片组件 - 用于60sAPI/休闲游戏/工具箱/AI应用四个板块
 */
export const FeatureGrid = styled.div`
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 40px;
  animation: ${fadeUp} 0.35s ease-out;

  @media (max-width: 1100px) { grid-template-columns: repeat(4, 1fr); }
  @media (max-width: 768px) { grid-template-columns: repeat(3, 1fr); gap: 12px; }
  @media (max-width: 480px) { grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 0 12px 32px; }
`;

export const FeatureCard = styled.div`
  background: rgba(255,255,255,0.96);
  border-radius: 16px;
  padding: 20px 12px 18px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  border: 1px solid rgba(0,0,0,0.04);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 140px;

  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: ${({ $color }) => $color || 'linear-gradient(90deg, #4ade80, #86efac)'};
    opacity: 0.9;
    transition: opacity 0.2s, height 0.2s;
  }

  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 28px rgba(0,0,0,0.12);
    border-color: rgba(0,0,0,0.08);
    &::before { opacity: 1; height: 4px; }
  }

  &:active { transform: translateY(-2px); }

  @media (max-width: 640px) {
    padding: 16px 10px 14px;
    border-radius: 14px;
    min-height: 120px;
  }
`;

export const FeatureCardIcon = styled.div`
  font-size: 32px;
  margin-bottom: 10px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: ${({ $bg }) => $bg || 'rgba(74, 222, 128, 0.1)'};
  border: 1px solid ${({ $border }) => $border || 'rgba(74, 222, 128, 0.25)'};

  svg {
    display: block;
    width: 24px;
    height: 24px;
    color: ${({ $iconColor }) => $iconColor || '#22c55e'};
  }

  @media (max-width: 640px) {
    font-size: 26px;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    margin-bottom: 8px;
    svg { width: 20px; height: 20px; }
  }
`;

export const FeatureCardTitle = styled.div`
  font-size: 17px;
  font-weight: 700;
  color: #1f2937;
  line-height: 1.3;
  margin-bottom: 8px;
  width: 100%;

  @media (max-width: 640px) { font-size: 15px; }
`;

export const FeatureCardDesc = styled.div`
  font-size: 14px;
  color: #9ca3af;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  padding: 0 4px;
  width: 100%;
  flex: 1;

  @media (max-width: 640px) { font-size: 12px; }
`;

export const FeatureCardTag = styled.span`
  display: inline-block;
  font-size: 10px;
  color: #6b7280;
  background: #f3f4f6;
  padding: 2px 8px;
  border-radius: 6px;
  margin-top: 8px;
  font-weight: 500;
`;

/**
 * 横向卡片 - 用于首页大模块入口
 */
export const ModuleGrid = styled.div`
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
  
  @media (max-width: 520px) { grid-template-columns: 1fr; gap: 12px; padding: 0 12px; }
`;

export const ModuleCard = styled(Link)`
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: rgba(255,255,255,0.95);
  border-radius: 16px;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  border: 1px solid rgba(0,0,0,0.04);
  transition: transform 0.2s, box-shadow 0.2s;
  
  &:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.08);
  }
  &:active { transform: translateY(-1px); }
  
  @media (max-width: 640px) { padding: 16px; gap: 12px; }
`;

export const ModuleIconBox = styled.div`
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: ${({ $bg }) => $bg || 'linear-gradient(135deg,#81c784,#a5d6a7)'};
  color: #fff;
  font-size: 20px;
  
  @media (max-width: 640px) {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    font-size: 18px;
  }
`;

export const ModuleInfo = styled.div`
  flex: 1;
  min-width: 0;
  text-align: left;
`;

export const ModuleTitle = styled.div`
  font-size: 16px;
  font-weight: 700;
  color: #1f2937;
  margin-bottom: 3px;
  @media (max-width: 640px) { font-size: 14px; }
`;

export const ModuleDesc = styled.div`
  font-size: 12px;
  color: #6b7280;
  line-height: 1.4;
  @media (max-width: 640px) { font-size: 11px; }
`;

export const ModuleTags = styled.div`
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 6px;
`;

export const ModuleTag = styled.span`
  font-size: 10px;
  color: #6b7280;
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
`;
