:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --card-border: #edf2f7;
  --text: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --accent: #2b6cb0;
  --accent-dark: #1a365d;
  --accent-green: #48bb78;
  --accent-green-dark: #276749;
  --badge-pdf: #fc8181;
  --chip-bg: #f7fafc;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.04);
  --error-bg: #fed7d7;
  --error-text: #9b2c2c;
  --spinner-track: #e2e8f0;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a;
    --card: #1e293b;
    --card-border: #334155;
    --text: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --accent: #60a5fa;
    --accent-dark: #93c5fd;
    --accent-green: #34d399;
    --accent-green-dark: #6ee7b7;
    --badge-pdf: #f87171;
    --chip-bg: #334155;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.3);
    --error-bg: #7f1d1d;
    --error-text: #fecaca;
    --spinner-track: #334155;
  }
}

[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --card-border: #334155;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --accent: #60a5fa;
  --accent-dark: #93c5fd;
  --accent-green: #34d399;
  --accent-green-dark: #6ee7b7;
  --badge-pdf: #f87171;
  --chip-bg: #334155;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.3);
  --error-bg: #7f1d1d;
  --error-text: #fecaca;
  --spinner-track: #334155;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  transition: background 0.2s, color 0.2s;
}

.container {
  max-width: 600px;
  width: 100%;
}

header {
  position: relative;
  margin-bottom: 20px;
}

h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  margin-top: 20px;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 14px;
}

.theme-toggle {
  position: absolute;
  top: 20px;
  right: 0;
  background: var(--chip-bg);
  border: 1px solid var(--card-border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 20px;
  cursor: pointer;
  transition: 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:active {
  transform: scale(0.92);
}

.search-box {
  display: flex;
  gap: 10px;
  background: var(--card);
  padding: 6px;
  border-radius: 50px;
  box-shadow: var(--shadow);
  border: 1px solid var(--card-border);
}

.search-box input {
  flex: 1;
  border: none;
  padding: 12px 20px;
  font-size: 16px;
  border-radius: 50px;
  outline: none;
  background: transparent;
  color: var(--text);
  min-width: 0;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-box button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 24px;
  border-radius: 50px;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: 0.2s;
  min-height: 48px;
}

.search-box button:active {
  transform: scale(0.95);
  background: var(--accent-dark);
}

[hidden] {
  display: none !important;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 40px 0;
  color: var(--text-secondary);
}

.spinner {
  border: 4px solid var(--spinner-track);
  border-top: 4px solid var(--accent);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.result-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 16px 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-card);
  transition: 0.2s;
  cursor: pointer;
}

.result-card h3 {
  font-size: 16px;
  color: var(--accent);
  margin-bottom: 6px;
  font-weight: 600;
  line-height: 1.3;
}

.result-card p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.result-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.domain {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--chip-bg);
  padding: 4px 10px;
  border-radius: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}

.btn-visit {
  background: var(--accent-green);
  color: #fff;
  padding: 8px 16px;
  border-radius: 30px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: 0.2s;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.btn-visit:active {
  background: var(--accent-green-dark);
}

.badge-pdf {
  background: var(--badge-pdf);
  color: #fff;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 700;
  margin-left: 8px;
  vertical-align: middle;
}

.no-results {
  text-align: center;
  color: var(--text-muted);
  margin-top: 40px;
}

.error-msg {
  background: var(--error-bg);
  color: var(--error-text);
  padding: 16px;
  border-radius: 12px;
  margin-top: 20px;
  line-height: 1.5;
}

footer {
  margin-top: 40px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--card-border);
  padding-top: 20px;
  line-height: 1.8;
}

.attribution a {
  color: var(--accent);
}

.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;
}

@media (min-width: 480px) {
  h1 { font-size: 32px; }
  .search-box button { padding: 12px 32px; }
}

@media (max-width: 380px) {
  body { padding-left: 12px; padding-right: 12px; }
  h1 { font-size: 24px; }
  .search-box { gap: 6px; }
  .search-box button { padding: 12px 16px; white-space: nowrap; flex-shrink: 0; }
  .result-card { padding: 14px 16px; }
}