:root {
  --primary: #007aff;
  --primary-hover: #0056b3;
  --code-bg: #2d2d2d;
  --code-text: #f8f8f2;
  --container-bg: rgba(255, 255, 255, 0.95);
  --body-bg-start: #f8f9fa;
  --body-bg-end: #e9ecef;
  --text: #333;
  --text-secondary: #666;
  --border: #eee;
  --notice-bg: #fff9e6;
  --notice-border: #ffd700;
  --table-hover: #fafafa;
  --table-header: #f8f9fa;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 4px;
  --transition: 0.3s ease;
  --mac-red: #ff5f56;
  --mac-yellow: #ffbd2e;
  --mac-green: #27c93f;
}

[data-theme="dark"] {
  --primary: #4da6ff;
  --primary-hover: #80bfff;
  --code-bg: #1a1a2e;
  --container-bg: rgba(30, 30, 40, 0.95);
  --body-bg-start: #1a1a2e;
  --body-bg-end: #16213e;
  --text: #e0e0e0;
  --text-secondary: #a0a0a0;
  --border: #333;
  --notice-bg: #2a2410;
  --notice-border: #ffd700;
  --table-hover: #252535;
  --table-header: #1e1e30;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #4da6ff;
    --primary-hover: #80bfff;
    --code-bg: #1a1a2e;
    --container-bg: rgba(30, 30, 40, 0.95);
    --body-bg-start: #1a1a2e;
    --body-bg-end: #16213e;
    --text: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border: #333;
    --notice-bg: #2a2410;
    --notice-border: #ffd700;
    --table-hover: #252535;
    --table-header: #1e1e30;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
  color: var(--text);
  margin: 0;
  padding: 20px;
  background: linear-gradient(135deg, var(--body-bg-start) 0%, var(--body-bg-end) 100%);
  background-attachment: fixed;
  transition: background var(--transition), color var(--transition);
}

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 30px;
  background: var(--container-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

h1, h2, h3 {
  color: var(--primary);
  margin-bottom: 1.2rem;
  line-height: 1.3;
}

h1 {
  font-size: 2.2em;
  text-align: center;
}

h2 {
  font-size: 1.6em;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.5rem;
}

h3 {
  font-size: 1.1em;
  margin-top: 2rem;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  text-decoration: underline;
  color: var(--primary-hover);
}

/* Theme toggle */
.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--container-bg);
  color: var(--text);
  font-size: 1.2em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: all var(--transition);
}

.theme-toggle:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-lg);
}

/* Notice box */
.notice-box {
  background: var(--notice-bg);
  border-left: 4px solid var(--notice-border);
  padding: 1rem;
  margin: 1.5rem 0;
  border-radius: var(--radius-xs);
  position: relative;
}

.notice-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2em;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  transition: color var(--transition);
}

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

/* Code blocks */
pre {
  position: relative;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 35px 20px 20px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 1.2rem 0;
  font-size: 0.9em;
}

pre::before {
  content: "";
  position: absolute;
  top: 14px;
  left: 15px;
  width: 12px;
  height: 12px;
  background: var(--mac-red);
  border-radius: 50%;
  box-shadow: 20px 0 0 var(--mac-yellow), 40px 0 0 var(--mac-green);
}

code {
  font-family: "SF Mono", "Fira Code", "Source Code Pro", Consolas, monospace;
}

.copy-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 5px 14px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-size: 0.85em;
  opacity: 0;
  transition: all var(--transition);
  white-space: nowrap;
}

pre:hover .copy-btn,
pre:focus-within .copy-btn {
  opacity: 1;
}

.copy-btn.copied {
  background: #34c759;
}

/* Table */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.5rem 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--container-bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

th, td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background-color: var(--table-header);
  font-weight: 600;
  white-space: nowrap;
}

tr:hover td {
  background-color: var(--table-hover);
}

td code {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.85em;
  white-space: nowrap;
}

/* Search */
.search-box {
  margin: 1rem 0 0.5rem;
}

.search-box input {
  width: 100%;
  max-width: 360px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95em;
  background: var(--container-bg);
  color: var(--text);
  transition: border-color var(--transition);
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

/* Domain cards */
.domain-list {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.domain-list li {
  background: var(--table-header);
  padding: 10px 14px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  font-family: monospace;
  font-size: 0.9em;
  transition: all var(--transition);
}

.domain-list li:hover {
  border-color: var(--primary);
  background: var(--container-bg);
}

.domain-list li .node-label {
  display: block;
  font-size: 0.75em;
  color: var(--text-secondary);
  margin-top: 2px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.domain-list li .latency {
  float: right;
  font-size: 0.8em;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.domain-list li .latency.checking {
  color: var(--text-secondary);
  background: transparent;
}

.domain-list li .latency.fast {
  color: #1a7f3f;
  background: #d4edda;
}

.domain-list li .latency.medium {
  color: #8a6d14;
  background: #fff3cd;
}

.domain-list li .latency.slow {
  color: #a94442;
  background: #f8d7da;
}

.domain-list li .latency.fail {
  color: #888;
  background: #eee;
}

[data-theme="dark"] .domain-list li .latency.fast {
  color: #4ade80;
  background: #14532d;
}

[data-theme="dark"] .domain-list li .latency.medium {
  color: #facc15;
  background: #4a3a0a;
}

[data-theme="dark"] .domain-list li .latency.slow {
  color: #f87171;
  background: #5f1a1a;
}

[data-theme="dark"] .domain-list li .latency.fail {
  color: #666;
  background: #222;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .domain-list li .latency.fast {
    color: #4ade80;
    background: #14532d;
  }
  :root:not([data-theme="light"]) .domain-list li .latency.medium {
    color: #facc15;
    background: #4a3a0a;
  }
  :root:not([data-theme="light"]) .domain-list li .latency.slow {
    color: #f87171;
    background: #5f1a1a;
  }
  :root:not([data-theme="light"]) .domain-list li .latency.fail {
    color: #666;
    background: #222;
  }
}


/* Badges */
.badge-group {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.github-badge {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-xs);
  font-size: 13px;
  overflow: hidden;
  line-height: 1.5;
  text-decoration: none;
}

.github-badge .badge-subject {
  background-color: #4d4d4d;
  color: #fff;
  padding: 4px 10px;
}

.github-badge .badge-value {
  color: #fff;
  padding: 4px 10px;
}

.bg-blue { background-color: #007ec6; }
.bg-green { background-color: #3bca6e; }
.bg-orange { background-color: #ffa500; }

a.github-badge:hover {
  text-decoration: none;
  opacity: 0.9;
}

/* Stats */
.stats {
  text-align: center;
  margin: 1.5rem 0;
}

/* Back to top */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--container-bg);
  color: var(--text);
  font-size: 1.2em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition);
  z-index: 999;
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

.back-to-top:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

/* Links section */
.links {
  margin: 1.5rem 0;
}

.links img {
  max-width: 100%;
  margin-top: 1rem;
  border-radius: var(--radius-xs);
}

/* Footer */
.footer {
  margin-top: 2.5rem;
  text-align: center;
}

.footer .badge-group {
  margin-bottom: 0.8rem;
}

.cf-info {
  margin: 1rem 0 0;
  font-size: 0.85em;
  color: var(--text-secondary);
  min-height: 1.3em;
}

/* No results */
.no-results {
  text-align: center;
  color: var(--text-secondary);
  padding: 2rem;
  display: none;
}

/* Responsive */
@media (max-width: 768px) {
  body { padding: 10px; }

  .container {
    padding: 18px;
    margin: 0;
    border-radius: var(--radius-sm);
  }

  h1 { font-size: 1.6em; }
  h2 { font-size: 1.3em; }

  pre {
    font-size: 0.8em;
    padding: 28px 12px 12px;
  }

  pre::before {
    top: 10px;
    left: 10px;
    width: 10px;
    height: 10px;
    box-shadow: 16px 0 0 var(--mac-yellow), 32px 0 0 var(--mac-green);
  }

  .copy-btn {
    opacity: 1;
    font-size: 0.75em;
    padding: 4px 10px;
    top: 8px;
    right: 8px;
  }

  .domain-list {
    grid-template-columns: 1fr;
  }

  th, td { padding: 8px 10px; font-size: 0.85em; }

  .theme-toggle {
    top: 8px;
    right: 8px;
    width: 34px;
    height: 34px;
    font-size: 1em;
  }

  .back-to-top {
    bottom: 16px;
    right: 16px;
    width: 34px;
    height: 34px;
  }
}

@media (max-width: 480px) {
  .badge-group { gap: 4px; }
  .github-badge { font-size: 11px; }
  .github-badge .badge-subject,
  .github-badge .badge-value { padding: 3px 7px; }
}

/* Print */
@media print {
  .theme-toggle,
  .back-to-top,
  .copy-btn,
  .notice-close { display: none !important; }
}
