/* Space Grotesk, self-hosted (SIL OFL 1.1, see fonts/OFL.txt). One variable file covers 500-600. */
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 500 600;
  font-display: swap;
  src: url(fonts/space-grotesk-latin.woff2) format('woff2');
}

:root {
  --bg: #121214;
  --panel: #18181b;
  --tile: #232328;
  --tile-hover: #2e2e35;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --label: #8b8bf5;
  --accent: #6366f1;
  --line: #2e2e35;
  --line-strong: #3a3a44;
  --s: 1;
  --font-display: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  transition: background-color 300ms, color 300ms;
}

body {
  min-height: 100vh;
  padding: 28px 32px 64px;
}

.top {
  display: flex;
  align-items: center;
  gap: 24px;
  max-width: 1280px;
  margin: 0 auto 32px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--text);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 2.1rem;
  letter-spacing: -0.02em;
}

.brand img { border-radius: 12px; }

.filter {
  margin-left: auto;
  width: min(360px, 100%);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  outline: none;
}

.filter:focus { border-color: var(--accent); }

.sections {
  --k: var(--s);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(440px, 100%), 1fr));
  gap: 20px;
  max-width: 1280px;
  margin: 0 auto;
}

.section {
  background: var(--panel);
  border-radius: 16px;
  padding: 16px 12px 8px;
  transition: background-color 300ms;
}

.section h2 {
  margin: 0 8px 10px;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--label);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, calc(96px * var(--k)));
  justify-content: start;
  gap: 4px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 6px 4px 10px;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  outline: none;
}

.tile .icon {
  display: grid;
  place-items: center;
  width: calc(72px * var(--k));
  height: calc(72px * var(--k));
  border-radius: calc(14px * var(--k));
  background: var(--tile);
  transition: background-color 300ms, transform 120ms, box-shadow 120ms;
}

.tile .icon img {
  width: calc(44px * var(--k));
  height: calc(44px * var(--k));
  object-fit: contain;
  border-radius: 6px;
}

.tile .icon .letter {
  font-family: var(--font-display);
  font-size: calc(1.6rem * var(--k));
  font-weight: 600;
  color: var(--label);
}

.tile .name {
  max-width: calc(92px * var(--k));
  font-size: calc(0.82rem * min(1.2, max(0.85, var(--k))));
  line-height: 1.25;
  text-align: center;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile:hover .icon,
.tile:focus-visible .icon { background: var(--tile-hover); transform: translateY(-2px); }
.tile:hover .name,
.tile:focus-visible .name { color: var(--text); }
.tile:focus-visible .icon { box-shadow: 0 0 0 2px var(--accent); }
.tile.first .icon { box-shadow: 0 0 0 2px var(--accent); }

.hidden { display: none !important; }

@media (max-width: 640px) {
  body { padding: 20px 16px 48px; }
  .top { flex-wrap: wrap; gap: 16px; margin-bottom: 20px; }
  .brand { font-size: 1.6rem; }
  .brand img { width: 44px; height: 44px; }
  .filter { margin-left: 0; width: 100%; }
  .setup-btn { width: 100%; }
  .sections { --k: calc(var(--s) * 0.85); }
}

.tile .icon img.invert { filter: invert(1); }
.light .tile .icon img.invert { filter: none; }

.setup-btn {
  flex: none;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.setup-btn:hover,
.setup-btn:focus-visible { color: var(--text); border-color: var(--accent); outline: none; }

.setup {
  width: min(520px, calc(100vw - 32px));
  padding: 24px 24px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
}

.setup::backdrop { background: rgba(0, 0, 0, 0.6); }

.setup h2 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}

.setup-note { margin: 0 0 12px; color: var(--muted); font-size: 0.88rem; line-height: 1.45; }

.setup ol { margin: 0 0 14px; padding-left: 20px; }
.setup li { margin-bottom: 10px; line-height: 1.7; font-size: 0.92rem; }

.setup-close { position: absolute; top: 10px; right: 12px; margin: 0; }
.setup-close button {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.setup-close button:hover { color: var(--text); }

.chip {
  display: inline-block;
  padding: 1px 8px;
  margin: 0 2px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--tile);
  color: var(--label);
  font: inherit;
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
  word-break: break-all;
}

.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.drag { cursor: grab; }

.load-error { color: var(--muted); grid-column: 1 / -1; }
.setup-install { margin: 0 0 14px; padding: 10px 12px; border-radius: 10px; background: var(--tile); font-size: 0.9rem; line-height: 1.6; }

.ext-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1280px;
  margin: -12px auto 20px;
  padding: 10px 12px 10px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 16%, var(--panel)), var(--panel) 70%);
  color: var(--text);
  font-size: 0.92rem;
}

.ext-banner span { flex: 1; }

.ext-add {
  flex: none;
  padding: 7px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

.ext-add:hover, .ext-add:focus-visible { filter: brightness(1.12); outline: none; }

.ext-close {
  flex: none;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

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

@media (max-width: 640px) {
  .ext-banner { flex-wrap: wrap; margin-top: 0; }
  .ext-banner span { flex-basis: calc(100% - 40px); }
}

.footer {
  max-width: 1280px;
  margin: 28px auto 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.footer:empty { display: none; }
.footer a { color: var(--label); }

/* Edit mode */
.setup-btn.on { color: var(--text); border-color: var(--accent); }
.edit-on .sections { user-select: none; -webkit-user-select: none; }
.edit-on .section[data-section] { position: relative; outline: 1px dashed var(--line-strong); outline-offset: -1px; }
.edit-on .section[data-section] h2 { cursor: grab; touch-action: none; padding-right: 100px; min-height: 1.2em; }
.edit-on .section[data-section] .tile[data-key] { cursor: grab; touch-action: none; }
.edit-on .section[data-section] .tiles { min-height: calc(96px * var(--k)); }
.edit-on .tile[data-key] .icon { position: relative; }
.edit-on .tile[data-key] .icon::after {
  content: '×';
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--line-strong);
  color: var(--text);
  font: 14px/20px var(--font-body);
  text-align: center;
  transition: background-color 150ms, transform 150ms;
}
.edit-on .tile[data-key]:hover .icon::after { transform: scale(1.15); }
.edit-on .tile.off .icon::after { content: '+'; background: var(--accent); color: #fff; }
.edit-on .tile.custom .icon::after { background: #b91c1c; color: #fff; }
.tile .icon > *, .tile .name { transition: opacity 200ms; }
.tile.off .icon > *, .tile.off .name { opacity: 0.3; }
.tile.dragging, .section.dragging {
  position: relative;
  z-index: 10;
  pointer-events: none;
  opacity: 0.92;
}
.tile.dragging .icon { box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45), 0 0 0 2px var(--accent); transform: scale(1.06); }
.section.dragging { box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45); }

.tile.add { border: 0; background: none; font: inherit; cursor: pointer; }
.tile.add .icon { background: none; border: 1.5px dashed var(--line-strong); }
.tile.add:hover .icon { border-color: var(--accent); }

.add-form {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 4px;
}
.add-form input, .new-section input, .edit-select {
  flex: 1 1 160px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 150ms;
}
.add-form input:focus, .new-section input:focus, .edit-select:focus { border-color: var(--accent); }
input.bad { border-color: #ef4444; animation: nudge 300ms; }
@keyframes nudge { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.section-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; }
.tool {
  width: 28px;
  height: 24px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--tile);
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  transition: color 120ms, border-color 120ms, transform 120ms;
}
.tool:hover, .tool:focus-visible { color: var(--text); border-color: var(--accent); outline: none; }
.tool:active { transform: scale(0.92); }

.edit-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 24px;
  max-width: 1280px;
  margin: -12px auto 20px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.88rem;
  transition: background-color 300ms;
}
.edit-field, .edit-check { display: flex; align-items: center; gap: 8px; }
.edit-check { cursor: pointer; }
.edit-check input { accent-color: var(--accent); width: 16px; height: 16px; }
.edit-select { flex: none; padding: 6px 8px; }
.edit-bar input[type=range] { width: 140px; accent-color: var(--accent); }
.edit-bar output { min-width: 3.2em; color: var(--text); font-variant-numeric: tabular-nums; }
.themes { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 150ms, box-shadow 150ms;
}
.swatch:hover { transform: scale(1.15); }
.swatch[aria-checked=true] { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.theme-name { color: var(--text); min-width: 5em; }

.edit-tray {
  max-width: 1280px;
  margin: 20px auto 0;
  padding: 6px 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.9;
}
.edit-tray p { margin: 10px 0; }
.edit-tray .chip { transition: border-color 120ms, color 120ms, transform 120ms; }
.edit-tray .chip:active { transform: scale(0.95); }
.new-section { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; max-width: 420px; }
.tray-actions .setup-btn { margin-right: 8px; }

/* Layouts */
.sections.columns { display: block; columns: 3; column-gap: 20px; }
.sections.columns > * { break-inside: avoid; margin-bottom: 20px; }
@media (max-width: 1100px) { .sections.columns { columns: 2; } }
@media (max-width: 700px) { .sections.columns { columns: 1; } }

.spotlight {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 20px;
  padding: 20px;
  border-radius: 16px;
  background: var(--panel);
  transition: background-color 300ms;
}
.spotlight .tile.hero .icon { width: calc(168px * var(--k)); height: calc(168px * var(--k)); border-radius: calc(32px * var(--k)); }
.spotlight .tile.hero .icon img { width: calc(104px * var(--k)); height: calc(104px * var(--k)); }
.spotlight .tile.hero .letter { font-size: calc(4rem * var(--k)); }
.spotlight .tile.hero .name { max-width: none; font-size: 1.05rem; color: var(--text); }
.spotlight .tile.big .icon { width: calc(108px * var(--k)); height: calc(108px * var(--k)); border-radius: calc(22px * var(--k)); }
.spotlight .tile.big .icon img { width: calc(66px * var(--k)); height: calc(66px * var(--k)); }
.spotlight .tile.big .letter { font-size: calc(2.4rem * var(--k)); }
.spotlight .tile.big .name { max-width: calc(120px * var(--k)); }

.section.flat .tiles { gap: 8px; }

.no-names .tile .name { display: none; }
.no-names .tiles { grid-template-columns: repeat(auto-fill, calc(80px * var(--k))); }
.no-names .tile { padding-bottom: 6px; }

@media (max-width: 640px) {
  .edit-bar { margin-top: 0; gap: 12px 16px; }
  .edit-bar input[type=range] { width: 110px; }
  .edit-on .section[data-section] h2 { padding-right: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
