/* Design plan
     Color: cool neutral paper + one blue accent taken from the source's
     tintColor; per-app tints only ever appear as washes, never as controls.
     Type: system UI stack (SF Pro on Apple devices, PingFang for Chinese) and
     tabular numerals for versions, sizes and dates. No webfonts, so the page
     renders instantly where Google Fonts is unreachable.
     Layout: a single column, an editorial hero, a scrolling recent-updates
     rail, then an app-store grid whose cards expand into a full-width detail. */
  :root {
    color-scheme: light;
    --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #eef1f5;
    --fg: #101317;
    --soft: #3b424c;
    --muted: #656e7b;
    --line: #e1e5eb;
    --accent: #2563eb;
    --accent-ink: #1d4ed8;
    --accent-soft: #e7effe;
    --on-accent: #ffffff;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 18px 40px -24px rgba(16, 24, 40, 0.25);
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      color-scheme: dark;
      --bg: #0b0d11;
      --surface: #14171d;
      --surface-2: #1b2028;
      --fg: #f1f3f7;
      --soft: #c2c9d4;
      --muted: #939caa;
      --line: #252b35;
      --accent: #6e9dff;
      --accent-ink: #a9c4ff;
      --accent-soft: #17233b;
      --on-accent: #071022;
      --shadow: 0 1px 1px rgba(0, 0, 0, 0.4), 0 20px 44px -24px rgba(0, 0, 0, 0.9);
    }
  }
  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b0d11;
    --surface: #14171d;
    --surface-2: #1b2028;
    --fg: #f1f3f7;
    --soft: #c2c9d4;
    --muted: #939caa;
    --line: #252b35;
    --accent: #6e9dff;
    --accent-ink: #a9c4ff;
    --accent-soft: #17233b;
    --on-accent: #071022;
    --shadow: 0 1px 1px rgba(0, 0, 0, 0.4), 0 20px 44px -24px rgba(0, 0, 0, 0.9);
  }

  *, *::before, *::after { box-sizing: border-box; }
  body {
    margin: 0;
    background-color: var(--bg);
    background-image: radial-gradient(900px 420px at 12% -160px, color-mix(in srgb, var(--accent) 12%, transparent), transparent 68%);
    color: var(--fg);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }
  .page {
    max-width: 1180px;
    margin-inline: auto;
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
    padding-block: clamp(16px, 2.4vw, 28px) 56px;
  }
  a { color: inherit; }
  img { max-width: 100%; }
  :where(a, button, input, select):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding-block: 4px 20px;
  }
  .brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    color: var(--fg);
    text-decoration: none;
    font-size: 15px;
    font-weight: 660;
    letter-spacing: -0.01em;
  }
  .brand-mark {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--surface-2);
  }
  .controls { display: flex; flex-wrap: wrap; gap: 8px; }
  .segment {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 999px;
  }
  .segment button {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 12px;
    font-weight: 650;
    line-height: 1.4;
    padding: 5px 10px;
    border-radius: 999px;
    cursor: pointer;
  }
  .segment button[aria-pressed="true"] {
    background: var(--surface);
    color: var(--fg);
    box-shadow: 0 1px 2px rgba(9, 12, 18, 0.08);
  }

  .hero-main {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 22px;
    align-items: center;
  }
  .hero-icon {
    width: 88px;
    height: 88px;
    border-radius: 24%;
    object-fit: cover;
    background: var(--surface-2);
    box-shadow: var(--shadow);
  }
  .hero-copy { min-width: 0; display: flex; flex-direction: column; gap: 7px; }
  h1 {
    margin: 0;
    font-size: clamp(30px, 5vw, 42px);
    font-weight: 750;
    line-height: 1.03;
    letter-spacing: -0.035em;
    text-wrap: balance;
  }
  .hero-sub {
    margin: 0;
    max-width: 60ch;
    color: var(--soft);
    font-size: 16.5px;
    line-height: 1.45;
  }
  .hero-meta {
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 9px;
    color: var(--muted);
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
  }
  .hero-meta .sep { color: var(--line); }
  .hero-clients { margin: 0; color: var(--muted); font-size: 12.5px; }
  .hero-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 22px;
  }
  .mode-note { color: var(--muted); font-size: 12.5px; }

  .btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 9px 15px;
    font: inherit;
    font-size: 13.5px;
    font-weight: 640;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
  }
  .btn-primary { background: var(--accent); color: var(--on-accent); }
  .btn-primary:hover { filter: brightness(1.05); }
  .btn-ghost { border-color: var(--line); color: var(--fg); background: var(--surface); }
  .btn-ghost:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
  .btn svg { flex: 0 0 auto; }

  .section { margin-top: 38px; }
  .section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
  }
  .section-head h2 {
    margin: 0;
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.02em;
  }
  .section-sub { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }

  .track {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 2px 2px 10px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  .update {
    flex: 0 0 268px;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s;
  }
  .update:hover { border-color: color-mix(in srgb, var(--accent) 34%, var(--line)); }
  .update-media {
    position: relative;
    aspect-ratio: 1200 / 630;
    overflow: hidden;
    background: var(--surface-2);
  }
  .update-media.noimg {
    background: linear-gradient(135deg, color-mix(in srgb, var(--tint, var(--accent)) 24%, var(--surface-2)), var(--surface-2));
  }
  .update-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .update-media.noimg img { display: none; }
  .update-body { display: flex; flex-direction: column; gap: 6px; padding: 11px 13px 13px; }
  .update-top {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: var(--muted);
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
  }
  .update-app { color: var(--fg); font-weight: 650; }
  .update-caption {
    margin: 0;
    font-size: 13px;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
  }
  .search { position: relative; flex: 1 1 260px; min-width: 0; }
  .search input {
    width: 100%;
    padding: 10px 14px 10px 36px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--fg);
    font: inherit;
    font-size: 14px;
    outline: none;
  }
  .search input::placeholder { color: var(--muted); }
  .search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
  }
  .sort { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
  .sort select {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--fg);
    font: inherit;
    font-size: 13px;
    outline: none;
  }
  .count { margin-left: auto; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }

  .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(286px, 1fr)); gap: 12px; }
  .card {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    transition: border-color 0.15s, box-shadow 0.15s;
  }
  .card:hover { border-color: color-mix(in srgb, var(--accent) 26%, var(--line)); }
  .card.open {
    grid-column: 1 / -1;
    border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
    box-shadow: var(--shadow);
  }
  .card-head { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
  .icon-tile {
    position: relative;
    display: grid;
    place-items: center;
    flex: 0 0 52px;
    width: 52px;
    height: 52px;
    overflow: hidden;
    border-radius: 23%;
    background: var(--surface-2);
    background: color-mix(in srgb, var(--tint, var(--accent)) 18%, var(--surface-2));
  }
  .icon-letter {
    font-size: 20px;
    font-weight: 700;
    color: color-mix(in srgb, var(--tint, var(--accent)) 72%, var(--fg));
    opacity: 0.72;
  }
  .icon-tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
  .app-titles { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
  .app-name {
    margin: 0;
    font-size: 15.5px;
    font-weight: 660;
    line-height: 1.25;
    letter-spacing: -0.015em;
    overflow-wrap: anywhere;
  }
  .app-dev {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .ver {
    position: relative;
    flex: 0 0 auto;
    max-width: 96px;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 11.5px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
  }
  .ver-text {
    display: block;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* Long build versions (nightly timestamps, commit hashes) would squeeze the
     app name in a collapsed card; an expanded card spans the grid, so it has
     room for the full string. */
  .card.open .ver { max-width: none; }
  /* Full version on hover, only for badges the width cap actually clips
     (app.js sets data-tip after measuring the text). */
  .ver[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    top: calc(100% + 7px);
    right: 0;
    z-index: 30;
    padding: 6px 9px;
    border-radius: 9px;
    background: var(--fg);
    color: var(--surface);
    box-shadow: var(--shadow);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.12s ease, visibility 0.12s;
  }
  .ver[data-tip]:hover::after {
    opacity: 1;
    visibility: visible;
  }
  .app-sub {
    margin: 0;
    color: var(--soft);
    font-size: 13px;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    color: var(--muted);
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
  }
  .meta span + span { position: relative; }
  .meta span + span::before {
    content: "·";
    position: absolute;
    left: -8px;
    color: var(--line);
  }
  .card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: auto; }
  .btn-add { background: var(--accent-soft); color: var(--accent-ink); }
  .btn-add:hover { filter: saturate(1.15) brightness(0.98); }
  .btn-details {
    padding: 8px 8px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
  }
  .btn-details:hover { color: var(--fg); background: var(--surface-2); }
  .chev { transition: transform 0.18s; }
  .card.open .chev { transform: rotate(180deg); }

  .details { border-top: 1px solid var(--line); padding-top: 14px; display: grid; gap: 14px; }
  .details-cols {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    gap: 22px;
  }
  .details-cols.one { grid-template-columns: minmax(0, 1fr); }
  .details h4 {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  .shots { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }
  .shots img {
    height: 288px;
    width: auto;
    max-width: none;
    display: block;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-2);
  }
  .details p {
    margin: 0;
    color: var(--soft);
    font-size: 13px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }
  .notes p { color: var(--muted); font-size: 12.5px; }
  .md p { white-space: normal; margin: 0 0 8px; }
  .md p:last-child { margin-bottom: 0; }
  .md-title { margin: 12px 0 4px; color: var(--fg); font-size: 13.5px; font-weight: 650; }
  .md-title:first-child { margin-top: 0; }
  .md ul, .md ol { margin: 0 0 8px 18px; padding: 0; color: var(--soft); font-size: 13px; }
  .md li { margin: 2px 0; }
  .md code { padding: 1px 4px; border-radius: 4px; background: var(--surface-2); font-family: var(--font-mono); font-size: 11.5px; }
  .md pre { margin: 0 0 8px; padding: 10px 12px; overflow: auto; border-radius: 10px; background: var(--surface-2); }
  .md pre code { padding: 0; background: none; }
  .md a { color: var(--accent-ink); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
  .md a:hover { border-color: var(--accent); }
  .md hr { margin: 10px 0; border: 0; border-top: 1px solid var(--line); }
  .md-row { color: var(--muted); font-size: 12.5px; }
  .notes .md { max-height: 320px; overflow: auto; padding-right: 6px; }
  .detail-links { display: flex; flex-wrap: wrap; gap: 8px; }
  .link-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--accent-ink);
    font-size: 12.5px;
    font-weight: 640;
    text-decoration: none;
  }
  .link-btn:hover { background: var(--accent-soft); }

  .empty { margin: 28px 0; text-align: center; color: var(--muted); font-size: 14px; }
  .footer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 44px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12.5px;
  }
  .footer p { margin: 0; }
  .footer a { color: var(--muted); text-decoration: none; border-bottom: 1px solid transparent; }
  .footer a:hover { color: var(--fg); border-color: var(--line); }
  .footer-links { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }

  @media (max-width: 820px) {
    .details-cols { grid-template-columns: minmax(0, 1fr); }
  }
  @media (max-width: 560px) {
    .hero-main { grid-template-columns: minmax(0, 1fr); gap: 14px; }
    .hero-icon { width: 64px; height: 64px; }
    .hero-sub { font-size: 15px; }
    .shots img { height: 220px; }
    .count { display: none; }
    .section { margin-top: 32px; }
  }
  @media (prefers-reduced-motion: reduce) {
    * { transition: none !important; scroll-behavior: auto !important; }
  }

  /* Loading skeleton, load failure and disabled controls */
  .card.skeleton { pointer-events: none; animation: sk-pulse 1.8s ease-in-out infinite; }
  .card.skeleton .card-head { align-items: center; }
  .sk-icon { flex: 0 0 52px; width: 52px; height: 52px; border-radius: 23%; background: var(--surface-2); }
  .sk-lines { flex: 1; display: flex; flex-direction: column; gap: 7px; }
  .sk-line { height: 10px; border-radius: 5px; background: var(--surface-2); }
  .sk-line.w40 { width: 40%; }
  .sk-line.w60 { width: 60%; }
  .sk-line.w70 { width: 70%; }
  .sk-line.w90 { width: 90%; }
  .card.skeleton > .sk-line + .sk-line { margin-top: 2px; }
  @keyframes sk-pulse { 50% { opacity: 0.55; } }
  @media (prefers-reduced-motion: reduce) { .card.skeleton { animation: none; } }
  .status { margin: 28px 0; text-align: center; color: var(--muted); font-size: 14px; }
  .status a { color: var(--accent-ink); }
  .btn[aria-disabled="true"] { opacity: 0.55; pointer-events: none; }
  input:disabled, select:disabled { opacity: 0.65; cursor: not-allowed; }
