:root {
  --bg: #f5f5f5;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #888;
  --border: #e0e0e0;
  --accent: #00b4d8;
  --accent-hover: #0096c7;
  --badge-bg: #e0f7fa;
  --badge-text: #00838f;
  --shadow: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-hover: 0 4px 16px rgba(0,0,0,0.1);
  --header-bg: #0a0a0f;
  --header-text: #e0e0e0;
  --header-accent: #00b4d8;
  --mono: "SF Mono", "Fira Code", "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0a0a0f;
  --bg-card: #141420;
  --bg-input: #1a1a2e;
  --text: #d4d4d8;
  --text-secondary: #a1a1aa;
  --text-muted: #6b6b76;
  --border: #27273a;
  --accent: #00b4d8;
  --accent-hover: #38d9f5;
  --badge-bg: #0c2d3e;
  --badge-text: #38d9f5;
  --shadow: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-hover: 0 4px 16px rgba(0,0,0,0.5);
  --header-bg: #06060a;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 1.2rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left { display: flex; align-items: baseline; gap: 1.2rem; }

h1 {
  font-family: var(--mono);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
h1 a {
  color: var(--header-accent);
  text-decoration: none;
}

.subtitle {
  font-family: var(--mono);
  font-size: 0.75rem;
  opacity: 0.5;
  letter-spacing: 0.04em;
}

.header-right { display: flex; align-items: center; gap: 0.8rem; }

.header-link {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--header-text);
  text-decoration: none;
  opacity: 0.6;
  transition: opacity 0.15s;
}
.header-link:hover { opacity: 1; }

#theme-toggle {
  background: none;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 4px;
  color: var(--header-text);
  cursor: pointer;
  padding: 5px 7px;
  display: flex;
  align-items: center;
  transition: border-color 0.2s;
}
#theme-toggle:hover { border-color: var(--accent); }

[data-theme="dark"] .icon-sun { display: inline; }
[data-theme="dark"] .icon-moon { display: none; }
html:not([data-theme="dark"]) .icon-sun { display: none; }
html:not([data-theme="dark"]) .icon-moon { display: inline; }

/* Main */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
  flex: 1;
}

.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

#search-input {
  flex: 1;
  padding: 0.65rem 0.9rem;
  font-size: 0.95rem;
  font-family: var(--mono);
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--text-muted); }

#type-filter,
#sort-order {
  padding: 0.65rem 0.9rem;
  font-size: 0.85rem;
  font-family: var(--mono);
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
  min-width: 150px;
}

.stats {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  letter-spacing: 0.02em;
}

/* Grid */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.75rem;
}

.device-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
}
.device-card:hover {
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
}

.card-thumb {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  background: var(--border);
  display: block;
}

.card-body {
  padding: 0.75rem 0.85rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.card-title {
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.3;
}
.card-title a {
  color: var(--text);
  text-decoration: none;
  transition: color 0.15s;
}
.card-title a:hover { color: var(--accent); }

.card-version {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.card-author {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--badge-bg);
  color: var(--badge-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.card-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.45;
  flex: 1;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.card-meta {
  display: flex;
  gap: 0.8rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* Load more */
.load-more-container { text-align: center; padding: 1.5rem 0; }

#load-more-btn {
  font-family: var(--mono);
  padding: 0.5rem 1.5rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
#load-more-btn:hover { border-color: var(--accent); color: var(--accent); }

.loading {
  text-align: center;
  padding: 3rem;
  font-family: var(--mono);
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Footer */
footer {
  text-align: center;
  padding: 1.2rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
footer a { color: var(--accent); text-decoration: none; }
.footer-links { margin-top: 0.4rem; }
.footer-links .sep { margin: 0 0.4rem; opacity: 0.3; }

/* Highlight */
mark {
  background: rgba(0, 180, 216, 0.25);
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}
[data-theme="dark"] mark {
  background: rgba(0, 180, 216, 0.3);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  position: relative;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 1;
}
.modal-close:hover { color: var(--text); border-color: var(--accent); }

.modal-thumb {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: 4px;
  margin-bottom: 1rem;
  background: var(--border);
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.modal-author {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0.75rem 0;
  white-space: pre-line;
}

.modal-details {
  margin: 0.75rem 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.modal-detail-row {
  display: flex;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
}
.modal-detail-row:last-child { border-bottom: none; }

.modal-detail-label {
  font-family: var(--mono);
  width: 120px;
  flex-shrink: 0;
  padding: 0.4rem 0.6rem;
  color: var(--text-muted);
  background: var(--bg);
}

.modal-detail-value {
  padding: 0.4rem 0.6rem;
  color: var(--text);
}

.modal-links {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.modal-btn {
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  text-decoration: none;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s;
}
.modal-btn:hover { background: var(--accent-hover); }

.modal-btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.modal-btn-secondary:hover { background: var(--accent); color: #fff; }

@media (max-width: 600px) {
  .search-bar { flex-direction: column; }
  #type-filter { min-width: unset; }
  .device-grid { grid-template-columns: 1fr; }
  .header-left { flex-direction: column; gap: 0.2rem; }
}
