:root {
  --bg: #0e1116; --bg-2: #161b22; --bg-3: #1f2630; --line: #2b3440;
  --text: #e6edf3; --muted: #8d99a8; --accent: #6ea8fe; --accent-ink: #0b1220;
  --ok: #56d39b; --warn: #f0b35a;
  --radius: 12px; --shadow: 0 6px 24px rgba(0, 0, 0, .28);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f5f7fa; --bg-2: #ffffff; --bg-3: #eef1f5; --line: #d6dce4;
  --text: #17202b; --muted: #5d6978; --accent: #1f5fd6; --accent-ink: #ffffff;
  --ok: #17794f; --warn: #94610c;
  --shadow: 0 6px 20px rgba(23, 32, 43, .09);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  width: 100%; min-height: 100vh; min-height: 100dvh;
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
kbd {
  font: 12px/1 ui-monospace, Consolas, monospace; padding: 3px 6px; border-radius: 5px;
  border: 1px solid var(--line); background: var(--bg-3); color: var(--muted);
}

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 10px 16px;
  align-items: center; justify-content: space-between; padding: 12px 20px;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .2px; }
.mark {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background:
    linear-gradient(var(--accent), var(--accent)) 0 0 / 9px 9px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 100% 0 / 9px 9px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 0 100% / 9px 9px no-repeat,
    linear-gradient(var(--ok), var(--ok)) 100% 100% / 9px 9px no-repeat;
}
.tools { display: flex; align-items: center; gap: 8px; flex: 1 1 260px; justify-content: flex-end; min-width: 0; }
.search { position: relative; flex: 1 1 200px; max-width: 360px; min-width: 0; }
.search input {
  width: 100%; padding: 8px 34px 8px 12px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit;
}
.search kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg-3); color: var(--text); font: inherit; text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.icon { width: 36px; padding: 7px 0; flex: none; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 12px 20px 0; }
.group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.group > span { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin-right: 2px; }
.chip {
  padding: 4px 11px; border-radius: 999px; border: 1px solid var(--line); background: transparent;
  color: var(--muted); font: inherit; font-size: 13px; cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- cards ---------- */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 16px; padding: 16px 20px 32px;
}
.card {
  display: flex; flex-direction: column; gap: 10px; min-width: 0; padding: 16px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.card:hover, .card:focus-within { border-color: var(--accent); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card h2 { margin: 0; font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; }
.tier {
  flex: none; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--warn); color: var(--warn); white-space: nowrap;
}
.desc { margin: 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.tag {
  padding: 2px 9px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg-3);
  color: var(--muted); font: 12px/1.5 ui-monospace, Consolas, monospace; cursor: pointer;
}
.tag:hover { color: var(--text); border-color: var(--accent); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.badge {
  padding: 2px 9px; border-radius: 999px; border: 1px solid var(--ok); background: transparent;
  color: var(--ok); font: inherit; font-size: 12px; cursor: pointer;
}
.changelog { margin: 0; padding: 10px 12px; list-style: none; border-radius: 8px; background: var(--bg-3); font-size: 13px; max-height: 220px; overflow: auto; }
.changelog li + li { margin-top: 8px; }
.changelog b { font-family: ui-monospace, Consolas, monospace; }
.changelog time { color: var(--muted); margin: 0 6px; }
.changelog .no-entry { color: var(--muted); font-style: italic; }
.card-foot { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; padding-top: 4px; }
select {
  padding: 7px 8px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; max-width: 100%;
}
.empty { margin: 8px 20px 32px; color: var(--muted); }

/* ---------- viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; background: var(--bg); }
.viewer[hidden] { display: none; }
.viewer-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.viewer-bar strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46vw; }
.spacer { flex: 1 1 0; }
.viewer iframe { flex: 1 1 auto; width: 100%; min-height: 0; border: 0; background: #fff; }

/* ---------- help ---------- */
dialog {
  width: min(92vw, 440px); padding: 20px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h2 { margin: 0 0 12px; font-size: 17px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0 0 12px; }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }

@media (max-width: 640px) {
  .top { padding: 10px 12px; }
  .filters { padding: 10px 12px 0; }
  .grid { padding: 12px 12px 24px; gap: 12px; }
  .search kbd { display: none; }
  .search input { padding-right: 12px; }
  .viewer-bar strong { max-width: 100%; flex: 1 1 100%; order: -1; }
}
@media (prefers-reduced-motion: no-preference) {
  .card { transition: border-color .12s, box-shadow .12s; }
}
