/* ---------- Tokens ---------- */
:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --radius-widget: 26px;
  --radius-icon: 22%;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Geist", system-ui, sans-serif;
  --tile-min: 92px;
  --icon: 58px;
  --icon-featured: 68px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b0d;
  --surface: rgba(30, 30, 33, 0.72);
  --surface-solid: #1c1c1f;
  --surface-hover: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.07);
  --highlight: rgba(255, 255, 255, 0.06);
  --text: #f5f5f7;
  --text-2: #a1a1a6;
  --text-3: #8a8a90;
  --accent: #2997ff;
  --accent-soft: rgba(41, 151, 255, 0.16);
  --plate: #f2f2f5;
  --plate-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 6px 16px -6px rgba(0, 0, 0, 0.6);
  --mono-a: #3a3a3f;
  --mono-b: #232326;
  --field: rgba(255, 255, 255, 0.07);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 20px 50px -24px rgba(0, 0, 0, 0.7);
  --ambient-1: rgba(41, 151, 255, 0.10);
  --ambient-2: rgba(120, 120, 140, 0.10);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f2f5;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --surface-hover: rgba(0, 0, 0, 0.04);
  --border: rgba(0, 0, 0, 0.06);
  --highlight: rgba(255, 255, 255, 0.9);
  --text: #1d1d1f;
  --text-2: #5e5e63;
  --text-3: #6e6e73;
  --accent: #0066cc;
  --accent-soft: rgba(0, 102, 204, 0.10);
  --plate: #ffffff;
  --plate-shadow: 0 1px 2px rgba(30, 30, 50, 0.12), 0 6px 16px -6px rgba(30, 30, 50, 0.18);
  --mono-a: #5b5b62;
  --mono-b: #3a3a40;
  --field: rgba(255, 255, 255, 0.9);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset, 0 18px 40px -26px rgba(40, 40, 60, 0.28);
  --ambient-1: rgba(0, 113, 227, 0.08);
  --ambient-2: rgba(255, 255, 255, 0.9);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
::selection { background: var(--accent-soft); color: var(--text); }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 10px; }
html { scrollbar-color: var(--text-3) transparent; }

.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(60vw 40vh at 18% -8%, var(--ambient-1), transparent 70%),
    radial-gradient(50vw 40vh at 92% 0%, var(--ambient-2), transparent 70%);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1880px;
  margin: 0 auto;
  padding: 18px clamp(16px, 3vw, 48px) 0;
}
.clock {
  margin: 0;
  display: flex;
  gap: 10px;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.clock .time { color: var(--text); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 19px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  transition: transform 160ms var(--ease-out), background-color 200ms ease;
}
.icon-btn:active { transform: scale(0.94); }
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover { background: var(--surface-solid); }
}

/* ---------- Hero / search ---------- */
.page {
  max-width: 1880px;
  margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 48px) 64px;
}
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 640px);
  align-items: end;
  gap: 16px 40px;
  padding: clamp(20px, 4vh, 44px) 0 clamp(20px, 3vh, 32px);
}
.hero h1 {
  margin: 0;
  font-size: clamp(32px, 3.4vw, 52px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  text-wrap: balance;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  height: 52px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--field);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  backdrop-filter: blur(24px) saturate(160%);
  transition: box-shadow 200ms ease, border-color 200ms ease;
}
.search:focus-within {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
  box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow);
}
.search-icon { position: absolute; left: 16px; font-size: 19px; color: var(--text-2); }
.search input {
  flex: 1;
  height: 100%;
  min-width: 0;
  padding: 0 52px 0 46px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  caret-color: var(--accent);
}
.search input::placeholder { color: var(--text-3); }
.search input:focus { outline: none; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-kbd {
  position: absolute;
  right: 14px;
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-3);
  font: 500 13px var(--font);
}
.search:focus-within .search-kbd { opacity: 0; }

.hint {
  grid-column: 2;
  min-height: 18px;
  margin: -6px 0 0 4px;
  color: var(--text-2);
  font-size: 13px;
}
.hint b { color: var(--text); font-weight: 600; }

/* ---------- Board ---------- */
.board { display: grid; gap: 20px; }
.board-top {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 560px), 1fr));
  gap: 20px;
}
.board-top[hidden] { display: none; }
.board-rest { columns: 300px; column-gap: 20px; }
.board-rest .widget { break-inside: avoid; margin-bottom: 20px; }
.icon.pending { opacity: 0.55; }
/* columnEnd groups end their column (only once there are 3+ columns). */
@media (min-width: 1100px) {
  .board-rest .widget.col-end { break-after: column; -webkit-column-break-after: always; }
}

.widget {
  position: relative;
  padding: 18px 14px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-widget);
  background: var(--surface);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(30px) saturate(160%);
  backdrop-filter: blur(30px) saturate(160%);
}
.widget h2 {
  margin: 0 6px 10px;
  color: var(--text-2);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.widget.featured h2 { color: var(--text); font-size: 20px; letter-spacing: -0.02em; margin-bottom: 14px; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-min), 1fr));
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.featured .tiles { --tile-min: 100px; }
.group-logo { display: block; height: 38px; width: auto; margin: 2px 0 4px; }
:root[data-theme="dark"] .group-logo { filter: invert(1) hue-rotate(180deg) brightness(1.15); }

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 4px 9px;
  border-radius: 16px;
  text-align: center;
  transition: background-color 200ms ease;
  -webkit-tap-highlight-color: transparent;
}
.tile .label {
  max-width: 100%;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--text);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  text-wrap: balance;
}
.featured .tile .label { font-size: 13.5px; }

.icon {
  --s: var(--icon);
  position: relative;
  display: grid;
  place-items: center;
  width: var(--s);
  height: var(--s);
  border-radius: var(--radius-icon);
  background: var(--plate);
  box-shadow: var(--plate-shadow);
  overflow: hidden;
  transition: transform 220ms var(--ease-out), box-shadow 220ms var(--ease-out);
}
.featured .icon { --s: var(--icon-featured); }
.icon img { width: 66%; height: 66%; object-fit: contain; }
.icon img.small { width: 40%; height: 40%; }
.icon img.cover { width: 100%; height: 100%; object-fit: cover; }
.icon .ph { font-size: calc(var(--s) * 0.48); color: #fff; }
.icon.mono {
  background: linear-gradient(160deg, var(--mono-a), var(--mono-b));
}
.icon.mono .letter {
  color: #fff;
  font-size: calc(var(--s) * 0.42);
  font-weight: 600;
  letter-spacing: -0.02em;
}
.icon.brand { background: linear-gradient(160deg, #3d9bff, #0060d1); }
.icon.brand .ph { font-size: calc(var(--s) * 0.5); }
.icon.local::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.tile:active .icon { transform: scale(0.94); transition-duration: 120ms; }
@media (hover: hover) and (pointer: fine) {
  .tile:hover { background: var(--surface-hover); }
  .tile:hover .icon { transform: translateY(-2px); }
}

/* Search target */
.tile.is-target { background: var(--accent-soft); }
.tile.is-target .label { color: var(--accent); font-weight: 600; }
.tile[hidden], .widget[hidden] { display: none; }

/* Docs disclosure */
.docs { margin: 8px 6px 0; border-top: 1px solid var(--border); padding-top: 8px; }
.docs summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 2px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}
.docs summary::-webkit-details-marker { display: none; }
.docs summary .ph { transition: transform 200ms var(--ease-out); }
.docs[open] summary .ph { transform: rotate(90deg); }
.docs ul {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 4px;
  padding: 0;
  list-style: none;
}
.docs a {
  display: inline-block;
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 12.5px;
  transition: background-color 200ms ease;
}
@media (hover: hover) and (pointer: fine) {
  .docs a:hover { background: var(--surface-hover); }
}

/* ---------- Entrance (one authored moment) ---------- */
@media (prefers-reduced-motion: no-preference) {
  .widget {
    animation: rise 560ms var(--ease-out) both;
    animation-delay: calc(var(--i, 0) * 45ms + 60ms);
  }
  .hero > * { animation: rise 520ms var(--ease-out) both; }
  .hero .search { animation-delay: 40ms; }
  @keyframes rise {
    from { opacity: 0; transform: translateY(14px) scale(0.985); filter: blur(6px); }
    to { opacity: 1; transform: none; filter: none; }
  }
}
@media (prefers-reduced-motion: reduce) {
  .widget, .hero > * { animation: fade 240ms ease both; }
  @keyframes fade { from { opacity: 0; } }
  .tile:hover .icon, .tile:active .icon { transform: none; }
}

/* Theme switch uses a view transition; the circle is driven from JS */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

@media (prefers-reduced-transparency: reduce) {
  .widget, .search, .icon-btn { background: var(--surface-solid); -webkit-backdrop-filter: none; backdrop-filter: none; }
}

/* ---------- Responsive ---------- */
@media (min-width: 1700px) {
  :root { --icon: 60px; --icon-featured: 72px; }
}
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
  .hint { grid-column: 1; }
}
@media (max-width: 700px) {
  .board, .board-top { gap: 14px; }
  .board-rest { columns: 1; }
  .board-rest .widget { margin-bottom: 14px; }
  .widget { padding: 16px 10px 10px; border-radius: 22px; }
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .featured .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  :root { --icon: 56px; --icon-featured: 58px; }
  .tile .label, .featured .tile .label { font-size: 11.5px; }
  .hero { position: sticky; top: 0; z-index: 2; padding-top: 12px; padding-bottom: 14px; background: linear-gradient(var(--bg) 78%, transparent); }
  .hero h1 { font-size: 30px; }
  .search-kbd { display: none; }
  .search input { padding-right: 16px; }
  .hint:empty { display: none; }
}
@media (max-width: 360px) {
  :root { --icon: 50px; --icon-featured: 50px; }
}
