:root {
  --bg: #0f0f12;
  --bg-card: #18181c;
  --bg-input: #1e1e24;
  --text: #e8e8ed;
  --text-muted: #8b8b98;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --success: #22c55e;
  --success-glow: rgba(34, 197, 94, 0.35);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.25);
  --new-entry: #eab308;
  --radius: 12px;
  --transition: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

.header {
  padding: 1.5rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.header-inner {
  max-width: 720px;
  margin: 0 auto;
  position: relative;
}

.logo {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.lang-switch {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  gap: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--bg-input);
}

.lang-btn {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

.lang-btn:hover {
  color: var(--text);
}

.lang-btn.active {
  background: var(--accent);
  color: white;
}

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

.form-section {
  margin-bottom: 2rem;
}

.rank-form {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 180px;
}

.rank-form label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.rank-form select {
  padding: 0.6rem 0.85rem;
  font-size: 1rem;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition);
}

.rank-form select:hover,
.rank-form select:focus {
  border-color: var(--accent);
  outline: none;
}

/* Autocomplete for business type */
.autocomplete-wrap {
  position: relative;
  width: 100%;
}

.autocomplete-wrap input {
  padding: 0.6rem 0.85rem;
  font-size: 1rem;
  width: 100%;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  transition: border-color var(--transition);
}

.autocomplete-wrap input:hover,
.autocomplete-wrap input:focus {
  border-color: var(--accent);
  outline: none;
}

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 0.25rem 0 0;
  padding: 0;
  list-style: none;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  max-height: 220px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.autocomplete-list[hidden] {
  display: none;
}

.autocomplete-list li {
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  transition: background var(--transition);
}

.autocomplete-list li:hover,
.autocomplete-list li[aria-selected="true"] {
  background: var(--bg-input);
  color: var(--accent);
}

.autocomplete-list li:not(:last-child) {
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

/* Qualifier choice (rank by) */
.qualifier-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.35rem;
}

.btn {
  padding: 0.6rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), transform 0.15s ease;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
}

/* Ranking section */
.ranking-section {
  margin-top: 2rem;
}

.ranking-header {
  margin-bottom: 1rem;
}

.ranking-title {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
  font-weight: 700;
}

.ranking-subtitle {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.ranking-progress-wrap {
  margin-bottom: 0.75rem;
}

.ranking-progress-bar {
  height: 8px;
  background: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.ranking-progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.ranking-progress-label {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.ranking-status {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.ranking-board {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
}

.share-result-wrap {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
}

.share-result-label {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.share-result-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.share-result-url {
  flex: 1;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
}

.btn-secondary {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--accent);
}

.ranking-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  z-index: 1;
}

.ranking-row .position {
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--text-muted);
  min-width: 2.5rem;
  text-align: center;
}

.ranking-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.ranking-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.ranking-row .name {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ranking-row .name.clickable {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 2px;
  transition: text-decoration-color var(--transition), color var(--transition);
}

.ranking-row .name.clickable:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.ranking-row .score {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 1rem;
}

.ranking-bar-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--bg-input);
  overflow: hidden;
}

.ranking-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

.ranking-row.flash-top {
  animation: topFlash 1.4s ease-out;
}

@keyframes topFlash {
  0%, 100% {
    box-shadow: 0 0 0 0 transparent;
  }
  15% {
    box-shadow: 0 0 0 3px var(--accent), 0 0 24px rgba(99, 102, 241, 0.5);
  }
  40% {
    box-shadow: 0 0 0 2px var(--accent), 0 0 16px rgba(99, 102, 241, 0.35);
  }
  70% {
    box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.4);
  }
}

/* Per-model breakdown modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 420px;
  padding: 1.5rem;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.modal-title {
  margin: 0 0 1rem;
  font-size: 1.15rem;
  font-weight: 700;
}

.per-model-list {
  margin: 0 0 1.25rem;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
}

.per-model-list li {
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
}

.per-model-list li:last-child {
  border-bottom: none;
}

/* Footer */
.footer {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.footer-text {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.footer-text a {
  color: var(--accent);
  text-decoration: none;
}

.footer-text a:hover {
  text-decoration: underline;
}
