/**
 * ============================================
 * Stylesheet: character-codex.css
 * Area:   海豹百科圖鑑 毛氈質感主題
 * Version: v1.0
 * ============================================
 */

:root {
  --felt-cream: #FFF8F0;
  --felt-warm-white: #FFFBF5;
  --felt-light-blue: #E8F4FD;
  --felt-deep-ocean: #1B2D4F;
  --felt-ocean-mid: #2A4A6B;
  --felt-tiffany: #81D8D0;
  --felt-coral: #FF7F7F;
  --felt-gold: #FFD700;
  --felt-shadow: 0 4px 20px rgba(139, 115, 85, 0.1);
  --felt-noise: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  --stitch-border: 2px dashed rgba(180, 160, 140, 0.35);
  --rarity-common: #95A5A6;
  --rarity-uncommon: #2ECC71;
  --rarity-rare: #3498DB;
  --rarity-epic: #9B59B6;
  --rarity-legendary: linear-gradient(135deg, #FFD700, #FFA500);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Nunito', 'Quicksand', -apple-system, sans-serif;
  background: var(--felt-cream);
  color: #4A3728;
  overflow-x: hidden;
}

#codex-app {
  position: relative;
  background: var(--felt-cream);
  background-image: var(--felt-noise);
  background-size: 200px 200px;
}

/* Particles */
.felt-particles { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.felt-particle { position: absolute; border-radius: 50%; opacity: 0; animation: feltParticleFall linear infinite; }
@keyframes feltParticleFall {
  0% { transform: translateY(-20px) rotate(0deg) scale(0.5); opacity: 0; }
  10% { opacity: 0.5; }
  90% { opacity: 0.3; }
  100% { transform: translateY(100vh) rotate(720deg) scale(0.3); opacity: 0; }
}

/* Header */
.cx-header {
  position: sticky; top: 0; z-index: 100;
  background: linear-gradient(135deg, #1a3a2a, #2d5a3f);
  background-image: var(--felt-noise), linear-gradient(135deg, #1a3a2a, #2d5a3f);
  background-size: 200px 200px, 100% 100%;
  border-bottom: 3px solid var(--felt-tiffany);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.cx-header-inner { max-width: 1200px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; }
.cx-logo { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.cx-logo-img { width: 36px; height: 36px; border-radius: 50%; animation: cx-breathe 3s ease-in-out infinite; }
@keyframes cx-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.cx-logo-text { font-family: 'ZCOOL KuaiLe', cursive; font-size: 1.3rem; color: var(--felt-tiffany); }
.cx-nav { display: flex; gap: 20px; }
.cx-nav-link { color: rgba(255,255,255,0.8); text-decoration: none; font-weight: 600; font-size: 0.9rem; padding: 6px 14px; border-radius: 20px; transition: all 0.3s; border: 1px solid transparent; }
.cx-nav-link:hover { color: white; background: rgba(129,216,208,0.15); border-color: rgba(129,216,208,0.3); }

/* Hero */
.cx-hero { position: relative; padding: 80px 24px 60px; text-align: center; overflow: hidden; min-height: 380px; display: flex; align-items: center; justify-content: center; }
.cx-hero-bg { position: absolute; inset: 0; background: linear-gradient(180deg, #1a3a2a 0%, #2d5a3f 40%, var(--felt-cream) 100%); z-index: 0; }
.cx-hero-felt-texture { position: absolute; inset: 0; background-image: var(--felt-noise); background-size: 200px 200px; opacity: 0.5; }
.cx-hero-ocean-waves { position: absolute; bottom: 0; left: 0; width: 200%; height: 80px; background: repeating-linear-gradient(90deg, transparent, transparent 40px, rgba(129,216,208,0.1) 40px, rgba(129,216,208,0.1) 80px); animation: cx-waves 8s linear infinite; }
@keyframes cx-waves { 0% { transform: translateX(0); } 100% { transform: translateX(-50%); } }

.cx-hero-content { position: relative; z-index: 1; }
.cx-hero-book { display: inline-block; position: relative; margin-bottom: 20px; }
.cx-book-emoji { font-size: 4rem; display: inline-block; animation: cx-book-open 3s ease-in-out infinite; }
@keyframes cx-book-open { 0%, 100% { transform: rotateY(0deg); } 50% { transform: rotateY(15deg); } }
.cx-book-glow { position: absolute; inset: -20px; border-radius: 50%; background: radial-gradient(circle, rgba(129,216,208,0.3) 0%, transparent 70%); animation: cx-glow 3s ease-in-out infinite; }
@keyframes cx-glow { 0%, 100% { opacity: 0.5; transform: scale(1); } 50% { opacity: 1; transform: scale(1.2); } }

.cx-hero-title { font-family: 'ZCOOL KuaiLe', cursive; font-size: 2.6rem; color: white; margin-bottom: 12px; text-shadow: 0 3px 12px rgba(0,0,0,0.3); }
.cx-hero-subtitle { color: rgba(255,255,255,0.85); font-size: 1.05rem; margin-bottom: 24px; }

.cx-hero-progress { max-width: 400px; margin: 0 auto; }
.cx-progress-bar { height: 10px; background: rgba(255,255,255,0.15); border-radius: 5px; overflow: hidden; margin-bottom: 8px; }
.cx-progress-fill { height: 100%; background: linear-gradient(90deg, var(--felt-tiffany), #4ECDC4, var(--felt-gold)); border-radius: 5px; width: 0%; transition: width 1.5s cubic-bezier(0.4,0,0.2,1); position: relative; }
.cx-progress-fill::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent); animation: cx-progress-shine 2s ease-in-out infinite; }
@keyframes cx-progress-shine { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
.cx-progress-text { font-size: 0.8rem; color: rgba(255,255,255,0.7); }

/* Search & Filter */
.cx-search-section { padding-top: 30px; padding-bottom: 10px; }
.cx-search-bar { max-width: 500px; margin: 0 auto 20px; }
.cx-search-input { width: 100%; padding: 14px 20px; border-radius: 30px; font-size: 1rem; border: var(--stitch-border); background: var(--felt-warm-white); transition: border-color 0.3s, box-shadow 0.3s; }
.cx-search-input:focus { outline: none; border-color: var(--felt-tiffany); box-shadow: 0 0 0 3px rgba(129,216,208,0.2); }
.cx-filter-bar { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.cx-filter-btn { background: var(--felt-warm-white); border: var(--stitch-border); border-radius: 24px; padding: 8px 18px; font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 0.85rem; color: #7A6B5D; cursor: pointer; transition: all 0.3s; }
.cx-filter-btn:hover { background: rgba(129,216,208,0.1); border-color: var(--felt-tiffany); color: var(--felt-deep-ocean); }
.cx-filter-active { background: linear-gradient(135deg, var(--felt-tiffany), #4ECDC4); color: var(--felt-ink, #214742); border-color: var(--felt-tiffany); }

/* Sections */
.cx-section { max-width: 1200px; margin: 0 auto; padding: 40px 24px; position: relative; z-index: 1; }
.cx-section-title { font-family: 'ZCOOL KuaiLe', cursive; font-size: 1.8rem; color: var(--felt-deep-ocean); text-align: center; margin-bottom: 36px; }
.felt-stitch-border::after { content: ''; display: block; width: 80px; height: 3px; margin: 12px auto 0; background: repeating-linear-gradient(90deg, var(--felt-tiffany) 0, var(--felt-tiffany) 8px, transparent 8px, transparent 12px); }
.felt-card { background: var(--felt-warm-white); background-image: var(--felt-noise); background-size: 200px 200px; border-radius: 20px; border: var(--stitch-border); box-shadow: var(--felt-shadow); transition: transform 0.3s, box-shadow 0.3s; }
.felt-card:hover { transform: translateY(-4px); box-shadow: 0 8px 32px rgba(139,115,85,0.15); }

/* Character Grid */
.cx-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 20px; }

.cx-char-card { position: relative; background: var(--felt-warm-white); background-image: var(--felt-noise); background-size: 200px 200px; border-radius: 18px; border: var(--stitch-border); box-shadow: var(--felt-shadow); overflow: hidden; cursor: pointer; transition: all 0.4s cubic-bezier(0.34,1.56,0.64,1); }
.cx-char-card:hover { transform: translateY(-8px) scale(1.03); box-shadow: 0 12px 40px rgba(139,115,85,0.2); }

.cx-char-rarity { position: absolute; top: 8px; right: 8px; padding: 3px 10px; border-radius: 10px; font-size: 0.65rem; font-weight: 800; color: #102A26; z-index: 2; letter-spacing: 0.5px; }
.cx-rarity-common { background: var(--rarity-common); }
.cx-rarity-uncommon { background: var(--rarity-uncommon); }
.cx-rarity-rare { background: var(--rarity-rare); }
.cx-rarity-epic { background: var(--rarity-epic); color: white; }
.cx-rarity-legendary { background: var(--rarity-legendary); animation: cx-legendary-glow 2s ease-in-out infinite; }
@keyframes cx-legendary-glow { 0%, 100% { box-shadow: 0 0 4px rgba(255,215,0,0.3); } 50% { box-shadow: 0 0 16px rgba(255,215,0,0.6); } }

.cx-char-img-wrap { position: relative; height: 160px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.cx-char-img-wrap::before { content: ''; position: absolute; inset: 0; background: radial-gradient(circle at center, rgba(129,216,208,0.08) 0%, transparent 70%); }
.cx-char-img { width: 120px; height: 120px; object-fit: contain; transition: transform 0.5s; filter: drop-shadow(0 4px 12px rgba(0,0,0,0.15)); }
.cx-char-card:hover .cx-char-img { transform: scale(1.12) rotate(3deg); }

.cx-char-locked .cx-char-img { filter: brightness(0) opacity(0.15); }
.cx-char-locked::after { content: '🔒'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 2rem; z-index: 3; }

.cx-char-info { padding: 12px 14px; text-align: center; }
.cx-char-name { font-family: 'ZCOOL KuaiLe', cursive; font-size: 0.9rem; color: var(--felt-deep-ocean); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cx-char-series { font-size: 0.7rem; color: var(--felt-muted, #496960); }

.cx-char-collected { position: absolute; top: 8px; left: 8px; width: 24px; height: 24px; background: var(--felt-tiffany); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.7rem; color: white; z-index: 2; animation: cx-collected-pop 0.5s cubic-bezier(0.34,1.56,0.64,1); }
@keyframes cx-collected-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }

/* Stats */
.cx-stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.cx-stat-card { padding: 28px; text-align: center; }
.cx-stat-icon { font-size: 2rem; margin-bottom: 8px; display: inline-block; animation: cx-stat-bounce 3s ease-in-out infinite; }
@keyframes cx-stat-bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.cx-stat-value { font-family: 'ZCOOL KuaiLe', cursive; font-size: 2rem; color: var(--felt-deep-ocean); }
.cx-stat-label { font-size: 0.8rem; color: var(--felt-muted, #496960); }

/* Detail Modal */
.cx-detail-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 9999; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(6px); animation: fadeIn 0.3s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.cx-detail-modal { background: var(--felt-warm-white); background-image: var(--felt-noise); background-size: 200px 200px; border-radius: 28px; padding: 0; max-width: 500px; width: 92%; border: var(--stitch-border); box-shadow: 0 24px 80px rgba(0,0,0,0.25); animation: cx-modal-pop 0.5s cubic-bezier(0.34,1.56,0.64,1); overflow: hidden; }
@keyframes cx-modal-pop { 0% { transform: scale(0.6) translateY(40px); opacity: 0; } 100% { transform: scale(1) translateY(0); opacity: 1; } }

.cx-detail-header { position: relative; height: 220px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.cx-detail-header-bg { position: absolute; inset: 0; }
.cx-detail-char-img { position: relative; z-index: 1; width: 160px; height: 160px; object-fit: contain; filter: drop-shadow(0 8px 24px rgba(0,0,0,0.2)); animation: cx-detail-float 3s ease-in-out infinite; }
@keyframes cx-detail-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

.cx-detail-close { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; background: rgba(0,0,0,0.3); color: white; border: none; border-radius: 50%; font-size: 1.2rem; cursor: pointer; z-index: 5; display: flex; align-items: center; justify-content: center; transition: background 0.3s; }
.cx-detail-close:hover { background: rgba(0,0,0,0.5); }

.cx-detail-body { padding: 24px 28px 28px; }
.cx-detail-name { font-family: 'ZCOOL KuaiLe', cursive; font-size: 1.5rem; color: var(--felt-deep-ocean); margin-bottom: 4px; }
.cx-detail-series { font-size: 0.85rem; color: var(--felt-muted, #496960); margin-bottom: 16px; }

.cx-detail-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.cx-detail-stat { text-align: center; padding: 10px; background: rgba(129,216,208,0.06); border-radius: 12px; }
.cx-detail-stat-label { font-size: 0.7rem; color: var(--felt-muted, #496960); margin-bottom: 4px; }
.cx-detail-stat-value { font-family: 'ZCOOL KuaiLe', cursive; font-size: 1.1rem; color: var(--felt-deep-ocean); }

.cx-detail-desc { font-size: 0.88rem; color: #5A4B3D; line-height: 1.7; margin-bottom: 16px; padding: 14px; background: rgba(129,216,208,0.04); border-radius: 14px; border: 1px solid rgba(129,216,208,0.1); }

.cx-detail-skills { margin-bottom: 16px; }
.cx-detail-skills-title { font-family: 'ZCOOL KuaiLe', cursive; font-size: 0.95rem; color: var(--felt-deep-ocean); margin-bottom: 8px; }
.cx-detail-skill { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.cx-detail-skill-name { font-size: 0.82rem; color: #5A4B3D; min-width: 80px; }
.cx-detail-skill-bar { flex: 1; height: 6px; background: rgba(0,0,0,0.06); border-radius: 3px; overflow: hidden; }
.cx-detail-skill-fill { height: 100%; border-radius: 3px; transition: width 1s ease; }

.cx-detail-collect-btn { width: 100%; padding: 14px; border: none; border-radius: 24px; font-family: 'ZCOOL KuaiLe', cursive; font-size: 1.05rem; cursor: pointer; transition: all 0.3s; position: relative; overflow: hidden; }
.cx-detail-collect-btn.cx-not-collected { background: linear-gradient(135deg, var(--felt-tiffany), #4ECDC4); color: var(--felt-ink, #214742); }
.cx-detail-collect-btn.cx-collected { background: rgba(129,216,208,0.1); color: var(--felt-sea-dark, #175E5A); border: 2px solid var(--felt-tiffany); }
.cx-detail-collect-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 15px rgba(78,205,196,0.3); }

/* Footer */
.cx-footer { text-align: center; padding: 40px 24px; background: linear-gradient(180deg, transparent, rgba(26,58,42,0.05)); }
.cx-footer-seal-img { width: 60px; height: 60px; object-fit: contain; margin-bottom: 12px; opacity: 0.6; }
.cx-footer p { font-size: 0.85rem; color: #9A8B7D; }

/* Animations */
.cx-float { animation: cx-float 4s ease-in-out infinite; }
@keyframes cx-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.cx-fade-up { opacity: 0; transform: translateY(30px); transition: opacity 0.6s, transform 0.6s; }
.cx-fade-up.cx-visible { opacity: 1; transform: translateY(0); }

/* Responsive */
@media (max-width: 768px) {
  .cx-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
  .cx-stats-grid { grid-template-columns: repeat(2, 1fr); }
  .cx-hero-title { font-size: 2rem; }
  .cx-char-img { width: 90px; height: 90px; }
  .cx-char-img-wrap { height: 120px; }
}
@media (max-width: 480px) {
  .cx-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
  .cx-nav { gap: 8px; }
  .cx-nav-link { font-size: 0.8rem; padding: 4px 10px; }
  .cx-filter-btn { font-size: 0.75rem; padding: 6px 12px; }
}

/* Keyboard focus must override the more specific legacy :focus reset. */
.cx-search-input:focus-visible { outline: 3px solid #17635D; outline-offset: 4px; }

/* Detail markup supplies these colors inline; scope overrides to the four light badges and numeric skill values. */
.cx-detail-body > div:first-child > span:is([style*="background:#95A5A6" i], [style*="background:#2ECC71" i], [style*="background:#3498DB" i], [style*="background:#FFD700" i]) { color: #102A26 !important; }
.cx-detail-skill > span:last-child { color: var(--felt-muted, #496960) !important; }
