:root {
  --bg-1: #fff6e9;
  --bg-2: #e6f5ef;
  --bg-3: #d9ecf7;
  --surface: #fffdfa;
  --surface-soft: #f8f4ed;
  --ink: #1f2a37;
  --ink-muted: #5f6a75;
  --line: #d7d8d2;
  --primary: #0b6e4f;
  --primary-strong: #065f46;
  --accent: #d97706;
  --danger-bg: #ffe8e6;
  --danger-fg: #9f2a1b;
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --shadow-lg: 0 20px 45px rgba(31, 42, 55, 0.12);
  --shadow-md: 0 10px 24px rgba(31, 42, 55, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: 28px 20px;
  color: var(--ink);
  font-family: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(1100px 550px at -10% -10%, rgba(11, 110, 79, 0.2), transparent 55%),
    radial-gradient(900px 500px at 110% 10%, rgba(217, 119, 6, 0.22), transparent 50%),
    linear-gradient(145deg, var(--bg-1) 0%, var(--bg-2) 48%, var(--bg-3) 100%);
}

.container {
  max-width: 980px;
  margin: 18px auto;
  background: linear-gradient(160deg, #fffefc 0%, var(--surface) 100%);
  border: 1px solid rgba(31, 42, 55, 0.08);
  border-radius: var(--radius-xl);
  padding: 30px;
  box-shadow: var(--shadow-lg);
  animation: page-enter 0.55s ease both;
}

.header {
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--primary);
}

.header h1 {
  margin: 0;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: clamp(2rem, 3.6vw, 3rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
}

.header .subtitle {
  margin: 10px 0 0;
  color: var(--ink-muted);
  font-size: 0.98rem;
  max-width: 66ch;
}

.search-box {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: linear-gradient(145deg, #ffffff 0%, var(--surface-soft) 100%);
  box-shadow: var(--shadow-md);
  margin-bottom: 18px;
}

#search-box {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--ink);
  padding: 14px 14px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#search-box::placeholder {
  color: #89919b;
}

#search-box:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(11, 110, 79, 0.12);
}

#search-button,
.secondary-button {
  appearance: none;
  border: 0;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

#search-button {
  min-width: 112px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, #157f62 100%);
  box-shadow: 0 10px 20px rgba(11, 110, 79, 0.28);
}

#search-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 26px rgba(11, 110, 79, 0.3);
}

#search-button:disabled {
  opacity: 0.72;
  cursor: not-allowed;
  transform: none;
}

.secondary-button {
  min-width: 86px;
  color: var(--ink);
  border: 1px solid var(--line);
  background: #fff;
}

.secondary-button:hover {
  transform: translateY(-1px);
  background: #fdfaf3;
  box-shadow: 0 10px 18px rgba(31, 42, 55, 0.12);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.controls label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-muted);
  font-size: 0.86rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: all 0.2s ease;
}

.controls label:hover {
  border-color: #bcc3cb;
  color: var(--ink);
  transform: translateY(-1px);
}

.controls input[type="radio"]:checked + label {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(140deg, #0b6e4f 0%, #0d8d63 100%);
  box-shadow: 0 8px 18px rgba(11, 110, 79, 0.25);
}

.alert {
  display: none;
  margin-bottom: 14px;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid rgba(159, 42, 27, 0.25);
  background: var(--danger-bg);
  color: var(--danger-fg);
  font-size: 0.92rem;
}

#results-container {
  display: grid;
  gap: 12px;
}

.loader-container {
  display: none;
  padding: 24px 0 16px;
  text-align: center;
}

.loader {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  margin: 0 auto;
  border: 4px solid rgba(11, 110, 79, 0.15);
  border-top-color: var(--primary);
  animation: spin 1s linear infinite;
}

.results-empty {
  text-align: center;
  font-size: 0.96rem;
  color: var(--ink-muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  padding: 20px 16px;
  background: rgba(255, 255, 255, 0.6);
}

.routing-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(11, 110, 79, 0.22);
  background: rgba(11, 110, 79, 0.07);
}

.routing-chip {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary-strong);
  background: #e6f7ef;
  border: 1px solid rgba(11, 110, 79, 0.18);
  border-radius: 999px;
  padding: 4px 9px;
}

#results-container .result {
  border: 1px solid #dfe4df;
  background: linear-gradient(145deg, #fff 0%, #fbf8f2 100%);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: 0 8px 18px rgba(31, 42, 55, 0.08);
  animation: card-in 0.45s ease both;
}

#results-container .result:nth-child(2) {
  animation-delay: 0.03s;
}
#results-container .result:nth-child(3) {
  animation-delay: 0.07s;
}
#results-container .result:nth-child(4) {
  animation-delay: 0.1s;
}
#results-container .result:nth-child(5) {
  animation-delay: 0.13s;
}
#results-container .result:nth-child(6) {
  animation-delay: 0.16s;
}

#results-container .result h3 {
  margin: 0 0 7px;
  line-height: 1.35;
}

#results-container .result a {
  color: #0e4d92;
  text-decoration: none;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.18rem;
  font-weight: 600;
}

#results-container .result a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
}

#results-container .result p {
  margin: 0;
  color: #3f4b57;
  line-height: 1.62;
  font-size: 0.96rem;
}

#results-container .result small {
  display: block;
  margin-top: 9px;
  color: #7c8692;
  font-size: 0.8rem;
}

mark,
.highlight {
  background-color: #ffedb6;
  border-radius: 4px;
  padding: 0 2px;
}

#research-controls,
#session-info {
  margin-top: 18px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #fff;
}

#research-controls h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

#research-controls label {
  margin-right: 8px;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

#research-controls select,
#research-controls button {
  margin-right: 8px;
  margin-top: 6px;
}

#research-controls select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.9rem;
}

#research-controls button {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 8px 10px;
  font-family: inherit;
  cursor: pointer;
}

#session-info p {
  margin: 6px 0;
  font-size: 0.88rem;
  color: var(--ink-muted);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes page-enter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@media (max-width: 860px) {
  .container {
    padding: 22px;
  }

  .search-box {
    grid-template-columns: 1fr;
  }

  #search-button,
  .secondary-button {
    width: 100%;
  }
}

@media (max-width: 560px) {
  body {
    padding: 14px 10px;
  }

  .container {
    border-radius: 16px;
    padding: 16px;
  }

  .controls label {
    width: 100%;
    justify-content: center;
    border-radius: 12px;
  }

  #results-container .result a {
    font-size: 1.04rem;
  }
}
