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

:root {
  --bg: #0f1117;
  --surface: #1a1c25;
  --border: #2a2d3a;
  --text: #e4e4e7;
  --text-muted: #8b8d98;
  --accent: #6c63ff;
  --accent-soft: rgba(108, 99, 255, 0.12);
  --green: #22c55e;
  --yellow: #eab308;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.site-logo {
  height: 1.8em;
  width: auto;
  border-radius: 6px;
}

.subtitle {
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-size: 1.05rem;
}

/* Mode Toggle */
.mode-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  width: fit-content;
}

.mode-btn {
  padding: 0.4rem 1.1rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

.mode-btn:not(.active):hover {
  color: var(--text);
}

.diameter-input {
  flex: 2;
}

/* Input Section */
.input-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
}

.input-row[hidden] {
  display: none;
}

.dimension-input {
  flex: 1;
}

.dimension-input label,
.unit-select label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.dimension-input input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 500;
  outline: none;
  transition: border-color 0.15s;
}

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

.times {
  font-size: 1.5rem;
  color: var(--text-muted);
  padding-bottom: 0.5rem;
  user-select: none;
}

.unit-select select {
  padding: 0.7rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}

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

.tolerance-row {
  margin-top: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.tolerance-row label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 100px;
}

.tolerance-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 4px;
}

/* Results */
.results {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.results-header {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.results-header strong {
  color: var(--text);
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.category-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.category-header {
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.category-icon {
  font-size: 1rem;
}

.match-item {
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
}

.match-item:last-child {
  border-bottom: none;
}

.match-name {
  font-weight: 600;
  font-size: 1rem;
}

.match-dims {
  font-size: 0.9rem;
  color: var(--accent);
  margin-top: 0.1rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.match-details {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.match-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  flex-shrink: 0;
}

.amazon-link {
  display: inline-block;
  margin-top: 0.3rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.amazon-link:hover {
  opacity: 1;
  text-decoration: underline;
}

.match-badge {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  white-space: nowrap;
}

.match-badge.exact {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
}

.match-badge.close {
  background: rgba(234, 179, 8, 0.15);
  color: var(--yellow);
}

.no-results {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 2rem 0;
}

.empty-state p {
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.example-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  padding: 0.45rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.example-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Ad Slot — single tasteful placement */
.ad-slot {
  margin: 2.5rem 0 1rem;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  overflow: hidden;
  opacity: 0.85;
  transition: opacity 0.2s;
}

.ad-slot:hover {
  opacity: 1;
}

.ad-slot ins {
  background: transparent;
}

.ad-slot-inline {
  margin: 0.5rem 0;
  min-height: 50px;
  opacity: 0.7;
}

/* Visually hidden — accessible to screen readers and crawlers */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* SEO Content Section */
.seo-content {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.7;
}

.seo-content h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.75rem;
}

.seo-content h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

.seo-content h4 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 1rem;
  margin-bottom: 0.25rem;
}

.seo-content p {
  margin-bottom: 0.5rem;
}

.seo-categories {
  margin-top: 0.5rem;
}

/* Footer */
footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

footer p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer-copyright {
  margin-top: 0.35rem;
  font-size: 0.75rem !important;
  opacity: 0.6;
}

/* Responsive */
@media (max-width: 500px) {
  h1 { font-size: 1.5rem; }

  .input-row {
    flex-wrap: wrap;
  }

  .dimension-input { flex: 1 1 40%; }
  .times { flex: 0 0 auto; padding-bottom: 0.3rem; }
  .unit-select { flex: 1 1 100%; }
  .unit-select select { width: 100%; }
}
