/* The apps home (docs/hub.md section 4): light and dark from the system setting, phone width without horizontal scroll. Tile colours come from
   config/apps.json (set by hub.js as the custom property --tile on each card). */
:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #111827;
  --muted: #4b5563;
  --border: #dfe3e8;
  --border-strong: #b9c0ca;
  --focus: #1d4ed8;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 5%);
  --shadow-hover: 0 2px 4px rgb(16 24 40 / 8%), 0 12px 28px rgb(16 24 40 / 10%);
  --radius: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 100%;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b26;
    --text: #e6e9ef;
    --muted: #a3acb9;
    --border: #283142;
    --border-strong: #45516a;
    --focus: #8ab4ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-hover: 0 2px 6px rgb(0 0 0 / 50%), 0 12px 28px rgb(0 0 0 / 35%);
  }
}

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

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  overflow-wrap: anywhere;
}

a {
  color: inherit;
}

a:focus-visible,
button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.wrap {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px;
}

@media (min-width: 640px) {
  .wrap {
    padding: 0 32px;
  }
}

/* header */
.top {
  padding: 40px 0 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 600;
}

.brand-mark {
  fill: currentColor;
  width: 18px;
  height: 18px;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 1.6rem + 2vw, 2.75rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.lede {
  margin: 12px 0 0;
  max-width: 40rem;
  color: var(--muted);
  font-size: 1.0625rem;
}

/* the apps */
.apps {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
  gap: 16px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 13rem;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

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

.tile {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--tile, #475569);
  color: #fff;
  font-size: 1.875rem;
  font-weight: 700;
  line-height: 1;
}

.app-name {
  margin: 20px 0 0;
  font-size: 1.375rem;
  line-height: 1.25;
  font-weight: 650;
}

/* the whole card is the link to the app (its ::after covers the card); the count is its own link above it */
.app-link {
  text-decoration: none;
}

.app-link::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
}

.app-link:focus-visible {
  outline: none;
}

.app-link:focus-visible::after {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.app-link:hover .app-name-text {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.app-desc {
  margin: 6px 0 0;
  color: var(--muted);
}

.app-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
  padding-top: 20px;
  min-height: 2.25rem;
}

.open {
  color: var(--muted);
  font-size: 0.9375rem;
  white-space: nowrap;
}

.count {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.count-num {
  font-variant-numeric: tabular-nums;
}

.count.has-items {
  background: var(--tile, #475569);
  color: #fff;
}

.count.has-items:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.count.none {
  gap: 4px;
  padding-inline: 0;
  color: var(--muted);
  font-weight: 500;
}

/* phones: the tile beside the name, so the three apps fit on one screen */
@media (max-width: 539px) {
  .app {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 16px;
    align-items: start;
    min-height: 0;
    padding: 20px;
  }

  .tile {
    grid-row: 1 / span 2;
    width: 56px;
    height: 56px;
    border-radius: 14px;
    font-size: 1.625rem;
  }

  .app-name {
    margin: 2px 0 0;
    font-size: 1.25rem;
  }

  .app-desc {
    grid-column: 2;
    margin-top: 2px;
  }

  .app-foot {
    grid-column: 1 / -1;
    padding-top: 16px;
    min-height: 0;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* loading, errors */
.message {
  margin: 24px 0 0;
  color: var(--muted);
}

.message p {
  margin: 0;
}

.message:empty,
.message[hidden] {
  display: none;
}

.retry {
  margin-top: 12px;
  padding: 8px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.retry:hover {
  border-color: var(--text);
}

.retry[hidden] {
  display: none;
}

/* footer */
.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: 40px;
  padding-top: 24px;
  padding-bottom: 40px;
  color: var(--muted);
  font-size: 0.9375rem;
}

.foot p {
  margin: 0;
}

.status-link {
  font-weight: 600;
  color: var(--text);
  text-underline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .app {
    transition: none;
  }

  .app:hover {
    transform: none;
  }
}
