/* --- Tokens --- */
:root {
  --bg: #f4f6f0;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --border: #e2e5da;
  --border-hover: #c8cdbf;
  --text: #1e2418;
  --text-secondary: #4d5645;
  --text-tertiary: #7c856f;
  --accent: #5a6d3a;
  --accent-fg: #ffffff;
  --accent-subtle: #edf1e4;
  --accent-ring: rgba(90, 109, 58, 0.25);
  --shadow-sm: 0 1px 2px rgba(30, 36, 24, 0.04);
  --shadow-md: 0 4px 16px rgba(30, 36, 24, 0.07);
  --shadow-lg: 0 8px 32px rgba(30, 36, 24, 0.10);
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --transition: 0.18s cubic-bezier(.4,0,.2,1);
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- Shell --- */
.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(244, 246, 240, 0.82);
  backdrop-filter: blur(16px) saturate(1.6);
  -webkit-backdrop-filter: blur(16px) saturate(1.6);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-xs);
  background: var(--accent);
  color: var(--accent-fg);
  display: grid;
  place-items: center;
}

.title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.subtitle {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-tertiary);
  font-weight: 400;
  line-height: 1.3;
}

/* --- Search --- */
.search-wrap {
  position: relative;
  width: 100%;
  max-width: 320px;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}

.search {
  width: 100%;
  padding: 0.6rem 1rem 0.6rem 2.5rem;
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

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

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

/* --- Main --- */
.main {
  flex: 1;
  padding: 2rem 1.5rem 3rem;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

/* --- Grid --- */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

/* --- Card --- */
.app-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  text-decoration: none;
  color: inherit;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.875rem 1rem;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.app-card:hover {
  background: var(--accent-subtle);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.app-card:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.app-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Card icon --- */
.app-card-image-wrap {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-xs);
  overflow: hidden;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.app-card-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  padding: 4px;
}

/* --- Card body --- */
.app-card-body {
  min-width: 0;
  flex: 1;
}

.app-card-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-card-desc {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--text-tertiary);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Card arrow hint --- */
.app-card::after {
  content: '';
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E");
  mask-size: contain;
  -webkit-mask-size: contain;
  background: var(--text-tertiary);
  opacity: 0;
  transition: opacity var(--transition), transform var(--transition);
}

.app-card:hover::after {
  opacity: 0.5;
  transform: translateX(2px);
}

/* --- States --- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 3rem;
  color: var(--text-tertiary);
  font-size: 0.85rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error {
  padding: 1rem 1.25rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-xs);
  color: #b91c1c;
  font-size: 0.85rem;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-tertiary);
  font-size: 0.9rem;
}

.hidden { display: none !important; }

/* --- Responsive --- */
@media (max-width: 640px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .search-wrap {
    max-width: 100%;
  }

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