/* ============================================
   agent.smith — Design System & Styles
   Tamagotchi vibes, pixel creatures, beige warmth
   ============================================ */

/* --- Custom Properties --- */
:root {
  --bg: #f5f0e8;
  --bg-card: #fffdf7;
  --bg-card-hover: #fff9ed;
  --text: #2c2416;
  --text-muted: #8a7e6b;
  --text-light: #b5a992;
  --accent: #e85d3a;
  --accent-hover: #d14e2d;
  --accent-soft: #fce8e2;
  --border: #e6dfd2;
  --border-hover: #d4c9b5;
  --tag-bg: #ede7db;
  --tag-bg-active: #2c2416;
  --tag-text: #6b5f4e;
  --tag-text-active: #f5f0e8;
  --shadow-sm: 0 1px 3px rgba(44, 36, 22, 0.06);
  --shadow-md: 0 4px 12px rgba(44, 36, 22, 0.08);
  --shadow-lg: 0 8px 24px rgba(44, 36, 22, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-serif: 'Instrument Serif', Georgia, serif;
  --font-mono: 'Space Mono', 'Courier New', monospace;
  --transition: 0.2s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--accent-hover);
}

/* --- Container --- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* --- Header --- */
.header {
  text-align: center;
  margin-bottom: 2.5rem;
  padding: 2rem 0 1rem;
}

.logo-creature {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 90px;
  margin-bottom: -0.1rem;
}

.logo {
  font-family: var(--font-serif);
  font-size: 3.5rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--text);
}

.logo-dot {
  color: var(--accent);
}

.tagline {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  letter-spacing: 0.02em;
}

/* --- Controls --- */
.controls {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
}

.search-wrap {
  flex: 1;
  position: relative;
  min-width: 200px;
}

.search-input {
  width: 100%;
  padding: 0.7rem 1rem 0.7rem 2.5rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-input::placeholder {
  color: var(--text-light);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  font-size: 1rem;
  pointer-events: none;
}

.controls-actions {
  display: flex;
  gap: 0.5rem;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.65rem 1.1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.btn:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.btn-primary:hover {
  background: #1a170f;
  border-color: #1a170f;
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
}

/* --- Tags --- */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 2rem;
}

.tag {
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  user-select: none;
}

.tag:hover {
  background: var(--border);
}

.tag.active {
  background: var(--tag-bg-active);
  color: var(--tag-text-active);
}

/* --- Grid --- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
  margin-bottom: 3rem;
}

/* --- Card --- */
.card {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  transition: all 0.3s ease;
  cursor: default;
  position: relative;
  overflow: hidden;
}

.card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card.highlighted {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-lg);
  animation: pulse-border 1.5s ease-in-out;
}

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-lg); }
  50% { box-shadow: 0 0 0 6px var(--accent-soft), var(--shadow-lg); }
}

.card-creature {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 72px;
  margin-bottom: 1rem;
  position: relative;
  overflow: hidden;
}

.creature-shadow {
  position: absolute;
  bottom: 4px;
  width: 36px;
  height: 7px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.card:hover .creature-pixel {
  animation: card-walk 1.6s linear infinite, card-hop 0.4s ease-in-out infinite;
}

.card:hover .creature-shadow {
  animation: card-walk 1.6s linear infinite, shadow-pulse 0.4s ease-in-out infinite;
}

@keyframes card-walk {
  0%   { margin-left: -30px; }
  100% { margin-left: 30px; }
}

@keyframes card-hop {
  0%, 100% { margin-top: 0; }
  40%      { margin-top: -5px; }
  60%      { margin-top: -5px; }
  85%      { margin-top: 1px; }
}

@keyframes shadow-pulse {
  0%, 100% { transform: scaleX(1); opacity: 1; }
  40%      { transform: scaleX(0.8); opacity: 0.7; }
  60%      { transform: scaleX(0.8); opacity: 0.7; }
  85%      { transform: scaleX(1.05); opacity: 1; }
}

.creature-pixel {
  width: 4px;
  height: 4px;
  background: transparent;
  transition: transform 0.2s ease;
}

.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  gap: 0.5rem;
}

.card-name {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.card-author {
  font-size: 0.7rem;
  color: var(--text-light);
  white-space: nowrap;
}

.card-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 1rem;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 1rem;
}

.card-tag {
  font-size: 0.65rem;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  background: var(--tag-bg);
  color: var(--tag-text);
}

.card-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.card-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.card-btn:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--bg-card);
}

.card-btn-copy:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- Empty State --- */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state-text {
  font-size: 0.9rem;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  padding: 0.6rem 1.2rem;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(44, 36, 22, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  max-width: 480px;
  width: 90%;
  position: relative;
  transform: translateY(20px);
  transition: transform 0.3s ease;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
  transition: color var(--transition);
}

.modal-close:hover {
  color: var(--text);
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 1.8rem;
  font-weight: 400;
  margin-bottom: 0.75rem;
}

.modal-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.modal-link {
  display: inline-flex;
  width: auto;
}

.modal-divider {
  height: 1px;
  background: var(--border);
  margin: 1.5rem 0;
}

.modal-hint {
  font-size: 0.75rem;
  color: var(--text-light);
  line-height: 1.5;
}

/* --- Detail View --- */
.detail-view {
  max-width: 800px;
  margin: 0 auto;
  animation: fadeIn 0.3s ease both;
}

.detail-back {
  margin-bottom: 2rem;
}

.detail-creature {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 160px;
  margin-bottom: 2rem;
  position: relative;
  overflow: hidden;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
}

.tama-walker {
  position: relative;
}

.tama-walker .creature-shadow {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 10px;
  animation: shadow-pulse-detail 0.5s ease-in-out infinite;
}

@keyframes shadow-pulse-detail {
  0%, 100% { transform: translateX(-50%) scaleX(1); opacity: 1; }
  35%      { transform: translateX(-50%) scaleX(0.75); opacity: 0.6; }
  65%      { transform: translateX(-50%) scaleX(0.75); opacity: 0.6; }
  85%      { transform: translateX(-50%) scaleX(1.05); opacity: 1; }
}


@keyframes tama-walk {
  0%        { transform: translateX(-220px) scaleX(1); }
  48%       { transform: translateX(220px) scaleX(1); }
  49%       { transform: translateX(220px) scaleX(1); }
  50%       { transform: translateX(220px) scaleX(-1); }
  98%       { transform: translateX(-220px) scaleX(-1); }
  99%       { transform: translateX(-220px) scaleX(-1); }
  100%      { transform: translateX(-220px) scaleX(1); }
}

@keyframes tama-hop {
  0%, 100% { margin-top: 0; }
  35%      { margin-top: -10px; }
  65%      { margin-top: -10px; }
  85%      { margin-top: 2px; }
}

.detail-info {
  text-align: center;
  margin-bottom: 2.5rem;
}

.detail-name {
  font-family: var(--font-serif);
  font-size: 2.5rem;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.detail-author {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 1rem;
}

.detail-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 600px;
  margin: 0 auto 1.25rem;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.detail-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.detail-copy-btn {
  font-size: 0.8rem;
}

.detail-readme {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.detail-readme-title {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-muted);
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--tag-bg);
}

.detail-readme-content {
  padding: 2rem 1.5rem;
}

/* --- Prose (README styling) --- */
.prose h1 {
  font-family: var(--font-serif);
  font-size: 1.8rem;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.prose h2 {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--text);
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

.prose h3 {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 400;
  color: var(--text);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

.prose p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 1rem;
}

.prose ul {
  list-style: none;
  padding-left: 1rem;
  margin-bottom: 1rem;
}

.prose ul li {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.7;
  position: relative;
  padding-left: 1rem;
}

.prose ul li::before {
  content: "—";
  position: absolute;
  left: 0;
  color: var(--text-light);
}

.prose pre {
  background: #2c2416;
  color: #e8dcc8;
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  background: var(--tag-bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  color: var(--accent);
}

.prose pre code {
  background: none;
  padding: 0;
  color: inherit;
  border-radius: 0;
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.prose strong {
  color: var(--text);
  font-weight: 700;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.prose blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 1rem;
}

/* --- Footer --- */
.footer {
  text-align: center;
  padding: 2rem 0;
  border-top: 1px solid var(--border);
  color: var(--text-light);
  font-size: 0.75rem;
}

.pixel-heart {
  color: var(--accent);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .container {
    padding: 1.5rem 1rem;
  }

  .logo {
    font-size: 2.5rem;
  }

  .controls {
    flex-direction: column;
  }

  .search-wrap {
    width: 100%;
  }

  .controls-actions {
    width: 100%;
    justify-content: stretch;
  }

  .controls-actions .btn {
    flex: 1;
    justify-content: center;
  }

  .grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* --- Subtle animations --- */
@media (prefers-reduced-motion: no-preference) {
  .card {
    animation: fadeIn 0.3s ease both;
  }

  .card:nth-child(1) { animation-delay: 0.05s; }
  .card:nth-child(2) { animation-delay: 0.1s; }
  .card:nth-child(3) { animation-delay: 0.15s; }
  .card:nth-child(4) { animation-delay: 0.2s; }
  .card:nth-child(5) { animation-delay: 0.25s; }
  .card:nth-child(6) { animation-delay: 0.3s; }
  .card:nth-child(7) { animation-delay: 0.35s; }
  .card:nth-child(8) { animation-delay: 0.4s; }
}

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