:root {
  --bg: #0d0d0f;
  --surface: #141417;
  --surface2: #1c1c21;
  --border: #2a2a32;
  --accent: #c084fc;
  --accent2: #a78bfa;
  --accent-rgb: 192, 132, 252;
  --text: #f0f0f4;
  --muted: #6b6b7a;
  --radius: 10px;
  --mono: 'Space Mono', monospace;
  --sans: 'Syne', sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  padding: 14px 18px 34px;
}

.home-topbar {
  width: min(1240px, 100%);
  margin: 0 auto 16px;
  position: sticky;
  top: 8px;
  z-index: 50;
  border: 1px solid rgba(var(--accent-rgb), 0.26);
  border-radius: 18px;
  background: rgba(15, 15, 20, 0.84);
  backdrop-filter: blur(10px);
  padding: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(var(--accent-rgb), 0.45);
  background: rgba(var(--accent-rgb), 0.12);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent2);
}

.brand-mark svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

h1 {
  margin: 0 0 3px;
  font-size: clamp(1.55rem, 2.4vw, 2.2rem);
  letter-spacing: -0.03em;
  line-height: 1;
}

.sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 560px;
  min-width: min(560px, 100%);
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.search-wrap {
  flex: 1 1 auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(28, 28, 33, 0.9);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
}

.search-icon {
  width: 16px;
  height: 16px;
  color: var(--muted);
  flex: 0 0 auto;
}

.search-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#homeSearchInput {
  width: 100%;
  min-height: 42px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.82rem;
}

#homeSearchInput::placeholder {
  color: var(--muted);
}

.device-badge {
  border: 1px solid rgba(var(--accent-rgb), 0.4);
  border-radius: 999px;
  padding: 9px 11px;
  font-family: var(--mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent2);
  white-space: nowrap;
}

.settings-toggle-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(var(--accent-rgb), 0.4);
  background: rgba(var(--accent-rgb), 0.08);
  color: var(--accent2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.settings-toggle-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.settings-toggle-btn:hover,
.settings-toggle-btn.is-open {
  background: rgba(var(--accent-rgb), 0.16);
  border-color: rgba(var(--accent-rgb), 0.7);
}

.export-settings-btn {
  border: 1px solid rgba(var(--accent-rgb), 0.4);
  border-radius: 999px;
  padding: 9px 14px;
  background: rgba(var(--accent-rgb), 0.08);
  color: var(--accent2);
  font-family: var(--mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.1s ease;
}

.export-settings-btn:hover {
  background: rgba(var(--accent-rgb), 0.16);
  border-color: rgba(var(--accent-rgb), 0.7);
}

.export-settings-btn:active {
  transform: translateY(1px);
}

.import-settings-btn {
  border: 1px solid rgba(var(--accent-rgb), 0.4);
  border-radius: 999px;
  padding: 9px 14px;
  background: rgba(var(--accent-rgb), 0.08);
  color: var(--accent2);
  font-family: var(--mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.1s ease;
}

.import-settings-btn:hover {
  background: rgba(var(--accent-rgb), 0.16);
  border-color: rgba(var(--accent-rgb), 0.7);
}

.import-settings-btn:active {
  transform: translateY(1px);
}

.home-settings-panel {
  width: min(420px, calc(100vw - 36px));
  position: absolute;
  right: 0px;
  top: calc(100% + 8px);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface2);
  padding: 12px;
  display: grid;
  gap: 12px;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.35);
  z-index: 80;
  margin-top: 6px;
}

.home-settings-panel[hidden] {
  display: none;
}

.home-settings-group {
  display: grid;
  gap: 8px;
}

.home-settings-title {
  font-family: var(--mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.home-settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.theme-mode-options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.theme-option {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--muted);
}

.theme-option input[type='radio'] {
  accent-color: var(--accent);
}

.theme-color-control {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--muted);
}

.theme-color-control input[type='color'] {
  width: 38px;
  height: 26px;
  border: 1px solid rgba(var(--accent-rgb), 0.5);
  border-radius: 6px;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.settings-status {
  margin-top: 0;
  min-height: 18px;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.settings-status--success {
  color: #7ef2a7;
}

.settings-status--error {
  color: #ff6b81;
}

.wrap {
  width: min(1240px, 100%);
  margin: 0 auto;
}

.group {
  margin-bottom: 12px;
}

.group-title {
  margin: 0 0 10px;
  font-family: var(--mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.7rem;
}

.favorites-divider {
  height: 1px;
  margin: 16px 0;
  background: linear-gradient(90deg, rgba(var(--accent-rgb), 0), rgba(var(--accent-rgb), 0.45), rgba(var(--accent-rgb), 0));
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.tile {
  position: relative;
  border: 1.5px solid var(--border);
  border-radius: 16px;
  background: linear-gradient(180deg, var(--surface2), var(--surface));
  min-height: 220px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.tile:hover {
  border-color: var(--accent2);
  box-shadow: 0 12px 28px rgba(var(--accent-rgb), 0.22);
  transform: translateY(-2px);
}

.tile.is-disabled-tool {
  border-color: rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(30, 30, 34, 0.8), rgba(17, 17, 20, 0.8));
  opacity: 0.62;
}

.tile.is-disabled-tool:hover {
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: none;
  transform: none;
}

.tile.is-favorite-tile {
  cursor: grab;
}

.tile.is-favorite-tile:active {
  cursor: grabbing;
}

body.is-reordering-favorites {
  user-select: none;
  touch-action: none;
}

body.is-reordering-favorites .tile.is-favorite-tile .tile-link,
body.is-reordering-favorites .tile.is-favorite-tile .favorite-btn {
  pointer-events: none;
}

.tile.is-reorder-dragging {
  z-index: 60;
  border-color: rgba(var(--accent-rgb), 0.85);
  box-shadow: 0 16px 36px rgba(var(--accent-rgb), 0.35);
  transition: none;
  cursor: grabbing;
  pointer-events: none;
}

.tile.is-reorder-dragging:hover {
  transform: none;
}

.tile.is-reorder-target {
  border-color: rgba(var(--accent-rgb), 0.95);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.3), 0 12px 28px rgba(var(--accent-rgb), 0.22);
}

.tile-link {
  height: 100%;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  padding: 20px;
}

.tile-link-disabled {
  cursor: not-allowed;
}

.tile-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(var(--accent-rgb), 0.45);
  background: rgba(var(--accent-rgb), 0.14);
  color: var(--accent2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tile-icon svg,
.tile-icon img {
  width: 20px;
  height: 20px;
  display: block;
}

.tile-icon svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tile-copy {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.name {
  font-size: clamp(1.25rem, 1.9vw, 1.7rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.tile-status {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #ffbd6a;
}

.arrow {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.favorite-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(13, 13, 15, 0.85);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.favorite-btn:hover {
  border-color: var(--accent2);
  color: var(--accent2);
}

.favorite-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
}

.favorite-btn.is-active {
  border-color: rgba(var(--accent-rgb), 0.72);
  color: var(--accent2);
  background: rgba(var(--accent-rgb), 0.14);
}

.favorite-btn.is-active svg {
  fill: currentColor;
}

.favorite-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.reorder-controls {
  position: absolute;
  bottom: 14px;
  right: 14px;
  display: flex;
  gap: 8px;
  z-index: 2;
}

.reorder-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(13, 13, 15, 0.85);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.95rem;
  cursor: pointer;
  position: relative;
}

.reorder-btn::after {
  content: '↑';
  display: block;
}

.reorder-btn.reorder-down::after {
  content: '↓';
}

@media (min-width: 721px) {
  .reorder-btn::after {
    content: '←';
  }

  .reorder-btn.reorder-down::after {
    content: '→';
  }
}

.reorder-btn:hover:not(:disabled) {
  border-color: var(--accent2);
  color: var(--accent2);
}

.reorder-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

@media (max-width: 720px) {
  .tools-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .reorder-controls {
    bottom: 12px;
    right: 12px;
    gap: 6px;
  }
}

@media (max-width: 520px) {
  .tools-grid {
    grid-template-columns: 1fr;
  }

  .reorder-btn {
    flex: 1 1 0;
    min-width: 0;
  }
}

.no-results {
  margin: 14px 0 0;
  color: var(--muted);
  border: 1px dashed rgba(var(--accent-rgb), 0.35);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.76rem;
}

body[data-theme='light'] .home-topbar {
  background: rgba(255, 255, 255, 0.9);
}

body[data-theme='light'] .search-wrap {
  background: rgba(255, 255, 255, 0.96);
}

body[data-theme='light'] .favorite-btn {
  background: rgba(255, 255, 255, 0.92);
}

@media (max-width: 1100px) {
  .home-topbar {
    align-items: stretch;
  }

  .topbar-controls {
    min-width: 0;
    width: 100%;
  }

  .tools-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  body {
    padding: 10px 12px 22px;
  }

  .home-topbar {
    top: 4px;
    padding: 12px;
  }

  .topbar-controls {
    min-width: 0;
  }

  .home-settings-actions {
    width: 100%;
  }

  .home-settings-panel {
    right: 12px;
    width: calc(100vw - 24px);
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

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

  .tile {
    min-height: 0;
  }
}
