:root {
  --paper: #f4efe6;
  --card: #fffdf8;
  --ink: #1c2420;
  --muted: #5e6a62;
  --line: #e2dacb;
  --forest: #1f3d2b;
  --forest-2: #2d5a3f;
  --blaze: #e8743b;
  --blaze-ink: #9a3f12;
  --radius: 18px;
  --shadow: 0 1px 0 rgba(31, 61, 43, .04), 0 8px 24px -12px rgba(31, 61, 43, .25);
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121815;
    --card: #1a221e;
    --ink: #ece6da;
    --muted: #a3ada6;
    --line: #2a3530;
    --forest: #8fc4a1;
    --forest-2: #b5dcc2;
    --blaze: #f08a55;
    --blaze-ink: #f6a77d;
    --shadow: 0 1px 0 rgba(0, 0, 0, .2), 0 10px 30px -14px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
.wrap { width: min(1100px, 100% - 32px); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- header */
.masthead {
  padding: calc(env(safe-area-inset-top) + 28px) 0 22px;
  border-bottom: 1px dashed var(--line);
}
.masthead .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand img { border-radius: 12px; }
h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(28px, 5vw, 40px);
  letter-spacing: -.01em;
  line-height: 1;
  margin: 0;
  color: var(--forest);
}
.tagline { margin: 6px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; }

/* ---------- buttons */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 9px 16px;
  font: 600 14px/1 var(--font);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
  transition: transform .12s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--forest); color: var(--paper); }
.btn.primary:hover { background: var(--forest-2); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: var(--forest); }
.icon-btn { background: none; border: 0; font-size: 18px; color: var(--muted); cursor: pointer; padding: 6px 10px; border-radius: 8px; }
.icon-btn:hover { background: var(--line); }
:focus-visible { outline: 3px solid var(--blaze); outline-offset: 2px; }

/* ---------- controls */
.controls { padding: 24px 0 8px; display: grid; gap: 14px; }
.search {
  display: flex; align-items: center; gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 14px;
  box-shadow: var(--shadow);
}
.search svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; flex: none; }
.search input {
  flex: 1; border: 0; background: transparent; color: var(--ink);
  font: 17px/1 var(--font); padding: 15px 0; outline: none; min-width: 0;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 13px;
  font: 500 14px/1.2 var(--font);
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--forest); border-color: var(--forest); color: var(--paper); }
.count { color: var(--muted); font-size: 14px; margin: 10px 0 12px; min-height: 1.5em; }

/* ---------- grid */
.grid {
  list-style: none; margin: 0 0 40px; padding: 0;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
}
.card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent, var(--forest)) 45%, var(--line)); }
.card::before {
  content: ""; position: absolute; left: 18px; top: 0; width: 34px; height: 4px;
  border-radius: 0 0 4px 4px; background: var(--accent, var(--blaze));
}
.card-head { display: flex; gap: 12px; align-items: center; }
.app-icon {
  width: 48px; height: 48px; flex: none;
  border-radius: 12px; overflow: hidden;
  display: grid; place-items: center;
  background: var(--accent, var(--forest)); color: #fff;
  font: 700 20px/1 var(--display);
}
.app-icon img { width: 100%; height: 100%; object-fit: cover; background: #fff; }
.app-icon.lg { width: 64px; height: 64px; font-size: 26px; border-radius: 16px; }
.card h3 { margin: 0; font-size: 17px; line-height: 1.25; }
.card h3 button { all: unset; cursor: pointer; }
.card h3 button:focus-visible { outline: 3px solid var(--blaze); outline-offset: 2px; border-radius: 4px; }
.card h3 button::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.cat { font-size: 12.5px; color: var(--blaze-ink); font-weight: 600; letter-spacing: .02em; }
.desc {
  margin: 0; color: var(--muted); font-size: 15px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-foot { margin-top: auto; display: flex; gap: 8px; align-items: center; justify-content: space-between; padding-top: 4px; }
.card-foot .btn { position: relative; z-index: 1; }
.host { margin: 0; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-new { font-size: 11px; font-weight: 700; color: var(--paper); background: var(--blaze); border-radius: 999px; padding: 2px 7px; margin-left: 6px; vertical-align: 2px; }

/* ---------- empty */
.empty { text-align: center; padding: 48px 16px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty-title { font: 700 22px/1.2 var(--display); color: var(--ink); margin: 0 0 6px; }
code { background: var(--line); border-radius: 6px; padding: 1px 6px; font-size: .9em; }

/* ---------- dialog */
dialog {
  width: min(520px, 100% - 24px);
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
  color: var(--ink);
  padding: 8px 24px 24px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .45);
}
dialog::backdrop { background: rgba(18, 24, 21, .45); backdrop-filter: blur(3px); }
.close-row { display: flex; justify-content: flex-end; }
.d-head { display: flex; gap: 14px; align-items: center; }
.d-head h2 { margin: 0; font: 700 24px/1.15 var(--display); }
.d-desc { font-size: 16px; margin: 16px 0 12px; }
.tags { list-style: none; padding: 0; margin: 0 0 18px; display: flex; flex-wrap: wrap; gap: 6px; }
.tags li { font-size: 12.5px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; color: var(--muted); }
.d-actions { display: flex; gap: 10px; }
.d-actions .btn { padding: 12px 20px; font-size: 15px; }

/* ---------- misc */
.footer { color: var(--muted); font-size: 13px; padding: 12px 0 calc(env(safe-area-inset-bottom) + 24px); }
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  box-shadow: var(--shadow);
}
.skeleton { height: 170px; border-radius: var(--radius); background: linear-gradient(90deg, var(--card), var(--line), var(--card)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
