/* ============================================================
   Downloads — Apple-style theme (auto light/dark, indigo accent)
   ============================================================ */

:root {
  --accent: #5b5bd6;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(91, 91, 214, 0.12);
  --accent-fg: #ffffff;

  --bg: #fbfbfd;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --text: #1d1d1f;
  --text-2: #515154;
  --muted: #86868b;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.12);

  --danger: #e5484d;
  --danger-hover: #d33840;
  --success: #2a9d57;

  --radius: 14px;
  --radius-lg: 22px;
  --radius-pill: 980px;
  --maxw: 1040px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #7c7cf5;
    --accent-hover: #8d8df7;
    --accent-soft: rgba(124, 124, 245, 0.18);

    --bg: #000000;
    --bg-elev: #0c0c0e;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f5f5f7;
    --text-2: #c7c7cc;
    --muted: #8e8e93;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
    --danger: #ff6369;
    --danger-hover: #ff7a7f;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

h1, h2, h3 { letter-spacing: -0.02em; font-weight: 600; line-height: 1.1; }
h1 { font-size: clamp(2rem, 5vw, 3rem); margin: 0 0 0.4rem; }
h2 { font-size: 1.4rem; margin: 0 0 0.6rem; }

/* ---------- header / shell ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  height: 52px;
  padding: 0 clamp(1rem, 4vw, 2rem);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text);
  letter-spacing: -0.01em;
}
.brand:hover { color: var(--text); }
.brand .mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #9b6cff);
  color: #fff;
}
.brand .mark svg { width: 16px; height: 16px; }

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(2rem, 6vw, 4.5rem) clamp(1rem, 4vw, 2rem) 4rem;
}

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 2.5rem 1rem 3rem;
}

/* ---------- index ---------- */
.page-head { text-align: center; margin-bottom: clamp(2rem, 5vw, 3.5rem); }
.page-head .subtitle {
  color: var(--text-2);
  font-size: clamp(1.05rem, 2.5vw, 1.35rem);
  max-width: 40ch;
  margin: 0 auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.1rem;
}
.card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  color: inherit;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
  color: inherit;
}
.card .icon { width: 64px; height: 64px; border-radius: 16px; flex: none; }
.card-body { min-width: 0; }
.card-body h2 { font-size: 1.15rem; margin: 0 0 0.15rem; }
.card-body p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .chev { margin-left: auto; color: var(--muted); flex: none; }

/* shared icon visuals */
.icon { object-fit: cover; background: var(--surface-2); }
.icon.placeholder {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #9b6cff);
  color: #fff;
  font-weight: 600;
  font-size: 1.5rem;
}

/* ---------- app detail ---------- */
.app-detail { text-align: center; max-width: 720px; margin: 0 auto; }
.app-detail .icon.large {
  width: 128px;
  height: 128px;
  border-radius: 28px;
  box-shadow: var(--shadow);
  margin-bottom: 1.4rem;
}
.app-detail .icon.large.placeholder { font-size: 3rem; }
.app-detail .desc {
  color: var(--text-2);
  font-size: 1.15rem;
  max-width: 52ch;
  margin: 0.6rem auto 2.4rem;
  white-space: pre-wrap;
}

.downloads { display: flex; flex-direction: column; align-items: center; gap: 0.9rem; max-width: 560px; margin: 0 auto; }

/* primary (best-match) button */
.dl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.7rem 1.4rem;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.dl-btn svg { width: 20px; height: 20px; flex: none; }
.dl-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); color: var(--text); }
.dl-btn .ver { opacity: 0.6; font-weight: 400; font-size: 0.9em; }

.dl-btn.best {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-fg);
  font-size: 1.12rem;
  font-weight: 600;
  padding: 0.95rem 2rem;
  box-shadow: 0 8px 24px var(--accent-soft);
}
.dl-btn.best:hover { background: var(--accent-hover); color: var(--accent-fg); box-shadow: var(--shadow); }

.dl-secondary {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.7rem;
  margin-top: 0.4rem;
}
.dl-divider {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 1.4rem 0 0.2rem;
}

/* command / install snippet block */
.cmd-block {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  overflow: hidden;
}
.cmd-block.best { border-color: var(--accent); box-shadow: 0 8px 24px var(--accent-soft); }
.cmd-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.cmd-plat { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 600; font-size: 0.95rem; }
.cmd-plat svg { width: 18px; height: 18px; }
.cmd-plat .ver { opacity: 0.6; font-weight: 400; }
.cmd-block pre {
  margin: 0;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
  white-space: pre;
  -webkit-text-size-adjust: 100%;
}
.cmd-block code { font: inherit; }

/* ---------- generic UI ---------- */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
  font-size: 1.05rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  border: none;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.btn:hover { background: var(--accent-hover); color: #fff; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--surface); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--border); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn.small { padding: 0.4rem 0.85rem; font-size: 0.85rem; }

/* ---------- forms / admin ---------- */
.admin-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.8rem;
  flex-wrap: wrap;
}
.admin-nav .actions { display: flex; gap: 0.6rem; align-items: center; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: clamp(1.3rem, 4vw, 2rem);
}

.form-narrow { max-width: 420px; margin: 2rem auto 0; }

label { display: block; margin: 1.1rem 0 0.4rem; font-weight: 500; font-size: 0.92rem; color: var(--text-2); }
.panel > form > label:first-of-type { margin-top: 0; }

input, textarea, select {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; }
select { appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2386868b' d='M6 8 1.5 3.5 2.9 2 6 5.2 9.1 2l1.4 1.5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.8rem center; padding-right: 2.2rem;
}

.flash {
  padding: 0.8rem 1rem;
  border-radius: 12px;
  background: var(--accent-soft);
  margin-bottom: 1.2rem;
  font-size: 0.95rem;
}
.flash.error { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* square icon uploader */
.icon-upload { display: flex; align-items: center; gap: 1rem; }
.icon-dropzone {
  position: relative;
  width: 120px;
  height: 120px;
  flex: none;
  border-radius: 24px;
  border: 2px dashed var(--border-strong);
  background: var(--surface-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s ease, background 0.15s ease;
  text-align: center;
}
.icon-dropzone:hover, .icon-dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.icon-dropzone input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; padding: 0;
}
.icon-dropzone .preview {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none;
}
.icon-dropzone.has-image .preview { display: block; }
.icon-dropzone.has-image .dz-hint { display: none; }
.dz-hint { color: var(--muted); font-size: 0.8rem; padding: 0.5rem; pointer-events: none; }
.dz-hint svg { width: 26px; height: 26px; display: block; margin: 0 auto 0.35rem; opacity: 0.7; }
.icon-upload .dz-meta { color: var(--muted); font-size: 0.85rem; }

/* platform rows */
#rows { display: flex; flex-direction: column; gap: 0.7rem; margin-bottom: 0.8rem; }
.row-platform {
  display: grid;
  grid-template-columns: 150px 120px 1fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.row-platform .src { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; }
.row-platform .src input { min-width: 0; }
.row-platform textarea.cmd-input {
  min-width: 0;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
}
.row-platform .btn.danger {
  padding: 0; width: 36px; height: 36px; justify-content: center; border-radius: 10px; font-size: 1.1rem;
}
@media (max-width: 620px) {
  .row-platform { grid-template-columns: 1fr 1fr; }
  .row-platform .src { grid-column: 1 / -1; flex-wrap: wrap; }
}

.form-actions { display: flex; gap: 0.6rem; align-items: center; margin-top: 1.6rem; }

/* table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.85rem 1rem; vertical-align: middle; }
thead th {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 600; background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
tbody tr + tr td { border-top: 1px solid var(--border); }
td .title-cell { display: flex; align-items: center; gap: 0.7rem; }
td .title-cell .icon { width: 38px; height: 38px; border-radius: 10px; font-size: 1rem; }
.row-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; justify-content: flex-end; }

.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.25rem 0.65rem; border-radius: var(--radius-pill);
  font-size: 0.78rem; font-weight: 600;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.published { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.badge.draft { background: var(--surface-2); color: var(--muted); }

.copybar { display: flex; gap: 0.4rem; align-items: center; max-width: 340px; }
.copybar input { font-size: 0.85rem; padding: 0.45rem 0.7rem; }

/* ---------- modal (replaces native confirm/alert) ---------- */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  color: var(--text);
  max-width: 92vw;
}
.modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.modal[open] { animation: modal-in 0.16s ease; }
.modal[open]::backdrop { animation: backdrop-in 0.16s ease; }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: 400px;
  max-width: 92vw;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.6rem;
}
.modal-title { margin: 0 0 0.5rem; font-size: 1.25rem; }
.modal-msg { margin: 0 0 1.5rem; color: var(--text-2); line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; }

.btn.danger-solid { background: var(--danger); color: #fff; border: none; }
.btn.danger-solid:hover { background: var(--danger-hover); color: #fff; }

/* not found */
.notfound { text-align: center; padding: 4rem 1rem; }
.notfound h1 { font-size: 5rem; margin-bottom: 0.5rem; }
.notfound p { color: var(--muted); font-size: 1.1rem; margin-bottom: 1.5rem; }
