:root,
html[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #171923;
  --surface-hover: #1e2230;
  --border: rgba(255, 255, 255, 0.07);
  --border-hover: rgba(255, 255, 255, 0.14);
  --text-primary: #e8eaf0;
  --text-secondary: #7a8099;
  --text-dim: #4a5068;
  --accent: #5b8af0;
  --accent-glow: rgba(91, 138, 240, 0.18);
  --accent-light: rgba(91, 138, 240, 0.08);
  --dot-idle: #2e3450;
  --link-hover-bg: rgba(255, 255, 255, 0.05);
  --scrollbar-thumb: #2a2f45;
  --search-option-bg: #1e2230;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-ui: "Outfit", -apple-system, sans-serif;
  --font-mono: "DM Mono", "Fira Code", monospace;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-hover: #f0f2f8;
  --border: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.15);
  --text-primary: #1a1d2e;
  --text-secondary: #5a6080;
  --text-dim: #9ba3bf;
  --accent: #3b6ef0;
  --accent-glow: rgba(59, 110, 240, 0.15);
  --accent-light: rgba(59, 110, 240, 0.07);
  --dot-idle: #c8cce0;
  --link-hover-bg: rgba(0, 0, 0, 0.04);
  --scrollbar-thumb: #c8cce0;
  --search-option-bg: #ffffff;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition:
    background-color 0.22s ease,
    border-color 0.22s ease,
    color 0.22s ease,
    box-shadow 0.22s ease;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Header ─── */
header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  position: relative;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logo-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
  font-family: var(--font-mono);
}

h1 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}

/* ─── Search ─── */
.search-wrap {
  flex: 1;
  max-width: 400px;
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-engine {
  padding: 0 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  height: 32px;
  outline: none;
  cursor: pointer;
  font-family: var(--font-ui);
}
.search-engine option {
  background: var(--search-option-bg);
}

.search-input {
  flex: 1;
  height: 32px;
  padding: 0 10px;
  background: transparent;
  border: none;
  font-size: 12px;
  color: var(--text-primary);
  outline: none;
  font-family: var(--font-ui);
}
.search-input::placeholder {
  color: var(--text-dim);
}

.search-btn {
  height: 32px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.03em;
  font-family: var(--font-ui);
  transition: background 0.15s;
}
.search-btn:hover {
  background: #7099f5;
}

/* ─── Date/Time badge ─── */
.header-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

/* ─── Main grid ─── */
main {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: thin;
  scrollbar-color: #2a2f45 transparent;
}
main::-webkit-scrollbar {
  width: 4px;
}
main::-webkit-scrollbar-track {
  background: transparent;
}
main::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

/* ─── Category row ─── */
.category-row {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 14px 6px 0;
  transition:
    border-color 0.15s,
    background 0.15s;
  min-height: 36px;
}
.category-row:hover {
  border-color: var(--border-hover);
  background: var(--surface-hover);
}

/* ─── Category label ─── */
.row-title {
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--tag-text);
  background: var(--tag-bg);
  border: 1px solid var(--tag-border);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  white-space: nowrap;
  flex-shrink: 0;
  margin: 0 12px;
  letter-spacing: 0.04em;
  min-width: 44px;
  text-align: center;
}

/* Unique accent per category */
.cat-0 .row-title {
  --tag-bg: rgba(91, 138, 240, 0.12);
  --tag-border: rgba(91, 138, 240, 0.25);
  --tag-text: #7ea6f5;
}
.cat-1 .row-title {
  --tag-bg: rgba(99, 214, 177, 0.1);
  --tag-border: rgba(99, 214, 177, 0.22);
  --tag-text: #5ecfaa;
}
.cat-2 .row-title {
  --tag-bg: rgba(255, 183, 77, 0.1);
  --tag-border: rgba(255, 183, 77, 0.22);
  --tag-text: #f5c15e;
}
.cat-3 .row-title {
  --tag-bg: rgba(167, 139, 250, 0.1);
  --tag-border: rgba(167, 139, 250, 0.22);
  --tag-text: #b79ff8;
}
.cat-4 .row-title {
  --tag-bg: rgba(251, 113, 133, 0.1);
  --tag-border: rgba(251, 113, 133, 0.22);
  --tag-text: #f87089;
}
.cat-5 .row-title {
  --tag-bg: rgba(56, 189, 248, 0.1);
  --tag-border: rgba(56, 189, 248, 0.22);
  --tag-text: #4bbde8;
}
.cat-6 .row-title {
  --tag-bg: rgba(52, 211, 153, 0.1);
  --tag-border: rgba(52, 211, 153, 0.22);
  --tag-text: #37c898;
}
.cat-7 .row-title {
  --tag-bg: rgba(251, 146, 60, 0.1);
  --tag-border: rgba(251, 146, 60, 0.22);
  --tag-text: #fb9a44;
}
.cat-8 .row-title {
  --tag-bg: rgba(248, 113, 113, 0.1);
  --tag-border: rgba(248, 113, 113, 0.22);
  --tag-text: #f67878;
}
.cat-9 .row-title {
  --tag-bg: rgba(129, 140, 248, 0.1);
  --tag-border: rgba(129, 140, 248, 0.22);
  --tag-text: #8b9bf8;
}
.cat-10 .row-title {
  --tag-bg: rgba(34, 197, 94, 0.1);
  --tag-border: rgba(34, 197, 94, 0.22);
  --tag-text: #2ec46d;
}

/* Colored dot on hover per category */
.cat-0 .link-item:hover {
  --dot-color: #7ea6f5;
}
.cat-1 .link-item:hover {
  --dot-color: #5ecfaa;
}
.cat-2 .link-item:hover {
  --dot-color: #f5c15e;
}
.cat-3 .link-item:hover {
  --dot-color: #b79ff8;
}
.cat-4 .link-item:hover {
  --dot-color: #f87089;
}
.cat-5 .link-item:hover {
  --dot-color: #4bbde8;
}
.cat-6 .link-item:hover {
  --dot-color: #37c898;
}
.cat-7 .link-item:hover {
  --dot-color: #fb9a44;
}
.cat-8 .link-item:hover {
  --dot-color: #f67878;
}
.cat-9 .link-item:hover {
  --dot-color: #8b9bf8;
}
.cat-10 .link-item:hover {
  --dot-color: #2ec46d;
}

/* ─── Link list ─── */
.link-list {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1px 4px;
  align-items: center;
}

/* ─── Link item ─── */
.link-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 400;
  transition:
    background 0.12s,
    color 0.12s;
  white-space: nowrap;
  overflow: hidden;
}
.link-item:hover {
  background: var(--link-hover-bg);
  color: var(--text-primary);
}
.link-item:hover .dot {
  background: var(--dot-color, var(--accent));
  transform: scale(1.4);
}

.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--dot-idle);
  flex-shrink: 0;
  transition:
    background 0.15s,
    transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.link-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Divider between label + links ─── */
.divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}

/* ─── Footer ─── */
footer {
  text-align: center;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  padding: 6px 0;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  letter-spacing: 0.04em;
}

/* Light theme category tag overrides — stronger saturation for readability */
html[data-theme="light"] .cat-0 .row-title {
  --tag-bg: rgba(59, 110, 240, 0.09);
  --tag-border: rgba(59, 110, 240, 0.22);
  --tag-text: #2558d9;
}
html[data-theme="light"] .cat-1 .row-title {
  --tag-bg: rgba(16, 170, 120, 0.09);
  --tag-border: rgba(16, 170, 120, 0.22);
  --tag-text: #0e9166;
}
html[data-theme="light"] .cat-2 .row-title {
  --tag-bg: rgba(200, 130, 0, 0.09);
  --tag-border: rgba(200, 130, 0, 0.22);
  --tag-text: #9a6200;
}
html[data-theme="light"] .cat-3 .row-title {
  --tag-bg: rgba(130, 90, 230, 0.09);
  --tag-border: rgba(130, 90, 230, 0.22);
  --tag-text: #6b3fd4;
}
html[data-theme="light"] .cat-4 .row-title {
  --tag-bg: rgba(220, 50, 90, 0.09);
  --tag-border: rgba(220, 50, 90, 0.22);
  --tag-text: #c42354;
}
html[data-theme="light"] .cat-5 .row-title {
  --tag-bg: rgba(0, 150, 210, 0.09);
  --tag-border: rgba(0, 150, 210, 0.22);
  --tag-text: #006fa0;
}
html[data-theme="light"] .cat-6 .row-title {
  --tag-bg: rgba(20, 160, 110, 0.09);
  --tag-border: rgba(20, 160, 110, 0.22);
  --tag-text: #0e8a60;
}
html[data-theme="light"] .cat-7 .row-title {
  --tag-bg: rgba(210, 100, 20, 0.09);
  --tag-border: rgba(210, 100, 20, 0.22);
  --tag-text: #b05010;
}
html[data-theme="light"] .cat-8 .row-title {
  --tag-bg: rgba(210, 60, 60, 0.09);
  --tag-border: rgba(210, 60, 60, 0.22);
  --tag-text: #b53030;
}
html[data-theme="light"] .cat-9 .row-title {
  --tag-bg: rgba(90, 100, 230, 0.09);
  --tag-border: rgba(90, 100, 230, 0.22);
  --tag-text: #4450c8;
}
html[data-theme="light"] .cat-10 .row-title {
  --tag-bg: rgba(20, 160, 70, 0.09);
  --tag-border: rgba(20, 160, 70, 0.22);
  --tag-text: #0e8040;
}

/* ─── Theme toggle button ─── */
.theme-toggle {
  flex-shrink: 0;
  width: 34px;
  height: 20px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border-hover);
  cursor: pointer;
  position: relative;
  padding: 0;
  outline: none;
  transition:
    background 0.22s,
    border-color 0.22s;
}
.theme-toggle:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.theme-toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-dim);
  transition:
    transform 0.22s cubic-bezier(0.34, 1.2, 0.64, 1),
    background 0.22s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  line-height: 1;
}
html[data-theme="light"] .theme-toggle {
  background: #e8edff;
  border-color: rgba(59, 110, 240, 0.3);
}
html[data-theme="light"] .theme-toggle-knob {
  transform: translateX(14px);
  background: var(--accent);
}

/* icon inside knob */
.knob-icon {
  pointer-events: none;
  user-select: none;
}

/* ─── Tablet ─── */
@media (max-width: 991px) {
  .link-list {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ─── Mobile ─── */
@media (max-width: 767px) {
  /* Body scrolls naturally */
  html,
  body {
    height: auto;
    overflow: auto;
  }
  body {
    overflow-x: hidden;
  }

  /* Header: two-row stack */
  header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
    align-items: center;
  }
  /* Row 1: logo + clock + toggle */
  .logo-area {
    flex: 1;
    min-width: 0;
  }
  .header-time {
    font-size: 10px;
  }

  /* Row 2: search bar full width */
  .search-wrap {
    order: 10; /* push to second row */
    width: 100%;
    max-width: 100%;
    flex: none;
  }

  /* Main padding tighter */
  main {
    padding: 8px 10px;
    gap: 6px;
    overflow: visible;
  }

  /* Category row: vertical stack — label on top, links below */
  .category-row {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 10px 8px;
    gap: 0;
  }
  .category-row:hover {
    background: var(--surface);
  } /* no hover flicker on touch */

  /* Label row inside category */
  .row-title {
    margin: 0 0 8px 0;
    font-size: 9px;
    padding: 2px 8px;
    align-self: flex-start;
  }

  /* Hide the vertical divider */
  .divider {
    display: none;
  }

  /* Links: comfortable 2-column grid with good tap targets */
  .link-list {
    width: 100%;
    grid-template-columns: repeat(2, 1fr);
    gap: 2px 0;
  }

  .link-item {
    padding: 7px 6px;
    font-size: 13px;
    white-space: normal; /* allow wrapping on mobile */
    gap: 7px;
  }

  .dot {
    width: 6px;
    height: 6px;
    flex-shrink: 0;
  }

  footer {
    padding: 10px 0;
    font-size: 10px;
  }
}

/* ─── Very small phones (≤390px) ─── */
@media (max-width: 390px) {
  .link-list {
    grid-template-columns: 1fr 1fr;
  }
  .link-item {
    font-size: 12px;
    padding: 6px 4px;
  }
}
