:root {
  --bg: #ffffff;
  --bg-card: #f5f5f7;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --accent: #007aff;
  --accent-hover: #0056cc;
  --border: #d2d2d7;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --bg-card: #2c2c2e;
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --border: #48484a;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  }
}

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

html {
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

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

a:hover {
  text-decoration: underline;
}

/* Hero */
.hero {
  text-align: center;
  padding: 3rem 1rem 2rem;
  border-bottom: 1px solid var(--border);
}

.source-icon {
  border-radius: 22%;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.hero h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hero .subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-top: 0.25rem;
}

/* Buttons */
.add-source-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 1.25rem;
  border-radius: 980px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  transition: opacity 0.2s;
}

.btn:hover {
  opacity: 0.85;
  text-decoration: none;
}

.btn-classic {
  background: #147ce5;
}

.btn-pal {
  background: #30b050;
}

/* Source URLs */
.source-urls {
  margin-top: 1.25rem;
  text-align: left;
  max-width: 540px;
  margin-left: auto;
  margin-right: auto;
}

.source-urls-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  text-align: center;
}

.source-url-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-card);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.4rem;
}

.source-url-tag {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  min-width: 40px;
}

.tag-classic { color: #147ce5; }
.tag-pal { color: #30b050; }

.source-url-value {
  flex: 1;
  font-size: 0.72rem;
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: all;
  min-width: 0;
}

.copy-btn {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.copy-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.copy-btn.copied {
  background: #30b050;
  color: #fff;
  border-color: #30b050;
}

/* Main */
main {
  flex: 1;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1rem;
  min-width: 0;
}

h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* Apps list */
.apps-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

.app-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
  overflow: hidden;
}

.app-card img {
  width: 56px;
  height: 56px;
  border-radius: 12.5%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border);
}

.app-info {
  flex: 1;
  min-width: 0;
}

.app-info h3 {
  font-size: 1rem;
  font-weight: 600;
}

.app-info .app-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.app-info .app-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.app-actions {
  display: flex;
  flex-direction: row;
  gap: 0.35rem;
  flex-shrink: 0;
}

.app-actions .btn {
  font-size: 0.75rem;
  padding: 0.4rem 0.8rem;
}

.btn-small-classic {
  background: #147ce5;
}

.btn-small-pal {
  background: #30b050;
}

.btn-download {
  background: #e8611a;
}

/* App detail panel (expandable) */
.app-card {
  cursor: pointer;
  transition: box-shadow 0.2s;
}

.app-card:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

.app-card.expanded {
  flex-direction: column;
  align-items: stretch;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.app-card.expanded > .app-info,
.app-card.expanded > .app-actions {
  flex-shrink: 0;
}

.app-detail-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.25s ease, margin 0.25s ease;
  opacity: 0;
  margin-top: 0;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

.app-detail-panel.open {
  max-height: 2000px;
  opacity: 1;
  margin-top: 1rem;
}

/* Screenshots gallery */
.detail-screenshots {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.detail-screenshots::-webkit-scrollbar {
  height: 4px;
}

.detail-screenshots::-webkit-scrollbar-track {
  background: transparent;
}

.detail-screenshots::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.detail-screenshots img {
  width: 140px;
  height: auto;
  border-radius: 10px;
  scroll-snap-align: start;
  flex-shrink: 0;
  object-fit: cover;
  background: var(--border);
}

/* Description */
.detail-description {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 1rem;
  white-space: pre-line;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Version info grid */
.detail-version-info {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.detail-info-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}

.detail-info-item {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.detail-info-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.detail-info-value {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
}

/* Changelog */
.detail-changelog {
  margin-top: 0.25rem;
}

.detail-changelog-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
  color: var(--text);
}

.detail-changelog-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.detail-changelog-entry {
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.detail-changelog-entry:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.detail-changelog-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.3rem;
}

.detail-changelog-version {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
}

.detail-changelog-date {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.detail-changelog-notes {
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-secondary);
  white-space: pre-line;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Info section */
.info-section {
  margin-top: 2.5rem;
}

.how-to {
  padding-left: 1.25rem;
  margin-bottom: 1rem;
}

.how-to li {
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
}

.note {
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: var(--bg-card);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
}

/* Empty / Loading */
.loading,
.empty {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Footer */
footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 1rem;
  text-align: center;
}

.footer-content {
  max-width: 720px;
  margin: 0 auto;
}

.disclaimer {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  line-height: 1.6;
}

.copyright {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.links {
  font-size: 0.8rem;
}

.links a {
  color: var(--text-secondary);
}

.links a:hover {
  color: var(--accent);
}

/* Responsive */
@media (max-width: 480px) {
  .hero {
    padding: 2rem 1rem 1.5rem;
  }

  .hero h1 {
    font-size: 1.4rem;
  }

  .btn {
    font-size: 0.8rem;
    padding: 0.55rem 1rem;
  }

  .app-card {
    flex-wrap: wrap;
  }

  .app-card.expanded {
    flex-wrap: nowrap;
  }
}
