/* ============================================================
   CSS Variables — Light / Dark
   ============================================================ */
:root {
  --bg:           #f0f2f7;
  --surface:      #ffffff;
  --surface-2:    #f7f8fb;
  --border:       #e4e7ef;
  --text:         #111827;
  --text-muted:   #6b7280;
  --text-subtle:  #9ca3af;
  --accent:       #4f46e5;
  --accent-hover: #4338ca;
  --accent-dim:   #ede9fe;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:    0 4px 16px rgba(0,0,0,.10);
  --shadow-hover: 0 8px 28px rgba(79,70,229,.18);
  --radius:       14px;
  --radius-sm:    8px;

  --badge-smart-bg:   #d1fae5;
  --badge-smart-fg:   #065f46;
  --badge-home-bg:    #dbeafe;
  --badge-home-fg:    #1e40af;
  --badge-ext-bg:     #ede9fe;
  --badge-ext-fg:     #4c1d95;

  --header-bg:    rgba(255,255,255,.85);
  --header-border: rgba(0,0,0,.07);
}

[data-theme="dark"] {
  --bg:           #0d0f18;
  --surface:      #161926;
  --surface-2:    #1d2133;
  --border:       #272d45;
  --text:         #e8eaf0;
  --text-muted:   #9ca3af;
  --text-subtle:  #6b7280;
  --accent:       #818cf8;
  --accent-hover: #6366f1;
  --accent-dim:   #1e1b4b;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.3);
  --shadow-md:    0 4px 20px rgba(0,0,0,.4);
  --shadow-hover: 0 8px 28px rgba(99,102,241,.25);

  --badge-smart-bg:   #064e3b;
  --badge-smart-fg:   #6ee7b7;
  --badge-home-bg:    #1e3a5f;
  --badge-home-fg:    #93c5fd;
  --badge-ext-bg:     #2e1065;
  --badge-ext-fg:     #c4b5fd;

  --header-bg:    rgba(13,15,24,.88);
  --header-border: rgba(255,255,255,.06);
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  transition: background 0.25s, color 0.25s;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ============================================================
   Header
   ============================================================ */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.brand-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.brand-name {
  color: var(--text);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Date */
.date {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Clock */
.clock {
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  padding: 0.3rem 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  white-space: nowrap;
}

/* Install button */
.btn-install {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 99px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-install svg {
  width: 15px;
  height: 15px;
}

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

.btn-install:active {
  transform: scale(0.96);
}

/* Theme toggle */
.btn-theme {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.2s, background 0.2s, border-color 0.2s, transform 0.1s;
  flex-shrink: 0;
}

.btn-theme:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.btn-theme:active {
  transform: scale(0.92);
}

.btn-theme svg {
  width: 17px;
  height: 17px;
}

[data-theme="light"] .icon-moon,
[data-theme="dark"]  .icon-sun  { display: none; }
[data-theme="light"] .icon-sun,
[data-theme="dark"]  .icon-moon { display: block; }

/* ============================================================
   Main layout
   ============================================================ */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

/* ============================================================
   Section
   ============================================================ */
.section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.section-icon {
  display: inline-flex;
  align-items: center;
}

.section-icon svg {
  width: 18px;
  height: 18px;
  stroke: var(--accent);
}

.section-meta {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-subtle);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  font-family: ui-monospace, 'Cascadia Code', monospace;
  text-transform: none;
}

/* ============================================================
   Cards Grid
   ============================================================ */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

/* ============================================================
   Card
   ============================================================ */
.card {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.1rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition:
    box-shadow 0.2s,
    border-color 0.2s,
    transform 0.15s;
  cursor: pointer;
  outline-offset: 3px;
}

.card:hover {
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.card:focus-visible {
  outline: 2px solid var(--accent);
}

.card:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

/* Card icon */
.card-icon {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
}

.card-icon svg,
.card-icon img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.icon-letter {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: var(--radius-sm);
  letter-spacing: -0.02em;
}

/* Card body */
.card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.card-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.card-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.card-url {
  font-size: 0.72rem;
  color: var(--accent);
  font-family: ui-monospace, 'Cascadia Code', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.8;
}

/* ============================================================
   Badges
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 99px;
  white-space: nowrap;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.badge-smart {
  background: var(--badge-smart-bg);
  color: var(--badge-smart-fg);
}

.badge-home {
  background: var(--badge-home-bg);
  color: var(--badge-home-fg);
}

.badge-ext {
  background: var(--badge-ext-bg);
  color: var(--badge-ext-fg);
}

/* ============================================================
   Footer
   ============================================================ */
.footer {
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  font-size: 0.75rem;
  color: var(--text-subtle);
  border-top: 1px solid var(--border);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 640px) {
  .header-inner {
    height: 52px;
    padding: 0 1rem;
  }

  .clock {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }

  .btn-install span,
  .btn-install-text {
    display: none;
  }

  .main {
    padding: 1.25rem 0.85rem 2.5rem;
    gap: 2rem;
  }

  .cards-grid {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 0.9rem 1rem;
  }
}

@media (min-width: 900px) {
  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  }
}

/* ============================================================
   SW Update Toast
   ============================================================ */
@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.sw-toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s ease both;
  white-space: nowrap;
}

.sw-toast[hidden] { display: none; }

.sw-toast-text {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}

.sw-toast-text svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
  flex-shrink: 0;
}

.sw-toast-btn {
  padding: 0.3rem 0.8rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.sw-toast-btn:hover { background: var(--accent-hover); }

.sw-toast-close {
  background: none;
  border: none;
  color: var(--text-subtle);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.1rem 0.25rem;
  line-height: 1;
  transition: color 0.15s;
}

.sw-toast-close:hover { color: var(--text); }

/* ============================================================
   Card entrance animation
   ============================================================ */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card {
  animation: fadeInUp 0.35s ease both;
}

/* Stagger each card within its grid */
.cards-grid .card:nth-child(1)  { animation-delay: 0.04s; }
.cards-grid .card:nth-child(2)  { animation-delay: 0.09s; }
.cards-grid .card:nth-child(3)  { animation-delay: 0.14s; }
.cards-grid .card:nth-child(4)  { animation-delay: 0.19s; }
.cards-grid .card:nth-child(5)  { animation-delay: 0.24s; }
.cards-grid .card:nth-child(6)  { animation-delay: 0.29s; }

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
