:root {
  --color-brand: #473ae0;
  --color-brand-strong: #18164c;
  --color-brand-subtle: #edebfc;
  --color-text-emphasis: #18164c;
  --color-text-secondary: #6b7280;
  --color-text-subtle: #9ca3af;
  --color-border-default: #ebecef;
  --color-border-strong: #d1d5db;
  --color-bg-subtle: #f9fafb;
  --color-error: #b3261e;
  --color-error-bg: #fdecea;
  --radius-6: 6px;
  --radius-8: 8px;
  --radius-12: 12px;
  --radius-16: 16px;
  --shadow-xsmall: 0 1px 2px rgba(24, 22, 76, 0.05);
  --shadow-small: 0 2px 8px rgba(24, 22, 76, 0.06);
  --shadow-medium: 0 8px 24px rgba(24, 22, 76, 0.12);
  --shadow-large: 0 16px 40px rgba(24, 22, 76, 0.16);
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* {
  box-sizing: border-box;
}

/* Several elements below (.loading-overlay, .unlock-gate) set their own
   `display` value unconditionally for layout - author CSS always overrides
   the browser's default `[hidden] { display: none }` UA rule regardless of
   selector specificity, so without this, toggling the `hidden` attribute in
   JS on those elements has no visual effect. This rule must win. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: 1.5rem;
  background: #fff;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--color-text-emphasis);
}

.wrap {
  max-width: 880px;
  margin: 0 auto;
}

.tool-card {
  background: #fff;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-16);
  box-shadow: var(--shadow-small);
  padding: 24px;
}

.tool-fields {
  display: grid;
  grid-template-columns: 1.4fr 1fr auto;
  gap: 16px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-emphasis);
}

input[type="text"],
input[type="email"] {
  height: 44px;
  padding: 0 12px;
  font-family: inherit;
  font-size: 16px;
  color: var(--color-text-emphasis);
  background: #fff;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-6);
  box-shadow: var(--shadow-xsmall);
  outline: none;
  width: 100%;
}

input[type="text"]:focus,
input[type="email"]:focus {
  border-color: var(--color-brand);
}

input::placeholder {
  color: var(--color-text-subtle);
}

.field-error {
  margin: 0;
  font-size: 12px;
  color: var(--color-error);
}

.custom-select {
  position: relative;
}

button.custom-select-trigger {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-6);
  background: #fff;
  box-shadow: var(--shadow-xsmall);
  color: var(--color-text-emphasis);
  font-family: inherit;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  transition: border-color 120ms var(--ease-out);
}

button.custom-select-trigger:focus,
button.custom-select-trigger[aria-expanded="true"] {
  outline: none;
  border-color: var(--color-brand);
}

.custom-select-value.is-placeholder {
  color: var(--color-text-subtle);
}

.custom-select-arrow {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--color-text-secondary);
}

.custom-select-list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  margin: 0;
  padding: 6px 0;
  list-style: none;
  background: #fff;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-8);
  box-shadow: var(--shadow-medium);
}

.custom-select-option {
  padding: 9px 12px;
  font-size: 14px;
  color: var(--color-text-emphasis);
  cursor: pointer;
}

.custom-select-option:hover,
.custom-select-option.is-active {
  background: var(--color-brand-subtle);
}

.button-primary {
  height: 44px;
  padding: 0 24px;
  background: var(--color-brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-6);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 120ms var(--ease-out);
}

.button-primary:hover:not(:disabled) {
  background: #32299f;
}

.button-primary:active:not(:disabled) {
  background: var(--color-brand-strong);
}

.button-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.button-compact {
  height: 40px;
  flex-shrink: 0;
}

.tool-note {
  margin: 16px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--color-text-subtle);
}

.error-message {
  margin-top: 20px;
  padding: 12px 16px;
  border-radius: var(--radius-8);
  background: var(--color-error-bg);
  color: var(--color-error);
  font-size: 14px;
  text-align: center;
}

.results {
  margin-top: 40px;
}

.results-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 16px;
}

.results-head h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.3;
  font-weight: 600;
}

.results-meta {
  font-size: 12px;
  color: var(--color-text-subtle);
  white-space: nowrap;
}

.table-card {
  position: relative;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-12);
  overflow: hidden;
  background: #fff;
}

.table-row {
  display: grid;
  grid-template-columns: 2.2fr 1fr 1.15fr 1.3fr;
  align-items: center;
}

.table-head {
  background: var(--color-bg-subtle);
  border-bottom: 1px solid var(--color-border-default);
}

.col {
  padding: 12px 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.col-metric,
.col-shared {
  justify-content: flex-end;
  white-space: nowrap;
}

.col-shared {
  justify-content: flex-start;
}

.tip-trigger {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 1px solid var(--color-border-strong);
  background: #fff;
  color: var(--color-text-secondary);
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: border-color 120ms var(--ease-out), color 120ms var(--ease-out), background-color 120ms var(--ease-out);
}

.tip-trigger:hover {
  border-color: var(--color-brand);
  color: var(--color-brand);
  background: var(--color-brand-subtle);
}

.tooltip {
  position: absolute;
  top: 40px;
  right: 12px;
  z-index: 20;
  width: 280px;
  background: #fff;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-8);
  box-shadow: var(--shadow-medium);
  padding: 12px;
}

.tooltip-title {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-emphasis);
  margin-bottom: 4px;
}

.tooltip-body {
  display: block;
  font-size: 12px;
  line-height: 1.4;
  color: var(--color-text-secondary);
}

.row {
  display: grid;
  grid-template-columns: 2.2fr 1fr 1.15fr 1.3fr;
  align-items: center;
  border-bottom: 1px solid var(--color-border-default);
}

.row-rank {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.row-rank .badge {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-6);
  background: var(--color-brand-subtle);
  color: var(--color-brand-strong);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.locked-rows .row-rank .badge {
  background: var(--color-bg-subtle);
  color: var(--color-text-secondary);
}

.row-name {
  min-width: 0;
}

.row-name .label {
  display: block;
  font-size: 16px;
  font-weight: 500;
}

.row-name .domain {
  display: block;
  font-size: 12px;
  color: var(--color-text-subtle);
}

.row-traffic,
.row-keywords {
  padding: 16px 20px;
  text-align: right;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.row-keywords {
  color: var(--color-text-secondary);
}

.row-shared {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.row-shared .bar-track {
  flex: none;
  width: 64px;
  height: 6px;
  border-radius: 999px;
  background: var(--color-bg-subtle);
  overflow: hidden;
}

.row-shared .bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--color-brand);
}

.row-shared .value {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.locked-wrap {
  position: relative;
}

.locked-rows {
  filter: blur(5px);
  user-select: none;
  pointer-events: none;
  transition: filter 280ms var(--ease-out);
}

.locked-rows.is-unlocked {
  filter: none;
}

.unlock-gate {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0.94) 55%);
}

.unlock-card {
  background: #fff;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-16);
  box-shadow: var(--shadow-large);
  padding: 24px;
  max-width: 480px;
  width: 100%;
}

.unlock-copy h3 {
  margin: 0 0 4px;
  font-size: 18px;
  line-height: 1.4;
  font-weight: 600;
}

.unlock-copy p {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--color-text-secondary);
}

.unlock-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.unlock-form input[type="email"] {
  flex: 1;
  min-width: 180px;
  height: 40px;
  font-size: 14px;
}

.unlock-legal {
  margin: 8px 0 0 !important;
  font-size: 10px !important;
  line-height: 1.4 !important;
  color: var(--color-text-subtle) !important;
}

.unlock-legal a {
  color: var(--color-brand);
  text-decoration: underline;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2.5px solid var(--color-brand-subtle);
  border-top-color: var(--color-brand);
  animation: spin 700ms linear infinite;
}

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

#loading-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
}

@media (max-width: 640px) {
  .tool-fields {
    grid-template-columns: 1fr;
  }

  .table-row,
  .row {
    grid-template-columns: 1.6fr 1fr;
  }

  .col-shared,
  .row-shared,
  .table-row .col:nth-child(3),
  .row-keywords {
    display: none;
  }
}
