/* MathTools — Formula & concept reference */

.shell-ref {
  width: min(1200px, calc(100% - 2rem));
}

.search-field {
  position: relative;
  display: block;
}

.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-input {
  appearance: none;
  width: 100%;
  margin: 0;
  padding: 0.7rem 0.9rem 0.7rem 2.55rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

.search-input::placeholder {
  color: var(--muted);
  font-weight: 400;
}

.search-input:focus,
.search-input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.tools-empty {
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.category-rail-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.no-js-message {
  display: none;
  margin: 0 0 1.25rem;
  padding: 1rem 1.1rem;
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
  border-radius: var(--radius);
  color: var(--danger);
  font-weight: 500;
}

.ref-controls {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.ref-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.65rem;
}

.ref-filter-row .category-rail-wrap {
  flex: 1 1 280px;
  mask-image: none;
  flex-wrap: wrap;
  overflow: visible;
  padding-bottom: 0.15rem;
  margin-bottom: 0;
  gap: 0.35rem;
}

.type-filter {
  flex: 0 0 auto;
}

.type-select {
  appearance: none;
  min-width: 9.5rem;
  padding: 0.45rem 2rem 0.45rem 0.75rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  background:
    var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2393a0b4' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 0.65rem center;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.type-select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.ref-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.95fr);
  gap: 1rem;
  align-items: start;
  min-height: 28rem;
}

.ref-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: min(70vh, 42rem);
  overflow: auto;
  padding-right: 0.2rem;
  scroll-behavior: smooth;
}

.ref-card {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0.75rem 0.9rem;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    border-color 0.18s var(--ease),
    background 0.18s var(--ease),
    transform 0.18s var(--ease);
}

.ref-card:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}

.ref-card:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.ref-card.is-active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.ref-card-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.55rem;
  margin-bottom: 0.3rem;
}

.ref-card-name {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.ref-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.45rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--surface-2);
}

.ref-badge-type {
  color: var(--accent-ink);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  background: var(--accent-soft);
}

.ref-card-formula {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--accent-ink);
  white-space: pre-wrap;
  word-break: break-word;
}

.ref-card-desc {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ref-detail {
  position: sticky;
  top: 0.75rem;
  padding: 1.1rem 1.15rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: min(70vh, 42rem);
  overflow: auto;
}

.ref-detail-placeholder {
  color: var(--muted);
  font-size: 0.92rem;
}

.ref-detail-placeholder p {
  margin: 0;
}

.ref-detail-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}

.ref-detail-title {
  margin: 0 0 0.55rem;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.ref-detail-formula {
  margin: 0 0 1rem;
  padding: 0.85rem 0.95rem;
  font-family: var(--font-mono);
  font-size: 1.02rem;
  line-height: 1.45;
  color: var(--accent-ink);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

.ref-detail-section {
  margin: 0 0 1rem;
}

.ref-detail-section h3 {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.ref-detail-section p {
  margin: 0;
  font-size: 0.92rem;
}

.ref-vars {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.ref-vars li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  font-size: 0.88rem;
}

.ref-vars .sym {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-ink);
}

.ref-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.ref-tag {
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.ref-tag:hover,
.ref-tag:focus-visible {
  color: var(--accent-ink);
  border-color: var(--accent);
  outline: none;
}

.ref-related {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.ref-related-btn {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0.45rem 0.65rem;
  text-align: left;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.ref-related-btn:hover,
.ref-related-btn:focus-visible {
  border-color: var(--accent);
  color: var(--accent-ink);
  outline: none;
}

.ref-copy-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.ref-summary {
  margin: 1.1rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.ref-summary strong {
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: 600;
}

.field-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}

.field-chip:hover {
  border-color: var(--accent);
}

.field-chip:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-chip.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.field-chip .chip-count {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  opacity: 0.75;
}

@media (max-width: 860px) {
  .ref-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .ref-list {
    max-height: min(42vh, 22rem);
  }

  .ref-detail {
    position: static;
    max-height: none;
  }
}
